Skip to content

Commit a9a72d6

Browse files
committed
Fix lto2.test_avx_nontrapping
Followup to emscripten-core#22893
1 parent 2e84cfd commit a9a72d6

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ jobs:
544544
test_targets: "
545545
lto2.test_dylink_syslibs_all
546546
lto2.test_float_builtins
547+
lto2.test_avx_nontrapping
547548
lto0.test_exceptions_allowed_uncaught
548549
lto0.test_longjmp_standalone_standalone
549550
lto0.test_embind_i64_val

system/include/compat/emmintrin.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,9 @@ _mm_cvtpd_epi32(__m128d __a)
383383
int m[2];
384384
for(int i = 0; i < 2; ++i)
385385
{
386-
int x = lrint(__a[i]);
387-
if (x != 0 || fabs(__a[i]) < 2.0)
386+
double e = __a[i];
387+
int x = lrint(e);
388+
if ((x != 0 || fabs(e) < 2.0) && !isinf(e) && e <= LLONG_MAX && e >= LLONG_MIN)
388389
m[i] = (int)x;
389390
else
390391
m[i] = (int)0x80000000;
@@ -396,8 +397,10 @@ static __inline__ int __attribute__((__always_inline__, __nodebug__))
396397
_mm_cvtsd_si32(__m128d __a)
397398
{
398399
// TODO: OPTIMIZE!
399-
int x = lrint(__a[0]);
400-
if (x != 0 || fabs(__a[0]) < 2.0)
400+
double e = __a[0];
401+
if (isinf(e) || e > LLONG_MAX || e < LLONG_MIN) return (int)0x80000000;
402+
int x = lrint(e);
403+
if ((x != 0 || fabs(e)) < 2.0 && e <= LLONG_MAX && e >= LLONG_MIN)
401404
return (int)x;
402405
else
403406
return (int)0x80000000;
@@ -1045,8 +1048,9 @@ _mm_cvtps_epi32(__m128 __a)
10451048
} u;
10461049
for(int i = 0; i < 4; ++i)
10471050
{
1048-
int x = lrint(__a[i]);
1049-
if (x != 0 || fabs(__a[i]) < 2.0)
1051+
double e = __a[i];
1052+
int x = lrint(e);
1053+
if ((x != 0 || fabs(e) < 2.0) && !isinf(e) && e <= LLONG_MAX && e >= LLONG_MIN)
10501054
u.x[i] = x;
10511055
else
10521056
u.x[i] = (int)0x80000000;

0 commit comments

Comments
 (0)