This is mind blowing
Thanks to @kit-ty-kate
In rocky linux 9,
Install LLVM with sudo dnf install llvm llvm-devel. Install opam and dune to get the latest version (5.1) of OCaml.
For a dune file
(executable
(name llvmjit)
(libraries
llvm
llvm.executionengine
ctypes.foreign))
module L = Llvm
let context = L.global_context ()
let the_module = L.create_module context "my module"
let builder = L.builder context
let double_type = L.double_type context
let top_func_type = L.function_type double_type [||]
let the_function = L.declare_function "add_double" top_func_type the_module
let bb = L.append_block context "entry" the_function
let () = L.position_at_end bb builder
let n = L.const_float double_type 1.0
let m = L.const_float double_type 2.0
let ret_val = L.build_add n m "addtmp" builder
let () = ignore @@ L.build_ret ret_val builder
let () = L.dump_value the_function
This will net you
define double @add_double() {
entry:
ret double add (double 1.000000e+00, double 2.000000e+00)
ret double add (double 1.000000e+00, double 2.000000e+00)
}
aspnet benchmark hacks are very well known, they cheat in a lot of places. Even Go benchmarks are cheating.
I really wish someone roast Java, but it seems Java is the most cleanest one.