# How is Cfloatofint translated?

**URL:** <https://discuss.ocaml.org/t/how-is-cfloatofint-translated/12342>\
**Category:** Learning\
**Tags:** compiler\
**Created:** [June 7, 2023, 1:58pm UTC](https://discuss.ocaml.org/t/how-is-cfloatofint-translated/12342 "2023-06-07T13:58:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ifazk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ifazk/32/836_2.png) [@ifazk](https://discuss.ocaml.org/u/ifazk)\
**Post date:** [June 7, 2023, 1:58pm UTC](https://discuss.ocaml.org/t/how-is-cfloatofint-translated/12342/1 "2023-06-07T13:58:29Z")

</div>

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](https://nigeltao.github.io/blog/2020/eisel-lemire.html) would look like in OCaml.

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [June 7, 2023, 2:41pm UTC](https://discuss.ocaml.org/t/how-is-cfloatofint-translated/12342/2 "2023-06-07T14:41:11Z")

</div>

> [@ifazk](#):
>
> Trying to figure out what happens when I call “float\_of\_int” for native compilation to amd64 and arm64.

On `amd64` it is translated into the sequence

```auto
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

---

<div class="post-metadata">

**Author:** ![vlaviron](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vlaviron](https://discuss.ocaml.org/u/vlaviron)\
**Post date:** [June 7, 2023, 2:47pm UTC](https://discuss.ocaml.org/t/how-is-cfloatofint-translated/12342/3 "2023-06-07T14:47:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [June 7, 2023, 2:49pm UTC](https://discuss.ocaml.org/t/how-is-cfloatofint-translated/12342/4 "2023-06-07T14:49:18Z")

</div>

> [@vlaviron](#):
>
> (The `sarq` part is actually `untag_int`, not `Cfloatofint`)

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

Cheers,  
Nicolas
