From c7931cf4a91189dac85af5a4b09f853a8411e8e0 Mon Sep 17 00:00:00 2001 From: Andrew Hsieh Date: Tue, 26 May 2015 12:51:50 +0800 Subject: [PATCH] Fix fegetenv and fesetenv for arm Change-Id: Ied522151e7fd654c9d5bcf5647611538cfc15380 --- .../android-3/arch-arm/include/fenv.h | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/ndk/platforms/android-3/arch-arm/include/fenv.h b/ndk/platforms/android-3/arch-arm/include/fenv.h index a96f99ed8..126396065 100644 --- a/ndk/platforms/android-3/arch-arm/include/fenv.h +++ b/ndk/platforms/android-3/arch-arm/include/fenv.h @@ -66,14 +66,50 @@ extern const fenv_t __fe_dfl_env; static __inline int fegetenv(fenv_t* __envp) { fenv_t _fpscr; +#if !defined(__SOFTFP__) + #if !defined(__thumb__) || defined(__thumb2__) __asm__ __volatile__("vmrs %0,fpscr" : "=r" (_fpscr)); + #else + /* Switching from thumb1 to arm, do vmrs, then switch back */ + __asm__ __volatile__( + ".balign 4 \n\t" + "mov ip, pc \n\t" + "bx ip \n\t" + ".arm \n\t" + "vmrs %0, fpscr \n\t" + "add ip, pc, #1 \n\t" + "bx ip \n\t" + ".thumb \n\t" + : "=r" (_fpscr) : : "ip"); + #endif +#else + _fpscr = 0; +#endif *__envp = _fpscr; return 0; } static __inline int fesetenv(const fenv_t* __envp) { fenv_t _fpscr = *__envp; +#if !defined(__SOFTFP__) + #if !defined(__thumb__) || defined(__thumb2__) __asm__ __volatile__("vmsr fpscr,%0" : :"ri" (_fpscr)); + #else + /* Switching from thumb1 to arm, do vmsr, then switch back */ + __asm__ __volatile__( + ".balign 4 \n\t" + "mov ip, pc \n\t" + "bx ip \n\t" + ".arm \n\t" + "vmsr fpscr, %0 \n\t" + "add ip, pc, #1 \n\t" + "bx ip \n\t" + ".thumb \n\t" + : : "ri" (_fpscr) : "ip"); + #endif +#else + _fpscr = _fpscr; +#endif return 0; }