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