Skip to content

Commit 10f1a2c

Browse files
authored
Fix up more SSE implementations for nontrapping-fp (#22931)
Fixes lto2.test_sse1 and test_sse2 with checks similar to #22911 and #22893
1 parent f0cc3d0 commit 10f1a2c

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

system/include/compat/emmintrin.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,7 @@ _mm_cvttsd_si32(__m128d __a)
449449
{
450450
// TODO: OPTIMIZE!
451451
float elem = __a[0];
452-
if (isnan(elem) || elem > INT_MAX || elem < INT_MIN) return (int)0x80000000;
453-
if (lrint(elem) != 0 || fabs(elem) < 2.0)
452+
if ((lrint(elem) != 0 || fabs(elem) < 2.0) && !isnanf(elem) && elem <= INT_MAX && elem >= INT_MIN)
454453
// Use the trapping instruction here since we have explicit bounds checks
455454
// above.
456455
return __builtin_wasm_trunc_s_i32_f32(elem);
@@ -1008,9 +1007,10 @@ static __inline__ long long __attribute__((__always_inline__, __nodebug__))
10081007
_mm_cvtsd_si64(__m128d __a)
10091008
{
10101009
// TODO: optimize
1011-
if (isnan(__a[0]) || isinf(__a[0])) return 0x8000000000000000LL;
1012-
long long x = llrint(__a[0]);
1013-
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabs(__a[0]) < 2.f))
1010+
double e = __a[0];
1011+
if (isnan(e) || isinf(e)) return 0x8000000000000000LL;
1012+
long long x = llrint(e);
1013+
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabs(e) < 2.f) && e <= LLONG_MAX && e >= LLONG_MIN)
10141014
return x;
10151015
else
10161016
return 0x8000000000000000LL;

system/include/compat/xmmintrin.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,9 @@ _mm_cvtsi32_ss(__m128 __a, int __b)
596596

597597
static __inline__ int __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW)) _mm_cvtss_si32(__m128 __a)
598598
{
599-
int x = lrint(((__f32x4)__a)[0]);
600-
if (x != 0 || fabsf(((__f32x4)__a)[0]) < 2.f)
599+
float e = ((__f32x4)__a)[0];
600+
int x = lrint(e);
601+
if ((x != 0 || fabsf(e)) < 2.f && !isnan(e) && e <= INT_MAX && e >= INT_MIN)
601602
return x;
602603
else
603604
return (int)0x80000000;
@@ -607,9 +608,8 @@ static __inline__ int __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SL
607608
static __inline__ int __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW)) _mm_cvttss_si32(__m128 __a)
608609
{
609610
float e = ((__f32x4)__a)[0];
610-
if (isnanf(e) || e > INT_MAX || e < INT_MIN) return (int)0x80000000;
611611
int x = lrint(e);
612-
if ((x != 0 || fabsf(e) < 2.f))
612+
if ((x != 0 || fabsf(e) < 2.f) && !isnanf(e) && e <= INT_MAX && e >= INT_MIN)
613613
return (int)e;
614614
else
615615
return (int)0x80000000;
@@ -627,9 +627,9 @@ _mm_cvtsi64_ss(__m128 __a, long long __b)
627627
static __inline__ long long __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW))
628628
_mm_cvtss_si64(__m128 __a)
629629
{
630-
if (isnan(((__f32x4)__a)[0]) || isinf(((__f32x4)__a)[0])) return 0x8000000000000000LL;
631-
long long x = llrintf(((__f32x4)__a)[0]);
632-
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(((__f32x4)__a)[0]) < 2.f))
630+
float e = ((__f32x4)__a)[0];
631+
long long x = llrintf(e);
632+
if ((x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(e) < 2.f)) && !isnanf(e) && e <= LLONG_MAX && e >= LLONG_MIN)
633633
return x;
634634
else
635635
return 0x8000000000000000LL;
@@ -639,9 +639,8 @@ static __inline__ long long __attribute__((__always_inline__, __nodebug__, DIAGN
639639
_mm_cvttss_si64(__m128 __a)
640640
{
641641
float e = ((__f32x4)__a)[0];
642-
if (isnan(e) || isinf(e) || e > LLONG_MAX || e < LLONG_MIN) return 0x8000000000000000LL;
643642
long long x = llrintf(e);
644-
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(e) < 2.f))
643+
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(e) < 2.f) && !isnanf(e) && e <= LLONG_MAX && e >= LLONG_MIN)
645644
return (long long)e;
646645
else
647646
return 0x8000000000000000LL;

0 commit comments

Comments
 (0)