Skip to content

Commit

Permalink
[mojo-lang] Teach comptime interpreter about LLVM intrinsics.
Browse files Browse the repository at this point in the history
This teaches the mojo comptime interpreter about LLVM intrinsics,
at least for simple cases involving integer operands and results
(it would be straightforward to extend this to other types now).

This fixes #933 and
Fixes MOCO-138 and Fixes MOCO-504

MODULAR_ORIG_COMMIT_REV_ID: 900128df66da907a0bf61a3b2affb730ef253e17
  • Loading branch information
lattner authored and modularbot committed Sep 16, 2024
1 parent 5abb7ba commit 148d3d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ what we publish.

### ⭐️ New

- Mojo can now interpret simple LLVM intrinsics in parameter expressions,
enabling things like `count_leading_zeros` to work at compile time:
[Issue #933](https://github.com/modularml/mojo/issues/933).

- The VS Code Mojo Debugger now has a `buildArgs` JSON debug configuration
setting that can be used in conjunction with `mojoFile` to define the build
arguments when compiling the Mojo file.
Expand Down
9 changes: 9 additions & 0 deletions stdlib/test/builtin/test_uint.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from testing import assert_equal, assert_false, assert_not_equal, assert_true
from sys import bitwidthof
from bit import count_trailing_zeros


def test_simple_uint():
Expand Down Expand Up @@ -237,6 +238,13 @@ def test_pos():
assert_equal(UInt(0).__pos__(), UInt(0))


def test_comptime():
alias a: UInt = 32
# Verify that count_trailing_zeros works at comptime.
alias n = count_trailing_zeros(a)
assert_equal(n, 5)


def main():
test_simple_uint()
test_uint_representation()
Expand All @@ -260,3 +268,4 @@ def main():
test_indexer()
test_comparison()
test_pos()
test_comptime()

0 comments on commit 148d3d4

Please sign in to comment.