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 fast_exp2 with MSVC and sse4.2 #3804

Merged
Merged
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
14 changes: 13 additions & 1 deletion src/include/OpenImageIO/fmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,19 @@ OIIO_FORCEINLINE OIIO_HOSTDEVICE T fast_exp2 (const T& xval) {
r = madd(x, r, kD);
r = madd(x, r, kE);
r = madd(x, r, one);
return bitcast_to_float (bitcast_to_int(r) + (m << 23));

lgritz marked this conversation as resolved.
Show resolved Hide resolved
// Original code was:
// return bitcast_to_float (bitcast_to_int(r) + (m << 23));
// This was producing the wrong results when called via `sRGB_to_linear()`
// and `linear_to_sRGB()` on some Windows MSVC builds.
// We found that it was fixed by using a temporary intN, as below.
// Presumed to be an optimizer bug in MSVC versions 16.11.x
// and earlier.
// See PR #3804

intN i = bitcast_to_int(r);
T f = bitcast_to_float(i + (m << 23));
return f;
#else
T r;
for (int i = 0; i < r.elements; ++i)
Expand Down