Hacker News new | ask | show | jobs
by anonymouz 2954 days ago
The overhead that is being talked about in the blog post is mostly the impossibility to inline/optimize the C code of the callee, setting up the stack frame, etc.

How would OCaml avoid that?

1 comments

It does a reasonable job:

    external my_sqrt : float -> float = "caml_sqrt_float"
       "sqrt" [@@unboxed] [@@noalloc]

    let () =
      let x= my_sqrt 1.0 in
      Printf.printf "x = %f" x
becomes something like:

    ...
    camlInline__entry:
            .cfi_startproc
            subq    $8, %rsp
            .cfi_adjust_cfa_offset 8
    .L102:
            movsd   .L103(%rip), %xmm0
            sqrtsd  %xmm0, %xmm0
            movsd   %xmm0, (%rsp)
            movq    camlInline__6@GOTPCREL(%rip), %rbx
            movq    camlPervasives@GOTPCREL(%rip), %rax
            movq    208(%rax), %rax
            call    camlPrintf__fprintf_1291@PLT
    ....