Using BMI (pext_u64 and pdep_u64) in Mojo
How can I use pext and pdep in my Mojo project?
I need that Bit Manipulation Instructions to be efficient with some fancy lookups. Is there a way to use those instructions on x86 currently?
Those instructions are supported by every CPU with BMI2. I can use them in Rust simply importing them "use std::arch::x86_64::{_pdep_u64, _pext_u64};"
I can use them in Julia simply invoking them from C.
If anyone knows, please tell me. And if it's not possible, can I commit to Mojo development and make BMI2 instructions available? I would really like to have it in Mojo 😉
4 Replies
The LLVM intrinsic names are:
Use them with https://docs.modular.com/mojo/stdlib/sys/intrinsics/llvm_intrinsic
llvm_intrinsic | Modular
llvmintrinsicintrin AnyTrivialRegType, *types Bool = True -> type
Yes, that's exactly what I need
If you want to put them into the stdlib, they probably belong in the
bit
module, and PRs are welcome (https://github.com/modularml/mojo)GitHub
GitHub - modularml/mojo: The Mojo Programming Language
The Mojo Programming Language. Contribute to modularml/mojo development by creating an account on GitHub.
I didn't see this page, thanks
It works, nice, for anyone having same question, here's example:
from sys import llvm_intrinsic
def main():
alias intrin: StringLiteral = "llvm.x86.bmi.pext.64"
var x = llvm_intrinsicintrin, UInt64, UInt64(12309))
print(x) # 22