1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
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 package is the root of a set aimed at offering Ada bindings to a
33 -- subset of the Intel(r) Streaming SIMD Extensions with GNAT. The purpose
34 -- is to allow access from Ada to the SSE facilities defined in the Intel(r)
35 -- compiler manuals, in particular in the Intrinsics Reference of the C++
36 -- Compiler User's Guide, available from http://www.intel.com.
38 -- Assuming actual hardware support is available, this capability is
39 -- currently supported on the following set of targets:
41 -- GNU/Linux x86 and x86_64
42 -- Windows XP/Vista x86 and x86_64
44 -- This unit exposes vector _component_ types together with general comments
45 -- on the binding contents.
47 -- One other unit is offered as of today: GNAT.SSE.Vector_Types, which
48 -- exposes Ada types corresponding to the reference types (__m128 and the
49 -- like) over which a binding to the SSE GCC builtins may operate.
51 -- The exposed Ada types are private. Object initializations or value
52 -- observations may be performed with unchecked conversions or address
53 -- overlays, for example:
55 -- with Ada.Unchecked_Conversion;
56 -- with GNAT.SSE.Vector_Types; use GNAT.SSE, GNAT.SSE.Vector_Types;
58 -- procedure SSE_Base is
62 -- function ia32_addps (A, B : m128) return m128;
63 -- pragma Import (Intrinsic, ia32_addps, "__builtin_ia32_addps");
65 -- -- User views & conversions
67 -- type Vf32_View is array (1 .. 4) of GNAT.SSE.Float32;
68 -- for Vf32_View'Alignment use VECTOR_ALIGN;
70 -- function To_m128 is new Ada.Unchecked_Conversion (Vf32_View, m128);
72 -- Xf32 : constant Vf32_View := (1.0, 1.0, 2.0, 2.0);
73 -- Yf32 : constant Vf32_View := (2.0, 2.0, 1.0, 1.0);
75 -- X128 : constant m128 := To_m128 (Xf32);
76 -- Y128 : constant m128 := To_m128 (Yf32);
79 -- -- Operations & overlays
84 -- for Zf32'Address use Z128'Address;
86 -- Z128 := ia32_addps (X128, Y128);
87 -- if Zf32 /= (3.0, 3.0, 3.0, 3.0) then
88 -- raise Program_Error;
93 -- type m128_View_Kind is (SSE, F32);
94 -- type m128_Object (View : m128_View_Kind := F32) is record
96 -- when SSE => V128 : m128;
97 -- when F32 => Vf32 : Vf32_View;
100 -- pragma Unchecked_Union (m128_Object);
102 -- O1 : constant m128_Object := (View => SSE, V128 => X128);
104 -- if O1.Vf32 /= Xf32 then
105 -- raise Program_Error;
112 -----------------------------------
113 -- Common vector characteristics --
114 -----------------------------------
116 VECTOR_BYTES
: constant := 16;
117 -- Common size of all the SSE vector types, in bytes.
119 VECTOR_ALIGN
: constant := 16;
120 -- Common alignment of all the SSE vector types, in bytes.
122 -- Alignment-wise, the reference document reads:
123 -- << The compiler aligns __m128d and _m128i local and global data to
124 -- 16-byte boundaries on the stack. >>
126 -- We apply that consistently to all the Ada vector types, as GCC does
127 -- for the corresponding C types.
129 ----------------------------
130 -- Vector component types --
131 ----------------------------
133 type Float32
is new Float;
134 type Float64
is new Long_Float;
135 type Integer64
is new Long_Long_Integer;