[m-dev.] Fwd: single-precision floats on 64 bit platforms

Zoltan Somogyi zoltan.somogyi at runbox.com
Thu Apr 30 16:39:40 AEST 2020

I originally posted this with the output of a bootcheck in the
hlc.gc.spf grade, which shows a bunch of test case failures,
which as far as I can tell are all caused by less-than-expected
floating point precision (since the expected precision
is double precision). The output was too big uncompressed,
so here it is now compressed.

----- Start Forwarded Message -----
Sent: Thu, 30 Apr 2020 16:32:03 +1000 (AEST)
From: "Zoltan Somogyi" <zoltan.somogyi at runbox.com>
To: "developers" <developers at lists.mercurylang.org>
Subject: single-precision floats on 64 bit platforms

On 32 bit platforms, spf grades could be a major performance win
for applications that didn't need double precision, because it avoided boxing.
On 64 bit platforms, that is not an issue. On 64 bit platforms, for code
like this:

:- type t
    --->    f(int, float, int).

:- func test(float) = t.
test(F) = f(41, F, 42).

we generate the exact same code in both hlc.gc.spf and hlc.gc, namely

MR_hl_field(MR_mktag(0), HeadVar__2_2, 0) = ((MR_Box) (Var_4));
MR_hl_field(MR_mktag(0), HeadVar__2_2, 1) = MR_box_float(F_3);
MR_hl_field(MR_mktag(0), HeadVar__2_2, 2) = ((MR_Box) (Var_5));

With spf on 64 bit platforms, we are using only 32 bits of that middle word.
This does not seem to be a problem, since I don't recall hearing anyone
complain about it. So on 64 bit platforms, the only possible benefit of
spf grades is that float multiplies and divides *may* be a bit faster
than double multiplies and divides, though on most FP-intensive workloads,
such differences will be lost in the noise of the cost of traffic to and from
main memory. (IIRC, on most platforms, FP addition and subtraction take
just one cycle for both floats and doubles, due to carry lookahead.)

At the moment, the documentation of the spf grade (what little there is
of it) makes no mention of the fact that its use makes sense only
on 32 bit platforms.

I think it would improve the situation if we took one of two actions:

(a) documenting that spf reduces memory usage only on 32 bit platforms, or

(b) ignoring the setting of the spf grade component on 54 bit platforms,
and documenting this fact.

Any opinions?


----- End Forwarded Message -----

More information about the developers mailing list