diff options
-rw-r--r-- | volk/lib/CMakeLists.txt | 5 | ||||
-rw-r--r-- | volk/tmpl/volk_cpu.tmpl.c | 19 |
2 files changed, 24 insertions, 0 deletions
diff --git a/volk/lib/CMakeLists.txt b/volk/lib/CMakeLists.txt index db8cca6cd..b39e3ad21 100644 --- a/volk/lib/CMakeLists.txt +++ b/volk/lib/CMakeLists.txt @@ -29,6 +29,11 @@ if(HAVE_INTRIN_H) add_definitions(-DHAVE_INTRIN_H) endif() +CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H) +if(HAVE_FENV_H) + add_definitions(-DHAVE_FENV_H) +endif() + CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H) if(HAVE_DLFCN_H) add_definitions(-DHAVE_DLFCN_H) diff --git a/volk/tmpl/volk_cpu.tmpl.c b/volk/tmpl/volk_cpu.tmpl.c index 1aa36d2bf..81fc679cb 100644 --- a/volk/tmpl/volk_cpu.tmpl.c +++ b/volk/tmpl/volk_cpu.tmpl.c @@ -149,10 +149,29 @@ static int i_can_has_$arch.name (void) { #end for +#if defined(HAVE_FENV_H) + #include <fenv.h> + static inline void set_float_rounding(void){ + fesetround(FE_TONEAREST); + } +#elif defined(_MSC_VER) + #include <float.h> + static inline void set_float_rounding(void){ + unsigned int cwrd; + _controlfp_s(&cwrd, 0, 0); + _controlfp_s(&cwrd, _RC_NEAR, _MCW_RC); + } +#else + static inline void set_float_rounding(void){ + //do nothing + } +#endif + void volk_cpu_init() { #for $arch in $archs volk_cpu.has_$arch.name = &i_can_has_$arch.name; #end for + set_float_rounding(); } unsigned int volk_get_lvarch() { |