diff --git a/libdevice/msvc_math.cpp b/libdevice/msvc_math.cpp index 5ca0b5608ffa7..c4619dacdce01 100644 --- a/libdevice/msvc_math.cpp +++ b/libdevice/msvc_math.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#if defined(__SPIR__) || defined(__SPIRV__) || defined(__NVPTX__) +#if defined(__SPIR__) || defined(__SPIRV__) #include "device.h" #include @@ -281,4 +281,4 @@ float _FSinh(float x, float y) { // compute y * sinh(x), |y| <= 1 return neg ? -x : x; } } -#endif // __SPIR__ || __SPIRV__ || __NVPTX__ +#endif // __SPIR__ || __SPIRV__ diff --git a/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp b/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp index fe08d374ca51c..4dee54a8006c5 100644 --- a/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp +++ b/sycl/include/sycl/stl_wrappers/__sycl_cmath_wrapper_impl.hpp @@ -16,8 +16,7 @@ // The 'sycl_device_only' attribute enables device-side overloading. #define __SYCL_DEVICE __attribute__((sycl_device_only, always_inline)) -#define __SYCL_DEVICE_C \ - extern "C" __attribute__((sycl_device_only, always_inline)) +#define __SYCL_DEVICE_C extern "C" __SYCL_DEVICE #include @@ -259,9 +258,16 @@ __SYCL_SPIRV_MAP_BINARY_C(nextafter); __SYCL_SPIRV_MAP_BINARY_C(copysign); /// Classification and comparison -// -// unsupported: fpclassify +__SYCL_DEVICE_C int fpclassify(float x) { + return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, + FP_ZERO, x); +} +__SYCL_DEVICE_C int fpclassify(double x) { + return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, + FP_ZERO, x); +} + // unsupported: isfinite // unsupported: isinf // unsupported: isnan @@ -460,7 +466,7 @@ template __SYCL_DEVICE __sycl_promote_t scalbn(T x, int exp) { __SYCL_SPIRV_MAP_BINARY_CXX(copysign); // Classification and comparison -// using ::fpclassify; +using ::fpclassify; // using ::isfinite; // using ::isgreater; // using ::isgreaterequal; @@ -482,11 +488,29 @@ _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif +#if defined(_WIN32) +__SYCL_DEVICE_C double _Cosh(double x, double y) { return cosh(x) * y; } +__SYCL_DEVICE_C float _FCosh(float x, float y) { return coshf(x) * y; } +__SYCL_DEVICE_C short _Dtest(double *p) { return fpclassify(*p); } +__SYCL_DEVICE_C short _FDtest(float *p) { return fpclassify(*p); } +__SYCL_DEVICE_C double _Sinh(double x, double y) { return sinh(x) * y; } +__SYCL_DEVICE_C float _FSinh(float x, float y) { return sinhf(x) * y; } +__SYCL_DEVICE_C short _Exp(double *px, double y, short eoff) { + return exp(*px) * ldexp(y, eoff); +} +__SYCL_DEVICE_C short _FExp(float *px, float y, short eoff) { + return exp(*px) * ldexp(y, eoff); +} +__SYCL_DEVICE_C float _hypotf(float x, float y) { return hypotf(x, y); } +__SYCL_DEVICE_C int _fdsign(float x) { return __builtin_signbit(x); } +__SYCL_DEVICE_C int _dsign(double x) { return __builtin_signbit(x); } +#endif // defined(_WIN32) + #undef __SYCL_SPIRV_MAP_BINARY_C #undef __SYCL_SPIRV_MAP_BINARY_CXX #undef __SYCL_SPIRV_MAP_UNARY_C #undef __SYCL_SPIRV_MAP_UNARY_CXX #undef __SYCL_DEVICE_C #undef __SYCL_DEVICE -#endif -#endif +#endif // __SYCL_DEVICE_ONLY__ +#endif // __SYCL_CMATH_WRAPPER_IMPL_HPP__ diff --git a/sycl/include/sycl/stl_wrappers/cmath b/sycl/include/sycl/stl_wrappers/cmath index 42b7e9cd3e642..b411eb7e81e81 100644 --- a/sycl/include/sycl/stl_wrappers/cmath +++ b/sycl/include/sycl/stl_wrappers/cmath @@ -8,6 +8,17 @@ #pragma once +#if defined(__SYCL_DEVICE_ONLY__) && defined(_WIN32) +#if defined(__NVPTX__) || defined(__AMDGCN__) +// Forward declare device _*dsign functions before including cmath to enable +// compilation of math functions defined in UCRT headers. +extern "C" __attribute__((sycl_device_only, always_inline)) int +_fdsign(float x); +extern "C" __attribute__((sycl_device_only, always_inline)) int +_dsign(double x); +#endif // defined(__NVPTX__) || defined(__AMDGCN__) +#endif // defined(__SYCL_DEVICE_ONLY__) && defined(_WIN32) + // Include real STL header - the next one from the include search // directories. #if defined(__has_include_next) diff --git a/sycl/test/self-contained-headers/lit.local.cfg b/sycl/test/self-contained-headers/lit.local.cfg index 30a1d3e1a195c..767afc0f1b74e 100644 --- a/sycl/test/self-contained-headers/lit.local.cfg +++ b/sycl/test/self-contained-headers/lit.local.cfg @@ -7,4 +7,8 @@ config.test_format = SYCLHeadersTest() # standalone. `os.path.join` is required here so the filtering works # cross-platform config.sycl_headers_xfail = [ + # FIXME: remove this rule when the header is moved to the clang project + os.path.join( + "sycl", "stl_wrappers", "__sycl_cmath_wrapper_impl.hpp" + ), ]