public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Adjust again previous change to System.Fat_Gen
@ 2020-12-14 15:56 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-12-14 15:56 UTC (permalink / raw)
  To: gcc-patches; +Cc: Eric Botcazou

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

This removes the direct declaration of the smallest denormalized number
and replaces it with an overlay of the equivalent integer constant,
because such a direct declaration cannot be translated into C90.

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

gcc/ada/

	* libgnat/s-fatgen.adb: Add with clause for Interfaces and use
	type clause for Interfaces.Unsigned_64.
	(Small): Comment out.
	(Tiny): Likewise.
	(Tiny16): New integer constant.
	(Tiny32): Likewise.
	(Tiny64): Likewise.
	(Tiny80): New integer array constant.
	(Pred): Declare a local overlay for Tiny.
	(Succ): Likewise.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2964 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
@@ -35,12 +35,15 @@
 --  floating-point implementations.
 
 with Ada.Unchecked_Conversion;
+with Interfaces;
 with System.Unsigned_Types;
 
 pragma Warnings (Off, "non-static constant in preelaborated unit");
 --  Every constant is static given our instantiation model
 
 package body System.Fat_Gen is
+   use type Interfaces.Unsigned_64;
+
    pragma Assert (T'Machine_Radix = 2);
    --  This version does not handle radix 16
 
@@ -53,13 +56,22 @@ package body System.Fat_Gen is
    Invrad : constant T := 1.0 / Rad;
    --  Smallest positive mantissa in the canonical form (RM A.5.3(4))
 
-   Small : constant T := Rad ** (T'Machine_Emin - 1);
-   pragma Unreferenced (Small);
+   --  Small : constant T := Rad ** (T'Machine_Emin - 1);
    --  Smallest positive normalized number
 
-   Tiny : constant T := Rad ** (T'Machine_Emin - Mantissa);
+   --  Tiny : constant T := Rad ** (T'Machine_Emin - Mantissa);
    --  Smallest positive denormalized number
 
+   Tiny16 : constant Interfaces.Unsigned_16 := 1;
+   Tiny32 : constant Interfaces.Unsigned_32 := 1;
+   Tiny64 : constant Interfaces.Unsigned_64 := 1;
+   Tiny80 : constant array (1 .. 2) of Interfaces.Unsigned_64 :=
+              (1 * Standard'Default_Bit_Order,
+               2**48 * (1 - Standard'Default_Bit_Order));
+   --  We cannot use the direct declaration because it cannot be translated
+   --  into C90, as the hexadecimal floating constants were introduced in C99.
+   --  So we work around this by using an overlay of the integer constant.
+
    RM1 : constant T := Rad ** (Mantissa - 1);
    --  Smallest positive member of the large consecutive integers. It is equal
    --  to the ratio Small / Tiny, which means that multiplying by it normalizes
@@ -411,6 +423,13 @@ package body System.Fat_Gen is
    ----------
 
    function Pred (X : T) return T is
+      Tiny : constant T;
+      pragma Import (Ada, Tiny);
+      for Tiny'Address use (if     T'Size   = 16 then Tiny16'Address
+                             elsif T'Size   = 32 then Tiny32'Address
+                             elsif T'Size   = 64 then Tiny64'Address
+                             elsif Mantissa = 64 then Tiny80'Address
+                             else raise Program_Error);
       X_Frac : T;
       X_Exp  : UI;
 
@@ -676,6 +695,13 @@ package body System.Fat_Gen is
    ----------
 
    function Succ (X : T) return T is
+      Tiny : constant T;
+      pragma Import (Ada, Tiny);
+      for Tiny'Address use (if     T'Size   = 16 then Tiny16'Address
+                             elsif T'Size   = 32 then Tiny32'Address
+                             elsif T'Size   = 64 then Tiny64'Address
+                             elsif Mantissa = 64 then Tiny80'Address
+                             else raise Program_Error);
       X_Frac : T;
       X_Exp  : UI;
 



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

only message in thread, other threads:[~2020-12-14 15:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-14 15:56 [Ada] Adjust again previous change to System.Fat_Gen 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).