{"id":16867630,"url":"https://github.com/lioncash/biscuit","last_synced_at":"2025-03-22T07:30:50.580Z","repository":{"id":144763613,"uuid":"378542307","full_name":"lioncash/biscuit","owner":"lioncash","description":"A runtime code generator for RISC-V","archived":false,"fork":false,"pushed_at":"2025-03-13T06:00:01.000Z","size":858,"stargazers_count":43,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-18T09:05:59.080Z","etag":null,"topics":["assembly","code-generation","cpp","risc-v","riscv"],"latest_commit_sha":null,"homepage":"","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/lioncash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"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":"2021-06-20T02:28:56.000Z","updated_at":"2025-03-13T21:14:35.000Z","dependencies_parsed_at":"2024-01-19T13:48:07.296Z","dependency_job_id":"d989e3dc-4615-4f08-94cb-de31b682c5a1","html_url":"https://github.com/lioncash/biscuit","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lioncash%2Fbiscuit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lioncash%2Fbiscuit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lioncash%2Fbiscuit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lioncash%2Fbiscuit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lioncash","download_url":"https://codeload.github.com/lioncash/biscuit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244924935,"owners_count":20532872,"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":["assembly","code-generation","cpp","risc-v","riscv"],"created_at":"2024-10-13T14:55:06.029Z","updated_at":"2025-03-22T07:30:50.574Z","avatar_url":"https://github.com/lioncash.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Biscuit: RISC-V Runtime Code Generation Library\n\n*RISC it for the biscuit*\n\n## About\n\nAn experimental runtime code generator for RISC-V.\n\nThis allows for runtime code generation of RISC-V instructions. Similar\nto how [Xbyak](https://github.com/herumi/xbyak) allows for runtime code generation of x86 instructions.\n\n\n## Implemented ISA Features\n\nIncludes both 32-bit and 64-bit instructions in the following:\n\n| Feature       | Version |\n|:--------------|:-------:|\n| A             | 2.1     |\n| B             | 1.0     |\n| C             | 2.0     |\n| D             | 2.2     |\n| F             | 2.2     |\n| H             | 1.0     |\n| K             | 1.0.1   |\n| M             | 2.0     |\n| N             | 1.1     |\n| Q             | 2.2     |\n| RV32I         | 2.1     |\n| RV64I         | 2.1     |\n| S             | 1.12    |\n| V             | 1.0     |\n| Ssctr         | 1.0 rc6 |\n| Sstc          | 0.5.4   |\n| XTheadBa      | 1.0     |\n| XTheadCondMov | 1.0     |\n| Zabha         | 1.0     |\n| Zacas         | 1.0     |\n| Zawrs         | 1.01    |\n| Zcb           | 1.0.4   |\n| Zclsd         | 0.10    |\n| Zcmp          | 1.0.4   |\n| Zcmt          | 1.0.4   |\n| Zfa           | 1.0     |\n| Zfbfmin       | 1.0     |\n| Zfh           | 1.0     |\n| Zfhmin        | 1.0     |\n| Zicbom        | 1.0     |\n| Zicbop        | 1.0     |\n| Zicboz        | 1.0     |\n| Zicfilp       | 1.0     |\n| Zicfiss       | 1.0     |\n| Zicond        | 1.0.1   |\n| Zicsr         | 2.0     |\n| Zifencei      | 2.0     |\n| Zihintntl     | 1.0     |\n| Zilsd         | 0.10    |\n| Zvbb          | 1.0     |\n| Zvbc          | 1.0     |\n| Zvfbfmin      | 1.0     |\n| Zvfbfwma      | 1.0     |\n| Zvkn          | 1.0     |\n\nNote that usually only extensions considered ratified will be implemented\nas non-ratified documents are considerably more likely to have\nlarge changes made to them, which makes maintaining instruction\nAPIs a little annoying.\n\n\n## Dependencies\n\nBiscuit requires no external dependencies for its library other than the C++ standard library. \nThe tests, however, use the Catch2 testing library. This is included in tree so there's no need\nto worry about installing it yourself if you wish to run said tests.\n\n\n## Building Biscuit\n\n1. Generate the build files for the project with CMake\n2. Hit the build button in your IDE of choice, or run the relevant console command to build for the CMake generator you've chosen.\n3. Done.\n\n\n## Running Tests\n\n1. Generate the build files for the project with CMake\n2. Build the tests\n3. Run the test executable directly, or enter `ctest` into your terminal.\n\n\n## License\n\nThe library is licensed under the MIT license.\n\nWhile it's not a requirement whatsoever, it'd be pretty neat if you told me that you found the library useful :-)\n\n\n## Example\n\nThe following is an adapted equivalent of the `strlen` implementation within the RISC-V bit manipulation extension specification.\nFor brevity, it has been condensed to only handle little-endian platforms.\n\n```cpp\n// We prepare some contiguous buffer and give the pointer to the beginning\n// of the data and the total size of the buffer in bytes to the assembler.\n\nvoid strlen_example(uint8_t* buffer, size_t buffer_size) {\n    using namespace biscuit;\n\n    constexpr int ptrlog = 3;\n    constexpr int szreg  = 8;\n\n    Assembler as(buffer, buffer_size);\n    Label done;\n    Label loop;\n\n    as.ANDI(a3, a0, szreg - 1); // Offset\n    as.ANDI(a1, a0, 0xFF8);     // Align pointer\n\n    as.LI(a4, szreg);\n    as.SUB(a4, a4, a3);         // XLEN - offset\n    as.SLLI(a3, a3, ptrlog);    // offset * 8\n    as.LD(a2, 0, a1);           // Chunk\n\n    //\n    // Shift the partial/unaligned chunk we loaded to remove the bytes\n    // from before the start of the string, adding NUL bytes at the end.\n    //\n    as.SRL(a2, a2, a3);         // chunk \u003e\u003e (offset * 8)\n    as.ORCB(a2, a2);\n    as.NOT(a2, a2);\n\n    // Non-NUL bytes in the string have been expanded to 0x00, while\n    // NUL bytes have become 0xff. Search for the first set bit\n    // (corresponding to a NUL byte in the original chunk).\n    as.CTZ(a2, a2);\n\n    // The first chunk is special: compare against the number of valid\n    // bytes in this chunk.\n    as.SRLI(a0, a2, 3);\n    as.BGTU(a4, a0, \u0026done);\n    as.ADDI(a3, a1, szreg);\n    as.LI(a4, -1);\n\n    // Our critical loop is 4 instructions and processes data in 4 byte\n    // or 8 byte chunks.\n    as.Bind(\u0026loop);\n\n    as.LD(a2, szreg, a1);\n    as.ADDI(a1, a1, szreg);\n    as.ORCB(a2, a2);\n    as.BEQ(a2, a4, \u0026loop);\n\n    as.NOT(a2, a2);\n    as.CTZ(a2, a2);\n    as.SUB(a1, a1, a3);\n    as.ADD(a0, a0, a1);\n    as.SRLI(a2, a2, 3);\n    as.ADD(a0, a0, a2);\n\n    as.Bind(\u0026done);\n\n    as.RET();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flioncash%2Fbiscuit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flioncash%2Fbiscuit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flioncash%2Fbiscuit/lists"}