Commit f607cacf by Bob Duff Committed by Arnaud Charlet

uintp.adb (Most_Sig_2_Digits): In case Direct (Right)...

2017-04-25  Bob Duff  <duff@adacore.com>

	* uintp.adb (Most_Sig_2_Digits): In case Direct (Right), fetch
	Direct_Val (Right), instead of the incorrect Direct_Val (Left).
	(UI_GCD): Remove ??? comment involving possible efficiency
	improvements. This just isn't important after all these years.
	Also minor cleanup.
	* uintp.ads: Minor cleanup.

From-SVN: r247144
parent 28ad2460
2017-04-25 Bob Duff <duff@adacore.com>
* uintp.adb (Most_Sig_2_Digits): In case Direct (Right), fetch
Direct_Val (Right), instead of the incorrect Direct_Val (Left).
(UI_GCD): Remove ??? comment involving possible efficiency
improvements. This just isn't important after all these years.
Also minor cleanup.
* uintp.ads: Minor cleanup.
2017-04-25 Hristian Kirtchev <kirtchev@adacore.com> 2017-04-25 Hristian Kirtchev <kirtchev@adacore.com>
* exp_util.adb, exp_util.ads, sem_ch7.adb, sem_prag.adb, exp_ch3.adb: * exp_util.adb, exp_util.ads, sem_ch7.adb, sem_prag.adb, exp_ch3.adb:
......
...@@ -52,7 +52,7 @@ package body Uintp is ...@@ -52,7 +52,7 @@ package body Uintp is
UI_Power_2 : array (Int range 0 .. 64) of Uint; UI_Power_2 : array (Int range 0 .. 64) of Uint;
-- This table is used to memoize exponentiations by powers of 2. The Nth -- This table is used to memoize exponentiations by powers of 2. The Nth
-- entry, if set, contains the Uint value 2 ** N. Initially UI_Power_2_Set -- entry, if set, contains the Uint value 2**N. Initially UI_Power_2_Set
-- is zero and only the 0'th entry is set, the invariant being that all -- is zero and only the 0'th entry is set, the invariant being that all
-- entries in the range 0 .. UI_Power_2_Set are initialized. -- entries in the range 0 .. UI_Power_2_Set are initialized.
...@@ -149,9 +149,9 @@ package body Uintp is ...@@ -149,9 +149,9 @@ package body Uintp is
Left_Hat : out Int; Left_Hat : out Int;
Right_Hat : out Int); Right_Hat : out Int);
-- Returns leading two significant digits from the given pair of Uint's. -- Returns leading two significant digits from the given pair of Uint's.
-- Mathematically: returns Left / (Base ** K) and Right / (Base ** K) where -- Mathematically: returns Left / (Base**K) and Right / (Base**K) where
-- K is as small as possible S.T. Right_Hat < Base * Base. It is required -- K is as small as possible S.T. Right_Hat < Base * Base. It is required
-- that Left > Right for the algorithm to work. -- that Left >= Right for the algorithm to work.
function N_Digits (Input : Uint) return Int; function N_Digits (Input : Uint) return Int;
pragma Inline (N_Digits); pragma Inline (N_Digits);
...@@ -264,7 +264,7 @@ package body Uintp is ...@@ -264,7 +264,7 @@ package body Uintp is
------------------- -------------------
function Better_In_Hex return Boolean is function Better_In_Hex return Boolean is
T16 : constant Uint := Uint_2 ** Int'(16); T16 : constant Uint := Uint_2**Int'(16);
A : Uint; A : Uint;
begin begin
...@@ -506,6 +506,7 @@ package body Uintp is ...@@ -506,6 +506,7 @@ package body Uintp is
pragma Assert (Left >= Right); pragma Assert (Left >= Right);
if Direct (Left) then if Direct (Left) then
pragma Assert (Direct (Right));
Left_Hat := Direct_Val (Left); Left_Hat := Direct_Val (Left);
Right_Hat := Direct_Val (Right); Right_Hat := Direct_Val (Right);
return; return;
...@@ -533,7 +534,7 @@ package body Uintp is ...@@ -533,7 +534,7 @@ package body Uintp is
begin begin
if Direct (Right) then if Direct (Right) then
T := Direct_Val (Left); T := Direct_Val (Right);
R1 := abs (T / Base); R1 := abs (T / Base);
R2 := T rem Base; R2 := T rem Base;
Length_R := 2; Length_R := 2;
...@@ -1370,7 +1371,7 @@ package body Uintp is ...@@ -1370,7 +1371,7 @@ package body Uintp is
elsif Right <= Uint_64 then elsif Right <= Uint_64 then
-- 2 ** N for N in 2 .. 64 -- 2**N for N in 2 .. 64
if Left = Uint_2 then if Left = Uint_2 then
declare declare
...@@ -1390,7 +1391,7 @@ package body Uintp is ...@@ -1390,7 +1391,7 @@ package body Uintp is
return UI_Power_2 (Right_Int); return UI_Power_2 (Right_Int);
end; end;
-- 10 ** N for N in 2 .. 64 -- 10**N for N in 2 .. 64
elsif Left = Uint_10 then elsif Left = Uint_10 then
declare declare
...@@ -1585,20 +1586,6 @@ package body Uintp is ...@@ -1585,20 +1586,6 @@ package body Uintp is
else else
-- Use prior single precision steps to compute this Euclid step -- Use prior single precision steps to compute this Euclid step
-- For constructs such as:
-- sqrt_2: constant := 1.41421_35623_73095_04880_16887_24209_698;
-- sqrt_eps: constant long_float := long_float( 1.0 / sqrt_2)
-- ** long_float'machine_mantissa;
--
-- we spend 80% of our time working on this step. Perhaps we need
-- a special case Int / Uint dot product to speed things up. ???
-- Alternatively we could increase the single precision iterations
-- to handle Uint's of some small size ( <5 digits?). Then we
-- would have more iterations on small Uint. On the code above, we
-- only get 5 (on average) single precision iterations per large
-- iteration. ???
Tmp_UI := (UI_From_Int (A) * U) + (UI_From_Int (B) * V); Tmp_UI := (UI_From_Int (A) * U) + (UI_From_Int (B) * V);
V := (UI_From_Int (C) * U) + (UI_From_Int (D) * V); V := (UI_From_Int (C) * U) + (UI_From_Int (D) * V);
U := Tmp_UI; U := Tmp_UI;
......
...@@ -238,7 +238,7 @@ package Uintp is ...@@ -238,7 +238,7 @@ package Uintp is
(B : Uint; (B : Uint;
E : Uint; E : Uint;
Modulo : Uint) return Uint; Modulo : Uint) return Uint;
-- Efficiently compute (B ** E) rem Modulo -- Efficiently compute (B**E) rem Modulo
function UI_Modular_Inverse (N : Uint; Modulo : Uint) return Uint; function UI_Modular_Inverse (N : Uint; Modulo : Uint) return Uint;
-- Compute the multiplicative inverse of N in modular arithmetics with the -- Compute the multiplicative inverse of N in modular arithmetics with the
...@@ -438,7 +438,7 @@ private ...@@ -438,7 +438,7 @@ private
Base_Bits : constant := 15; Base_Bits : constant := 15;
-- Number of bits in base value -- Number of bits in base value
Base : constant Int := 2 ** Base_Bits; Base : constant Int := 2**Base_Bits;
-- Values in the range -(Base-1) .. Max_Direct are encoded directly as -- Values in the range -(Base-1) .. Max_Direct are encoded directly as
-- Uint values by adding a bias value. The value of Max_Direct is chosen -- Uint values by adding a bias value. The value of Max_Direct is chosen
...@@ -454,13 +454,13 @@ private ...@@ -454,13 +454,13 @@ private
-- avoid accidental use of Uint arithmetic on these values, which is never -- avoid accidental use of Uint arithmetic on these values, which is never
-- correct. -- correct.
type Ctrl is range Int'First .. Int'Last; type Ctrl is new Int;
Uint_Direct_Bias : constant Ctrl := Ctrl (Uint_Low_Bound) + Ctrl (Base); Uint_Direct_Bias : constant Ctrl := Ctrl (Uint_Low_Bound) + Ctrl (Base);
Uint_Direct_First : constant Ctrl := Uint_Direct_Bias + Ctrl (Min_Direct); Uint_Direct_First : constant Ctrl := Uint_Direct_Bias + Ctrl (Min_Direct);
Uint_Direct_Last : constant Ctrl := Uint_Direct_Bias + Ctrl (Max_Direct); Uint_Direct_Last : constant Ctrl := Uint_Direct_Bias + Ctrl (Max_Direct);
Uint_0 : constant Uint := Uint (Uint_Direct_Bias); Uint_0 : constant Uint := Uint (Uint_Direct_Bias + 0);
Uint_1 : constant Uint := Uint (Uint_Direct_Bias + 1); Uint_1 : constant Uint := Uint (Uint_Direct_Bias + 1);
Uint_2 : constant Uint := Uint (Uint_Direct_Bias + 2); Uint_2 : constant Uint := Uint (Uint_Direct_Bias + 2);
Uint_3 : constant Uint := Uint (Uint_Direct_Bias + 3); Uint_3 : constant Uint := Uint (Uint_Direct_Bias + 3);
...@@ -499,7 +499,7 @@ private ...@@ -499,7 +499,7 @@ private
Uint_Minus_80 : constant Uint := Uint (Uint_Direct_Bias - 80); Uint_Minus_80 : constant Uint := Uint (Uint_Direct_Bias - 80);
Uint_Minus_128 : constant Uint := Uint (Uint_Direct_Bias - 128); Uint_Minus_128 : constant Uint := Uint (Uint_Direct_Bias - 128);
Uint_Max_Simple_Mul : constant := Uint_Direct_Bias + 2 ** 15; Uint_Max_Simple_Mul : constant := Uint_Direct_Bias + 2**15;
-- If two values are directly represented and less than or equal to this -- If two values are directly represented and less than or equal to this
-- value, then we know the product fits in a 32-bit integer. This allows -- value, then we know the product fits in a 32-bit integer. This allows
-- UI_Mul to efficiently compute the product in this case. -- UI_Mul to efficiently compute the product in this case.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment