{"id":15101419,"url":"https://github.com/hydrogen602/math-go-brr","last_synced_at":"2026-01-07T11:16:54.309Z","repository":{"id":243187942,"uuid":"811723162","full_name":"hydrogen602/math-go-brr","owner":"hydrogen602","description":"Python and LLVM experiments","archived":false,"fork":false,"pushed_at":"2024-09-30T16:39:46.000Z","size":164,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T18:15:22.238Z","etag":null,"topics":["compiler","jit","llvm","python"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hydrogen602.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-06-07T07:08:15.000Z","updated_at":"2024-10-12T18:18:06.000Z","dependencies_parsed_at":"2024-07-16T07:15:36.159Z","dependency_job_id":null,"html_url":"https://github.com/hydrogen602/math-go-brr","commit_stats":null,"previous_names":["hydrogen602/math-go-brr"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hydrogen602%2Fmath-go-brr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hydrogen602%2Fmath-go-brr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hydrogen602%2Fmath-go-brr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hydrogen602%2Fmath-go-brr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hydrogen602","download_url":"https://codeload.github.com/hydrogen602/math-go-brr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245858879,"owners_count":20684057,"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","llvm","python"],"created_at":"2024-09-25T18:22:24.627Z","updated_at":"2026-01-07T11:16:54.269Z","avatar_url":"https://github.com/hydrogen602.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JIT Python function to LLVM IR for fast numeric operations POC\n\nThis is a simple POC to show the concept of taking a python, analyzing its AST, and generating LLVM IR code that does what the python code does, and then making a callable with LLVM's JIT feature all at runtime, using only a decorator.\n\nThe idea is that when a function is just basic math, there's no real need to deal with the overhead of python and its objects, and so instead we can translate it to basic LLVM IR `add` and `mul` instructions that have almost no overhead.\n\nNow Cyton and maturin/PyO3 already do this, but the idea is to not require any compilation step or make the user interact with anything that isn't python, so that it is near seamless to the user (well there is always the restriction that llvm is statically typed, plus any such function can only contain integer / float operations).\n\n---\n\n```python\n@brrr\ndef bar(a, b):\n    return a + b\n```\n\nHere, `brrr` takes `bar`, gets and parses its source, and then generates an llvm function that does the `add` instructions on two i64s, and then creates a python-callable to replace `bar` that calls the llvm JIT engine.\n\n---\n\n```python\n@brrr\ndef foo(a: int) -\u003e int:\n    b = 0\n    i = 0\n    while i \u003c a:\n        b = b + i\n        i = i + 1\n\n    return b\n\n\nstart = time()\nllvm_out = foo(10_000_000)\nprint(f\"LLVM JIT Compiled |\", time() - start)\n\n# foo.original_func is our plain-old Python function\nstart = time()\npython_out = foo.original_func(10_000_000)\nprint(f\"Regular Python    |\", time() - start)\n```\nOutputs: (On an M1Pro MacBookPro)\n```\nLLVM JIT Compiled | 0.026 sec\nRegular Python    | 0.383 sec\n```\n\n---\n\n# Direction\n\nPriority:\n- [ ] All basic math operations for integers (as i64)\n  - [x] `+`, `-`, `*`\n  - [ ] Division ops: `/`, `//`, `%`\n  - [ ] Power \u0026 bitwise: `**`, `\u003c\u003c`, `\u003e\u003e`, `\u0026`, `|`, `^`, `~`\n  - [ ] Augmented assignment for all: e.g. `+=`, `-=`, `*=`, etc.\n- [ ] All basic math operations for floats (as f64)\n- [x] Basic control flow that doesn't rely on python objects (if, while)\n- [x] Booleans, logic operations, and comparisons\n- [ ] Interop with numpy arrays, numpy C-API\n\nSecondary:\n- [ ] Recursion support\n- [ ] Nice error messages\n\nTertiary:\n- [ ] JIT Functions calling other JIT functions\n- [ ] closures: capturing of numeric variables\n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhydrogen602%2Fmath-go-brr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhydrogen602%2Fmath-go-brr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhydrogen602%2Fmath-go-brr/lists"}