diff options
author | Marat Dukhan <maratek@google.com> | 2020-05-14 01:22:54 -0700 |
---|---|---|
committer | Marat Dukhan <maratek@google.com> | 2020-05-14 01:22:54 -0700 |
commit | 4dfe081cf6bcd15db339cf2680b9281b8451eeb3 (patch) | |
tree | 163fb25e56cc7dea72ff60812fb7023d961b08cf | |
parent | 3c54eacb74f6f5e39077300c5564156c424d77ba (diff) | |
download | FP16-4dfe081cf6bcd15db339cf2680b9281b8451eeb3.tar.gz |
Optimized FP16 bitcasts for MSVC on ARM/ARM64
-rw-r--r-- | include/fp16/bitcasts.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/fp16/bitcasts.h b/include/fp16/bitcasts.h index 26a755c..86a4e22 100644 --- a/include/fp16/bitcasts.h +++ b/include/fp16/bitcasts.h @@ -8,6 +8,14 @@ #include <stdint.h> #endif +#if defined(__INTEL_COMPILER) + #include <immintrin.h> +#endif + +#if defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64)) + #include <intrin.h> +#endif + static inline float fp32_from_bits(uint32_t w) { #if defined(__OPENCL_VERSION__) @@ -16,6 +24,8 @@ static inline float fp32_from_bits(uint32_t w) { return __uint_as_float((unsigned int) w); #elif defined(__INTEL_COMPILER) return _castu32_f32(w); +#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64)) + return _CopyFloatFromInt32((__int32) w); #else union { uint32_t as_bits; @@ -32,6 +42,8 @@ static inline uint32_t fp32_to_bits(float f) { return (uint32_t) __float_as_uint(f); #elif defined(__INTEL_COMPILER) return _castf32_u32(f); +#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64)) + return (uint32_t) _CopyInt32FromFloat(f); #else union { float as_value; @@ -48,6 +60,8 @@ static inline double fp64_from_bits(uint64_t w) { return __longlong_as_double((long long) w); #elif defined(__INTEL_COMPILER) return _castu64_f64(w); +#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64)) + return _CopyDoubleFromInt64((__int64) w); #else union { uint64_t as_bits; @@ -64,6 +78,8 @@ static inline uint64_t fp64_to_bits(double f) { return (uint64_t) __double_as_longlong(f); #elif defined(__INTEL_COMPILER) return _castf64_u64(f); +#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64)) + return (uint64_t) _CopyInt64FromDouble(f); #else union { double as_value; |