|
| 1 | +#ifndef NPY_SIMDX |
| 2 | +#error "This is not a standalone header. Include simd.hpp instead." |
| 3 | +#defineNPY_SIMDX1// Prevent editors from graying out the happy branch |
| 4 | +#endif |
| 5 | + |
| 6 | +// NOTE: This file is included by simd.hpp multiple times with different namespaces |
| 7 | +// so avoid including any headers here |
| 8 | + |
| 9 | +/** |
| 10 | + * Determines whether the specified lane type is supported by the SIMD extension. |
| 11 | + * Always defined as false when SIMD is not enabled, so it can be used in SFINAE. |
| 12 | + * |
| 13 | + * @tparam TLane The lane type to check for support. |
| 14 | +*/ |
| 15 | +template<typename TLane> |
| 16 | +constexprboolkSupportLane = NPY_SIMDX !=0; |
| 17 | + |
| 18 | +#if NPY_SIMDX |
| 19 | +// Define lane type support based on Highway capabilities |
| 20 | +template<> |
| 21 | +constexprboolkSupportLane<hwy::float16_t> = HWY_HAVE_FLOAT16 !=0; |
| 22 | +template<> |
| 23 | +constexprboolkSupportLane<double> = HWY_HAVE_FLOAT64 !=0; |
| 24 | +template<> |
| 25 | +constexprboolkSupportLane<longdouble> = |
| 26 | + HWY_HAVE_FLOAT64 !=0 &&sizeof(longdouble) ==sizeof(double); |
| 27 | + |
| 28 | +/// Maximum number of lanes supported by the SIMD extension for the specified lane type. |
| 29 | +template<typename TLane> |
| 30 | +constexprsize_tkMaxLanes = HWY_MAX_LANES_D(_Tag<TLane>); |
| 31 | + |
| 32 | +/// Represents an N-lane vector based on the specified lane type. |
| 33 | +/// @tparam TLane The scalar type for each vector lane |
| 34 | +template<typename TLane> |
| 35 | +using Vec = hn::Vec<_Tag<TLane>>; |
| 36 | + |
| 37 | +/// Represents a mask vector with boolean values or as a bitmask. |
| 38 | +/// @tparam TLane The scalar type the mask corresponds to |
| 39 | +template<typename TLane> |
| 40 | +using Mask = hn::Mask<_Tag<TLane>>; |
| 41 | + |
| 42 | +/// Unaligned load of a vector from memory. |
| 43 | +template<typename TLane> |
| 44 | +HWY_API Vec<TLane> |
| 45 | +LoadU(const TLane *ptr) |
| 46 | +{ |
| 47 | +returnhn::LoadU(_Tag<TLane>(), ptr); |
| 48 | +} |
| 49 | + |
| 50 | +template<typename TLane> |
| 51 | +HWY_API Vec<TLane> |
| 52 | +LoadN(const TLane *ptr,size_t n) |
| 53 | +{ |
| 54 | +returnhn::LoadN(_Tag<TLane>(), ptr, n); |
| 55 | +} |
| 56 | + |
| 57 | +template<typename TLane> |
| 58 | +HWY_API Vec<TLane> |
| 59 | +LoadNOr(Vec<TLane> no,const TLane *ptr,size_t n) |
| 60 | +{ |
| 61 | +returnhn::LoadNOr(no, _Tag<TLane>(), ptr, n); |
| 62 | +} |
| 63 | + |
| 64 | +/// Unaligned store of a vector to memory. |
| 65 | +template<typename TLane> |
| 66 | +HWY_APIvoid |
| 67 | +StoreU(const Vec<TLane> &a, TLane *ptr) |
| 68 | +{ |
| 69 | +hn::StoreU(a, _Tag<TLane>(), ptr); |
| 70 | +} |
| 71 | + |
| 72 | +template<typename TLane> |
| 73 | +HWY_APIvoid |
| 74 | +StoreN(const Vec<TLane> &a, TLane *ptr,size_t n) |
| 75 | +{ |
| 76 | +hn::StoreN(a, _Tag<TLane>(), ptr, n); |
| 77 | +} |
| 78 | + |
| 79 | +/// Returns the number of vector lanes based on the lane type. |
| 80 | +template<typename TLane> |
| 81 | +HWY_APIconstexprsize_t |
| 82 | +Lanes(TLane tag =0) |
| 83 | +{ |
| 84 | +returnhn::Lanes(_Tag<TLane>()); |
| 85 | +} |
| 86 | + |
| 87 | +/// Returns an uninitialized N-lane vector. |
| 88 | +template<typename TLane> |
| 89 | +HWY_API Vec<TLane> |
| 90 | +Undefined(TLane tag =0) |
| 91 | +{ |
| 92 | +returnhn::Undefined(_Tag<TLane>()); |
| 93 | +} |
| 94 | + |
| 95 | +/// Returns N-lane vector with all lanes equal to zero. |
| 96 | +template<typename TLane> |
| 97 | +HWY_API Vec<TLane> |
| 98 | +Zero(TLane tag =0) |
| 99 | +{ |
| 100 | +returnhn::Zero(_Tag<TLane>()); |
| 101 | +} |
| 102 | + |
| 103 | +/// Returns N-lane vector with all lanes equal to the given value of type `TLane`. |
| 104 | +template<typename TLane> |
| 105 | +HWY_API Vec<TLane> |
| 106 | +Set(TLane val) |
| 107 | +{ |
| 108 | +returnhn::Set(_Tag<TLane>(), val); |
| 109 | +} |
| 110 | + |
| 111 | +/// Converts a mask to a vector based on the specified lane type. |
| 112 | +template<typename TLane,typename TMask> |
| 113 | +HWY_API Vec<TLane> |
| 114 | +VecFromMask(const TMask &m) |
| 115 | +{ |
| 116 | +returnhn::VecFromMask(_Tag<TLane>(), m); |
| 117 | +} |
| 118 | + |
| 119 | +/// Convert (Reinterpret) an N-lane vector to a different type without modifying the |
| 120 | +/// underlying data. |
| 121 | +template<typename TLaneTo,typename TVec> |
| 122 | +HWY_API Vec<TLaneTo> |
| 123 | +BitCast(const TVec &v) |
| 124 | +{ |
| 125 | +returnhn::BitCast(_Tag<TLaneTo>(), v); |
| 126 | +} |
| 127 | + |
| 128 | +// Import common Highway intrinsics |
| 129 | +using hn::Abs; |
| 130 | +using hn::Add; |
| 131 | +using hn::And; |
| 132 | +using hn::AndNot; |
| 133 | +using hn::Div; |
| 134 | +using hn::Eq; |
| 135 | +using hn::Ge; |
| 136 | +using hn::Gt; |
| 137 | +using hn::Le; |
| 138 | +using hn::Lt; |
| 139 | +using hn::Max; |
| 140 | +using hn::Min; |
| 141 | +using hn::Mul; |
| 142 | +using hn::Or; |
| 143 | +using hn::Sqrt; |
| 144 | +using hn::Sub; |
| 145 | +using hn::Xor; |
| 146 | + |
| 147 | +#endif// NPY_SIMDX |