On Tue, 11 Mar 2025, Jacek Caban wrote:

Instead of pseudo-pointers. This changes ABI.
---
mingw-w64-crt/misc/fesetenv.c | 32 ---------------------------
mingw-w64-headers/crt/fenv.h  | 41 ++++++++++++++++-------------------
2 files changed, 19 insertions(+), 54 deletions(-)

diff --git a/mingw-w64-crt/misc/fesetenv.c b/mingw-w64-crt/misc/fesetenv.c
index ac0dffe46..5a4426a30 100644
--- a/mingw-w64-crt/misc/fesetenv.c
+++ b/mingw-w64-crt/misc/fesetenv.c
@@ -24,38 +24,6 @@ int fesetenv(const fenv_t *env)
    unsigned int x87_cw, cw, x87_stat, stat;
    unsigned int mask = ~0u;

-#if defined(__i386__) || defined(__x86_64__)
-# if !defined(__arm64ec__)
-    if (env == FE_PC64_ENV)
-    {
-        /*
-         *  fninit initializes the control register to 0x37f,
-         *  the status register to zero and the tag word to 0FFFFh.
-         *  The other registers are unaffected.
-         */
-        __asm__ __volatile__ ("fninit");
-        return 0;
-    }
-# endif /* __arm64ec__ */
-    if (env == FE_PC53_ENV)
-    {
-        /*
-         * MS _fpreset() does same *except* it sets control word
-         * to 0x27f (53-bit precision).
-         * We force calling _fpreset in msvcrt.dll
-         */
-
-        (* __MINGW_IMP_SYMBOL(_fpreset))();
-        return 0;
-    }
-#endif /* defined(__i386__) || defined(__x86_64__) */
-    if (env == FE_DFL_ENV)
-    {
-        /* Use the choice made at app startup */
-        _fpreset();
-        return 0;
-    }
-
    if (!env->_Fe_ctl && !env->_Fe_stat) {
        _fpreset();
        return 0;
diff --git a/mingw-w64-headers/crt/fenv.h b/mingw-w64-headers/crt/fenv.h
index d5161757d..3ef5d5cb1 100644
--- a/mingw-w64-headers/crt/fenv.h
+++ b/mingw-w64-headers/crt/fenv.h
@@ -46,28 +46,6 @@

#ifndef RC_INVOKED

-#if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || 
defined(__aarch64__)
-
-/* If the default argument is used we use this value.  */
-#define FE_DFL_ENV  ((const fenv_t *) -1l)
-
-#else
-
-/*The C99 standard (7.6.9) allows us to define implementation-specific macros 
for
-  different fp environments */
-
-/* The default Intel x87 floating point environment (64-bit mantissa) */
-#define FE_PC64_ENV ((const fenv_t *)-1)
-
-/* The floating point environment set by MSVCRT _fpreset (53-bit mantissa) */
-#define FE_PC53_ENV ((const fenv_t *)-2)
-
-/* The FE_DFL_ENV macro is required by standard.
-  fesetenv will use the environment set at app startup.*/
-#define FE_DFL_ENV ((const fenv_t *) 0)
-
-#endif /* defined(_ARM_) || defined(__arm__) */
-
typedef struct
{
    unsigned long _Fe_ctl;
@@ -81,6 +59,25 @@ typedef unsigned long fexcept_t;
extern "C" {
#endif

+/* The FE_DFL_ENV macro is required by standard.
+  fesetenv will use the environment set at app startup.*/
+extern const __MINGW_SELECTANY fenv_t __mingw_fe_dfl_env = { 0, 0 };
+#define FE_DFL_ENV (&__mingw_fe_dfl_env)
+
+/*The C99 standard (7.6.9) allows us to define implementation-specific macros 
for
+  different fp environments */
+#if defined(__i386__) || defined(__x86_64__)
+
+/* The default Intel x87 floating point environment (64-bit mantissa) */
+extern const __MINGW_SELECTANY fenv_t __mingw_fe_pc64_env = { 0x3f3f003f, 0 };
+#define FE_PC64_ENV (&__mingw_fe_pc64_env)
+
+/* The floating point environment set by MSVCRT _fpreset (53-bit mantissa) */
+extern const __MINGW_SELECTANY fenv_t __mingw_fe_pc53_env = { 0x3f3f103f, 0 };
+#define FE_PC53_ENV (&__mingw_fe_pc53_env)

This kind of __MINGW_SELECTANY constant isn't in very wide use so far; are we certain that it works correctly with all toolchains?

As for the opaque bitmasks here; if I understand this correctly, it should be possible to express this with the public fenv.h FE_* constants, right? Although the crucial differing bit isn't one of the standard constants, but should be _PC_53 from float.h instead (which fenv_encode then should map into FENV_X_53)? The differing bit, 0x1000, seems wrong though - _PC_53 is 0x10000, while FENV_X_53 indeed is 0x1000.

Or am I missing something here?

Secondly, it would be nice to include an explanation about why we want to do this change. It seems mostly reasonable, but a few words about why you're doing it would be good.

// Martin



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to