Repository: numpy/numpy
File: numpy/_core/src/common/simd/simd.inc.hpp (C++)

Code before:
#error "This is not a standalone header. Include simd.hpp instead."
#endif

// NOTE: This file is included by simd.hpp multiple times with different namespaces
// so avoid including any headers here
// #define NPY_SIMDX 1  // uncomment to enable Highlighting

/**
 * Determines whether the specified lane type is supported by the SIMD extension.
 * Always defined as false when SIMD is not enabled, so it can be used in SFINAE.
 *
 * @tparam TLane The lane type to check for support.
 */
template <typename TLane>
constexpr bool kSupportLane = NPY_SIMDX != 0;

#if NPY_SIMDX
// Define lane type support based on Highway capabilities
template <>
constexpr bool kSupportLane<hwy::float16_t> = HWY_HAVE_FLOAT16 != 0;
template <>
constexpr bool kSupportLane<double> = HWY_HAVE_FLOAT64 != 0;

/// Represents an N-lane vector based on the specified lane type.
/// @tparam TLane The scalar type for each vector lane
template <typename TLane>
using Vec = hn::Vec<_Tag<TLane>>;

/// Represents a mask vector with boolean values or as a bitmask.
/// @tparam TLane The scalar type the mask corresponds to
template <typename TLane>
using Mask = hn::Mask<_Tag<TLane>>;

/// Unaligned load of a vector from memory.
template <typename TLane>
HWY_API Vec<TLane> LoadU(const TLane* ptr) {
    return hn::LoadU(_Tag<TLane>(), ptr);
}

/// Unaligned store of a vector to memory.
template <typename TLane>
HWY_API void StoreU(const Vec<TLane>& a, TLane* ptr) {
    hn::StoreU(a, _Tag<TLane>(), ptr);
}

/// Returns the number of vector lanes based on the lane type.
template <typename TLane>
HWY_API constexpr size_t Lanes(TLane tag = 0) {
    return hn::Lanes(_Tag<TLane>());
}


Review comment (suggestion):
It seems that we should consider _long double_:  
template <>
constexpr bool kSupportLane <_long double_> = false;

Code after:
#error "This is not a standalone header. Include simd.hpp instead."
#define NPY_HWY 1  // Prevent editors from graying out the happy branch
#endif

// Using anonymous namespace instead of inline to ensure each translation unit
// gets its own copy of constants based on local compilation flags
namespace {

// NOTE: This file is included by simd.hpp multiple times with different namespaces
// so avoid including any headers here

/**
 * Determines whether the specified lane type is supported by the SIMD extension.
 * Always defined as false when SIMD is not enabled, so it can be used in SFINAE.
 *
 * @tparam TLane The lane type to check for support.
 */
template <typename TLane>
constexpr bool kSupportLane = NPY_HWY != 0;

#if NPY_HWY
// Define lane type support based on Highway capabilities
template <>
constexpr bool kSupportLane<hwy::float16_t> = HWY_HAVE_FLOAT16 != 0;
template <>
constexpr bool kSupportLane<double> = HWY_HAVE_FLOAT64 != 0;
template <>
constexpr bool kSupportLane<long double> =
        HWY_HAVE_FLOAT64 != 0 && sizeof(long double) == sizeof(double);

/// Maximum number of lanes supported by the SIMD extension for the specified lane type.
template <typename TLane>
constexpr size_t kMaxLanes = HWY_MAX_LANES_D(_Tag<TLane>);

/// Represents an N-lane vector based on the specified lane type.
/// @tparam TLane The scalar type for each vector lane
template <typename TLane>
using Vec = hn::Vec<_Tag<TLane>>;

/// Represents a mask vector with boolean values or as a bitmask.
/// @tparam TLane The scalar type the mask corresponds to
template <typename TLane>
using Mask = hn::Mask<_Tag<TLane>>;

/// Unaligned load of a vector from memory.
template <typename TLane>
HWY_API Vec<TLane>
LoadU(const TLane *ptr)
{
    return hn::LoadU(_Tag<TLane>(), ptr);
}