-
Notifications
You must be signed in to change notification settings - Fork 69
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
Cody-Waite argument reduction for trigonometric functions #4112
Conversation
numerics/sin_cos.cpp
Outdated
x_reduced.error = 0; | ||
quadrant = 0; | ||
} else if (x <= π_over_2_threshold && x >= -π_over_2_threshold) { | ||
std::int64_t const n = _mm_cvtsd_si64(_mm_set_sd(x * (2 / π))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment noting that it so happens that 2 / π is correctly rounded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment explaining why we don't care too much about the rounding here.
numerics/sin_cos.cpp
Outdated
quadrant = 0; | ||
} else if (x <= π_over_2_threshold && x >= -π_over_2_threshold) { | ||
std::int64_t const n = _mm_cvtsd_si64(_mm_set_sd(x * (2 / π))); | ||
double const n_double = static_cast<double>(n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this faster than computing it using _mm_floor_sd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually significantly faster, shaving 7 cycles on Sin
and 5 on Cos
. The code is rather ugly, though. Updated the benchmark numbers.
Benchmarks:
#1760.