From: Peter Damianov <[email protected]> CRT_fp8.o and CRT_fp10.o select the x87 precision that _fpreset sets at program startup and for fesetenv(FE_DFL_ENV): 53 and 64 bits. Add CRT_fp4.o for 24 bits (single precision), with a matching __mingw_fe_dfl_env, so that GCC can link CRT_fp4.o, CRT_fp8.o and CRT_fp10.o for -mpc32, -mpc64 and -mpc80.
Like CRT_fp8.o, it is only built for x86. Add t_fesetenv_fp4, which runs t_fesetenv linked with CRT_fp4.o. Signed-off-by: Peter Damianov <[email protected]> --- mingw-w64-crt/Makefile.am | 7 +++- mingw-w64-crt/crt/CRT_fp4.c | 47 ++++++++++++++++++++++++ mingw-w64-crt/testcases/Makefile.am | 2 + mingw-w64-crt/testcases/t_fesetenv_fp4.c | 3 ++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 mingw-w64-crt/crt/CRT_fp4.c create mode 100644 mingw-w64-crt/testcases/t_fesetenv_fp4.c diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index f0bbc643c..f7ddef7ff 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -1447,7 +1447,8 @@ if !W32API crt32_DATA = \ lib32/crt1.o lib32/crt2.o lib32/crt1u.o lib32/crt2u.o lib32/dllcrt1.o lib32/dllcrt2.o \ lib32/CRT_fp8.o lib32/CRT_fp10.o lib32/txtmode.o lib32/binmode.o lib32/crtbegin.o lib32/crtend.o \ - lib32/gcrt0.o lib32/gcrt1.o lib32/gcrt2.o lib32/CRT_glob.o lib32/CRT_noglob.o + lib32/gcrt0.o lib32/gcrt1.o lib32/gcrt2.o lib32/CRT_glob.o lib32/CRT_noglob.o \ + lib32/CRT_fp4.o else crt32_DATA = endif @@ -1871,7 +1872,8 @@ if !W32API crt64_DATA = \ lib64/crt1.o lib64/crt2.o lib64/crt1u.o lib64/crt2u.o lib64/dllcrt1.o lib64/dllcrt2.o \ lib64/CRT_fp8.o lib64/CRT_fp10.o lib64/txtmode.o lib64/binmode.o lib64/crtbegin.o lib64/crtend.o \ - lib64/gcrt0.o lib64/gcrt1.o lib64/gcrt2.o lib64/CRT_glob.o lib64/CRT_noglob.o + lib64/gcrt0.o lib64/gcrt1.o lib64/gcrt2.o lib64/CRT_glob.o lib64/CRT_noglob.o \ + lib64/CRT_fp4.o else crt64_DATA = endif @@ -4583,6 +4585,7 @@ EXTRA_DIST += \ crt/crtdll.c \ crt/crtend.c \ crt/crtexe.c \ + crt/CRT_fp4.c \ crt/CRT_fp8.c \ crt/CRT_fp10.c \ crt/CRT_glob.c \ diff --git a/mingw-w64-crt/crt/CRT_fp4.c b/mingw-w64-crt/crt/CRT_fp4.c new file mode 100644 index 000000000..904877998 --- /dev/null +++ b/mingw-w64-crt/crt/CRT_fp4.c @@ -0,0 +1,47 @@ +/** + * 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. + */ + +/* Link this object to make program startup and fesetenv(FE_DFL_ENV) set + the x87 precision to 24 bits (single precision). */ + +#include <_mingw.h> +#include <fenv.h> +#include <float.h> + +/* FE_DFL_ENV as fegetenv encodes the state after this _fpreset (x87 + control word 0x007f, MXCSR 0x1f80). */ +const fenv_t __mingw_fe_dfl_env = { 0x3f3f203f, 0 }; + +extern void (* __MINGW_IMP_SYMBOL(_fpreset))(void); +void _fpreset (void); + +void _fpreset (void) +{ + (* __MINGW_IMP_SYMBOL(_fpreset))(); +#if defined(__i386__) + /* msvcrt _fpreset() on i386 changes the x87 precision to 53-bit, + * so change it to 24-bit */ + _control87(_PC_24, _MCW_PC); +#elif defined(__x86_64__) && !defined(__arm64ec__) + /* msvcrt _fpreset() on x86-64 does not touch the x87 FPU unit at all, + * so reset it now and change the default precision to 24-bit */ + static const unsigned short cw_24bit = 0x007F; + __asm__ __volatile__ ( + "fninit\n\t" + "fldcw %0" + : + : "m" (cw_24bit) + ); +#endif +} + +#ifdef __GNUC__ +void __attribute__ ((alias ("_fpreset"))) fpreset(void); +#else +void fpreset(void) { + _fpreset(); +} +#endif diff --git a/mingw-w64-crt/testcases/Makefile.am b/mingw-w64-crt/testcases/Makefile.am index 46ff37509..ae22367a6 100644 --- a/mingw-w64-crt/testcases/Makefile.am +++ b/mingw-w64-crt/testcases/Makefile.am @@ -214,6 +214,7 @@ endif if HOST_X86 testcase_progs += \ t_fesetenv_fp10 \ + t_fesetenv_fp4 \ t_fesetenv_fp8 endif @@ -259,6 +260,7 @@ t_global_ctors_LDFLAGS = $(AM_LDFLAGS) -static t_global_ctors_LDADD = @TARGET_LIBGCC_FILE_NAME@ $(LDADD) t_fesetenv_fp10_LDADD = -l:CRT_fp10.o $(LDADD) +t_fesetenv_fp4_LDADD = -l:CRT_fp4.o $(LDADD) t_fesetenv_fp8_LDADD = -l:CRT_fp8.o $(LDADD) # Compile t_intrinc in C99 mode diff --git a/mingw-w64-crt/testcases/t_fesetenv_fp4.c b/mingw-w64-crt/testcases/t_fesetenv_fp4.c new file mode 100644 index 000000000..7ed233b2f --- /dev/null +++ b/mingw-w64-crt/testcases/t_fesetenv_fp4.c @@ -0,0 +1,3 @@ +/* t_fesetenv linked with CRT_fp4.o (24-bit x87 precision). */ +#define EXPECT_X87_CW 0x007f +#include "t_fesetenv.c" -- 2.54.0.windows.1 _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
