Skip to content

Commit 80fd31a

Browse files
committed
Fix up more SSE implementations for nontrapping-fp
Fixes lto2.test_sse1 and test_sse2 with checks similar to
1 parent a90f70f commit 80fd31a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

system/include/compat/emmintrin.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef __emscripten_emmintrin_h__
88
#define __emscripten_emmintrin_h__
99

10+
#include <climits>
1011
#ifndef __SSE2__
1112
#error "SSE2 instruction set not enabled"
1213
#endif
@@ -1008,9 +1009,10 @@ static __inline__ long long __attribute__((__always_inline__, __nodebug__))
10081009
_mm_cvtsd_si64(__m128d __a)
10091010
{
10101011
// 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))
1012+
double e = __a[0];
1013+
if (isnan(e) || isinf(e)) return 0x8000000000000000LL;
1014+
long long x = llrint(e);
1015+
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabs(e) < 2.f) && e <= LLONG_MAX && e >= LLONG_MIN)
10141016
return x;
10151017
else
10161018
return 0x8000000000000000LL;

system/include/compat/xmmintrin.h

Lines changed: 7 additions & 5 deletions
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 <= (float)INT_MAX && e >= INT_MIN)
601602
return x;
602603
else
603604
return (int)0x80000000;
@@ -627,9 +628,10 @@ _mm_cvtsi64_ss(__m128 __a, long long __b)
627628
static __inline__ long long __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW))
628629
_mm_cvtss_si64(__m128 __a)
629630
{
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))
631+
float e = ((__f32x4)__a)[0];
632+
if (isnan(e) || isinf(e)) return 0x8000000000000000LL;
633+
long long x = llrintf(e);
634+
if ((x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(e) < 2.f)) && e <= (float)LLONG_MAX && e >= LLONG_MIN)
633635
return x;
634636
else
635637
return 0x8000000000000000LL;

0 commit comments

Comments
 (0)