types.h
1 /* 2 * Copyright (C) 2018-2020, Advanced Micro Devices, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 1. Redistributions of source code must retain the above copyright notice, 7 * this list of conditions and the following disclaimer. 8 * 2. Redistributions in binary form must reproduce the above copyright notice, 9 * this list of conditions and the following disclaimer in the documentation 10 * and/or other materials provided with the distribution. 11 * 3. Neither the name of the copyright holder nor the names of its contributors 12 * may be used to endorse or promote products derived from this software without 13 * specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 21 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * POSSIBILITY OF SUCH DAMAGE. 25 * 26 */ 27 28 #ifndef __LIBM_TYPES_H__ 29 #define __LIBM_TYPES_H__ 30 31 #include <stdint.h> 32 #include <float.h> 33 #include <complex.h> 34 #include <immintrin.h> 35 36 #define PASTE2(a, b) a##b 37 #define STRINGIFY2(x) #x 38 #define STRINGIFY(x) STRINGIFY2(x) 39 40 41 typedef short f16_t; 42 typedef float f32_t; 43 typedef double f64_t; 44 typedef long double f80_t; 45 46 typedef float _Complex fc32_t; 47 typedef double _Complex fc64_t; 48 49 #ifdef HAVE_NATIVE_LONG_LONG_DOUBLE 50 typedef long long double f128_t; 51 #else 52 typedef __m128 f128_t; 53 #endif 54 55 56 /***************************** 57 * Internal types 58 *****************************/ 59 typedef union { 60 uint32_t i; 61 float f; 62 } flt32u_t; 63 64 typedef union { 65 int32_t i; 66 float f; 67 } flt32_t; 68 69 typedef union { 70 double d; 71 uint64_t i; 72 } flt64u_t; 73 74 typedef union { 75 int64_t i; 76 double d; 77 } flt64_t; 78 79 80 81 /***************************** 82 * Internal vector types 83 *****************************/ 84 85 86 /* 87 * (u)int32 - 4 elements - 128 bit 88 */ 89 typedef union { 90 int32_t i[4]; 91 __m128i m128i; 92 } int128_t; 93 94 typedef union { 95 uint32_t i[4]; 96 __m128i m128i; 97 } int128u_t; 98 99 100 /* 101 * float32 - 4 elements - 128 bit 102 */ 103 typedef union { 104 int32_t i[4]; 105 float f[4]; 106 __m128 m128; 107 } flt128f_t; 108 109 typedef union { 110 uint32_t i[4]; 111 float f[4]; 112 __m128 m128; 113 } flt128fu_t; 114 115 /* 116 * float32 - 8 element - 256 bits 117 */ 118 typedef union { 119 int32_t i[8]; 120 float f[8]; 121 __m256 m256; 122 } flt256f_t; 123 124 typedef union { 125 uint32_t i[8]; 126 float f[8]; 127 __m256 m256; 128 } flt256fu_t; 129 130 /* 131 * float64 - 2 element - 128 bits 132 */ 133 typedef union { 134 int64_t i[2]; 135 double d[2]; 136 __m128d m128; 137 } flt128d_t; 138 139 typedef union { 140 uint64_t i[2]; 141 double d[2]; 142 __m256d m128; 143 } flt128du_t; 144 145 /* 146 * float64 - 4 element - 256 bits 147 */ 148 typedef union { 149 int64_t i[4]; 150 double d[4]; 151 __m256d m256d; 152 } flt256d_t; 153 154 typedef union { 155 uint64_t i[4]; 156 double d[4]; 157 __m256d m256d; 158 } flt256du_t; 159 160 161 162 /* 163 * Vector types 164 */ 165 166 #define VEC(x) __attribute__ ((__vector_size__ (x))) 167 #define MAY_ALIAS __attribute ((__may_alias__)) 168 169 /* Naming convention 170 * v_/vu_ - prefix, prefix-unaligned 171 * f/d/u/i - float/double unsigned/signed 172 * 32/64/80 - width of data 173 * x2/x4/x8 - number of elements 174 */ 175 176 typedef float v_f32x4_t VEC(16) MAY_ALIAS; 177 typedef uint32_t v_u32x4_t VEC(16) MAY_ALIAS; 178 typedef int32_t v_i32x4_t VEC(16) MAY_ALIAS; 179 typedef float v_f32x8_t VEC(32) MAY_ALIAS; 180 typedef uint32_t v_u32x8_t VEC(32) MAY_ALIAS; 181 typedef int32_t v_i32x8_t VEC(32) MAY_ALIAS; 182 183 typedef double v_f64x2_t VEC(16) MAY_ALIAS; 184 typedef uint64_t v_u64x2_t VEC(16) MAY_ALIAS; 185 typedef int64_t v_i64x2_t VEC(16) MAY_ALIAS; 186 typedef double v_f64x4_t VEC(32) MAY_ALIAS; 187 typedef uint64_t v_u64x4_t VEC(32) MAY_ALIAS; 188 typedef int64_t v_i64x4_t VEC(32) MAY_ALIAS; 189 190 191 /* 192 * Generic 32-bit, 4-element types 193 */ 194 typedef union { 195 v_f32x4_t f32x4; 196 v_i32x4_t i32x4; 197 } v_32x4; 198 199 typedef union { 200 v_f32x4_t f32x4; 201 v_u32x4_t u32x4; 202 } v_32x4_u; 203 204 /* 205 * Generic 32-bit, 8-element types 206 */ 207 typedef union { 208 v_f32x8_t f32x8; 209 v_i32x8_t i32x8; 210 } v_32x8; 211 212 typedef union { 213 v_f32x8_t f32x8; 214 v_u32x8_t u32x8; 215 } v_32x8_u; 216 217 /* 218 * Generic 64-bit, 2-element types 219 */ 220 typedef union { 221 v_f64x2_t f64x2; 222 v_i64x2_t i64x2; 223 } v_64x2; 224 225 typedef union { 226 v_f64x2_t f64x2; 227 v_u64x2_t u64x2; 228 } v_64x2_u; 229 230 /* 231 * Generic 64-bit, 4-element types 232 */ 233 typedef union { 234 v_f64x4_t f64x4; 235 v_i64x4_t i64x4; 236 } v_64x4; 237 238 typedef union { 239 v_f64x4_t f64x4; 240 v_u64x4_t u64x4; 241 } v_64x4_u; 242 243 #endif /* LIBM_TYPES_H */