Skip to content

BUG, SIMD: Fix rounding large numbers on SSE2#22750

Merged
seberg merged 1 commit intonumpy:mainfrom
seiko2plus:issue_22170
Dec 7, 2022
Merged

BUG, SIMD: Fix rounding large numbers on SSE2#22750
seberg merged 1 commit intonumpy:mainfrom
seiko2plus:issue_22170

Conversation

@seiko2plus
Copy link
Copy Markdown
Member

@seiko2plus seiko2plus commented Dec 6, 2022

closes #22170

Before SSE41, there were no native instructions for rounding
operations on double precision. We usually emulate it by assuming
that the MXCR register is set to rounding, adding a
large number 2^52 to X and then subtracting it back to
eliminate any excess precision as long as |X| is less than 2^52
otherwise returns X.

The current emulated intrinsics npyv_[rint, floor, ceil, trunc]_f64
was not checking whether |x| equal or large 2^52 which leads
to losing accuracy on large numbers.

  Before SSE41, there were no native instructions for rounding
  operations on double precision. We usually emulate it by assuming
  that the `MXCR` register is set to rounding, adding a
  large number `2^52` to `X` and then subtracting it back to
  eliminate any excess precision as long as `|X|` is less than `2^52`
  otherwise returns `X.`

  The current emulated intrinics `npyv_[rint,floor, ceil, trunc]_f64`
  was not checking whether `|x|` equal or large `2^52` which leads
  to losing accuracy on large numbers.
@seiko2plus seiko2plus changed the title BUG, SIMD: Fix rounding large numbers >= 2^52 on SSE2 BUG, SIMD: Fix rounding large numbers on SSE2 Dec 6, 2022
@seiko2plus seiko2plus added 00 - Bug component: SIMD Issues in SIMD (fast instruction sets) code or machinery labels Dec 6, 2022
@seiko2plus seiko2plus marked this pull request as ready for review December 7, 2022 02:10
@seberg
Copy link
Copy Markdown
Member

seberg commented Dec 7, 2022

LGTM, thanks Sayed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug component: SIMD Issues in SIMD (fast instruction sets) code or machinery

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: test_rint_big_int fails on Core 2 Duo CPU due to precision

3 participants