public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Make new implementation of System.Fat_Gen.Valid more robust
@ 2021-05-06  7:58 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-05-06  7:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Eric Botcazou

[-- Attachment #1: Type: text/plain, Size: 309 bytes --]

The comparison of any denormalized number with 0.0 may return True on
hardware not supporting denormals, so we need to do a bit comparison.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* libgnat/s-fatgen.adb (Valid): Do a bit comparison with 0.0
	when denormalized numbers are not supported.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 847 bytes --]

diff --git a/gcc/ada/libgnat/s-fatgen.adb b/gcc/ada/libgnat/s-fatgen.adb
--- a/gcc/ada/libgnat/s-fatgen.adb
+++ b/gcc/ada/libgnat/s-fatgen.adb
@@ -959,7 +959,19 @@ package body System.Fat_Gen is
       else pragma Assert (Exp = IEEE_Emin - 1);
          --  This is a denormalized number, valid if T'Denorm is True or 0.0
 
-         return T'Denorm or else X.all = 0.0;
+         if T'Denorm then
+            return True;
+
+         --  Note that we cannot do a direct comparison with 0.0 because the
+         --  hardware may evaluate it to True for all denormalized numbers.
+
+         else
+            --  First clear the sign bit (the exponent is already zero)
+
+            Rep (MSW) := Rep (MSW) and not Sign_Mask;
+
+            return (for all J in 0 .. Rep_Last => Rep (J) = 0);
+         end if;
       end if;
    end Valid;
 



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-06  7:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06  7:58 [Ada] Make new implementation of System.Fat_Gen.Valid more robust Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).