with System.Address_Operations; use System.Address_Operations;
with Unchecked_Conversion;
package body System.Compare_Array_Signed_8 is
type Word is mod 2 ** 32;
type Big_Words is array (Natural) of Word;
type Big_Words_Ptr is access Big_Words;
type Byte is range -128 .. +127;
for Byte'Size use 8;
type Big_Bytes is array (Natural) of Byte;
type Big_Bytes_Ptr is access Big_Bytes;
function To_Big_Words is new
Unchecked_Conversion (System.Address, Big_Words_Ptr);
function To_Big_Bytes is new
Unchecked_Conversion (System.Address, Big_Bytes_Ptr);
function Compare_Array_S8
(Left : System.Address;
Right : System.Address;
Left_Len : Natural;
Right_Len : Natural) return Integer
is
Compare_Len : constant Natural := Natural'Min (Left_Len, Right_Len);
begin
if ModA (OrA (Left, Right), 4) /= 0 or else Compare_Len < 4 then
return Compare_Array_S8_Unaligned (Left, Right, Left_Len, Right_Len);
end if;
declare
LeftP : constant Big_Words_Ptr := To_Big_Words (Left);
RightP : constant Big_Words_Ptr := To_Big_Words (Right);
Clen4 : constant Natural := Compare_Len / 4 - 1;
Clen4F : constant Natural := Clen4 * 4;
begin
for J in 0 .. Clen4 loop
if LeftP (J) /= RightP (J) then
return Compare_Array_S8_Unaligned
(AddA (Left, Address (4 * J)),
AddA (Right, Address (4 * J)),
4, 4);
end if;
end loop;
return Compare_Array_S8_Unaligned
(AddA (Left, Address (Clen4F)),
AddA (Right, Address (Clen4F)),
Left_Len - Clen4F,
Right_Len - Clen4F);
end;
end Compare_Array_S8;
function Compare_Array_S8_Unaligned
(Left : System.Address;
Right : System.Address;
Left_Len : Natural;
Right_Len : Natural) return Integer
is
Compare_Len : constant Natural := Natural'Min (Left_Len, Right_Len);
LeftP : constant Big_Bytes_Ptr := To_Big_Bytes (Left);
RightP : constant Big_Bytes_Ptr := To_Big_Bytes (Right);
begin
for J in 0 .. Compare_Len - 1 loop
if LeftP (J) /= RightP (J) then
if LeftP (J) > RightP (J) then
return +1;
else
return -1;
end if;
end if;
end loop;
if Left_Len = Right_Len then
return 0;
elsif Left_Len > Right_Len then
return +1;
else
return -1;
end if;
end Compare_Array_S8_Unaligned;
end System.Compare_Array_Signed_8;