about summary refs log tree commit diff stats
path: root/src/emu/x64run0f.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-04-06 11:28:47 +0200
committerptitSeb <sebastien.chev@gmail.com>2023-04-06 11:28:47 +0200
commit086daef49471bd5f8abecaf618bfdaee50ae729c (patch)
treec47f19e8ef84c5ab786d171d52a63092b3e010ed /src/emu/x64run0f.c
parent6898df1c862cfdaaa6f3ed502aa7abb79e4accee (diff)
downloadbox64-086daef49471bd5f8abecaf618bfdaee50ae729c.tar.gz
box64-086daef49471bd5f8abecaf618bfdaee50ae729c.zip
Added back some isnan testing to integer conversion (converting a nan, infinite or overflow value to int is UB, and so should be avoided for max cross platform compatibility)
Diffstat (limited to 'src/emu/x64run0f.c')
-rw-r--r--src/emu/x64run0f.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/emu/x64run0f.c b/src/emu/x64run0f.c
index 7c30a086..8cd5b312 100644
--- a/src/emu/x64run0f.c
+++ b/src/emu/x64run0f.c
@@ -212,12 +212,12 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
             GETEX(0);

             GETGM;

             tmp64s = EX->f[1];

-            if (tmp64s==(int32_t)tmp64s)

+            if (tmp64s==(int32_t)tmp64s && !isnanf(EX->f[1]))

                 GM->sd[1] = (int32_t)tmp64s;

             else

                 GM->sd[1] = INT32_MIN;

             tmp64s = EX->f[0];

-            if (tmp64s==(int32_t)tmp64s)

+            if (tmp64s==(int32_t)tmp64s && !isnanf(EX->f[0]))

                 GM->sd[0] = (int32_t)tmp64s;

             else

                 GM->sd[0] = INT32_MIN;

@@ -228,20 +228,23 @@ uintptr_t Run0F(x64emu_t *emu, rex_t rex, uintptr_t addr, int *step)
             GETEX(0);

             GETGM;

             for(int i=1; i>=0; --i) {

-                switch(emu->mxcsr.f.MXCSR_RC) {

-                    case ROUND_Nearest:

-                        tmp64s = nearbyintf(EX->f[i]);

-                        break;

-                    case ROUND_Down:

-                        tmp64s = floorf(EX->f[i]);

-                        break;

-                    case ROUND_Up:

-                        tmp64s = ceilf(EX->f[i]);

-                        break;

-                    case ROUND_Chop:

-                        tmp64s = EX->f[i];

-                        break;

-                }

+                if(isnanf(EX->f[i]))

+                    tmp64s = INT32_MIN;

+                else

+                    switch(emu->mxcsr.f.MXCSR_RC) {

+                        case ROUND_Nearest:

+                            tmp64s = nearbyintf(EX->f[i]);

+                            break;

+                        case ROUND_Down:

+                            tmp64s = floorf(EX->f[i]);

+                            break;

+                        case ROUND_Up:

+                            tmp64s = ceilf(EX->f[i]);

+                            break;

+                        case ROUND_Chop:

+                            tmp64s = EX->f[i];

+                            break;

+                    }

                 if (tmp64s==(int32_t)tmp64s)

                     GM->sd[i] = (int32_t)tmp64s;

                 else