1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . G E N E R I C _ V E C T O R _ O P E R A T I O N S --
9 -- Copyright (C) 2002-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 with System; use System;
33 with System.Address_Operations; use System.Address_Operations;
34 with System.Storage_Elements; use System.Storage_Elements;
36 with Ada.Unchecked_Conversion;
38 package body System.Generic_Vector_Operations is
40 IU : constant Integer := Integer (Storage_Unit);
41 VU : constant Address := Address (Vectors.Vector'Size / IU);
42 EU : constant Address := Address (Element_Array'Component_Size / IU);
44 ----------------------
45 -- Binary_Operation --
46 ----------------------
48 procedure Binary_Operation
49 (R, X, Y : System.Address;
50 Length : System.Storage_Elements.Storage_Count)
55 -- Address of next element to process in R, X and Y
57 VI : constant Integer_Address := To_Integer (VU);
59 Unaligned : constant Integer_Address :=
60 Boolean'Pos (ModA (OrA (OrA (RA, XA), YA), VU) /= 0) - 1;
61 -- Zero iff one or more argument addresses is not aligned, else all 1's
63 type Vector_Ptr is access all Vectors.Vector;
64 type Element_Ptr is access all Element;
66 function VP is new Ada.Unchecked_Conversion (Address, Vector_Ptr);
67 function EP is new Ada.Unchecked_Conversion (Address, Element_Ptr);
69 SA : constant Address :=
71 ((Integer_Address (Length) / VI * VI) and Unaligned));
72 -- First address of argument X to start serial processing
76 VP (RA).all := Vector_Op (VP (XA).all, VP (YA).all);
82 while XA < X + Length loop
83 EP (RA).all := Element_Op (EP (XA).all, EP (YA).all);
90 ----------------------
92 ----------------------
94 procedure Unary_Operation
95 (R, X : System.Address;
96 Length : System.Storage_Elements.Storage_Count)
100 -- Address of next element to process in R and X
102 VI : constant Integer_Address := To_Integer (VU);
104 Unaligned : constant Integer_Address :=
105 Boolean'Pos (ModA (OrA (RA, XA), VU) /= 0) - 1;
106 -- Zero iff one or more argument addresses is not aligned, else all 1's
108 type Vector_Ptr is access all Vectors.Vector;
109 type Element_Ptr is access all Element;
111 function VP is new Ada.Unchecked_Conversion (Address, Vector_Ptr);
112 function EP is new Ada.Unchecked_Conversion (Address, Element_Ptr);
114 SA : constant Address :=
116 ((Integer_Address (Length) / VI * VI) and Unaligned));
117 -- First address of argument X to start serial processing
121 VP (RA).all := Vector_Op (VP (XA).all);
126 while XA < X + Length loop
127 EP (RA).all := Element_Op (EP (XA).all);
133 end System.Generic_Vector_Operations;