{"id":17948649,"url":"https://github.com/htfy96/jit_blocks","last_synced_at":"2025-04-03T15:26:51.179Z","repository":{"id":259563633,"uuid":"875436778","full_name":"htfy96/jit_blocks","owner":"htfy96","description":"Common building blocks for JIT code, based on libgccjit","archived":false,"fork":false,"pushed_at":"2024-10-25T00:35:50.000Z","size":387,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-09T04:17:15.364Z","etag":null,"topics":["c","gccjit","jit","performance"],"latest_commit_sha":null,"homepage":"https://intmainreturn0.com/jit_blocks/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/htfy96.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-20T01:11:36.000Z","updated_at":"2024-10-25T00:38:30.000Z","dependencies_parsed_at":"2024-10-26T14:54:18.434Z","dependency_job_id":"940a8f95-41a4-449a-83d9-9371f7fc67f0","html_url":"https://github.com/htfy96/jit_blocks","commit_stats":null,"previous_names":["htfy96/jit_blocks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Fjit_blocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Fjit_blocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Fjit_blocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/htfy96%2Fjit_blocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/htfy96","download_url":"https://codeload.github.com/htfy96/jit_blocks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247026336,"owners_count":20871363,"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":["c","gccjit","jit","performance"],"created_at":"2024-10-29T09:08:04.579Z","updated_at":"2025-04-03T15:26:51.151Z","avatar_url":"https://github.com/htfy96.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jit_blocks\n\nJitBlocks is a C library built on the top of `libgccjit` that provides common building blocks for JIT-powered code.\n\nThis overview page is best viewed from [the rendered Doxygen page](https://htfy96.github.io/jit_blocks/).\n\n# API Overview\n\nAt a high level, there are two types of API interfaces:\n\n- **Easy** APIs. These APIs create a new compilation context using `::jit_blocks_get_easy_context_builder`, builds a function in it, frees the compilation context, and return the `gcc_jit_result` and function pointer to end users. It's user's responsibility to call `gcc_jit_result_release` on the returned `gcc_jit_result`. Users could replace the default context builder with `::jit_blocks_set_easy_context_builder`. Example:\n\n```c\n  gcc_jit_result* result = NULL;\n  jit_blocks_divide_by_k_int_t divide_by_42 =\n      jit_blocks_build_divide_by_k_int(42, \u0026result);\n  assert(divide_by_42 != NULL);\n  assert(divide_by_42(100) == 2);\n  gcc_jit_result_release(result);\n```\n\n- Low-level APIs. These APIs are suffixed with `_aux` and accept an additional `gcc_jit_context* custom_ctx` parameter. It **does not free the passed-in custom_ctx**. Users should free both `custom_ctx` and `result` at the end of call, as `custom_ctx`'s state is unspecified after call and should not be reused. Example:\n\n```c\n  gcc_jit_result* result = NULL;\n  gcc_jit_context* ctx = gcc_jit_context_acquire();\n  // set arbitrary option for this ctx\n  jit_blocks_divide_by_k_int_t divide_by_42 =\n      jit_blocks_build_divide_by_k_int_aux(42, ctx, \u0026result);\n  assert(divide_by_42 != NULL);\n  assert(divide_by_42(100) == 2);\n  gcc_jit_result_release(result);\n  gcc_jit_context_release(ctx);\n```\n\n## Easy context builder API\n\nSee @ref context_builder\n\n## divide-by API builder\n\nBuilds `divide_by_constant` functions. These division functions are often faster than writing `runtime_var / runtime_var` expressions, as compiler could utilize the known divisor and convert the division into multiplications. Provides similar speedup to [libdivide](https://libdivide.com/).\n\nSee @ref divide.\n\n## Function Calls builder\n\nBuilds a function that calls all specified function pointers in order. Compared to calling function vectors at runtime, it's more branch-predictor-friendly and allows more speculative execution.\n\nSee @ref funccalls\n\n## Expression Engine\n\nBuilds a stack-based arithmetic expression interpreter.\n\nSee @ref expr\n\n## Dynamic Switch builder\n\nBuilds a dynamic `switch (val) { case A: ... }` block. Useful when the dispatch table is only known at runtime.\n\nSee @ref dynswitch\n\n# Using this library\n\nFor CMake users, the recommended way is to add this project either as a git submodule, or download via [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) or [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake), and then add these lines to your CMakeLists.txt:\n\n```cmake\nadd_subdirectory(\"jit_blocks_dir\")\ntarget_link_libraries(YOUR_LIB PRIVATE jit_blocks::jit_blocks)\n```\n\nIt should automatically take care of all include directories and linking flags.\n\nAlternatively, you can also write Shell scripts following [BUILDING](./BUILDING.md) instructions, install them into a local directory, and then manually include the generated headers and built library.\n\n# Building and installing\n\nSee the [BUILDING](./BUILDING.md) document.\n\n# Contributing\n\nSee the [CONTRIBUTING](./CONTRIBUTING.md) document.\n\n# Licensing\n\nApache v2\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhtfy96%2Fjit_blocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhtfy96%2Fjit_blocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhtfy96%2Fjit_blocks/lists"}