| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- G N A T . S S E -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2009-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 |
-- 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. |
| 37 |
|
| 38 |
-- Assuming actual hardware support is available, this capability is |
| 39 |
-- currently supported on the following set of targets: |
| 40 |
|
| 41 |
-- GNU/Linux x86 and x86_64 |
| 42 |
-- Windows XP/Vista x86 and x86_64 |
| 43 |
-- Solaris x86 |
| 44 |
-- Darwin x86_64 |
| 45 |
|
| 46 |
-- This unit exposes vector _component_ types together with general comments |
| 47 |
-- on the binding contents. |
| 48 |
|
| 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. |
| 52 |
|
| 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: |
| 56 |
|
| 57 |
-- with Ada.Unchecked_Conversion; |
| 58 |
-- with GNAT.SSE.Vector_Types; use GNAT.SSE, GNAT.SSE.Vector_Types; |
| 59 |
|
| 60 |
-- procedure SSE_Base is |
| 61 |
|
| 62 |
-- -- Core operations |
| 63 |
|
| 64 |
-- function ia32_addps (A, B : m128) return m128; |
| 65 |
-- pragma Import (Intrinsic, ia32_addps, "__builtin_ia32_addps"); |
| 66 |
|
| 67 |
-- -- User views & conversions |
| 68 |
|
| 69 |
-- type Vf32_View is array (1 .. 4) of GNAT.SSE.Float32; |
| 70 |
-- for Vf32_View'Alignment use VECTOR_ALIGN; |
| 71 |
|
| 72 |
-- function To_m128 is new Ada.Unchecked_Conversion (Vf32_View, m128); |
| 73 |
|
| 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); |
| 76 |
|
| 77 |
-- X128 : constant m128 := To_m128 (Xf32); |
| 78 |
-- Y128 : constant m128 := To_m128 (Yf32); |
| 79 |
|
| 80 |
-- begin |
| 81 |
-- -- Operations & overlays |
| 82 |
|
| 83 |
-- declare |
| 84 |
-- Z128 : m128; |
| 85 |
-- Zf32 : Vf32_View; |
| 86 |
-- for Zf32'Address use Z128'Address; |
| 87 |
-- begin |
| 88 |
-- Z128 := ia32_addps (X128, Y128); |
| 89 |
-- if Zf32 /= (3.0, 3.0, 3.0, 3.0) then |
| 90 |
-- raise Program_Error; |
| 91 |
-- end if; |
| 92 |
-- end; |
| 93 |
|
| 94 |
-- declare |
| 95 |
-- type m128_View_Kind is (SSE, F32); |
| 96 |
-- type m128_Object (View : m128_View_Kind := F32) is record |
| 97 |
-- case View is |
| 98 |
-- when SSE => V128 : m128; |
| 99 |
-- when F32 => Vf32 : Vf32_View; |
| 100 |
-- end case; |
| 101 |
-- end record; |
| 102 |
-- pragma Unchecked_Union (m128_Object); |
| 103 |
|
| 104 |
-- O1 : constant m128_Object := (View => SSE, V128 => X128); |
| 105 |
-- begin |
| 106 |
-- if O1.Vf32 /= Xf32 then |
| 107 |
-- raise Program_Error; |
| 108 |
-- end if; |
| 109 |
-- end; |
| 110 |
-- end SSE_Base; |
| 111 |
|
| 112 |
package GNAT.SSE is |
| 113 |
|
| 114 |
----------------------------------- |
| 115 |
-- Common vector characteristics -- |
| 116 |
----------------------------------- |
| 117 |
|
| 118 |
VECTOR_BYTES : constant := 16; |
| 119 |
-- Common size of all the SSE vector types, in bytes. |
| 120 |
|
| 121 |
VECTOR_ALIGN : constant := 16; |
| 122 |
-- Common alignment of all the SSE vector types, in bytes. |
| 123 |
|
| 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. >> |
| 127 |
-- |
| 128 |
-- We apply that consistently to all the Ada vector types, as GCC does |
| 129 |
-- for the corresponding C types. |
| 130 |
|
| 131 |
---------------------------- |
| 132 |
-- Vector component types -- |
| 133 |
---------------------------- |
| 134 |
|
| 135 |
type Float32 is new Float; |
| 136 |
type Float64 is new Long_Float; |
| 137 |
type Integer64 is new Long_Long_Integer; |
| 138 |
|
| 139 |
end GNAT.SSE; |