1/**************************************************************************** 2 * Copyright (C) 2017 Intel Corporation. All Rights Reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 ****************************************************************************/ 23#if !defined(__SIMD_LIB_AVX512_HPP__) 24#error Do not include this file directly, use "simdlib.hpp" instead. 25#endif 26 27//============================================================================ 28// SIMD16 AVX512 (F) implementation for Knights Family Processors 29// 30//============================================================================ 31 32#define SIMD_WRAPPER_1_(op, intrin) \ 33 static SIMDINLINE Float SIMDCALL op(Float a) { return intrin(a); } 34 35#define SIMD_WRAPPER_1(op) SIMD_WRAPPER_1_(op, _mm512_##op) 36 37#define SIMD_WRAPPER_2_(op, intrin) \ 38 static SIMDINLINE Float SIMDCALL op(Float a, Float b) { return _mm512_##intrin(a, b); } 39#define SIMD_WRAPPER_2(op) SIMD_WRAPPER_2_(op, op) 40 41#define SIMD_WRAPPERI_2_(op, intrin) \ 42 static SIMDINLINE Float SIMDCALL op(Float a, Float b) \ 43 { \ 44 return _mm512_castsi512_ps( \ 45 _mm512_##intrin(_mm512_castps_si512(a), _mm512_castps_si512(b))); \ 46 } 47 48#define SIMD_DWRAPPER_2(op) \ 49 static SIMDINLINE Double SIMDCALL op(Double a, Double b) { return _mm512_##op(a, b); } 50 51#define SIMD_WRAPPER_2I_(op, intrin) \ 52 template <int ImmT> \ 53 static SIMDINLINE Float SIMDCALL op(Float a, Float b) \ 54 { \ 55 return _mm512_##intrin(a, b, ImmT); \ 56 } 57#define SIMD_WRAPPER_2I(op) SIMD_WRAPPER_2I_(op, op) 58 59#define SIMD_DWRAPPER_2I_(op, intrin) \ 60 template <int ImmT> \ 61 static SIMDINLINE Double SIMDCALL op(Double a, Double b) \ 62 { \ 63 return _mm512_##intrin(a, b, ImmT); \ 64 } 65#define SIMD_DWRAPPER_2I(op) SIMD_DWRAPPER_2I_(op, op) 66 67#define SIMD_WRAPPER_3(op) \ 68 static SIMDINLINE Float SIMDCALL op(Float a, Float b, Float c) { return _mm512_##op(a, b, c); } 69 70#define SIMD_IWRAPPER_1(op) \ 71 static SIMDINLINE Integer SIMDCALL op(Integer a) { return _mm512_##op(a); } 72#define SIMD_IWRAPPER_1_8(op) \ 73 static SIMDINLINE Integer SIMDCALL op(SIMD256Impl::Integer a) { return _mm512_##op(a); } 74 75#define SIMD_IWRAPPER_1_4(op) \ 76 static SIMDINLINE Integer SIMDCALL op(SIMD128Impl::Integer a) { return _mm512_##op(a); } 77 78#define SIMD_IWRAPPER_1I_(op, intrin) \ 79 template <int ImmT> \ 80 static SIMDINLINE Integer SIMDCALL op(Integer a) \ 81 { \ 82 return intrin(a, ImmT); \ 83 } 84#define SIMD_IWRAPPER_1I(op) SIMD_IWRAPPER_1I_(op, _mm512_##op) 85 86#define SIMD_IWRAPPER_2_(op, intrin) \ 87 static SIMDINLINE Integer SIMDCALL op(Integer a, Integer b) { return _mm512_##intrin(a, b); } 88#define SIMD_IWRAPPER_2(op) SIMD_IWRAPPER_2_(op, op) 89 90#define SIMD_IWRAPPER_2_CMP(op, cmp) \ 91 static SIMDINLINE Integer SIMDCALL op(Integer a, Integer b) { return cmp(a, b); } 92 93#define SIMD_IFWRAPPER_2(op, intrin) \ 94 static SIMDINLINE Integer SIMDCALL op(Integer a, Integer b) \ 95 { \ 96 return castps_si(_mm512_##intrin(castsi_ps(a), castsi_ps(b))); \ 97 } 98 99#define SIMD_IWRAPPER_2I_(op, intrin) \ 100 template <int ImmT> \ 101 static SIMDINLINE Integer SIMDCALL op(Integer a, Integer b) \ 102 { \ 103 return _mm512_##intrin(a, b, ImmT); \ 104 } 105#define SIMD_IWRAPPER_2I(op) SIMD_IWRAPPER_2I_(op, op) 106 107SIMD_WRAPPERI_2_(and_ps, and_epi32); // return a & b (float treated as int) 108SIMD_WRAPPERI_2_(andnot_ps, andnot_epi32); // return (~a) & b (float treated as int) 109SIMD_WRAPPERI_2_(or_ps, or_epi32); // return a | b (float treated as int) 110SIMD_WRAPPERI_2_(xor_ps, xor_epi32); // return a ^ b (float treated as int) 111 112#undef SIMD_WRAPPER_1_ 113#undef SIMD_WRAPPER_1 114#undef SIMD_WRAPPER_2 115#undef SIMD_WRAPPER_2_ 116#undef SIMD_WRAPPERI_2_ 117#undef SIMD_DWRAPPER_2 118#undef SIMD_DWRAPPER_2I 119#undef SIMD_WRAPPER_2I_ 120#undef SIMD_WRAPPER_3_ 121#undef SIMD_WRAPPER_2I 122#undef SIMD_WRAPPER_3 123#undef SIMD_IWRAPPER_1 124#undef SIMD_IWRAPPER_2 125#undef SIMD_IFWRAPPER_2 126#undef SIMD_IWRAPPER_2I 127#undef SIMD_IWRAPPER_1 128#undef SIMD_IWRAPPER_1I 129#undef SIMD_IWRAPPER_1I_ 130#undef SIMD_IWRAPPER_2 131#undef SIMD_IWRAPPER_2_ 132#undef SIMD_IWRAPPER_2I 133