diff --git a/src/TypeSupport.h b/src/TypeSupport.h index e474bd5..739b05c 100644 --- a/src/TypeSupport.h +++ b/src/TypeSupport.h @@ -17,14 +17,14 @@ #ifndef YUV_SRC_TYPESUPPORT_H_ #define YUV_SRC_TYPESUPPORT_H_ -#include "hwy/base.h" +#include "hwy/highway.h" #include #include #if defined(__GNUC__) || defined(__clang__) #define TYPE_INLINE static __attribute__((flatten)) inline #else -#define SPARKYUV_INLINE static inline +#define TYPE_INLINE static inline #endif #define ENABLE_TYPE_IS_F16(T) typename std::enable_if<(std::is_same::value), int>::type = 0 @@ -32,8 +32,12 @@ template TYPE_INLINE float LoadFloat(const T *src) { +#if HWY_HAVE_FLOAT16 + return static_cast(src[0]); +#else auto uSource = reinterpret_cast(src); return hwy::F32FromF16(hwy::float16_t::FromBits(uSource[0])); +#endif } template @@ -43,8 +47,12 @@ TYPE_INLINE float LoadFloat(const T *src) { template TYPE_INLINE V LoadPixel(const T *src) { +#if HWY_HAVE_FLOAT16 + return static_cast(src[0]); +#else auto uSource = reinterpret_cast(src); return static_cast(hwy::F32FromF16(hwy::float16_t::FromBits(uSource[0]))); +#endif } template @@ -59,27 +67,39 @@ TYPE_INLINE V TransformCast(T t) { template TYPE_INLINE V TransformCast(T t) { +#if HWY_HAVE_FLOAT16 + return static_cast(t); +#else return hwy::F16FromF32(t); +#endif } template TYPE_INLINE void StoreRoundedFloat(V *v, T t) { - v[0] = ::roundf(t); + v[0] = static_cast(::roundf(t)); } template TYPE_INLINE void StoreRoundedFloat(V *v, T t) { +#if HWY_HAVE_FLOAT16 + v[0] = static_cast(::roundf(t)); +#else reinterpret_cast(v)[0] = hwy::F16FromF32(::roundf(t)).bits; +#endif } template TYPE_INLINE void StoreFloat(V *v, T t) { - v[0] = roundf(t); + v[0] = static_cast(t); } template TYPE_INLINE void StoreFloat(V *v, T t) { +#if HWY_HAVE_FLOAT16 + v[0] = static_cast(t); +#else reinterpret_cast(v)[0] = hwy::F16FromF32(t).bits; +#endif } #endif //YUV_SRC_TYPESUPPORT_H_