Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up more SSE implementations for nontrapping-fp #22931

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions system/include/compat/emmintrin.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,7 @@ _mm_cvttsd_si32(__m128d __a)
{
// TODO: OPTIMIZE!
float elem = __a[0];
if (isnan(elem) || elem > INT_MAX || elem < INT_MIN) return (int)0x80000000;
if (lrint(elem) != 0 || fabs(elem) < 2.0)
if ((lrint(elem) != 0 || fabs(elem) < 2.0) && !isnanf(elem) && elem <= INT_MAX && elem >= INT_MIN)
// Use the trapping instruction here since we have explicit bounds checks
// above.
return __builtin_wasm_trunc_s_i32_f32(elem);
Expand Down Expand Up @@ -1008,9 +1007,10 @@ static __inline__ long long __attribute__((__always_inline__, __nodebug__))
_mm_cvtsd_si64(__m128d __a)
{
// TODO: optimize
if (isnan(__a[0]) || isinf(__a[0])) return 0x8000000000000000LL;
long long x = llrint(__a[0]);
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabs(__a[0]) < 2.f))
double e = __a[0];
if (isnan(e) || isinf(e)) return 0x8000000000000000LL;
long long x = llrint(e);
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabs(e) < 2.f) && e <= LLONG_MAX && e >= LLONG_MIN)
return x;
else
return 0x8000000000000000LL;
Expand Down
17 changes: 8 additions & 9 deletions system/include/compat/xmmintrin.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,9 @@ _mm_cvtsi32_ss(__m128 __a, int __b)

static __inline__ int __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW)) _mm_cvtss_si32(__m128 __a)
{
int x = lrint(((__f32x4)__a)[0]);
if (x != 0 || fabsf(((__f32x4)__a)[0]) < 2.f)
float e = ((__f32x4)__a)[0];
int x = lrint(e);
if ((x != 0 || fabsf(e)) < 2.f && !isnan(e) && e <= INT_MAX && e >= INT_MIN)
return x;
else
return (int)0x80000000;
Expand All @@ -607,9 +608,8 @@ static __inline__ int __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SL
static __inline__ int __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW)) _mm_cvttss_si32(__m128 __a)
{
float e = ((__f32x4)__a)[0];
if (isnanf(e) || e > INT_MAX || e < INT_MIN) return (int)0x80000000;
int x = lrint(e);
if ((x != 0 || fabsf(e) < 2.f))
if ((x != 0 || fabsf(e) < 2.f) && !isnanf(e) && e <= INT_MAX && e >= INT_MIN)
return (int)e;
else
return (int)0x80000000;
Expand All @@ -627,9 +627,9 @@ _mm_cvtsi64_ss(__m128 __a, long long __b)
static __inline__ long long __attribute__((__always_inline__, __nodebug__, DIAGNOSE_SLOW))
_mm_cvtss_si64(__m128 __a)
{
if (isnan(((__f32x4)__a)[0]) || isinf(((__f32x4)__a)[0])) return 0x8000000000000000LL;
long long x = llrintf(((__f32x4)__a)[0]);
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(((__f32x4)__a)[0]) < 2.f))
float e = ((__f32x4)__a)[0];
long long x = llrintf(e);
if ((x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(e) < 2.f)) && !isnanf(e) && e <= LLONG_MAX && e >= LLONG_MIN)
return x;
else
return 0x8000000000000000LL;
Expand All @@ -639,9 +639,8 @@ static __inline__ long long __attribute__((__always_inline__, __nodebug__, DIAGN
_mm_cvttss_si64(__m128 __a)
{
float e = ((__f32x4)__a)[0];
if (isnan(e) || isinf(e) || e > LLONG_MAX || e < LLONG_MIN) return 0x8000000000000000LL;
long long x = llrintf(e);
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(e) < 2.f))
if (x != 0xFFFFFFFF00000000ULL && (x != 0 || fabsf(e) < 2.f) && !isnanf(e) && e <= LLONG_MAX && e >= LLONG_MIN)
return (long long)e;
else
return 0x8000000000000000LL;
Expand Down
Loading