-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'topic/vadim/32bit' into 'master'
Support 32bit platforms See merge request eng/ide/VSS!328
- Loading branch information
Showing
8 changed files
with
182 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
source/json/implementation/vss-json-implementation-arithmetic_64.ads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-- | ||
-- Copyright (C) 2024, AdaCore | ||
-- | ||
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
-- | ||
|
||
-- Multiply and Multiply_Add opertations on Integer_64 that returns | ||
-- unpacked Integer_128 result and can be implemented in hardware. | ||
|
||
with Interfaces; | ||
|
||
package VSS.JSON.Implementation.Arithmetic_64 | ||
with Preelaborate | ||
is | ||
|
||
procedure Multiply | ||
(A : Interfaces.Unsigned_64; | ||
B : Interfaces.Unsigned_64; | ||
L : out Interfaces.Unsigned_64; | ||
H : out Interfaces.Unsigned_64) with Inline; | ||
-- Multiplication of two 64-bit unsigned integers into 128-bit values, | ||
-- splitted into high and low 64-bit unsigned integers. On x86_64 it is | ||
-- optimized into single instruction. | ||
|
||
procedure Multiply_Add | ||
(Left : Interfaces.Unsigned_64; | ||
Right : Interfaces.Unsigned_64; | ||
Result : out Interfaces.Unsigned_64; | ||
Overflow : in out Interfaces.Unsigned_64) with Inline; | ||
-- Multiplication of two 64-bit unsigned integers into 128-bit values, | ||
-- add of carry. Result is splitted into high and low 64-bit unsigned | ||
-- integers. On x86_64 it is optimized into few instructions. | ||
|
||
end VSS.JSON.Implementation.Arithmetic_64; |
54 changes: 54 additions & 0 deletions
54
source/json/implementation/vss-json-implementation-arithmetic_64__128.adb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
-- | ||
-- Copyright (C) 2024, AdaCore | ||
-- | ||
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
-- | ||
|
||
pragma Ada_2022; | ||
|
||
package body VSS.JSON.Implementation.Arithmetic_64 | ||
with Preelaborate | ||
is | ||
|
||
-------------- | ||
-- Multiply -- | ||
-------------- | ||
|
||
procedure Multiply | ||
(A : Interfaces.Unsigned_64; | ||
B : Interfaces.Unsigned_64; | ||
L : out Interfaces.Unsigned_64; | ||
H : out Interfaces.Unsigned_64) | ||
is | ||
use type Interfaces.Unsigned_128; | ||
|
||
R : constant Interfaces.Unsigned_128 := | ||
Interfaces.Unsigned_128 (A) * Interfaces.Unsigned_128 (B); | ||
|
||
begin | ||
L := Interfaces.Unsigned_64 (R mod 2 ** 64); | ||
H := Interfaces.Unsigned_64 (R / 2 ** 64); | ||
end Multiply; | ||
|
||
------------------ | ||
-- Multiply_Add -- | ||
------------------ | ||
|
||
procedure Multiply_Add | ||
(Left : Interfaces.Unsigned_64; | ||
Right : Interfaces.Unsigned_64; | ||
Result : out Interfaces.Unsigned_64; | ||
Overflow : in out Interfaces.Unsigned_64) | ||
is | ||
use type Interfaces.Unsigned_128; | ||
|
||
R : constant Interfaces.Unsigned_128 := | ||
Interfaces.Unsigned_128 (Left) * Interfaces.Unsigned_128 (Right) | ||
+ Interfaces.Unsigned_128 (Overflow); | ||
|
||
begin | ||
Result := Interfaces.Unsigned_64 (R mod 2 ** 64); | ||
Overflow := Interfaces.Unsigned_64 (R / 2 ** 64); | ||
end Multiply_Add; | ||
|
||
end VSS.JSON.Implementation.Arithmetic_64; |
67 changes: 67 additions & 0 deletions
67
source/json/implementation/vss-json-implementation-arithmetic_64__64.adb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
-- | ||
-- Copyright (C) 2024, AdaCore | ||
-- | ||
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
-- | ||
|
||
pragma Ada_2022; | ||
|
||
package body VSS.JSON.Implementation.Arithmetic_64 | ||
with Preelaborate | ||
is | ||
|
||
-------------- | ||
-- Multiply -- | ||
-------------- | ||
|
||
procedure Multiply | ||
(A : Interfaces.Unsigned_64; | ||
B : Interfaces.Unsigned_64; | ||
L : out Interfaces.Unsigned_64; | ||
H : out Interfaces.Unsigned_64) | ||
is | ||
use type Interfaces.Unsigned_64; | ||
|
||
AL : constant Interfaces.Unsigned_64 := A and 16#FFFF_FFFF#; | ||
AH : constant Interfaces.Unsigned_64 := Interfaces.Shift_Right (A, 32); | ||
BL : constant Interfaces.Unsigned_64 := B and 16#FFFF_FFFF#; | ||
BH : constant Interfaces.Unsigned_64 := Interfaces.Shift_Right (B, 32); | ||
|
||
U : constant Interfaces.Unsigned_64 := AL * BL; | ||
T : constant Interfaces.Unsigned_64 := | ||
AH * BL + Interfaces.Shift_Right (U, 32); | ||
TL : constant Interfaces.Unsigned_64 := T and 16#FFFF_FFFF#; | ||
W1 : constant Interfaces.Unsigned_64 := TL + AL * BH; | ||
W2 : constant Interfaces.Unsigned_64 := Interfaces.Shift_Right (T, 32); | ||
|
||
begin | ||
L := A * B; | ||
H := AH * BH + W2 + Interfaces.Shift_Right (W1, 32); | ||
end Multiply; | ||
|
||
------------------ | ||
-- Multiply_Add -- | ||
------------------ | ||
|
||
procedure Multiply_Add | ||
(Left : Interfaces.Unsigned_64; | ||
Right : Interfaces.Unsigned_64; | ||
Result : out Interfaces.Unsigned_64; | ||
Overflow : in out Interfaces.Unsigned_64) | ||
is | ||
use type Interfaces.Unsigned_64; | ||
|
||
C : constant Interfaces.Unsigned_64 := Overflow; | ||
L : Interfaces.Unsigned_64; | ||
|
||
begin | ||
Multiply (Left, Right, L, Overflow); | ||
|
||
Result := L + C; | ||
|
||
if Result < L or Result < C then | ||
Overflow := @ + 1; | ||
end if; | ||
end Multiply_Add; | ||
|
||
end VSS.JSON.Implementation.Arithmetic_64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters