{"id":13418034,"url":"https://github.com/BitFunnel/NativeJIT","last_synced_at":"2025-03-15T02:32:26.576Z","repository":{"id":44097995,"uuid":"55872490","full_name":"BitFunnel/NativeJIT","owner":"BitFunnel","description":"A C++ expression -\u003e x64 JIT","archived":false,"fork":false,"pushed_at":"2020-08-21T07:00:42.000Z","size":3788,"stargazers_count":1138,"open_issues_count":34,"forks_count":84,"subscribers_count":61,"default_branch":"master","last_synced_at":"2024-10-16T00:22:45.082Z","etag":null,"topics":["compiler","jit"],"latest_commit_sha":null,"homepage":"http://bitfunnel.org/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BitFunnel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-09T23:53:19.000Z","updated_at":"2024-09-28T17:56:05.000Z","dependencies_parsed_at":"2022-08-23T11:10:58.399Z","dependency_job_id":null,"html_url":"https://github.com/BitFunnel/NativeJIT","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitFunnel%2FNativeJIT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitFunnel%2FNativeJIT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitFunnel%2FNativeJIT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitFunnel%2FNativeJIT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BitFunnel","download_url":"https://codeload.github.com/BitFunnel/NativeJIT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221532188,"owners_count":16838913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","jit"],"created_at":"2024-07-30T22:00:57.581Z","updated_at":"2025-03-15T02:32:26.568Z","avatar_url":"https://github.com/BitFunnel.png","language":"C++","readme":"[![Build status](https://ci.appveyor.com/api/projects/status/o957b44rhm8vt24g/branch/master?svg=true)](https://ci.appveyor.com/project/MichaelHopcroft/nativejit)\n[![Build status](https://doozer.io/badge/mikehopcroft/NativeJIT/buildstatus/master)](https://doozer.io/user/mikehopcroft/NativeJIT/builds)\n\nNativeJIT\n====\n\nNativeJIT is an open-source cross-platform library for high-performance\njust-in-time compilation of expressions involving C data structures.\nThe compiler is light weight and fast\nand it takes no dependencies beyond the standard C++ runtime.\nIt runs on Linux, OSX, and Windows.\nThe generated code is optimized with particular attention paid\nto register allocation.\n\nThe compiler was developed by the [Bing](http://www.bing.com/) team for use in the Bing search engine.\nOne important use is scoring documents containing keywords that match a user's query.\nThe scoring process attempts to gauge how well each document matches the user's intent,\nand as such, depends on the specifics of how each query was phrased.\nBing formulates a custom expression for each query\nand then uses NativeJIT to compile the expression into x64 code that will\nbe run on a large set of candidate documents spread across a cluster of\nmachines.\n\nWe knew from the get go that throughput and latency\nwould be essential when processing queries at scale,\nso we put a lot of effort in to making NativeJIT run fast.\n\nOur design point was scenarios where\n\n* The expression isn't known until runtime.\n* The expression will be evaluated enough times to amortize the cost of compilation.\n* Latency and throughput demands require low cost for compilation.\n\n\nHere's trivial \"Hello, world\" level example that computes the area of a circle:\n\n```cpp\n#include \"NativeJIT/CodeGen/ExecutionBuffer.h\"\n#include \"NativeJIT/CodeGen/FunctionBuffer.h\"\n#include \"NativeJIT/Function.h\"\n#include \"Temporary/Allocator.h\"\n\n#include \u003ciostream\u003e\n\nusing NativeJIT::Allocator;\nusing NativeJIT::ExecutionBuffer;\nusing NativeJIT::Function;\nusing NativeJIT::FunctionBuffer;\n\nint main()\n{\n    // Create allocator and buffers for pre-compiled and post-compiled code.\n    ExecutionBuffer codeAllocator(8192);\n    Allocator allocator(8192);\n    FunctionBuffer code(codeAllocator, 8192);\n\n    // Create the factory for expression nodes.\n    // Our area expression will take a single float parameter and return a float.\n    Function\u003cfloat, float\u003e expression(allocator, code);\n\n    // Multiply input parameter by itself to get radius squared.\n    auto \u0026 rsquared = expression.Mul(expression.GetP1(), expression.GetP1());\n\n    // Multiply by PI.\n    const float  PI = 3.14159265358979f;\n    auto \u0026 area = expression.Mul(rsquared, expression.Immediate(PI));\n\n    // Compile expression into a function.\n    auto function = expression.Compile(area);\n\n    // Now run our expression!\n    float radius = 2.0;\n    std::cout \u003c\u003c \"The area of a circle with radius \" \u003c\u003c radius\n              \u003c\u003c \" is \" \u003c\u003c function(radius);\n\n    return 0;\n}\n```\n\nHere is the generated assembly code on Windows:\n\n```asm\nPI_CONSTANT:\n   db 0f 49 40                              ; PI constant is stored in memory.\nENTRY_POINT:\n  sub         rsp,8                         ; Standard function prologue.\n  mov         qword ptr [rsp],rbp           ; Standard function prologue.\n  lea         rbp,[rsp+8]                   ; Standard function prologue.\n  mulss       xmm0,xmm0                     ; Multiply by radius parameter by itself.\n  mulss       xmm0,dword ptr [29E2A580000h] ; Multiply by PI.\n  mov         rbp,qword ptr [rsp]           ; Standard function epilogue.\n  add         rsp,8                         ; Standard function epilogue.\n```\n\n\nThis example shows an expression that multiplies a number by itself.\nWe also support a wide variety of arithmetic and logical operations, pointer and array operations, conditionals, accessing structure fields, and calling out to C functions.\n[See our preliminary API docs for more information](http://bitfunnel.org/getting-started-with-nativejit/) and the `Examples/` directory for more examples.\n\n\nDependencies\n------------\n\nIn order to build NativeJIT you will need CMake (2.8.11+), and a modern C++\ncompiler (gcc 5+, clang 3.4+, or VC 2015+). You can run CMake directly to generate the appropriate build setup for your platform. Alternately, we have some scripts that have the defaults that we use available.\n\n### *nix\n\nFor *nix platforms (including OS X),\n\n```sh\n./Configure_Make.sh\ncd build-make\nmake\nmake test\n```\n\n#### Ubuntu\n\nIf you're on Ubuntu 15+, you can install dependencies with:\n\n```sh\nsudo apt-get install clang cmake\n```\n\nOn Ubuntu 14 and below, you'll need to install a newer version of CMake. To\ninstall a new-enough CMake, see [this link](http://askubuntu.com/questions/610291/how-to-install-cmake-3-2-on-ubuntu-14-04).\nIf you're using gcc, you'll also need to make sure you have gcc-5 (`sudo apt-get install g++-5`).\n\nTo override the default compiler, set the `CXX` and `CC` environment variables.\nFor example, if you have clang-3.8 installed as `clang-3.8` and are using bash:\n\n```sh\nexport CXX=\"clang++-3.8\"\nexport CC=\"clang-3.8\"\n```\n\n#### OS X\n\nInstall XCode and then run the following command to install required packages\nusing Homebrew ([http://brew.sh/](http://brew.sh/)):\n\n```sh\nbrew install cmake\n```\n\nNativeJIT can be built on OS X using either standard \\*nix makefiles or XCode.\nIn order to generate and build makefiles, in the root `NativeJIT` directory run:\n\nIf you want to create an Xcode project instead of using Makefiles, run:\n\n```sh\n./Configure_XCode.sh\n```\n\n### Windows\n\nInstall the following tools:\n\n- Visual Studio 2015 with C++ compiler\n- CMake ([http://www.cmake.org/download/](http://www.cmake.org/download/))\n\nYou can get [the free version of Visual Studio here](https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx).\nNote that if you're installing Visual Studio for the first time and select the\ndefault install options, you won't get a C++ compiler. To force the install of\nthe C++ compiler, you need to either create a new C++ project or open an\nexisting C++ project.\n\nIn order to configure solution for Visual Studio 2015 run the following\ncommands from the root `NativeJIT` directory:\n\n```sh\n.\\Configure_MSVC.bat\n```\n\nFrom now on you can use the generated solution `build-msvc\\NativeJIT.sln` from Visual Studio\nor build from command line using `cmake`.\n","funding_links":[],"categories":["TODO scan for Android support in followings","C++","Scripting"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBitFunnel%2FNativeJIT","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBitFunnel%2FNativeJIT","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBitFunnel%2FNativeJIT/lists"}