1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . S S E . V E C T O R _ T Y P E S --
9 -- Copyright (C) 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 -- This unit exposes the Ada __m128 like data types to represent the contents
33 -- of SSE registers, for use by the SSE intrinsics.
35 package GNAT.SSE.Vector_Types is
37 -- The reference guide states a few usage guidelines for the C types :
39 -- << Since these new data types are not basic ANSI C data types, you
40 -- must observe the following usage restrictions:
42 -- * Use new data types only on either side of an assignment, as a
43 -- return value, or as a parameter. You cannot use it with other
44 -- arithmetic expressions ("+", "-", and so on).
46 -- * Use new data types as objects in aggregates, such as unions to
47 -- access the byte elements and structures.
49 -- * Use new data types only with the respective intrinsics described
50 -- in this documentation. >>
52 type M128 is private; -- SSE >= 1
53 type M128d is private; -- SSE >= 2
54 type M128i is private; -- SSE >= 2
57 -- GCC'wise, vector operations operate on objects of vector modes,
58 -- conveyed through vector types obtained by setting an attribute on what
59 -- looks like a component typedef. For example, in C (xmmintrin.h):
61 -- typedef float __v4sf __attribute__ ((__vector_size__ (16)));
63 -- We can obtain the same low level GCC effect in Ada with
64 -- Machine_Attribute pragmas, as in
66 -- type Vf is new Float;
67 -- pragma Machine_Attribute (Vf, "vector_size", 16);
69 -- which makes Vf a 16bytes long V4SFmode type for GCC. The effect on the
70 -- type layout is not conveyed to the front-end, however, so the latter
71 -- still sees "Vf" as a 4bytes long single float. This leads to numerous
72 -- potential pitfalls if this type is directly exposed user land, so we
73 -- add wrapper records with rep clauses to compensate.
75 -- The wrapper records all have a single component of the twisted low
76 -- level type, so they inherit the mode while the rep clauses convey the
77 -- size and alignment information to the front-end.
83 -- << The __m128 data type can hold four 32-bit floating-point values. >>
85 type V4sf is new Float32;
86 pragma Machine_Attribute (V4sf, "vector_size", VECTOR_BYTES);
91 for M128'Size use VECTOR_BYTES * 8;
92 for M128'Alignment use VECTOR_ALIGN;
98 -- << The __m128d data type can hold two 64-bit floating-point values. >>
100 type V2df is new Float64;
101 pragma Machine_Attribute (V2df, "vector_size", VECTOR_BYTES);
106 for M128d'Size use VECTOR_BYTES * 8;
107 for M128d'Alignment use VECTOR_ALIGN;
113 -- << The __m128i data type can hold sixteen 8-bit, eight 16-bit, four
114 -- 32-bit, or two 64-bit integer values. >>
116 type V2di is new Integer64;
117 pragma Machine_Attribute (V2di, "vector_size", VECTOR_BYTES);
122 for M128i'Size use VECTOR_BYTES * 8;
123 for M128i'Alignment use VECTOR_ALIGN;
125 end GNAT.SSE.Vector_Types;