From: George Kyriazis Date: Fri, 13 Apr 2018 21:14:42 +0000 (-0500) Subject: swr/rast: Add some SIMD_T utility functors X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fa4ab7910e3492b09b40e00c0b82a7bb1bae03d0;p=mesa.git swr/rast: Add some SIMD_T utility functors VecEqual and VecHash Reviewed-by: Bruce Cherniak --- diff --git a/src/gallium/drivers/swr/rasterizer/common/simdlib.hpp b/src/gallium/drivers/swr/rasterizer/common/simdlib.hpp index 4114645d92e..24cf27d4dbc 100644 --- a/src/gallium/drivers/swr/rasterizer/common/simdlib.hpp +++ b/src/gallium/drivers/swr/rasterizer/common/simdlib.hpp @@ -580,3 +580,69 @@ template using Double = typename SIMD_T::Double; template using Integer = typename SIMD_T::Integer; template using Vec4 = typename SIMD_T::Vec4; template using Mask = typename SIMD_T::Mask; + +template +struct SIMDVecEqual +{ + INLINE bool operator () (Integer a, Integer b) const + { + Integer c = SIMD_T::xor_si(a, b); + return SIMD_T::testz_si(c, c); + } + + INLINE bool operator () (Float a, Float b) const + { + return this->operator()(SIMD_T::castps_si(a), SIMD_T::castps_si(b)); + } + + INLINE bool operator () (Double a, Double b) const + { + return this->operator()(SIMD_T::castpd_si(a), SIMD_T::castpd_si(b)); + } +}; + +template +struct SIMDVecHash +{ + INLINE uint32_t operator ()(Integer val) const + { +#if defined(_WIN64) || !defined(_WIN32) // assume non-Windows is always 64-bit + static_assert(sizeof(void*) == 8, "This path only meant for 64-bit code"); + + uint64_t crc32 = 0; + const uint64_t *pData = reinterpret_cast(&val); + static const uint32_t loopIterations = sizeof(val) / sizeof(void*); + static_assert(loopIterations * sizeof(void*) == sizeof(val), "bad vector size"); + + for (uint32_t i = 0; i < loopIterations; ++i) + { + crc32 = _mm_crc32_u64(crc32, pData[i]); + } + + return static_cast(crc32); +#else + static_assert(sizeof(void*) == 4, "This path only meant for 32-bit code"); + + uint32_t crc32 = 0; + const uint32_t *pData = reinterpret_cast(&val); + static const uint32_t loopIterations = sizeof(val) / sizeof(void*); + static_assert(loopIterations * sizeof(void*) == sizeof(val), "bad vector size"); + + for (uint32_t i = 0; i < loopIterations; ++i) + { + crc32 = _mm_crc32_u32(crc32, pData[i]); + } + + return crc32; +#endif + }; + + INLINE uint32_t operator ()(Float val) const + { + return operator()(SIMD_T::castps_si(val)); + }; + INLINE uint32_t operator ()(Double val) const + { + return operator()(SIMD_T::castpd_si(val)); + } +};