fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
2e4d385
main
1/* SoX Resampler Library Copyright (c) 2007-16 robs@users.sourceforge.net 2* Licence for this file: LGPL v2.1 See LICENCE for details. */ 3 4#if !definedsoxr_rint_included 5#define soxr_rint_included 6 7#include "std-types.h" 8 9/* For x86, compiler-supplied versions of these functions (where available) 10* can have poor performance (e.g. mingw32), so prefer these asm versions: */ 11 12#if defined__GNUC__ && (defined__i386__ || defined__x86_64__ ) 13#define FPU_RINT32 14#define FPU_RINT16 15#define rint32D (a ,b ) __asm__ __volatile__("fistpl %0": "=m"(a): "t"(b): "st") 16#define rint16D (a ,b ) __asm__ __volatile__("fistps %0": "=m"(a): "t"(b): "st") 17#define rint32F rint32D 18#define rint16F rint16D 19#define FE_INVALID 1 20static __inlineint fe_test_invalid (void ) { 21int status_word ; 22 __asm__ __volatile__("fnstsw %%ax" :"=a" (status_word )); 23return status_word & FE_INVALID ; 24 } 25static __inlineint fe_clear_invalid (void ) { 26int32_t status [7 ]; 27 __asm__ __volatile__("fnstenv %0" :"=m" (status )); 28status [1 ] &= ~FE_INVALID ; 29 __asm__ __volatile__("fldenv %0" : :"m" (* status )); 30return 0 ; 31 } 32#elif defined_MSC_VER && defined_M_IX86 33#define FPU_RINT32 34#define FPU_RINT16 35#define rint_fn (N ,Y ,X ) \ 36 static __inline void N(Y *y, X x) {Y t; {__asm fld x __asm fistp t} *y=t;} 37rint_fn (rint32d ,int32_t ,double ) 38rint_fn (rint32f ,int32_t ,float ) 39rint_fn (rint16d ,int16_t ,double ) 40rint_fn (rint16f ,int16_t ,float ) 41#define rint32D (y ,x ) rint32d(&(y),x) 42#define rint32F (y ,x ) rint32f(&(y),x) 43#define rint16D (y ,x ) rint16d(&(y),x) 44#define rint16F (y ,x ) rint16f(&(y),x) 45#define FE_INVALID 1 46static __inlineint fe_test_invalid (void ) { 47short status_word ; 48 __asmfnstsw status_word 49return status_word & FE_INVALID ; 50 } 51static __inlineint fe_clear_invalid (void ) { 52int32_t status [7 ]; 53 __asmfnstenv status 54status [1 ] &= ~FE_INVALID ; 55 __asmfldenv status 56return 0 ; 57 } 58#elif defined_MSC_VER && defined_M_X64 59#include <emmintrin.h> 60#include <float.h> 61#define FPU_RINT32 62#define FPU_RINT16 63static __inlinevoid rint32d (int32_t * y ,double x ) { 64* y = _mm_cvtsd_si32 (_mm_load_sd (& x ));} 65static __inlinevoid rint32f (int32_t * y ,float x ) { 66* y = _mm_cvtss_si32 (_mm_load_ss (& x ));} 67static __inlinevoid rint16d (int16_t * y ,double x ) { 68x = x * 65536 + 32738 ;* y = (int16_t )(_mm_cvtsd_si32 (_mm_load_sd (& x )) >>16 );} 69#define rint32D (y ,x ) rint32d(&(y),x) 70#define rint32F (y ,x ) rint32f(&(y),x) 71#define rint16D (y ,x ) rint16d(&(y),x) 72#define rint16F (y ,x ) rint16d(&(y),(double)(x)) 73#define FE_INVALID 1 74#define fe_test_invalid () (_statusfp() & _SW_INVALID) 75#define fe_clear_invalid _clearfp/* Note: clears all. */ 76#elif HAVE_LRINT && LONG_MAX == 2147483647L && HAVE_FENV_H 77#include <math.h> 78#include <fenv.h> 79#define FPU_RINT32 80#define rint32D (y ,x ) ((y)=lrint(x)) 81#define rint32F (y ,x ) ((y)=lrintf(x)) 82#define fe_test_invalid () fetestexcept(FE_INVALID) 83#define fe_clear_invalid () feclearexcept(FE_INVALID) 84#endif 85 86#if !definedFPU_RINT32 87#define rint32D (y ,x ) ((y)=(int32_t)((x) < 0? x - .5 : x + .5)) 88#define rint32F (y ,x ) rint32D(y,(double)(x)) 89#endif 90 91#if !definedFPU_RINT16 92#define rint16D (y ,x ) ((y)=(int16_t)((x) < 0? x - .5 : x + .5)) 93#define rint16F (y ,x ) rint16D(y,(double)(x)) 94#endif 95 96static __inlineint32_t rint32 (double input ) { 97int32_t result ;rint32D (result ,input );return result ;} 98 99static __inlineint16_t rint16 (double input ) { 100int16_t result ;rint16D (result ,input );return result ;} 101 102#endif