aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2020-11-23 11:39:05 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2020-12-14 10:51:55 -0500
commit951d7d1319923e5188df3224a9f79ee5804bac80 (patch)
treeb88c429620a3e3d7e05f348dcb984c30be590c7f /gcc
parent430dd877b8692d1711d772cf5d19526d7a452bb6 (diff)
downloadgcc-951d7d1319923e5188df3224a9f79ee5804bac80.zip
gcc-951d7d1319923e5188df3224a9f79ee5804bac80.tar.gz
gcc-951d7d1319923e5188df3224a9f79ee5804bac80.tar.bz2
[Ada] Small adjustments to fixed-point I/O units
gcc/ada/ * libgnat/a-tifiio.adb: Adjust documentation. (OK_Get_32): Compare the object size of the base type. (OK_Put_32): Likewise. (OK_Get_64): Likewise. (OK_Put_64): Likewise. * libgnat/a-tifiio__128.adb: Adjust documentation. (OK_Get_32): Compare the object size of the base type. (OK_Put_32): Likewise. (OK_Get_64): Likewise. (OK_Put_64): Likewise. (OK_Get_128): Likewise. (OK_Put_128): Likewise. * libgnat/a-wtfiio.adb (OK_Get_32): Likewise. (OK_Put_32): Likewise. (OK_Get_64): Likewise. (OK_Put_64): Likewise * libgnat/a-wtfiio__128.adb (OK_Get_32): Likewise. (OK_Put_32): Likewise. (OK_Get_64): Likewise. (OK_Put_64): Likewise. (OK_Get_128): Likewise. (OK_Put_128): Likewise. * libgnat/a-ztfiio.adb (OK_Get_32): Likewise. (OK_Put_32): Likewise. (OK_Get_64): Likewise. (OK_Put_64): Likewise * libgnat/a-ztfiio__128.adb (OK_Get_32): Likewise. (OK_Put_32): Likewise. (OK_Get_64): Likewise. (OK_Put_64): Likewise. (OK_Get_128): Likewise. (OK_Put_128): Likewise.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/libgnat/a-tifiio.adb35
-rw-r--r--gcc/ada/libgnat/a-tifiio__128.adb43
-rw-r--r--gcc/ada/libgnat/a-wtfiio.adb8
-rw-r--r--gcc/ada/libgnat/a-wtfiio__128.adb12
-rw-r--r--gcc/ada/libgnat/a-ztfiio.adb8
-rw-r--r--gcc/ada/libgnat/a-ztfiio__128.adb12
6 files changed, 72 insertions, 46 deletions
diff --git a/gcc/ada/libgnat/a-tifiio.adb b/gcc/ada/libgnat/a-tifiio.adb
index b7d9471..61c68ec 100644
--- a/gcc/ada/libgnat/a-tifiio.adb
+++ b/gcc/ada/libgnat/a-tifiio.adb
@@ -29,8 +29,9 @@
-- --
------------------------------------------------------------------------------
--- Fixed point I/O
--- ---------------
+-- -------------------
+-- - Fixed point I/O -
+-- -------------------
-- The following text documents implementation details of the fixed point
-- input/output routines in the GNAT runtime. The first part describes the
@@ -40,7 +41,7 @@
-- Subsequently these are reduced to implementation constraints and the impact
-- of these constraints on a few possible approaches to input/output is given.
-- Based on this analysis, a specific implementation is selected for use in
--- the GNAT runtime. Finally, the chosen algorithm is analyzed numerically in
+-- the GNAT runtime. Finally the chosen algorithms are analyzed numerically in
-- order to provide user-level documentation on limits for range and precision
-- of fixed point types as well as accuracy of input/output conversions.
@@ -68,7 +69,7 @@
-- Operations
-- ----------
--- 'Image and 'Wide_Image (see RM 3.5(34))
+-- [Wide_[Wide_]]Image attribute (see RM 3.5(27.1/2))
-- These attributes return a decimal real literal best approximating
-- the value (rounded away from zero if halfway between) with a
@@ -88,7 +89,7 @@
-- attributes, although it would be nice to be able to output more
-- than S'Aft digits after the decimal point for values of subtype S.
--- 'Value and 'Wide_Value attribute (RM 3.5(40-55))
+-- [Wide_[Wide_]]Value attribute (RM 3.5(39.1/2))
-- Since the input can be given in any base in the range 2..16,
-- accurate conversion to a fixed point number may require
@@ -121,7 +122,7 @@
-- be less than 2.0**(-53).
-- In GNAT, Fine_Delta is 2.0**(-63), and Duration for example is a 64-bit
--- type. This means that a floating-point type with 63 bits of mantissa needs
+-- type. This means that a floating-point type with 64 bits of mantissa needs
-- to be used, which is only generally available on the x86 architecture. It
-- would still be possible to use multi-precision floating point to perform
-- calculations using longer mantissas, but this is a much harder approach.
@@ -137,9 +138,21 @@
-- Fixed-precision integer arithmetic has the advantage of simplicity and
-- speed. For the most common fixed point types this would be a perfect
--- solution. The downside however may be a too limited set of acceptable
+-- solution. The downside however may be a restricted set of acceptable
-- fixed point types.
+-- Implementation Choices
+-- ----------------------
+
+-- The current implementation in the GNAT runtime uses fixed-precision integer
+-- arithmetic for fixed point types whose Small is the ratio of two integers
+-- whose magnitude is bounded relatively to the size of the mantissa, with a
+-- two-tiered approach for 32-bit and 64-bit fixed point types. For the other
+-- fixed point types, the implementation uses floating-point arithmetic.
+
+-- The exact requirements of the algorithms are analyzed and documented along
+-- with the implementation in their respective units.
+
with Interfaces;
with Ada.Text_IO.Fixed_Aux;
with Ada.Text_IO.Float_Aux;
@@ -171,7 +184,7 @@ package body Ada.Text_IO.Fixed_IO is
-- static (although it is not a static expressions in the RM sense).
OK_Get_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -182,7 +195,7 @@ package body Ada.Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -196,7 +209,7 @@ package body Ada.Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Image_F
OK_Get_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
@@ -207,7 +220,7 @@ package body Ada.Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
diff --git a/gcc/ada/libgnat/a-tifiio__128.adb b/gcc/ada/libgnat/a-tifiio__128.adb
index 4dea63c..578beb1 100644
--- a/gcc/ada/libgnat/a-tifiio__128.adb
+++ b/gcc/ada/libgnat/a-tifiio__128.adb
@@ -29,8 +29,9 @@
-- --
------------------------------------------------------------------------------
--- Fixed point I/O
--- ---------------
+-- -------------------
+-- - Fixed point I/O -
+-- -------------------
-- The following text documents implementation details of the fixed point
-- input/output routines in the GNAT runtime. The first part describes the
@@ -40,7 +41,7 @@
-- Subsequently these are reduced to implementation constraints and the impact
-- of these constraints on a few possible approaches to input/output is given.
-- Based on this analysis, a specific implementation is selected for use in
--- the GNAT runtime. Finally, the chosen algorithm is analyzed numerically in
+-- the GNAT runtime. Finally the chosen algorithms are analyzed numerically in
-- order to provide user-level documentation on limits for range and precision
-- of fixed point types as well as accuracy of input/output conversions.
@@ -68,7 +69,7 @@
-- Operations
-- ----------
--- 'Image and 'Wide_Image (see RM 3.5(34))
+-- [Wide_[Wide_]]Image attribute (see RM 3.5(27.1/2))
-- These attributes return a decimal real literal best approximating
-- the value (rounded away from zero if halfway between) with a
@@ -88,7 +89,7 @@
-- attributes, although it would be nice to be able to output more
-- than S'Aft digits after the decimal point for values of subtype S.
--- 'Value and 'Wide_Value attribute (RM 3.5(40-55))
+-- [Wide_[Wide_]]Value attribute (RM 3.5(39.1/2))
-- Since the input can be given in any base in the range 2..16,
-- accurate conversion to a fixed point number may require
@@ -120,9 +121,9 @@
-- available has 53 bits of mantissa. This means that Fine_Delta cannot
-- be less than 2.0**(-53).
--- In GNAT, Fine_Delta is 2.0**(-63), and Duration for example is a 64-bit
--- type. This means that a floating-point type with 63 bits of mantissa needs
--- to be used, which is only generally available on the x86 architecture. It
+-- In GNAT, Fine_Delta is 2.0**(-127), and Duration for example is a 64-bit
+-- type. This means that a floating-point type with 128 bits of mantissa needs
+-- to be used, which currently does not exist in any common architecture. It
-- would still be possible to use multi-precision floating point to perform
-- calculations using longer mantissas, but this is a much harder approach.
@@ -137,9 +138,21 @@
-- Fixed-precision integer arithmetic has the advantage of simplicity and
-- speed. For the most common fixed point types this would be a perfect
--- solution. The downside however may be a too limited set of acceptable
+-- solution. The downside however may be a restricted set of acceptable
-- fixed point types.
+-- Implementation Choices
+-- ----------------------
+
+-- The current implementation in the GNAT runtime uses fixed-precision integer
+-- arithmetic for fixed point types whose Small is the ratio of two integers
+-- whose magnitude is bounded relatively to the size of the mantissa, with a
+-- three-tiered approach for 32-bit, 64-bit and 128-bit fixed point types. For
+-- other fixed point types, the implementation uses floating-point arithmetic.
+
+-- The exact requirements of the algorithms are analyzed and documented along
+-- with the implementation in their respective units.
+
with Interfaces;
with Ada.Text_IO.Fixed_Aux;
with Ada.Text_IO.Float_Aux;
@@ -178,7 +191,7 @@ package body Ada.Text_IO.Fixed_IO is
-- in the RM sense).
OK_Get_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -189,7 +202,7 @@ package body Ada.Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -203,7 +216,7 @@ package body Ada.Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Image_F
OK_Get_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
@@ -214,7 +227,7 @@ package body Ada.Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
@@ -228,7 +241,7 @@ package body Ada.Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Image_F
OK_Get_128 : constant Boolean :=
- Num'Object_Size <= 128
+ Num'Base'Object_Size <= 128
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**127)
or else
@@ -239,7 +252,7 @@ package body Ada.Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_128 : constant Boolean :=
- Num'Object_Size <= 128
+ Num'Base'Object_Size <= 128
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**127)
or else
diff --git a/gcc/ada/libgnat/a-wtfiio.adb b/gcc/ada/libgnat/a-wtfiio.adb
index fa9c1e0..570c5da 100644
--- a/gcc/ada/libgnat/a-wtfiio.adb
+++ b/gcc/ada/libgnat/a-wtfiio.adb
@@ -62,7 +62,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- static (although it is not a static expressions in the RM sense).
OK_Get_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -73,7 +73,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -87,7 +87,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Image_F
OK_Get_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
@@ -98,7 +98,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
diff --git a/gcc/ada/libgnat/a-wtfiio__128.adb b/gcc/ada/libgnat/a-wtfiio__128.adb
index 846c036..aa45e5d 100644
--- a/gcc/ada/libgnat/a-wtfiio__128.adb
+++ b/gcc/ada/libgnat/a-wtfiio__128.adb
@@ -69,7 +69,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- in the RM sense).
OK_Get_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -80,7 +80,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -94,7 +94,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Image_F
OK_Get_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
@@ -105,7 +105,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
@@ -119,7 +119,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Image_F
OK_Get_128 : constant Boolean :=
- Num'Object_Size <= 128
+ Num'Base'Object_Size <= 128
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**127)
or else
@@ -130,7 +130,7 @@ package body Ada.Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_128 : constant Boolean :=
- Num'Object_Size <= 128
+ Num'Base'Object_Size <= 128
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**127)
or else
diff --git a/gcc/ada/libgnat/a-ztfiio.adb b/gcc/ada/libgnat/a-ztfiio.adb
index 57b258e..3c3224d 100644
--- a/gcc/ada/libgnat/a-ztfiio.adb
+++ b/gcc/ada/libgnat/a-ztfiio.adb
@@ -62,7 +62,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- static (although it is not a static expressions in the RM sense).
OK_Get_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -73,7 +73,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -87,7 +87,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Image_F
OK_Get_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
@@ -98,7 +98,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
diff --git a/gcc/ada/libgnat/a-ztfiio__128.adb b/gcc/ada/libgnat/a-ztfiio__128.adb
index fcb7077..3254fb8 100644
--- a/gcc/ada/libgnat/a-ztfiio__128.adb
+++ b/gcc/ada/libgnat/a-ztfiio__128.adb
@@ -70,7 +70,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- in the RM sense).
OK_Get_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -81,7 +81,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_32 : constant Boolean :=
- Num'Object_Size <= 32
+ Num'Base'Object_Size <= 32
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**31)
or else
@@ -95,7 +95,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Image_F
OK_Get_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
@@ -106,7 +106,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_64 : constant Boolean :=
- Num'Object_Size <= 64
+ Num'Base'Object_Size <= 64
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**63)
or else
@@ -120,7 +120,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Image_F
OK_Get_128 : constant Boolean :=
- Num'Object_Size <= 128
+ Num'Base'Object_Size <= 128
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**127)
or else
@@ -131,7 +131,7 @@ package body Ada.Wide_Wide_Text_IO.Fixed_IO is
-- These conditions are derived from the prerequisites of System.Value_F
OK_Put_128 : constant Boolean :=
- Num'Object_Size <= 128
+ Num'Base'Object_Size <= 128
and then
((Num'Small_Numerator = 1 and then Num'Small_Denominator <= 2**127)
or else