annotate gcc/ada/libgnat/g-altive.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- G N A T . A L T I V E C --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 2004-2017, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -------------------------
kono
parents:
diff changeset
33 -- General description --
kono
parents:
diff changeset
34 -------------------------
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- This is the root of a package hierarchy offering an Ada binding to the
kono
parents:
diff changeset
37 -- PowerPC AltiVec extensions, a set of 128bit vector types together with a
kono
parents:
diff changeset
38 -- set of subprograms operating on them. Relevant documents are:
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 -- o AltiVec Technology, Programming Interface Manual (1999-06)
kono
parents:
diff changeset
41 -- to which we will refer as [PIM], describes the data types, the
kono
parents:
diff changeset
42 -- functional interface and the ABI conventions.
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 -- o AltiVec Technology, Programming Environments Manual (2002-02)
kono
parents:
diff changeset
45 -- to which we will refer as [PEM], describes the hardware architecture
kono
parents:
diff changeset
46 -- and instruction set.
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- These documents, as well as a number of others of general interest on the
kono
parents:
diff changeset
49 -- AltiVec technology, are available from the Motorola/AltiVec Web site at:
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 -- http://www.freescale.com/altivec
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 -- The binding interface is structured to allow alternate implementations:
kono
parents:
diff changeset
54 -- for real AltiVec capable targets, and for other targets. In the latter
kono
parents:
diff changeset
55 -- case, everything is emulated in software. The two versions are referred
kono
parents:
diff changeset
56 -- to as:
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 -- o The Hard binding for AltiVec capable targets (with the appropriate
kono
parents:
diff changeset
59 -- hardware support and corresponding instruction set)
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -- o The Soft binding for other targets (with the low level primitives
kono
parents:
diff changeset
62 -- emulated in software).
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 -- In addition, interfaces that are not strictly part of the base AltiVec API
kono
parents:
diff changeset
65 -- are provided, such as vector conversions to and from array representations,
kono
parents:
diff changeset
66 -- which are of interest for client applications (e.g. for vector
kono
parents:
diff changeset
67 -- initialization purposes).
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 -- Only the soft binding is available today
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 -----------------------------------------
kono
parents:
diff changeset
72 -- General package architecture survey --
kono
parents:
diff changeset
73 -----------------------------------------
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 -- The various vector representations are all "containers" of elementary
kono
parents:
diff changeset
76 -- values, the possible types of which are declared in this root package to
kono
parents:
diff changeset
77 -- be generally accessible.
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 -- From the user standpoint, the binding materializes as a consistent
kono
parents:
diff changeset
80 -- hierarchy of units:
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 -- GNAT.Altivec
kono
parents:
diff changeset
83 -- (component types)
kono
parents:
diff changeset
84 -- |
kono
parents:
diff changeset
85 -- o----------------o----------------o-------------o
kono
parents:
diff changeset
86 -- | | | |
kono
parents:
diff changeset
87 -- Vector_Types Vector_Operations Vector_Views Conversions
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 -- Users can manipulate vectors through two families of types: Vector
kono
parents:
diff changeset
90 -- types and View types.
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 -- Vector types are available through the Vector_Types and Vector_Operations
kono
parents:
diff changeset
93 -- packages, which implement the core binding to the AltiVec API, as
kono
parents:
diff changeset
94 -- described in [PIM-2.1 data types] and [PIM-4 AltiVec operations and
kono
parents:
diff changeset
95 -- predicates].
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 -- The layout of Vector objects is dependant on the target machine
kono
parents:
diff changeset
98 -- endianness, and View types were devised to offer a higher level user
kono
parents:
diff changeset
99 -- interface. With Views, a vector of 4 uints (1, 2, 3, 4) is always declared
kono
parents:
diff changeset
100 -- with a VUI_View := (Values => (1, 2, 3, 4)), element 1 first, natural
kono
parents:
diff changeset
101 -- notation to denote the element values, and indexed notation is available
kono
parents:
diff changeset
102 -- to access individual elements.
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 -- View types do not represent Altivec vectors per se, in the sense that the
kono
parents:
diff changeset
105 -- Altivec_Operations are not available for them. They are intended to allow
kono
parents:
diff changeset
106 -- Vector initializations as well as access to the Vector component values.
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 -- The GNAT.Altivec.Conversions package is provided to convert a View to the
kono
parents:
diff changeset
109 -- corresponding Vector and vice-versa.
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 ---------------------------
kono
parents:
diff changeset
112 -- Underlying principles --
kono
parents:
diff changeset
113 ---------------------------
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 -- Internally, the binding relies on an abstraction of the Altivec API, a
kono
parents:
diff changeset
116 -- rich set of functions around a core of low level primitives mapping to
kono
parents:
diff changeset
117 -- AltiVec instructions. See for instance "vec_add" in [PIM-4.4 Generic and
kono
parents:
diff changeset
118 -- Specific AltiVec operations], with no less than six result/arguments
kono
parents:
diff changeset
119 -- combinations of byte vector types that map to "vaddubm".
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 -- The "soft" version is a software emulation of the low level primitives.
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 -- The "hard" version would map to real AltiVec instructions via GCC builtins
kono
parents:
diff changeset
124 -- and inlining.
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 -- See the "Design Notes" section below for additional details on the
kono
parents:
diff changeset
127 -- internals.
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 -------------------
kono
parents:
diff changeset
130 -- Example usage --
kono
parents:
diff changeset
131 -------------------
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 -- Here is a sample program declaring and initializing two vectors, 'add'ing
kono
parents:
diff changeset
134 -- them and displaying the result components:
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 -- with GNAT.Altivec.Vector_Types; use GNAT.Altivec.Vector_Types;
kono
parents:
diff changeset
137 -- with GNAT.Altivec.Vector_Operations; use GNAT.Altivec.Vector_Operations;
kono
parents:
diff changeset
138 -- with GNAT.Altivec.Vector_Views; use GNAT.Altivec.Vector_Views;
kono
parents:
diff changeset
139 -- with GNAT.Altivec.Conversions; use GNAT.Altivec.Conversions;
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 -- use GNAT.Altivec;
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 -- with Ada.Text_IO; use Ada.Text_IO;
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 -- procedure Sample is
kono
parents:
diff changeset
146 -- Va : Vector_Unsigned_Int := To_Vector ((Values => (1, 2, 3, 4)));
kono
parents:
diff changeset
147 -- Vb : Vector_Unsigned_Int := To_Vector ((Values => (1, 2, 3, 4)));
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 -- Vs : Vector_Unsigned_Int;
kono
parents:
diff changeset
150 -- Vs_View : VUI_View;
kono
parents:
diff changeset
151 -- begin
kono
parents:
diff changeset
152 -- Vs := Vec_Add (Va, Vb);
kono
parents:
diff changeset
153 -- Vs_View := To_View (Vs);
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 -- for I in Vs_View.Values'Range loop
kono
parents:
diff changeset
156 -- Put_Line (Unsigned_Int'Image (Vs_View.Values (I)));
kono
parents:
diff changeset
157 -- end loop;
kono
parents:
diff changeset
158 -- end;
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 -- $ gnatmake sample.adb
kono
parents:
diff changeset
161 -- [...]
kono
parents:
diff changeset
162 -- $ ./sample
kono
parents:
diff changeset
163 -- 2
kono
parents:
diff changeset
164 -- 4
kono
parents:
diff changeset
165 -- 6
kono
parents:
diff changeset
166 -- 8
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 ------------------------------------------------------------------------------
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 with System;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 package GNAT.Altivec is
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 -- Definitions of constants and vector/array component types common to all
kono
parents:
diff changeset
175 -- the versions of the binding.
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 -- All the vector types are 128bits
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 VECTOR_BIT : constant := 128;
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 -------------------------------------------
kono
parents:
diff changeset
182 -- [PIM-2.3.1 Alignment of vector types] --
kono
parents:
diff changeset
183 -------------------------------------------
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 -- "A defined data item of any vector data type in memory is always
kono
parents:
diff changeset
186 -- aligned on a 16-byte boundary. A pointer to any vector data type always
kono
parents:
diff changeset
187 -- points to a 16-byte boundary. The compiler is responsible for aligning
kono
parents:
diff changeset
188 -- vector data types on 16-byte boundaries."
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 VECTOR_ALIGNMENT : constant := Natural'Min (16, Standard'Maximum_Alignment);
kono
parents:
diff changeset
191 -- This value is used to set the alignment of vector datatypes in both the
kono
parents:
diff changeset
192 -- hard and the soft binding implementations.
kono
parents:
diff changeset
193 --
kono
parents:
diff changeset
194 -- We want this value to never be greater than 16, because none of the
kono
parents:
diff changeset
195 -- binding implementations requires larger alignments and such a value
kono
parents:
diff changeset
196 -- would cause useless space to be allocated/wasted for vector objects.
kono
parents:
diff changeset
197 -- Furthermore, the alignment of 16 matches the hard binding leading to
kono
parents:
diff changeset
198 -- a more faithful emulation.
kono
parents:
diff changeset
199 --
kono
parents:
diff changeset
200 -- It needs to be exactly 16 for the hard binding, and the initializing
kono
parents:
diff changeset
201 -- expression is just right for this purpose since Maximum_Alignment is
kono
parents:
diff changeset
202 -- expected to be 16 for the real Altivec ABI.
kono
parents:
diff changeset
203 --
kono
parents:
diff changeset
204 -- The soft binding doesn't rely on strict 16byte alignment, and we want
kono
parents:
diff changeset
205 -- the value to be no greater than Standard'Maximum_Alignment in this case
kono
parents:
diff changeset
206 -- to ensure it is supported on every possible target.
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 -------------------------------------------------------
kono
parents:
diff changeset
209 -- [PIM-2.1] Data Types - Interpretation of contents --
kono
parents:
diff changeset
210 -------------------------------------------------------
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 ---------------------
kono
parents:
diff changeset
213 -- char components --
kono
parents:
diff changeset
214 ---------------------
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 CHAR_BIT : constant := 8;
kono
parents:
diff changeset
217 SCHAR_MIN : constant := -2 ** (CHAR_BIT - 1);
kono
parents:
diff changeset
218 SCHAR_MAX : constant := 2 ** (CHAR_BIT - 1) - 1;
kono
parents:
diff changeset
219 UCHAR_MAX : constant := 2 ** CHAR_BIT - 1;
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 type unsigned_char is mod UCHAR_MAX + 1;
kono
parents:
diff changeset
222 for unsigned_char'Size use CHAR_BIT;
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 type signed_char is range SCHAR_MIN .. SCHAR_MAX;
kono
parents:
diff changeset
225 for signed_char'Size use CHAR_BIT;
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 subtype bool_char is unsigned_char;
kono
parents:
diff changeset
228 -- ??? There is a difference here between what the Altivec Technology
kono
parents:
diff changeset
229 -- Programming Interface Manual says and what GCC says. In the manual,
kono
parents:
diff changeset
230 -- vector_bool_char is a vector_unsigned_char, while in altivec.h it
kono
parents:
diff changeset
231 -- is a vector_signed_char.
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 bool_char_True : constant bool_char := bool_char'Last;
kono
parents:
diff changeset
234 bool_char_False : constant bool_char := 0;
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 ----------------------
kono
parents:
diff changeset
237 -- short components --
kono
parents:
diff changeset
238 ----------------------
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 SHORT_BIT : constant := 16;
kono
parents:
diff changeset
241 SSHORT_MIN : constant := -2 ** (SHORT_BIT - 1);
kono
parents:
diff changeset
242 SSHORT_MAX : constant := 2 ** (SHORT_BIT - 1) - 1;
kono
parents:
diff changeset
243 USHORT_MAX : constant := 2 ** SHORT_BIT - 1;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 type unsigned_short is mod USHORT_MAX + 1;
kono
parents:
diff changeset
246 for unsigned_short'Size use SHORT_BIT;
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 subtype unsigned_short_int is unsigned_short;
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 type signed_short is range SSHORT_MIN .. SSHORT_MAX;
kono
parents:
diff changeset
251 for signed_short'Size use SHORT_BIT;
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 subtype signed_short_int is signed_short;
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 subtype bool_short is unsigned_short;
kono
parents:
diff changeset
256 -- ??? See bool_char
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 bool_short_True : constant bool_short := bool_short'Last;
kono
parents:
diff changeset
259 bool_short_False : constant bool_short := 0;
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 subtype bool_short_int is bool_short;
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 --------------------
kono
parents:
diff changeset
264 -- int components --
kono
parents:
diff changeset
265 --------------------
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 INT_BIT : constant := 32;
kono
parents:
diff changeset
268 SINT_MIN : constant := -2 ** (INT_BIT - 1);
kono
parents:
diff changeset
269 SINT_MAX : constant := 2 ** (INT_BIT - 1) - 1;
kono
parents:
diff changeset
270 UINT_MAX : constant := 2 ** INT_BIT - 1;
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 type unsigned_int is mod UINT_MAX + 1;
kono
parents:
diff changeset
273 for unsigned_int'Size use INT_BIT;
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 type signed_int is range SINT_MIN .. SINT_MAX;
kono
parents:
diff changeset
276 for signed_int'Size use INT_BIT;
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 subtype bool_int is unsigned_int;
kono
parents:
diff changeset
279 -- ??? See bool_char
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 bool_int_True : constant bool_int := bool_int'Last;
kono
parents:
diff changeset
282 bool_int_False : constant bool_int := 0;
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 ----------------------
kono
parents:
diff changeset
285 -- float components --
kono
parents:
diff changeset
286 ----------------------
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 FLOAT_BIT : constant := 32;
kono
parents:
diff changeset
289 FLOAT_DIGIT : constant := 6;
kono
parents:
diff changeset
290 FLOAT_MIN : constant := -16#0.FFFF_FF#E+32;
kono
parents:
diff changeset
291 FLOAT_MAX : constant := 16#0.FFFF_FF#E+32;
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 type C_float is digits FLOAT_DIGIT range FLOAT_MIN .. FLOAT_MAX;
kono
parents:
diff changeset
294 for C_float'Size use FLOAT_BIT;
kono
parents:
diff changeset
295 -- Altivec operations always use the standard native floating-point
kono
parents:
diff changeset
296 -- support of the target. Note that this means that there may be
kono
parents:
diff changeset
297 -- minor differences in results between targets when the floating-
kono
parents:
diff changeset
298 -- point implementations are slightly different, as would happen
kono
parents:
diff changeset
299 -- with normal non-Altivec floating-point operations. In particular
kono
parents:
diff changeset
300 -- the Altivec simulations may yield slightly different results
kono
parents:
diff changeset
301 -- from those obtained on a true hardware Altivec target if the
kono
parents:
diff changeset
302 -- floating-point implementation is not 100% compatible.
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 ----------------------
kono
parents:
diff changeset
305 -- pixel components --
kono
parents:
diff changeset
306 ----------------------
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 subtype pixel is unsigned_short;
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 -----------------------------------------------------------
kono
parents:
diff changeset
311 -- Subtypes for variants found in the GCC implementation --
kono
parents:
diff changeset
312 -----------------------------------------------------------
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 subtype c_int is signed_int;
kono
parents:
diff changeset
315 subtype c_short is c_int;
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 LONG_BIT : constant := 32;
kono
parents:
diff changeset
318 -- Some of the GCC builtins are built with "long" arguments and
kono
parents:
diff changeset
319 -- expect SImode to come in.
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 SLONG_MIN : constant := -2 ** (LONG_BIT - 1);
kono
parents:
diff changeset
322 SLONG_MAX : constant := 2 ** (LONG_BIT - 1) - 1;
kono
parents:
diff changeset
323 ULONG_MAX : constant := 2 ** LONG_BIT - 1;
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 type signed_long is range SLONG_MIN .. SLONG_MAX;
kono
parents:
diff changeset
326 type unsigned_long is mod ULONG_MAX + 1;
kono
parents:
diff changeset
327
kono
parents:
diff changeset
328 subtype c_long is signed_long;
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 subtype c_ptr is System.Address;
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 ---------------------------------------------------------
kono
parents:
diff changeset
333 -- Access types, for the sake of some argument passing --
kono
parents:
diff changeset
334 ---------------------------------------------------------
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 type signed_char_ptr is access all signed_char;
kono
parents:
diff changeset
337 type unsigned_char_ptr is access all unsigned_char;
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 type short_ptr is access all c_short;
kono
parents:
diff changeset
340 type signed_short_ptr is access all signed_short;
kono
parents:
diff changeset
341 type unsigned_short_ptr is access all unsigned_short;
kono
parents:
diff changeset
342
kono
parents:
diff changeset
343 type int_ptr is access all c_int;
kono
parents:
diff changeset
344 type signed_int_ptr is access all signed_int;
kono
parents:
diff changeset
345 type unsigned_int_ptr is access all unsigned_int;
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 type long_ptr is access all c_long;
kono
parents:
diff changeset
348 type signed_long_ptr is access all signed_long;
kono
parents:
diff changeset
349 type unsigned_long_ptr is access all unsigned_long;
kono
parents:
diff changeset
350
kono
parents:
diff changeset
351 type float_ptr is access all Float;
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 --
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 type const_signed_char_ptr is access constant signed_char;
kono
parents:
diff changeset
356 type const_unsigned_char_ptr is access constant unsigned_char;
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 type const_short_ptr is access constant c_short;
kono
parents:
diff changeset
359 type const_signed_short_ptr is access constant signed_short;
kono
parents:
diff changeset
360 type const_unsigned_short_ptr is access constant unsigned_short;
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 type const_int_ptr is access constant c_int;
kono
parents:
diff changeset
363 type const_signed_int_ptr is access constant signed_int;
kono
parents:
diff changeset
364 type const_unsigned_int_ptr is access constant unsigned_int;
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 type const_long_ptr is access constant c_long;
kono
parents:
diff changeset
367 type const_signed_long_ptr is access constant signed_long;
kono
parents:
diff changeset
368 type const_unsigned_long_ptr is access constant unsigned_long;
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 type const_float_ptr is access constant Float;
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 -- Access to const volatile arguments need specialized types
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 type volatile_float is new Float;
kono
parents:
diff changeset
375 pragma Volatile (volatile_float);
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 type volatile_signed_char is new signed_char;
kono
parents:
diff changeset
378 pragma Volatile (volatile_signed_char);
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 type volatile_unsigned_char is new unsigned_char;
kono
parents:
diff changeset
381 pragma Volatile (volatile_unsigned_char);
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 type volatile_signed_short is new signed_short;
kono
parents:
diff changeset
384 pragma Volatile (volatile_signed_short);
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 type volatile_unsigned_short is new unsigned_short;
kono
parents:
diff changeset
387 pragma Volatile (volatile_unsigned_short);
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 type volatile_signed_int is new signed_int;
kono
parents:
diff changeset
390 pragma Volatile (volatile_signed_int);
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 type volatile_unsigned_int is new unsigned_int;
kono
parents:
diff changeset
393 pragma Volatile (volatile_unsigned_int);
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 type volatile_signed_long is new signed_long;
kono
parents:
diff changeset
396 pragma Volatile (volatile_signed_long);
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 type volatile_unsigned_long is new unsigned_long;
kono
parents:
diff changeset
399 pragma Volatile (volatile_unsigned_long);
kono
parents:
diff changeset
400
kono
parents:
diff changeset
401 type constv_char_ptr is access constant volatile_signed_char;
kono
parents:
diff changeset
402 type constv_signed_char_ptr is access constant volatile_signed_char;
kono
parents:
diff changeset
403 type constv_unsigned_char_ptr is access constant volatile_unsigned_char;
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 type constv_short_ptr is access constant volatile_signed_short;
kono
parents:
diff changeset
406 type constv_signed_short_ptr is access constant volatile_signed_short;
kono
parents:
diff changeset
407 type constv_unsigned_short_ptr is access constant volatile_unsigned_short;
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 type constv_int_ptr is access constant volatile_signed_int;
kono
parents:
diff changeset
410 type constv_signed_int_ptr is access constant volatile_signed_int;
kono
parents:
diff changeset
411 type constv_unsigned_int_ptr is access constant volatile_unsigned_int;
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 type constv_long_ptr is access constant volatile_signed_long;
kono
parents:
diff changeset
414 type constv_signed_long_ptr is access constant volatile_signed_long;
kono
parents:
diff changeset
415 type constv_unsigned_long_ptr is access constant volatile_unsigned_long;
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 type constv_float_ptr is access constant volatile_float;
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 private
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 -----------------------
kono
parents:
diff changeset
422 -- Various constants --
kono
parents:
diff changeset
423 -----------------------
kono
parents:
diff changeset
424
kono
parents:
diff changeset
425 CR6_EQ : constant := 0;
kono
parents:
diff changeset
426 CR6_EQ_REV : constant := 1;
kono
parents:
diff changeset
427 CR6_LT : constant := 2;
kono
parents:
diff changeset
428 CR6_LT_REV : constant := 3;
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 end GNAT.Altivec;
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 --------------------
kono
parents:
diff changeset
433 -- Design Notes --
kono
parents:
diff changeset
434 --------------------
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 ------------------------
kono
parents:
diff changeset
437 -- General principles --
kono
parents:
diff changeset
438 ------------------------
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 -- The internal organization has been devised from a number of driving ideas:
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 -- o From the clients standpoint, the two versions of the binding should be
kono
parents:
diff changeset
443 -- as easily exchangable as possible,
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 -- o From the maintenance standpoint, we want to avoid as much code
kono
parents:
diff changeset
446 -- duplication as possible.
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 -- o From both standpoints above, we want to maintain a clear interface
kono
parents:
diff changeset
449 -- separation between the base bindings to the Motorola API and the
kono
parents:
diff changeset
450 -- additional facilities.
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 -- The identification of the low level interface is directly inspired by the
kono
parents:
diff changeset
453 -- the base API organization, basically consisting of a rich set of functions
kono
parents:
diff changeset
454 -- around a core of low level primitives mapping to AltiVec instructions.
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 -- See for instance "vec_add" in [PIM-4.4 Generic and Specific AltiVec
kono
parents:
diff changeset
457 -- operations]: no less than six result/arguments combinations of byte vector
kono
parents:
diff changeset
458 -- types map to "vaddubm".
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 -- The "hard" version of the low level primitives map to real AltiVec
kono
parents:
diff changeset
461 -- instructions via the corresponding GCC builtins. The "soft" version is
kono
parents:
diff changeset
462 -- a software emulation of those.
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 ---------------------------------------
kono
parents:
diff changeset
465 -- The Low_Level_Vectors abstraction --
kono
parents:
diff changeset
466 ---------------------------------------
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 -- The AltiVec C interface spirit is to map a large set of C functions down
kono
parents:
diff changeset
469 -- to a much smaller set of AltiVec instructions, most of them operating on a
kono
parents:
diff changeset
470 -- set of vector data types in a transparent manner. See for instance the
kono
parents:
diff changeset
471 -- case of vec_add, which maps six combinations of result/argument types to
kono
parents:
diff changeset
472 -- vaddubm for signed/unsigned/bool variants of 'char' components.
kono
parents:
diff changeset
473
kono
parents:
diff changeset
474 -- The GCC implementation of this idiom for C/C++ is to setup builtins
kono
parents:
diff changeset
475 -- corresponding to the instructions and to expose the C user function as
kono
parents:
diff changeset
476 -- wrappers around those builtins with no-op type conversions as required.
kono
parents:
diff changeset
477 -- Typically, for the vec_add case mentioned above, we have (altivec.h):
kono
parents:
diff changeset
478 --
kono
parents:
diff changeset
479 -- inline __vector signed char
kono
parents:
diff changeset
480 -- vec_add (__vector signed char a1, __vector signed char a2)
kono
parents:
diff changeset
481 -- {
kono
parents:
diff changeset
482 -- return (__vector signed char)
kono
parents:
diff changeset
483 -- __builtin_altivec_vaddubm ((__vector signed char) a1,
kono
parents:
diff changeset
484 -- (__vector signed char) a2);
kono
parents:
diff changeset
485 -- }
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 -- inline __vector unsigned char
kono
parents:
diff changeset
488 -- vec_add (__vector __bool char a1, __vector unsigned char a2)
kono
parents:
diff changeset
489 -- {
kono
parents:
diff changeset
490 -- return (__vector unsigned char)
kono
parents:
diff changeset
491 -- __builtin_altivec_vaddubm ((__vector signed char) a1,
kono
parents:
diff changeset
492 -- (__vector signed char) a2);
kono
parents:
diff changeset
493 -- }
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 -- The central idea for the Ada bindings is to leverage on the existing GCC
kono
parents:
diff changeset
496 -- architecture, with the introduction of a Low_Level_Vectors abstraction.
kono
parents:
diff changeset
497 -- This abstaction acts as a representative of the vector-types and builtins
kono
parents:
diff changeset
498 -- compiler interface for either the Hard or the Soft case.
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 -- For the Hard binding, Low_Level_Vectors exposes data types with a GCC
kono
parents:
diff changeset
501 -- internal translation identical to the "vector ..." C types, and a set of
kono
parents:
diff changeset
502 -- subprograms mapping straight to the internal GCC builtins.
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 -- For the Soft binding, Low_Level_Vectors exposes the same set of types
kono
parents:
diff changeset
505 -- and subprograms, with bodies simulating the instructions behavior.
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 -- Vector_Types/Operations "simply" bind the user types and operations to
kono
parents:
diff changeset
508 -- some Low_Level_Vectors implementation, selected in accordance with the
kono
parents:
diff changeset
509 -- target
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 -- To achieve a complete Hard/Soft independence in the Vector_Types and
kono
parents:
diff changeset
512 -- Vector_Operations implementations, both versions of the low level support
kono
parents:
diff changeset
513 -- are expected to expose a number of facilities:
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 -- o Private data type declarations for base vector representations embedded
kono
parents:
diff changeset
516 -- in the user visible vector types, that is:
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 -- LL_VBC, LL_VUC and LL_VSC
kono
parents:
diff changeset
519 -- for vector_bool_char, vector_unsigned_char and vector_signed_char
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 -- LL_VBS, LL_VUS and LL_VSS
kono
parents:
diff changeset
522 -- for vector_bool_short, vector_unsigned_short and vector_signed_short
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 -- LL_VBI, LL_VUI and LL_VSI
kono
parents:
diff changeset
525 -- for vector_bool_int, vector_unsigned_int and vector_signed_int
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 -- as well as:
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 -- LL_VP for vector_pixel and LL_VF for vector_float
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 -- o Primitive operations corresponding to the AltiVec hardware instruction
kono
parents:
diff changeset
532 -- names, like "vaddubm". The whole set is not described here. The actual
kono
parents:
diff changeset
533 -- sets are inspired from the GCC builtins which are invoked from GCC's
kono
parents:
diff changeset
534 -- "altivec.h".
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 -- o An LL_Altivec convention identifier, specifying the calling convention
kono
parents:
diff changeset
537 -- to be used to access the aforementioned primitive operations.
kono
parents:
diff changeset
538
kono
parents:
diff changeset
539 -- Besides:
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 -- o Unchecked_Conversion are expected to be allowed between any pair of
kono
parents:
diff changeset
542 -- exposed data types, and are expected to have no effect on the value
kono
parents:
diff changeset
543 -- bit patterns.
kono
parents:
diff changeset
544
kono
parents:
diff changeset
545 -------------------------
kono
parents:
diff changeset
546 -- Vector views layout --
kono
parents:
diff changeset
547 -------------------------
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 -- Vector Views combine intuitive user level ordering for both elements
kono
parents:
diff changeset
550 -- within a vector and bytes within each element. They basically map to an
kono
parents:
diff changeset
551 -- array representation where array(i) always represents element (i), in the
kono
parents:
diff changeset
552 -- natural target representation. This way, a user vector (1, 2, 3, 4) is
kono
parents:
diff changeset
553 -- represented as:
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 -- Increasing Addresses
kono
parents:
diff changeset
556 -- ------------------------------------------------------------------------->
kono
parents:
diff changeset
557
kono
parents:
diff changeset
558 -- | 0x0 0x0 0x0 0x1 | 0x0 0x0 0x0 0x2 | 0x0 0x0 0x0 0x3 | 0x0 0x0 0x0 0x4 |
kono
parents:
diff changeset
559 -- | V (0), BE | V (1), BE | V (2), BE | V (3), BE |
kono
parents:
diff changeset
560
kono
parents:
diff changeset
561 -- on a big endian target, and as:
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 -- | 0x1 0x0 0x0 0x0 | 0x2 0x0 0x0 0x0 | 0x3 0x0 0x0 0x0 | 0x4 0x0 0x0 0x0 |
kono
parents:
diff changeset
564 -- | V (0), LE | V (1), LE | V (2), LE | V (3), LE |
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 -- on a little-endian target
kono
parents:
diff changeset
567
kono
parents:
diff changeset
568 -------------------------
kono
parents:
diff changeset
569 -- Vector types layout --
kono
parents:
diff changeset
570 -------------------------
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 -- In the case of the hard binding, the layout of the vector type in
kono
parents:
diff changeset
573 -- memory is documented by the Altivec documentation. In the case of the
kono
parents:
diff changeset
574 -- soft binding, the simplest solution is to represent a vector as an
kono
parents:
diff changeset
575 -- array of components. This representation can depend on the endianness.
kono
parents:
diff changeset
576 -- We can consider three possibilities:
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 -- * First component at the lowest address, components in big endian format.
kono
parents:
diff changeset
579 -- It is the natural way to represent an array in big endian, and it would
kono
parents:
diff changeset
580 -- also be the natural way to represent a quad-word integer in big endian.
kono
parents:
diff changeset
581
kono
parents:
diff changeset
582 -- Example:
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 -- Let V be a vector of unsigned int which value is (1, 2, 3, 4). It is
kono
parents:
diff changeset
585 -- represented as:
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 -- Addresses growing
kono
parents:
diff changeset
588 -- ------------------------------------------------------------------------->
kono
parents:
diff changeset
589 -- | 0x0 0x0 0x0 0x1 | 0x0 0x0 0x0 0x2 | 0x0 0x0 0x0 0x3 | 0x0 0x0 0x0 0x4 |
kono
parents:
diff changeset
590 -- | V (0), BE | V (1), BE | V (2), BE | V (3), BE |
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 -- * First component at the lowest address, components in little endian
kono
parents:
diff changeset
593 -- format. It is the natural way to represent an array in little endian.
kono
parents:
diff changeset
594
kono
parents:
diff changeset
595 -- Example:
kono
parents:
diff changeset
596
kono
parents:
diff changeset
597 -- Let V be a vector of unsigned int which value is (1, 2, 3, 4). It is
kono
parents:
diff changeset
598 -- represented as:
kono
parents:
diff changeset
599
kono
parents:
diff changeset
600 -- Addresses growing
kono
parents:
diff changeset
601 -- ------------------------------------------------------------------------->
kono
parents:
diff changeset
602 -- | 0x1 0x0 0x0 0x0 | 0x2 0x0 0x0 0x0 | 0x3 0x0 0x0 0x0 | 0x4 0x0 0x0 0x0 |
kono
parents:
diff changeset
603 -- | V (0), LE | V (1), LE | V (2), LE | V (3), LE |
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 -- * Last component at the lowest address, components in little endian format.
kono
parents:
diff changeset
606 -- It is the natural way to represent a quad-word integer in little endian.
kono
parents:
diff changeset
607
kono
parents:
diff changeset
608 -- Example:
kono
parents:
diff changeset
609
kono
parents:
diff changeset
610 -- Let V be a vector of unsigned int which value is (1, 2, 3, 4). It is
kono
parents:
diff changeset
611 -- represented as:
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 -- Addresses growing
kono
parents:
diff changeset
614 -- ------------------------------------------------------------------------->
kono
parents:
diff changeset
615 -- | 0x4 0x0 0x0 0x0 | 0x3 0x0 0x0 0x0 | 0x2 0x0 0x0 0x0 | 0x1 0x0 0x0 0x0 |
kono
parents:
diff changeset
616 -- | V (3), LE | V (2), LE | V (1), LE | V (0), LE |
kono
parents:
diff changeset
617
kono
parents:
diff changeset
618 -- There is actually a fourth case (components in big endian, first
kono
parents:
diff changeset
619 -- component at the lowest address), but it does not have any interesting
kono
parents:
diff changeset
620 -- properties: it is neither the natural way to represent a quad-word on any
kono
parents:
diff changeset
621 -- machine, nor the natural way to represent an array on any machine.
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 -- Example:
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 -- Let V be a vector of unsigned int which value is (1, 2, 3, 4). It is
kono
parents:
diff changeset
626 -- represented as:
kono
parents:
diff changeset
627
kono
parents:
diff changeset
628 -- Addresses growing
kono
parents:
diff changeset
629 -- ------------------------------------------------------------------------->
kono
parents:
diff changeset
630 -- | 0x0 0x0 0x0 0x4 | 0x0 0x0 0x0 0x3 | 0x0 0x0 0x0 0x2 | 0x0 0x0 0x0 0x1 |
kono
parents:
diff changeset
631 -- | V (3), BE | V (2), BE | V (1), BE | V (0), BE |
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 -- Most of the Altivec operations are specific to a component size, and
kono
parents:
diff changeset
634 -- can be implemented with any of these three formats. But some operations
kono
parents:
diff changeset
635 -- are defined by the same Altivec primitive operation for different type
kono
parents:
diff changeset
636 -- sizes:
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 -- * operations doing arithmetics on a complete vector, seen as a quad-word;
kono
parents:
diff changeset
639 -- * operations dealing with memory.
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 -- Operations on a complete vector:
kono
parents:
diff changeset
642 -- --------------------------------
kono
parents:
diff changeset
643
kono
parents:
diff changeset
644 -- Examples:
kono
parents:
diff changeset
645
kono
parents:
diff changeset
646 -- vec_sll/vsl : shift left on the entire vector.
kono
parents:
diff changeset
647 -- vec_slo/vslo: shift left on the entire vector, by octet.
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 -- Those operations works on vectors seens as a quad-word.
kono
parents:
diff changeset
650 -- Let us suppose that we have a conversion operation named To_Quad_Word
kono
parents:
diff changeset
651 -- for converting vector types to a quad-word.
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 -- Let A be a Altivec vector of 16 components:
kono
parents:
diff changeset
654 -- A = (A(0), A(1), A(2), A(3), ... , A(14), A(15))
kono
parents:
diff changeset
655 -- Let B be a Altivec vector of 8 components verifying:
kono
parents:
diff changeset
656 -- B = (A(0) |8| A(1), A(2) |8| A(3), ... , A(14) |8| A(15))
kono
parents:
diff changeset
657 -- Let C be a Altivec vector of 4 components verifying:
kono
parents:
diff changeset
658 -- C = (A(0) |8| A(1) |8| A(2) |8| A(3), ... ,
kono
parents:
diff changeset
659 -- A(12) |8| A(13) |8| A(14) |8| A(15))
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 -- (definition: |8| is the concatenation operation between two bytes;
kono
parents:
diff changeset
662 -- i.e. 0x1 |8| 0x2 = 0x0102)
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 -- According to [PIM - 4.2 byte ordering], we have the following property:
kono
parents:
diff changeset
665 -- To_Quad_Word (A) = To_Quad_Word (B) = To_Quad_Word (C)
kono
parents:
diff changeset
666
kono
parents:
diff changeset
667 -- Let To_Type_Of_A be a conversion operation from the type of B to the
kono
parents:
diff changeset
668 -- type of A. The quad-word operations are only implemented by one
kono
parents:
diff changeset
669 -- Altivec primitive operation. That means that, if QW_Operation is a
kono
parents:
diff changeset
670 -- quad-word operation, we should have:
kono
parents:
diff changeset
671 -- QW_Operation (To_Type_of_A (B)) = QW_Operation (A)
kono
parents:
diff changeset
672
kono
parents:
diff changeset
673 -- That is true iff:
kono
parents:
diff changeset
674 -- To_Quad_Word (To_Type_of_A (B)) = To_Quad_Word (A)
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 -- As To_Quad_Word is a bijection. we have:
kono
parents:
diff changeset
677 -- To_Type_of_A (B) = A
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 -- resp. any combination of A, B, C:
kono
parents:
diff changeset
680 -- To_Type_of_A (C) = A
kono
parents:
diff changeset
681 -- To_Type_of_B (A) = B
kono
parents:
diff changeset
682 -- To_Type_of_C (B) = C
kono
parents:
diff changeset
683 -- ...
kono
parents:
diff changeset
684
kono
parents:
diff changeset
685 -- Making sure that the properties described above are verified by the
kono
parents:
diff changeset
686 -- conversion operations between vector types has different implications
kono
parents:
diff changeset
687 -- depending on the layout of the vector types:
kono
parents:
diff changeset
688 -- * with format 1 and 3: only a unchecked conversion is needed;
kono
parents:
diff changeset
689 -- * with format 2 and 4: some reorganisation is needed for conversions
kono
parents:
diff changeset
690 -- between vector types with different component sizes; that has a cost on the
kono
parents:
diff changeset
691 -- efficiency, plus the complexity of having different memory pattern for
kono
parents:
diff changeset
692 -- the same quad-word value, depending on the type.
kono
parents:
diff changeset
693
kono
parents:
diff changeset
694 -- Operation dealing with memory:
kono
parents:
diff changeset
695 -- ------------------------------
kono
parents:
diff changeset
696
kono
parents:
diff changeset
697 -- These operations are either load operation (vec_ld and the
kono
parents:
diff changeset
698 -- corresponding primitive operation: vlx) or store operation (vec_st
kono
parents:
diff changeset
699 -- and the corresponding primitive operation: vstx).
kono
parents:
diff changeset
700
kono
parents:
diff changeset
701 -- According to [PIM 4.4 - vec_ld], those operations take in input
kono
parents:
diff changeset
702 -- either an access to a vector (e.g. a const_vector_unsigned_int_ptr)
kono
parents:
diff changeset
703 -- or an access to a flow of components (e.g. a const_unsigned_int_ptr),
kono
parents:
diff changeset
704 -- relying on the same Altivec primitive operations. That means that both
kono
parents:
diff changeset
705 -- should have the same representation in memory.
kono
parents:
diff changeset
706
kono
parents:
diff changeset
707 -- For the stream, it is easier to adopt the format of the target. That
kono
parents:
diff changeset
708 -- means that, in memory, the components of the vector should also have the
kono
parents:
diff changeset
709 -- format of the target. meaning that we will prefer:
kono
parents:
diff changeset
710 -- * On a big endian target: format 1 or 4
kono
parents:
diff changeset
711 -- * On a little endian target: format 2 or 3
kono
parents:
diff changeset
712
kono
parents:
diff changeset
713 -- Conclusion:
kono
parents:
diff changeset
714 -- -----------
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 -- To take into consideration the constraint brought about by the routines
kono
parents:
diff changeset
717 -- operating on quad-words and the routines operating on memory, the best
kono
parents:
diff changeset
718 -- choice seems to be:
kono
parents:
diff changeset
719
kono
parents:
diff changeset
720 -- * On a big endian target: format 1;
kono
parents:
diff changeset
721 -- * On a little endian target: format 3.
kono
parents:
diff changeset
722
kono
parents:
diff changeset
723 -- Those layout choices are enforced by GNAT.Altivec.Low_Level_Conversions,
kono
parents:
diff changeset
724 -- which is the endianness-dependant unit providing conversions between
kono
parents:
diff changeset
725 -- vector views and vector types.
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 ----------------------
kono
parents:
diff changeset
728 -- Layouts summary --
kono
parents:
diff changeset
729 ----------------------
kono
parents:
diff changeset
730
kono
parents:
diff changeset
731 -- For a user abstract vector of 4 uints (1, 2, 3, 4), increasing
kono
parents:
diff changeset
732 -- addresses from left to right:
kono
parents:
diff changeset
733
kono
parents:
diff changeset
734 -- =========================================================================
kono
parents:
diff changeset
735 -- BIG ENDIAN TARGET MEMORY LAYOUT for (1, 2, 3, 4)
kono
parents:
diff changeset
736 -- =========================================================================
kono
parents:
diff changeset
737
kono
parents:
diff changeset
738 -- View
kono
parents:
diff changeset
739 -- -------------------------------------------------------------------------
kono
parents:
diff changeset
740 -- | 0x0 0x0 0x0 0x1 | 0x0 0x0 0x0 0x2 | 0x0 0x0 0x0 0x3 | 0x0 0x0 0x0 0x4 |
kono
parents:
diff changeset
741 -- | V (0), BE | V (1), BE | V (2), BE | V (3), BE |
kono
parents:
diff changeset
742 -- -------------------------------------------------------------------------
kono
parents:
diff changeset
743
kono
parents:
diff changeset
744 -- Vector
kono
parents:
diff changeset
745 -- -------------------------------------------------------------------------
kono
parents:
diff changeset
746 -- | 0x0 0x0 0x0 0x1 | 0x0 0x0 0x0 0x2 | 0x0 0x0 0x0 0x3 | 0x0 0x0 0x0 0x4 |
kono
parents:
diff changeset
747 -- | V (0), BE | V (1), BE | V (2), BE | V (3), BE |
kono
parents:
diff changeset
748 -- -------------------------------------------------------------------------
kono
parents:
diff changeset
749
kono
parents:
diff changeset
750 -- =========================================================================
kono
parents:
diff changeset
751 -- LITTLE ENDIAN TARGET MEMORY LAYOUT for (1, 2, 3, 4)
kono
parents:
diff changeset
752 -- =========================================================================
kono
parents:
diff changeset
753
kono
parents:
diff changeset
754 -- View
kono
parents:
diff changeset
755 -- -------------------------------------------------------------------------
kono
parents:
diff changeset
756 -- | 0x1 0x0 0x0 0x0 | 0x2 0x0 0x0 0x0 | 0x3 0x0 0x0 0x0 | 0x4 0x0 0x0 0x0 |
kono
parents:
diff changeset
757 -- | V (0), LE | V (1), LE | V (2), LE | V (3), LE |
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 -- Vector
kono
parents:
diff changeset
760 -- -------------------------------------------------------------------------
kono
parents:
diff changeset
761 -- | 0x4 0x0 0x0 0x0 | 0x3 0x0 0x0 0x0 | 0x2 0x0 0x0 0x0 | 0x1 0x0 0x0 0x0 |
kono
parents:
diff changeset
762 -- | V (3), LE | V (2), LE | V (1), LE | V (0), LE |
kono
parents:
diff changeset
763 -- -------------------------------------------------------------------------
kono
parents:
diff changeset
764
kono
parents:
diff changeset
765 -- These layouts are common to both the soft and hard implementations on
kono
parents:
diff changeset
766 -- Altivec capable targets.