Is there a way to run code from @code_native

I want to @code_native a function, make some edits to the assembly and then run it.

For example a function I want to edit is

using SIMD

f(x, y) = any(x > y)

x = Vec{8, Float32}(1)
y = Vec{8, Float32}(0)

I would like some way to copy @code_native debuginfo=:none f(x, y) and then run it.

You can llvmcall and use assembly, but you’d need to edit it.
Alternatively, if it’s big enough that those modifications are unwieldy, you could compile into a shared library with gcc and ccall it.

Here is an example: VectorizationBase.jl/intrin_funcs.jl at 2842337a85aefc5e3352e1b6272589f4e53c58ee · JuliaSIMD/VectorizationBase.jl · GitHub
See here for more details: LLVM Language Reference Manual — LLVM 17.0.0git documentation

2 Likes