|
| 1 | +/*************************************************************************** |
| 2 | + * Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and * |
| 3 | + * Martin Renou * |
| 4 | + * Copyright (c) QuantStack * |
| 5 | + * Copyright (c) Serge Guelton * |
| 6 | + * Copyright (c) Marco Barbone * |
| 7 | + * * |
| 8 | + * Distributed under the terms of the BSD 3-Clause License. * |
| 9 | + * * |
| 10 | + * The full license is in the file LICENSE, distributed with this software. * |
| 11 | + ****************************************************************************/ |
| 12 | + |
| 13 | +#ifndef XSIMD_AVX_128_HPP |
| 14 | +#define XSIMD_AVX_128_HPP |
| 15 | + |
| 16 | +#include <type_traits> |
| 17 | + |
| 18 | +#include "../types/xsimd_avx_register.hpp" |
| 19 | +#include "../types/xsimd_batch_constant.hpp" |
| 20 | + |
| 21 | +namespace xsimd |
| 22 | +{ |
| 23 | + namespace kernel |
| 24 | + { |
| 25 | + using namespace types; |
| 26 | + |
| 27 | + // broadcast |
| 28 | + template <class A, class T, class = std::enable_if_t<std::is_same<T, float>::value>> |
| 29 | + XSIMD_INLINE batch<T, A> broadcast(T val, requires_arch<avx_128>) noexcept |
| 30 | + { |
| 31 | + return _mm_broadcast_ss(&val); |
| 32 | + } |
| 33 | + |
| 34 | + // eq |
| 35 | + template <class A> |
| 36 | + XSIMD_INLINE batch_bool<float, A> eq(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx_128>) noexcept |
| 37 | + { |
| 38 | + return _mm_cmp_ps(self, other, _CMP_EQ_OQ); |
| 39 | + } |
| 40 | + template <class A> |
| 41 | + XSIMD_INLINE batch_bool<double, A> eq(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx_128>) noexcept |
| 42 | + { |
| 43 | + return _mm_cmp_pd(self, other, _CMP_EQ_OQ); |
| 44 | + } |
| 45 | + |
| 46 | + // gt |
| 47 | + template <class A> |
| 48 | + XSIMD_INLINE batch_bool<float, A> gt(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx_128>) noexcept |
| 49 | + { |
| 50 | + return _mm_cmp_ps(self, other, _CMP_GT_OQ); |
| 51 | + } |
| 52 | + template <class A> |
| 53 | + XSIMD_INLINE batch_bool<double, A> gt(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx_128>) noexcept |
| 54 | + { |
| 55 | + return _mm_cmp_pd(self, other, _CMP_GT_OQ); |
| 56 | + } |
| 57 | + |
| 58 | + // ge |
| 59 | + template <class A> |
| 60 | + XSIMD_INLINE batch_bool<float, A> ge(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx_128>) noexcept |
| 61 | + { |
| 62 | + return _mm_cmp_ps(self, other, _CMP_GE_OQ); |
| 63 | + } |
| 64 | + template <class A> |
| 65 | + XSIMD_INLINE batch_bool<double, A> ge(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx_128>) noexcept |
| 66 | + { |
| 67 | + return _mm_cmp_pd(self, other, _CMP_GE_OQ); |
| 68 | + } |
| 69 | + |
| 70 | + // lt |
| 71 | + template <class A> |
| 72 | + XSIMD_INLINE batch_bool<float, A> lt(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx_128>) noexcept |
| 73 | + { |
| 74 | + return _mm_cmp_ps(self, other, _CMP_LT_OQ); |
| 75 | + } |
| 76 | + template <class A> |
| 77 | + XSIMD_INLINE batch_bool<double, A> lt(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx_128>) noexcept |
| 78 | + { |
| 79 | + return _mm_cmp_pd(self, other, _CMP_LT_OQ); |
| 80 | + } |
| 81 | + |
| 82 | + // le |
| 83 | + template <class A> |
| 84 | + XSIMD_INLINE batch_bool<float, A> le(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx_128>) noexcept |
| 85 | + { |
| 86 | + return _mm_cmp_ps(self, other, _CMP_LE_OQ); |
| 87 | + } |
| 88 | + template <class A> |
| 89 | + XSIMD_INLINE batch_bool<double, A> le(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx_128>) noexcept |
| 90 | + { |
| 91 | + return _mm_cmp_pd(self, other, _CMP_LE_OQ); |
| 92 | + } |
| 93 | + |
| 94 | + // neq |
| 95 | + template <class A> |
| 96 | + XSIMD_INLINE batch_bool<float, A> neq(batch<float, A> const& self, batch<float, A> const& other, requires_arch<avx_128>) noexcept |
| 97 | + { |
| 98 | + return _mm_cmp_ps(self, other, _CMP_NEQ_UQ); |
| 99 | + } |
| 100 | + template <class A> |
| 101 | + XSIMD_INLINE batch_bool<double, A> neq(batch<double, A> const& self, batch<double, A> const& other, requires_arch<avx_128>) noexcept |
| 102 | + { |
| 103 | + return _mm_cmp_pd(self, other, _CMP_NEQ_UQ); |
| 104 | + } |
| 105 | + |
| 106 | + // load_masked |
| 107 | + template <class A, bool... Values, class Mode> |
| 108 | + XSIMD_INLINE batch<float, A> load_masked(float const* mem, batch_bool_constant<float, A, Values...> mask, convert<float>, Mode, requires_arch<avx_128>) noexcept |
| 109 | + { |
| 110 | + return _mm_maskload_ps(mem, mask.as_batch()); |
| 111 | + } |
| 112 | + template <class A, bool... Values, class Mode> |
| 113 | + XSIMD_INLINE batch<double, A> load_masked(double const* mem, batch_bool_constant<double, A, Values...> mask, convert<double>, Mode, requires_arch<avx_128>) noexcept |
| 114 | + { |
| 115 | + return _mm_maskload_pd(mem, mask.as_batch()); |
| 116 | + } |
| 117 | + |
| 118 | + // store_masked |
| 119 | + template <class A, bool... Values, class Mode> |
| 120 | + XSIMD_INLINE void store_masked(float* mem, batch<float, A> const& src, batch_bool_constant<float, A, Values...> mask, Mode, requires_arch<avx_128>) noexcept |
| 121 | + { |
| 122 | + return _mm_maskstore_ps(mem, mask.as_batch(), src); |
| 123 | + } |
| 124 | + |
| 125 | + template <class A, bool... Values, class Mode> |
| 126 | + XSIMD_INLINE void store_masked(double* mem, batch<double, A> const& src, batch_bool_constant<double, A, Values...> mask, Mode, requires_arch<avx_128>) noexcept |
| 127 | + { |
| 128 | + return _mm_maskstore_pd(mem, mask.as_batch(), src); |
| 129 | + } |
| 130 | + |
| 131 | + // swizzle (dynamic mask) |
| 132 | + template <class A, class T, class ITy, class = std::enable_if_t<std::is_floating_point<T>::value && sizeof(T) == sizeof(ITy)>> |
| 133 | + XSIMD_INLINE batch<T, A> swizzle(batch<T, A> const& self, batch<ITy, A> mask, requires_arch<avx_128>) noexcept |
| 134 | + { |
| 135 | + XSIMD_IF_CONSTEXPR(std::is_same<T, float>::value) |
| 136 | + { |
| 137 | + return _mm_permutevar_ps(self, mask); |
| 138 | + } |
| 139 | + else |
| 140 | + { |
| 141 | + // FIXME: _mm_permutevar_pd fails validation, but it shouldn't o_O |
| 142 | + return swizzle(self, mask, sse4_2 {}); |
| 143 | + // return _mm_permutevar_pd(self, mask); |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + // swizzle (constant mask) |
| 148 | + template <class A, uint32_t V0, uint32_t V1, uint32_t V2, uint32_t V3> |
| 149 | + XSIMD_INLINE batch<float, A> swizzle(batch<float, A> const& self, batch_constant<uint32_t, A, V0, V1, V2, V3>, requires_arch<avx_128>) noexcept |
| 150 | + { |
| 151 | + return _mm_permute_ps(self, detail::mod_shuffle(V0, V1, V2, V3)); |
| 152 | + } |
| 153 | + |
| 154 | + template <class A, uint32_t V0, uint32_t V1> |
| 155 | + XSIMD_INLINE batch<double, A> swizzle(batch<double, A> const& self, batch_constant<uint64_t, A, V0, V1>, requires_arch<avx_128>) noexcept |
| 156 | + { |
| 157 | + return _mm_permute_pd(self, detail::mod_shuffle(V0, V1)); |
| 158 | + } |
| 159 | + |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +#endif |
0 commit comments