{"id":22940769,"url":"https://github.com/inductivecomputerscience/i-slash-x86","last_synced_at":"2025-08-12T21:31:25.584Z","repository":{"id":184480715,"uuid":"671936758","full_name":"InductiveComputerScience/i-slash-x86","owner":"InductiveComputerScience","description":"A programming language that gives direct control of x86 processors","archived":false,"fork":false,"pushed_at":"2025-08-08T14:43:48.000Z","size":134,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-08T16:31:00.035Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/InductiveComputerScience.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2023-07-28T13:42:59.000Z","updated_at":"2025-08-08T14:43:52.000Z","dependencies_parsed_at":"2023-07-28T16:32:50.247Z","dependency_job_id":"fbf2e2d5-6bdb-4d94-bdc5-940ce3fe61d4","html_url":"https://github.com/InductiveComputerScience/i-slash-x86","commit_stats":null,"previous_names":["inductivecomputerscience/i-slash-x86"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/InductiveComputerScience/i-slash-x86","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InductiveComputerScience%2Fi-slash-x86","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InductiveComputerScience%2Fi-slash-x86/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InductiveComputerScience%2Fi-slash-x86/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InductiveComputerScience%2Fi-slash-x86/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InductiveComputerScience","download_url":"https://codeload.github.com/InductiveComputerScience/i-slash-x86/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InductiveComputerScience%2Fi-slash-x86/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270140289,"owners_count":24534372,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-12-14T13:30:57.689Z","updated_at":"2025-08-12T21:31:25.564Z","avatar_url":"https://github.com/InductiveComputerScience.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# I/x86\n\nA programming language that gives direct control of x86 processors. It is translated directly into x86 assembly, line by line. It will always have native access to all features of x86-64 processors, including its newest extensions.\n\nThe idea behind the programming language is that all programming is assembly programming, and this language helps the programmer program assembly. Once the programmer is happy with the instructions used, the generated assembly code is easy to recognize, and can be hand-tuned to unlock the final percentages of performance.\n\nThe language is set up such that it is as simple as possible and is easy to use. The compiler is not complicated, only about 1500 lines of code that anyone can understand.\n\nBenefits of the language includes:\n\n * Simple language, simple compiler.\n * Access to all features of the x86 processor.\n * Use all features of the x86 processor to speed up your programs.\n * All behavior is defined and specified (No undefined or unspecified behavior.)\n * What you see is what you get. (No as-if rule.)\n * All the code is executed. (No surprising code removal.)\n * It is easy to further optimize the resulting assembly as the code will be a direct translation. It is easy to recognize all the code.\n\n## The Language\n\n[More about the language here.](language.md)\n\n## Uses\n\n * You want a program that always does what you asked it to do. This is good for stability, robustness and security.\n * You want to create an optimized versions of functions.\n\n### Operations\n\nUse the operations in the x86 CPU directly like this:\n\n```\nAdd x, a, b\nSub x, a, b\nMul x, a, b\nDiv x, a, b\n```\n\nFor example, the Div instruction is translated like this:\n\n```\nmov rax, qword [a]\nmov rdx, 0\ndiv qword [b]\nmov qword [x], rax\n```\n\n### Expressions\n\nOr write inline expressions. Here `a / b + c * d` is the expression, `exp` marks the beginning of an expression, `a` marks the expression as an arithmetic expression and finally, `u64` says that the type of the expression is unsigned 64-bit.\n\n```\nexp a u64: x = a / b + c * d\n```\n\nHere, the type is 64-bit float, or double precision.\n\n```\nexp a f64: h1 = (x2 - x)/(x2 - x1)*q11 + (x - x1)/(x2 - x1)*q12\n```\n\nThere are also bitwise expressions\n\n```\nexp bw b32: total = d2 | d1 \u003c\u003c 8 | d0 \u003c\u003c 16\n```\n\nAnd boolean-relational expressions\n\n```\nexp b: i \u003c len \u0026 !found\n```\n\nIn the future, there will be more kinds of expressions. You can easily extend the compiler with your own expression types.\n\nThe three expression types listed here are based on the open-source formula translators:\n\n * [Arithmetic Formula Translation](https://repo.progsbase.com/repoviewer/no.inductive.libraries/FormulaTranslation/0.1.6///ArithmeticFormulaToTFormFunctions/)\n * [Bitwise Formula Translation](https://repo.progsbase.com/repoviewer/no.inductive.libraries/FormulaTranslation/0.1.6///BitwiseFormulaToTFormFunctions/)\n * [Boolean-Relational Formula Translation](https://repo.progsbase.com/repoviewer/no.inductive.libraries/FormulaTranslation/0.1.6///BooleanFormulaToTFormFunctions/)\n\n### Functions\n\nMake a function `f` as follows:\n\n```\nFnc f\n  ...\nRet\n```\n\nThe input, output and local variables are set up in a structure with the same name as the function followed by `S`.\n\n```\nBgs fS\n  u64 x\n  u64 a\n  u64 b\nEns\n```\n\n### Calling Functions\n\nCall functions by passing it an instance of its structure. You set the input before calling the function and read the output after calling the function.\n\n```\nCall f, i\n```\n\nA header is generated for C/C++ for easily calling the functions:\n\n```\n#include \"code.h\"\n\n...\n\nstruct fS s;\ns.a = 5;\ns.b = 5;\nf(\u0026s);\n// s.x contains the return value.\n```\n\n\n## How the Compiler Works\n\n### Overview\n\n1. The compiler traverses the code to convert all expressions to a series of instructions.\n2. The compiler traverses the code to identify the type of each instruction. The type includes:\n a) Whether the parameters are variables or literals.\n b) The type of the operands.\n3. A C-header is generated.\n3. NASM processes the macros and assembles the code.\n\n### Details\n\n1. The compiler will translate the expression into a series of CPU operations (by traversing the expression left-first):\n\n```\n; exp a u64: x = a / b + c * d\nDiv t0, a, b\nMul t1, c, d\nAdd x, t0, t1\n```\n\n2. Then identify the types. Here \"mm\" means both parameters are memory, u64 means unsigned 64-bit integer division.\n\n```\nDiv.mmu64 t0, a, b\n...\n```\n\nThen convert each of these to a series of CPU-instructions with explicit handling of CPU registers. This one performs 64-bit unsigned integer division of two variables.\n\n```\nmov rax, qword [rdi + a]\nmov rdx, 0\nmov rcx, qword [rdi + b]\ndiv rcx\nmov qword [rdi + t0], rax\n...\n```\n\nThis can then be passed to an assembler, NASM, to complete the compilation.\n\n\n## Examples\n\n### Finding the index of a character in a string\n```\nFnc IndexOfCharacter\n  Mov found, false\n  Mov i, 0\n  Loop\n    Len len, string\n  If exp b: i \u003c len \u0026 !found\n    Idr c, string, i\n    If exp b: c = character\n      Mov found, true\n      Acw indexReference, numberValue, i\n    Endb\n    Inc i\n  EndLoop\n  Mov retval, found\nRet\n```\n\nThe input, output and local variables are given in a separate structure.\n\n```\nBgs NumberReference\n  u64 numberValue\nEns\n\nBgs IndexOfCharacterS\n  u32a string\n  u32 character\n  u32 c\n  str NumberReference indexReference\n  u8 retval\n  u64 i\n  b1 found\n  u64 len\n  b1 tb10\n  b1 tb11\n  b1 tb12\nEns\n```\n\nA header for C is also generated, so that you can call the functions from C or C++.\n\n\n\n### Getting Random Numbers Using Rdrand\n\n```\nBgs RdrandGuaranteedS\n  u64 n\n  b1 c\n  b1 tb10\nEns\n\nFnc RdrandGuaranteed\n  Mov c, 0\n  Loop\n  If exp b: c = 0\n    Rdrand n, c\n  EndLoop\nRet\n```\n\n### Converting a String to Upper Case Using SIMD\n\n```\nBgs ToUpperILS\n  u8x32a str\n  u64 len\n  u64 len32\n  u64 len1\n  u64 i\n  b1 tb10\n  u8x32 a\n  u8x32 z\n  u8x32 x32\n  u8x32 x\n  u8x32 lcm\n  b8x32 tb8x320\n  b8x32 tb8x321\n  b8x32 tb8x322\n  u8x32 padding\nEns\n\nFnc ToUpperIL\n  Len len, str\n  Div len32, len, 32\n\n  Mov a, 'a'\n  Mov z, 'z'\n  Mov x32, 32\n\n  Mov i, 0\n  Loop\n  If exp b: i \u003c len32\n    Idr x, str, i\n\n    exp b b8x32: lcm = (x \u003e= a \u0026 x \u003c= z) \u0026 x32\n    exp a u8x32: x = x - lcm\n\n    Idw str, i, x\n\n    Inc i\n  EndLoop\nRet\n```\n## Building the Compiler/Translator\nTo build the translator you need Java 8 or higher. Simply run the following command to compile, or use your favourite IDE.\n\n```\nmkdir build\ncd Translator\njavac exec/Run.java -cp exec:Translator/main:imports -d ../build\n```\n\nTo then make an executable jar-file, run the following:\n\n```\ncd ../build\njar cfe ../Translator.jar Run *\n```\n\n## Running the Translator/Compiler\n\nRunning the translator/compiler using class files:\n\n```\njava -classpath build Run\n```\n\nOr run it using the jar file:\n\n```\njava -jar Translator.jar\n```\n\nIt takes four arguments\n1) The input file with I/x86-code. e.g. `ioc.idx`\n2) The output file where expressions have been expanded. e.g. `ioc.idx.1`\n3) The assembly output file for NASM. e.g. `ioc.asm`\n4) The C header for calling the functions from C. e.g. `ioc.h`\n\n```\njava -jar Translator.jar ioc.idx ioc.idx.1 ioc.asm ioc.h\n```\n\n## Build and Run the Examples\nTo build and run the examples, you need Java 8, GCC and NASM. First, make sure to build the compiler/translator as described above.\n\n```\ncd examples\nbash make.sh\nbash make-toupper.sh\n```\n\nThis should give output similar to this:\n\n```\nFound: 1, Index: 4\nToUpper (plain C -O3 AVX2): 39599 us\nToUpperBL (C branchless v1 -O3 AVX2): 3018 us\nToUpperBL2 (C branchless v2 -O3 AVX2): 2207 us\nToUpper (I/x86 using AVX2): 3447 us\n```\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finductivecomputerscience%2Fi-slash-x86","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finductivecomputerscience%2Fi-slash-x86","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finductivecomputerscience%2Fi-slash-x86/lists"}