1 #pragma once 2 3 #include <stdlib.h> 4 5 // Defines SIMINT_AVX, etc 6 #include "simint/vectorization/vector_config.h" 7 8 #if defined SIMINT_AVX512 || defined SIMINT_MICAVX512 9 #include "simint/vectorization/intrinsics_avx512.h" 10 #elif defined SIMINT_AVX || defined SIMINT_AVX2 11 #include "simint/vectorization/intrinsics_avx.h" 12 #elif defined SIMINT_SSE 13 #include "simint/vectorization/intrinsics_sse.h" 14 #elif defined SIMINT_SCALAR 15 #include "simint/vectorization/intrinsics_scalar.h" 16 #else 17 #error Vector type is not set 18 #endif 19 20 #define SIMINT_SIMD_ALIGN_DBL (SIMINT_SIMD_LEN*8) 21 #define SIMINT_SIMD_ALIGN_INT (SIMINT_SIMD_LEN*sizeof(int)) 22 23 // "Max" alignment. Can be used to allocate memory of mixed types 24 // (ie ints and doubles can be allocated this way) 25 #define SIMINT_SIMD_ALIGN SIMINT_SIMD_ALIGN_DBL 26 27 28 #if defined __INTEL_COMPILER 29 #define SIMINT_ASSUME_ALIGN_DBL(x) __assume_aligned((x), SIMINT_SIMD_ALIGN_DBL) 30 #define SIMINT_ASSUME_ALIGN_INT(x) __assume_aligned((x), SIMINT_SIMD_ALIGN_INT) 31 #elif defined __clang__ 32 // TODO - find these 33 #define SIMINT_ASSUME_ALIGN_DBL(x) 34 #define SIMINT_ASSUME_ALIGN_INT(x) 35 #elif defined __GNUC__ 36 // TODO - find these 37 #define SIMINT_ASSUME_ALIGN_DBL(x) 38 #define SIMINT_ASSUME_ALIGN_INT(x) 39 #else 40 #define SIMINT_ASSUME_ALIGN_DBL(x) 41 #define SIMINT_ASSUME_ALIGN_INT(x) 42 #endif 43 44 45 46 // Aligned memory allocation 47 #ifdef SIMINT_SCALAR 48 #define SIMINT_ALLOC(x) malloc((x)) 49 #define SIMINT_FREE(x) free((x)) 50 #else 51 #define SIMINT_ALLOC(x) _mm_malloc((x), SIMINT_SIMD_ALIGN) 52 #define SIMINT_FREE(x) _mm_free((x)) 53 #endif 54 55 56 // round up the number of elements to the nearest boundary 57 #define SIMINT_SIMD_ROUND(x) ((x + ((SIMINT_SIMD_LEN-1))) & (~(SIMINT_SIMD_LEN-1))) 58 59 60 // align an array 61 // ie double somearr[200] SIMINT_ALIGN_ARRAY 62 #define SIMINT_ALIGN_ARRAY_DBL __attribute__((aligned(SIMINT_SIMD_ALIGN_DBL))) 63 #define SIMINT_ALIGN_ARRAY_INT __attribute__((aligned(SIMINT_SIMD_ALIGN_INT))) 64 65 66 // Number of shells to use in a batch 67 #define SIMINT_NSHELL_SIMD (2*SIMINT_SIMD_LEN) 68 69