When are floating-point registers used in OCaml?

I was wondering when OCaml, on x86_64, uses floating-point registers xmm0-15? I know they can be used when passing unboxed floats to and from C functions. Are they also used in other cases? Does it depend on flambda being enabled?


They are used to store intermediate results of floating point operations.
For example, let z = x +. y in ... will translate to (in pseudo-syntax):

xmm0 := load_float(x, 0)
xmm1 := load_float(y, 1)
xmm0 := add_float(xmm0, xmm1)
z := alloc_float(xmm0)

Whether flamdba is enabled or not has no influence on that.
The compiler also has optimisations to remove the extra field loads and allocations when possible, but currently at function boundaries only regular values (in integer registers) are allowed.

1 Like

Their main use is to store (unboxed) intermediate results in floating-point calculations within the body of a function. The exact set of intermediate results that are unboxed depends on a number of factors. See Unboxed floats in OCaml | LexiFi for more information. (This is all for the Closure backend. I don’t know if FLambda performs further float unboxing.)


1 Like

This answers my question, thanks to you both!