Skip to content

Commit c0ee586

Browse files
authored
[SYCL][libdevice] Keep sign bit of result for std::sin(-0) (#17440)
For input '-0', __spirv_ocl_sin returns +0 for float and returns -0 for double, MSVC complex math implementation does depend on this, discarding the signbit for sin(-0) will lead to some corner case failures in exp(std::complex<float>) e2e tests. This patch is a workaround for the issue. --------- Signed-off-by: jinge90 <[email protected]>
1 parent f1992a0 commit c0ee586

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

libdevice/fallback-cmath.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,13 @@ float __devicelib_fmaf(float x, float y, float z) {
168168
return __spirv_ocl_fma(x, y, z);
169169
}
170170

171+
#if defined(__SPIR__) || defined(__SPIRV__)
172+
DEVICE_EXTERN_C_INLINE
173+
float __devicelib_sinf(float x) { return (x == 0.0f) ? x : __spirv_ocl_sin(x); }
174+
#else
171175
DEVICE_EXTERN_C_INLINE
172176
float __devicelib_sinf(float x) { return __spirv_ocl_sin(x); }
177+
#endif
173178

174179
DEVICE_EXTERN_C_INLINE
175180
float __devicelib_cosf(float x) { return __spirv_ocl_cos(x); }

0 commit comments

Comments
 (0)