#pragma once #include #include namespace ircolib { static inline auto round_ceil(float f) { #ifdef SIMD_SUPPORT __m128 t = _mm_set_ss(f); t = _mm_round_ss(t, t, _MM_FROUND_TO_POS_INF); return _mm_cvtss_f32(t); #else return ceilf(f); #endif } static inline auto round_ceil(double f) { #ifdef SIMD_SUPPORT __m128d t = _mm_set_sd(f); t = _mm_round_sd(t, t, _MM_FROUND_TO_POS_INF); return _mm_cvtsd_f64(t); #else return ceil(f); #endif } static inline auto round_nearest(float f) { #ifdef SIMD_SUPPORT __m128 t = _mm_set_ss(f); t = _mm_round_ss(t, t, _MM_FROUND_TO_NEAREST_INT); return _mm_cvtss_f32(t); #else return roundf(f); #endif } static inline auto round_nearest(double f) { #ifdef SIMD_SUPPORT __m128d t = _mm_set_sd(f); t = _mm_round_sd(t, t, _MM_FROUND_TO_NEAREST_INT); return _mm_cvtsd_f64(t); #else return round(f); #endif } static inline auto round_current(float f) { #ifdef SIMD_SUPPORT auto t = _mm_set_ss(f); t = _mm_round_ss(t, t, _MM_FROUND_CUR_DIRECTION); return _mm_cvtss_f32(t); #else return rint(f); #endif } static inline auto round_current(double f) { #ifdef SIMD_SUPPORT auto t = _mm_set_sd(f); t = _mm_round_sd(t, t, _MM_FROUND_CUR_DIRECTION); return _mm_cvtsd_f64(t); #else return rint(f); #endif } static inline auto round_floor(float f) { #ifdef SIMD_SUPPORT __m128 t = _mm_set_ss(f); t = _mm_round_ss(t, t, _MM_FROUND_TO_NEG_INF); return _mm_cvtss_f32(t); #else return floor(f); #endif } static inline auto round_floor(double f) { #ifdef SIMD_SUPPORT __m128d t = _mm_set_sd(f); t = _mm_round_sd(t, t, _MM_FROUND_TO_NEG_INF); return _mm_cvtsd_f64(t); #else return floor(f); #endif } static inline auto round_trunc(float f) { #ifdef SIMD_SUPPORT __m128 t = _mm_set_ss(f); t = _mm_round_ss(t, t, _MM_FROUND_TO_ZERO); return _mm_cvtss_f32(t); #else return trunc(f); #endif } static inline auto round_trunc(double f) { #ifdef SIMD_SUPPORT __m128d t = _mm_set_sd(f); t = _mm_round_sd(t, t, _MM_FROUND_TO_ZERO); return _mm_cvtsd_f64(t); #else return trunc(f); #endif } } // namespace ircolib