From: Vijay Kiran Kamuju Subject: [PATCH] V3 msvcrt : add arm implementation for _control87 Message-Id: <20171112151359.4580-1-infyquest@gmail.com> Date: Sun, 12 Nov 2017 16:13:59 +0100 Signed-off-by: Vijay Kiran Kamuju --- dlls/msvcrt/math.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index b7288cf6cf..9b4298c89f 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -1233,6 +1233,48 @@ unsigned int CDECL _control87(unsigned int newval, unsigned int mask) if ((x86_cw ^ sse2_cw) & (MSVCRT__MCW_EM | MSVCRT__MCW_RC)) x86_cw |= MSVCRT__EM_AMBIGUOUS; return x86_cw; +#elif defined(__arm__) + unsigned long fpword; + unsigned int flags = 0; + + __asm__ __volatile__( "vmrs %0, fpscr" : "=r" (fpword) ); + if (fpword & 0x1) flags |= MSVCRT__EM_INVALID; + if (fpword & 0x2) flags |= MSVCRT__EM_ZERODIVIDE; + if (fpword & 0x4) flags |= MSVCRT__EM_OVERFLOW; + if (fpword & 0x8) flags |= MSVCRT__EM_UNDERFLOW; + if (fpword & 0x10) flags |= MSVCRT__EM_INEXACT; + if (fpword & 0x80) flags |= MSVCRT__EM_DENORMAL; + switch (fpword & 0xc00000) + { + case 0xc00000: flags |= MSVCRT__RC_UP|MSVCRT__RC_DOWN; break; + case 0x800000: flags |= MSVCRT__RC_DOWN; break; + case 0x400000: flags |= MSVCRT__RC_UP; break; + } + if (fpword & 0x1000000) flags |= MSVCRT__DN_FLUSH; + + TRACE( "arm flags=%08x newval=%08x mask=%08x\n", flags, newval, mask ); + if (mask) + { + flags = (flags & ~mask) | (newval & mask); + + /* Convert (masked) value back to fp word */ + fpword = 0; + if (flags & MSVCRT__EM_INVALID) fpword |= 0x1; + if (flags & MSVCRT__EM_ZERODIVIDE) fpword |= 0x2; + if (flags & MSVCRT__EM_OVERFLOW) fpword |= 0x4; + if (flags & MSVCRT__EM_UNDERFLOW) fpword |= 0x8; + if (flags & MSVCRT__EM_INEXACT) fpword |= 0x10; + if (flags & MSVCRT__EM_DENORMAL) fpword |= 0x80; + switch (flags & MSVCRT__MCW_RC) + { + case MSVCRT__RC_UP|MSVCRT__RC_DOWN: fpword |= 0xc00000; break; + case MSVCRT__RC_DOWN: fpword |= 0x800000; break; + case MSVCRT__RC_UP: fpword |= 0x200000; break; + } + if (flags & MSVCRT__DN_FLUSH) fpword |= 0x1000000; + __asm__ __volatile__( "vmsr fpscr, %0" : : "r" (fpword) ); + } + return flags; #else FIXME( "not implemented\n" ); return 0; -- 2.15.0