diff --git a/libdevice/cmath_wrapper.cpp b/libdevice/cmath_wrapper.cpp index 1a5cec90d28cd..d59395b2d0994 100644 --- a/libdevice/cmath_wrapper.cpp +++ b/libdevice/cmath_wrapper.cpp @@ -198,9 +198,7 @@ float nearbyintf(float x) { return __nv_nearbyintf(x); } extern "C" SYCL_EXTERNAL float __nv_rintf(float); DEVICE_EXTERN_C_INLINE float rintf(float x) { return __nv_rintf(x); } -#endif // __NVPTX__ - -#ifdef __AMDGCN__ +#elif defined(__AMDGCN__) extern "C" SYCL_EXTERNAL float __ocml_nearbyint_f32(float); DEVICE_EXTERN_C_INLINE float nearbyintf(float x) { return __ocml_nearbyint_f32(x); } @@ -208,6 +206,9 @@ float nearbyintf(float x) { return __ocml_nearbyint_f32(x); } extern "C" SYCL_EXTERNAL float __ocml_rint_f32(float); DEVICE_EXTERN_C_INLINE float rintf(float x) { return __ocml_rint_f32(x); } -#endif // __AMDGCN__ +#else +DEVICE_EXTERN_C_INLINE +float rintf(float x) { return __spirv_ocl_rint(x); } +#endif #endif // __SPIR__ || __SPIRV__ || __NVPTX__ || __AMDGCN__ diff --git a/libdevice/cmath_wrapper_fp64.cpp b/libdevice/cmath_wrapper_fp64.cpp index 8d9c70ea0fe69..720982799ea71 100644 --- a/libdevice/cmath_wrapper_fp64.cpp +++ b/libdevice/cmath_wrapper_fp64.cpp @@ -188,9 +188,7 @@ double nearbyint(double x) { return __nv_nearbyint(x); } extern "C" SYCL_EXTERNAL double __nv_rint(double); DEVICE_EXTERN_C_INLINE double rint(double x) { return __nv_rint(x); } -#endif // __NVPTX__ - -#ifdef __AMDGCN__ +#elif defined(__AMDGCN__) extern "C" SYCL_EXTERNAL double __ocml_nearbyint_f64(double); DEVICE_EXTERN_C_INLINE double nearbyint(double x) { return __ocml_nearbyint_f64(x); } @@ -198,7 +196,10 @@ double nearbyint(double x) { return __ocml_nearbyint_f64(x); } extern "C" SYCL_EXTERNAL double __ocml_rint_f64(double); DEVICE_EXTERN_C_INLINE double rint(double x) { return __ocml_rint_f64(x); } -#endif // __AMDGCN__ +#else +DEVICE_EXTERN_C_INLINE +double rint(double x) { return __spirv_ocl_rint(x); } +#endif #if defined(_MSC_VER) #include diff --git a/libdevice/test/check_cmath.txt b/libdevice/test/check_cmath.txt new file mode 100644 index 0000000000000..856dea8c0e772 --- /dev/null +++ b/libdevice/test/check_cmath.txt @@ -0,0 +1,12 @@ +REQUIRES: libsycldevice + +Check functions in fp32 libdevice spirv file. + +RUN: llvm-spirv --spirv-target-env=SPV-IR -r %libsycldevice_spv_dir/libsycl-cmath.spv -o %t.bc +RUN: llvm-dis %t.bc -o %t.ll +RUN: FileCheck %s --input-file %t.ll + +CHECK: target triple ={{.*}}spir64 + +CHECK-LABEL: define spir_func float @rintf( +CHECK: call spir_func float @_Z16__spirv_ocl_rintf(