From 24abd41a1422cbdb5adfa7985fee1df80f965d36 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Thu, 13 Mar 2025 15:24:46 +0800 Subject: [PATCH 1/2] [SYCL][libdevice] Keep siginbit of result for std::sin(-0) For input '-0', __spirv_ocl_sin returns +0 for float and returns -0 for double, although no definition exists in standard for -0 input, 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) e2e tests. This patch is a workaround for the issue. --- libdevice/fallback-cmath.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libdevice/fallback-cmath.cpp b/libdevice/fallback-cmath.cpp index 37b2250b4b6aa..4ef10af34d01e 100644 --- a/libdevice/fallback-cmath.cpp +++ b/libdevice/fallback-cmath.cpp @@ -168,8 +168,13 @@ float __devicelib_fmaf(float x, float y, float z) { return __spirv_ocl_fma(x, y, z); } +#if !defined(__NVPTX__) && !defined(__AMDGCN__) +DEVICE_EXTERN_C_INLINE +float __devicelib_sinf(float x) { return (x == 0.0f) ? x : __spirv_ocl_sin(x); } +#else DEVICE_EXTERN_C_INLINE float __devicelib_sinf(float x) { return __spirv_ocl_sin(x); } +#endif DEVICE_EXTERN_C_INLINE float __devicelib_cosf(float x) { return __spirv_ocl_cos(x); } From 131f5e957db1a22f337d774cb77f17f640487bb2 Mon Sep 17 00:00:00 2001 From: jinge90 Date: Mon, 17 Mar 2025 11:41:30 +0800 Subject: [PATCH 2/2] reverse macro Signed-off-by: jinge90 --- libdevice/fallback-cmath.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdevice/fallback-cmath.cpp b/libdevice/fallback-cmath.cpp index 4ef10af34d01e..97cb4cf67b4c7 100644 --- a/libdevice/fallback-cmath.cpp +++ b/libdevice/fallback-cmath.cpp @@ -168,7 +168,7 @@ float __devicelib_fmaf(float x, float y, float z) { return __spirv_ocl_fma(x, y, z); } -#if !defined(__NVPTX__) && !defined(__AMDGCN__) +#if defined(__SPIR__) || defined(__SPIRV__) DEVICE_EXTERN_C_INLINE float __devicelib_sinf(float x) { return (x == 0.0f) ? x : __spirv_ocl_sin(x); } #else