Debian Codegraph @

gcc/ada/libgnat/s-geveop.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
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 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2002-2025, Free Software Foundation, Inc. --
10 -- --
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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 with System.Storage_Elements; use System.Storage_Elements;
33
34 with Ada.Unchecked_Conversion;
35
36 package body System.Generic_Vector_Operations is
37
38 IU : constant Integer := Integer (Storage_Unit);
39 VU : constant Storage_Count := Storage_Count (Vectors.Vector'Size / IU);
40 EU : constant Storage_Count :=
41 Storage_Count (Element_Array'Component_Size / IU);
42
43 ----------------------
44 -- Binary_Operation --
45 ----------------------
46
47 procedure Binary_Operation
48 (R, X, Y : System.Address;
49 Length : System.Storage_Elements.Storage_Count)
50 is
51 VI : constant Integer_Address := Integer_Address (VU);
52
53 Unaligned : constant Integer_Address :=
54 (if R mod VU /= 0 or X mod VU /= 0 or Y mod VU /= 0 then 0 else -1);
55 -- Zero iff one or more argument addresses is not aligned, else all 1's
56
57 type Vector_Ptr is access all Vectors.Vector;
58 type Element_Ptr is access all Element;
59
60 function VP is new Ada.Unchecked_Conversion (Address, Vector_Ptr);
61 function EP is new Ada.Unchecked_Conversion (Address, Element_Ptr);
62
63 pragma Assert (VI > 0);
64 -- VI = VU
65 -- VU = Vectors.Vector'Size / Storage_Unit
66 -- Vector'Size = System.Word_Size
67 -- System.Word_Size is a multiple of Storage_Unit
68 -- Vector'Size > Storage_Unit
69 -- VI > 0
70 SA : constant Address :=
71 X + Storage_Offset
72 ((Integer_Address (Length) / VI * VI) and Unaligned);
73 -- First address of argument X to start serial processing
74
75 RA : Address := R;
76 XA : Address := X;
77 YA : Address := Y;
78 -- Address of next element to process in R, X and Y
79
80 begin
81 while XA < SA loop
82 VP (RA).all := Vector_Op (VP (XA).all, VP (YA).all);
83 XA := XA + VU;
84 YA := YA + VU;
85 RA := RA + VU;
86 end loop;
87
88 while XA < X + Length loop
89 EP (RA).all := Element_Op (EP (XA).all, EP (YA).all);
90 XA := XA + EU;
91 YA := YA + EU;
92 RA := RA + EU;
93 end loop;
94 end Binary_Operation;
95
96 ----------------------
97 -- Unary_Operation --
98 ----------------------
99
100 procedure Unary_Operation
101 (R, X : System.Address;
102 Length : System.Storage_Elements.Storage_Count)
103 is
104 VI : constant Integer_Address := Integer_Address (VU);
105
106 Unaligned : constant Integer_Address :=
107 (if R mod VU /= 0 or X mod VU /= 0 then 0 else -1);
108 -- Zero iff one or more argument addresses is not aligned, else all 1's
109
110 type Vector_Ptr is access all Vectors.Vector;
111 type Element_Ptr is access all Element;
112
113 function VP is new Ada.Unchecked_Conversion (Address, Vector_Ptr);
114 function EP is new Ada.Unchecked_Conversion (Address, Element_Ptr);
115
116 pragma Assert (VI > 0);
117 -- VI = VU
118 -- VU = Vectors.Vector'Size / Storage_Unit
119 -- Vector'Size = System.Word_Size
120 -- System.Word_Size is a multiple of Storage_Unit
121 -- Vector'Size > Storage_Unit
122 -- VI > 0
123 SA : constant Address :=
124 X + Storage_Offset
125 ((Integer_Address (Length) / VI * VI) and Unaligned);
126 -- First address of argument X to start serial processing
127
128 RA : Address := R;
129 XA : Address := X;
130 -- Address of next element to process in R and X
131
132 begin
133 while XA < SA loop
134 VP (RA).all := Vector_Op (VP (XA).all);
135 XA := XA + VU;
136 RA := RA + VU;
137 end loop;
138
139 while XA < X + Length loop
140 EP (RA).all := Element_Op (EP (XA).all);
141 XA := XA + EU;
142 RA := RA + EU;
143 end loop;
144 end Unary_Operation;
145
146 end System.Generic_Vector_Operations;