diff options
author | Bernhard Schommer <bernhardschommer@gmail.com> | 2022-03-22 16:03:57 +0100 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2022-04-25 16:34:11 +0200 |
commit | 967c04de6c02bef349df579cddbfcac8cf262e6d (patch) | |
tree | 65be52a638e7f7ff559ea90a4111da0278b032bf /lib/Floats.v | |
parent | 9d3521b4db46773239a2c5f9f6970de826075508 (diff) | |
download | compcert-967c04de6c02bef349df579cddbfcac8cf262e6d.tar.gz compcert-967c04de6c02bef349df579cddbfcac8cf262e6d.zip |
Introduce float_conversion_default_nan parameter for float-float conversions
For RISC-V we need to return the canonical NaN value if the argument of
a float32->float64 or float64->float32 conversion is any NaN.
This is in line with 11.3 from the RISC-V manual, the description of
the conversion operations as well as what the spike ISA simulator and
qemu do.
Other platforms convert the NaN payload (by truncation or expansion)
in float32->float64 and float64->float32 conversions.
Fixes: #428
Diffstat (limited to 'lib/Floats.v')
-rw-r--r-- | lib/Floats.v | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Floats.v b/lib/Floats.v index 43caebb0..fd0a3d32 100644 --- a/lib/Floats.v +++ b/lib/Floats.v @@ -174,7 +174,9 @@ Definition expand_nan s p H : {x | is_nan _ _ x = true} := Definition of_single_nan (f : float32) : { x : float | is_nan _ _ x = true } := match f with | B754_nan s p H => - if Archi.float_of_single_preserves_sNaN + if Archi.float_conversion_default_nan + then default_nan_64 + else if Archi.float_of_single_preserves_sNaN then expand_nan s p H else quiet_nan_64 (s, expand_nan_payload p) | _ => default_nan_64 @@ -189,7 +191,10 @@ Definition reduce_nan_payload (p: positive) := Definition to_single_nan (f : float) : { x : float32 | is_nan _ _ x = true } := match f with - | B754_nan s p H => quiet_nan_32 (s, reduce_nan_payload p) + | B754_nan s p H => + if Archi.float_conversion_default_nan + then default_nan_32 + else quiet_nan_32 (s, reduce_nan_payload p) | _ => default_nan_32 end. |