x86 Intrinsics

How to use x86 intrinsics in Mojo? Also I see in the documentation (https://docs.modular.com/mojo/stdlib/sys/intrinsics/llvm_intrinsic) on using llvm_intrinscs. Can someone please share some example on how they've used them. I'm trying to use it but getting error:
from sys.intrinsics import llvm_intrinsic

fn main():
var intrin: StringLiteral = "llvm.sqrt.f32"
var type: AnyType
var has_side_effect: Bool = False

llvm_intrinsic[intrin, type, has_side_effect] ()
from sys.intrinsics import llvm_intrinsic

fn main():
var intrin: StringLiteral = "llvm.sqrt.f32"
var type: AnyType
var has_side_effect: Bool = False

llvm_intrinsic[intrin, type, has_side_effect] ()
ERROR:
error: cannot use a dynamic value in call parameter
llvm_intrinsic[intrin, type, has_side_effect] ()
error: cannot use a dynamic value in call parameter
llvm_intrinsic[intrin, type, has_side_effect] ()
llvm_intrinsic | Modular Docs
llvmintrinsicintrin AnyRegType, hasside_effect: Bool = true -> $1
3 Replies
sora
sora7mo ago
The return type should be Float32 or something. You can find many examples of its use in the stdlib.
Michael K
Michael K7mo ago
The error is telling you that you are using runtime var instead of compile time alias or parameter. So you can replace var with alias on your 3 inputs above or just write them into the function call. And as noted above, the return type is there so that the compile knows what type to assign to the return value. Everything must have a known type at compile time. So AnyType will not work.
taalhaataahir01022001
Thanks working now
Want results from more Discord servers?
Add your server