with System; use System;
with System.Address_Operations; use System.Address_Operations;
with System.Storage_Elements; use System.Storage_Elements;
with Unchecked_Conversion;
package body System.Generic_Vector_Operations is
IU : constant Integer := Integer (Storage_Unit);
VU : constant Address := Address (Vectors.Vector'Size / IU);
EU : constant Address := Address (Element_Array'Component_Size / IU);
procedure Binary_Operation
(R, X, Y : System.Address;
Length : System.Storage_Elements.Storage_Count)
is
RA : Address := R;
XA : Address := X;
YA : Address := Y;
VI : constant Integer_Address := To_Integer (VU);
Unaligned : constant Integer_Address :=
Boolean'Pos (ModA (OrA (OrA (RA, XA), YA), VU) /= 0) - 1;
type Vector_Ptr is access all Vectors.Vector;
type Element_Ptr is access all Element;
function VP is new Unchecked_Conversion (Address, Vector_Ptr);
function EP is new Unchecked_Conversion (Address, Element_Ptr);
SA : constant Address :=
AddA (XA, To_Address
((Integer_Address (Length) / VI * VI) and Unaligned));
begin
while XA < SA loop
VP (RA).all := Vector_Op (VP (XA).all, VP (YA).all);
XA := AddA (XA, VU);
YA := AddA (YA, VU);
RA := AddA (RA, VU);
end loop;
while XA < X + Length loop
EP (RA).all := Element_Op (EP (XA).all, EP (YA).all);
XA := AddA (XA, EU);
YA := AddA (YA, EU);
RA := AddA (RA, EU);
end loop;
end Binary_Operation;
procedure Unary_Operation
(R, X : System.Address;
Length : System.Storage_Elements.Storage_Count)
is
RA : Address := R;
XA : Address := X;
VI : constant Integer_Address := To_Integer (VU);
Unaligned : constant Integer_Address :=
Boolean'Pos (ModA (OrA (RA, XA), VU) /= 0) - 1;
type Vector_Ptr is access all Vectors.Vector;
type Element_Ptr is access all Element;
function VP is new Unchecked_Conversion (Address, Vector_Ptr);
function EP is new Unchecked_Conversion (Address, Element_Ptr);
SA : constant Address :=
AddA (XA, To_Address
((Integer_Address (Length) / VI * VI) and Unaligned));
begin
while XA < SA loop
VP (RA).all := Vector_Op (VP (XA).all);
XA := AddA (XA, VU);
RA := AddA (RA, VU);
end loop;
while XA < X + Length loop
EP (RA).all := Element_Op (EP (XA).all);
XA := AddA (XA, EU);
RA := AddA (RA, EU);
end loop;
end Unary_Operation;
end System.Generic_Vector_Operations;