How is Cfloatofint translated?

Trying to figure out what happens when I call “float_of_int” for native compilation to amd64 and arm64. I understand that the Cmm generated is roughly box_float (Cop(Cfloatofint (untag_int myfloat))). What does Cfloatofint get translated to?

Underlying Motivation: Looking at how the fast pass of the Eisel-Lemire float parsing algorithm would look like in OCaml.

On amd64 it is translated into the sequence

sarq        $1, %rax
cvtsi2sdq   %rax, %xmm0

where %rax contains the integer. The resulting double in %xmm0 may be boxed depending on the context.

I don’t have an arm64 machine at hand to try.

Cheers,
Nicolas

1 Like

(The sarq part is actually untag_int, not Cfloatofint)
On Arm64 scvtf is used.

1 Like

Thanks, indeed. I was rather thinking of float_of_int instead of Cfloattoint.

Cheers,
Nicolas