1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2009-2017, 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
46 -- This unit exposes vector _component_ types together with general comments
47 -- on the binding contents.
49 -- One other unit is offered as of today: GNAT.SSE.Vector_Types, which
50 -- exposes Ada types corresponding to the reference types (__m128 and the
51 -- like) over which a binding to the SSE GCC builtins may operate.
53 -- The exposed Ada types are private. Object initializations or value
54 -- observations may be performed with unchecked conversions or address
55 -- overlays, for example:
57 -- with Ada.Unchecked_Conversion;
58 -- with GNAT.SSE.Vector_Types; use GNAT.SSE, GNAT.SSE.Vector_Types;
60 -- procedure SSE_Base is
64 -- function ia32_addps (A, B : m128) return m128;
65 -- pragma Import (Intrinsic, ia32_addps, "__builtin_ia32_addps");
67 -- -- User views & conversions
69 -- type Vf32_View is array (1 .. 4) of GNAT.SSE.Float32;
70 -- for Vf32_View'Alignment use VECTOR_ALIGN;
72 -- function To_m128 is new Ada.Unchecked_Conversion (Vf32_View, m128);
74 -- Xf32 : constant Vf32_View := (1.0, 1.0, 2.0, 2.0);
75 -- Yf32 : constant Vf32_View := (2.0, 2.0, 1.0, 1.0);
77 -- X128 : constant m128 := To_m128 (Xf32);
78 -- Y128 : constant m128 := To_m128 (Yf32);
81 -- -- Operations & overlays
86 -- for Zf32'Address use Z128'Address;
88 -- Z128 := ia32_addps (X128, Y128);
89 -- if Zf32 /= (3.0, 3.0, 3.0, 3.0) then
90 -- raise Program_Error;
95 -- type m128_View_Kind is (SSE, F32);
96 -- type m128_Object (View : m128_View_Kind := F32) is record
98 -- when SSE => V128 : m128;
99 -- when F32 => Vf32 : Vf32_View;
102 -- pragma Unchecked_Union (m128_Object);
104 -- O1 : constant m128_Object := (View => SSE, V128 => X128);
106 -- if O1.Vf32 /= Xf32 then
107 -- raise Program_Error;
114 -----------------------------------
115 -- Common vector characteristics --
116 -----------------------------------
118 VECTOR_BYTES
: constant := 16;
119 -- Common size of all the SSE vector types, in bytes.
121 VECTOR_ALIGN
: constant := 16;
122 -- Common alignment of all the SSE vector types, in bytes.
124 -- Alignment-wise, the reference document reads:
125 -- << The compiler aligns __m128d and _m128i local and global data to
126 -- 16-byte boundaries on the stack. >>
128 -- We apply that consistently to all the Ada vector types, as GCC does
129 -- for the corresponding C types.
131 ----------------------------
132 -- Vector component types --
133 ----------------------------
135 type Float32
is new Float;
136 type Float64
is new Long_Float;
137 type Integer64
is new Long_Long_Integer;