zig/lib/libc/mingw/misc/fegetround.c
Andrew Kelley 49d1a4c562 move lib dirs to lib subdir
also start prefering NtDll API. so far:
 * NtQueryInformationFile
 * NtClose

adds a performance workaround for windows unicode conversion. but that
should probably be removed before merging
2019-07-15 17:54:50 -04:00

29 lines
1.0 KiB
C

/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <fenv.h>
/* 7.6.3.1
The fegetround function returns the value of the rounding direction
macro representing the current rounding direction. */
int
fegetround (void)
{
#if defined(_ARM_) || defined(__arm__)
fenv_t _env;
__asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
return (_env.__cw & (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO));
#elif defined(_ARM64_) || defined(__aarch64__)
unsigned __int64 fpcr;
__asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
return (fpcr & (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO));
#else
int _control;
__asm__ volatile ("fnstcw %0" : "=m" (*&_control));
return (_control & (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO));
#endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
}