diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 88a32797d5915..c96f29c2a6802 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -46,8 +46,6 @@ endif() set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_DEFAULT_TARGET} CACHE STRING "Semicolon-separated list of libclc targets to build, or 'all'." ) -option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF ) - option( LIBCLC_USE_SPIRV_BACKEND "Build SPIR-V targets with the SPIR-V backend." OFF ) @@ -239,19 +237,6 @@ set( tahiti_aliases pitcairn verde oland hainan bonaire kabini kaveri hawaii configure_file( libclc.pc.in libclc.pc @ONLY ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig" ) -if( ENABLE_RUNTIME_SUBNORMAL ) - foreach( file IN ITEMS subnormal_use_default subnormal_disable ) - link_bc( - TARGET ${file} - INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/opencl/lib/generic/${file}.ll - ) - install( - FILES $ - DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" - ) - endforeach() -endif() - set_source_files_properties( # CLC builtins ${CMAKE_CURRENT_SOURCE_DIR}/clc/lib/generic/math/clc_native_cos.cl @@ -350,12 +335,6 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) set( opencl_lib_files ) - if( NOT ARCH STREQUAL spirv AND NOT ARCH STREQUAL spirv64 AND - NOT ARCH STREQUAL clspv AND NOT ARCH STREQUAL clspv64 AND - NOT ENABLE_RUNTIME_SUBNORMAL ) - list( APPEND opencl_lib_files opencl/lib/generic/subnormal_use_default.ll ) - endif() - libclc_configure_lib_source( opencl_lib_files LIB_ROOT_DIR opencl @@ -412,6 +391,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) # Error on undefined macros -Werror=undef -fdiscard-value-names + -fdenormal-fp-math=dynamic ) if( NOT "${cpu}" STREQUAL "" ) diff --git a/libclc/clc/include/clc/math/clc_subnormal_config.h b/libclc/clc/include/clc/math/clc_subnormal_config.h index 14693ed01e033..e44ec1958b101 100644 --- a/libclc/clc/include/clc/math/clc_subnormal_config.h +++ b/libclc/clc/include/clc/math/clc_subnormal_config.h @@ -10,7 +10,6 @@ #include -_CLC_DECL bool __clc_subnormals_disabled(); _CLC_DECL bool __clc_fp16_subnormals_supported(); _CLC_DECL bool __clc_fp32_subnormals_supported(); _CLC_DECL bool __clc_fp64_subnormals_supported(); diff --git a/libclc/clc/include/clc/math/math.h b/libclc/clc/include/clc/math/math.h index c2647f66b4006..f181cc5f0f51a 100644 --- a/libclc/clc/include/clc/math/math.h +++ b/libclc/clc/include/clc/math/math.h @@ -65,14 +65,18 @@ bool __attribute__((noinline)) __clc_runtime_has_hw_fma32(void); #define LOG_MAGIC_NUM_SP32 (1 + NUMEXPBITS_SP32 - EXPBIAS_SP32) -_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) { - int ix = __clc_as_int(x); - if (!__clc_fp32_subnormals_supported() && ((ix & EXPBITS_SP32) == 0) && - ((ix & MANTBITS_SP32) != 0)) { - ix &= SIGNBIT_SP32; - x = __clc_as_float(ix); - } +static _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) { +#ifdef CLC_SPIRV + // The function is only used in __clc_sw_fma. + // FIXME delete this once SPIR-V backend supports SPV_KHR_fma. + return __builtin_elementwise_abs(x) < 0x1p-149f + ? __builtin_elementwise_copysign(0.0f, x) + : x; +#else + if (!__builtin_isfpclass(x, __FPCLASS_SNAN)) + return __builtin_elementwise_canonicalize(x); return x; +#endif } #ifdef cl_khr_fp64 diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES index d6db515c1d47f..9e024c4ae7392 100644 --- a/libclc/clc/lib/generic/SOURCES +++ b/libclc/clc/lib/generic/SOURCES @@ -143,6 +143,7 @@ math/clc_sincos_helpers.cl math/clc_sinh.cl math/clc_sinpi.cl math/clc_sqrt.cl +math/clc_subnormal_config.cl math/clc_sw_fma.cl math/clc_tables.cl math/clc_tan.cl diff --git a/libclc/clc/lib/generic/math/clc_exp10.cl b/libclc/clc/lib/generic/math/clc_exp10.cl index 0c394ee19475a..fb33367851fda 100644 --- a/libclc/clc/lib/generic/math/clc_exp10.cl +++ b/libclc/clc/lib/generic/math/clc_exp10.cl @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include diff --git a/libclc/clc/lib/generic/math/clc_hypot.cl b/libclc/clc/lib/generic/math/clc_hypot.cl index c934ab29da91b..fd046bccaed51 100644 --- a/libclc/clc/lib/generic/math/clc_hypot.cl +++ b/libclc/clc/lib/generic/math/clc_hypot.cl @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/libclc/clc/lib/generic/math/clc_pow.cl b/libclc/clc/lib/generic/math/clc_pow.cl index 70d3d614a8d36..c20d3829ea076 100644 --- a/libclc/clc/lib/generic/math/clc_pow.cl +++ b/libclc/clc/lib/generic/math/clc_pow.cl @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/libclc/clc/lib/generic/math/clc_pown.cl b/libclc/clc/lib/generic/math/clc_pown.cl index 5aa9560174b99..cfc415753fd1a 100644 --- a/libclc/clc/lib/generic/math/clc_pown.cl +++ b/libclc/clc/lib/generic/math/clc_pown.cl @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/libclc/clc/lib/generic/math/clc_powr.cl b/libclc/clc/lib/generic/math/clc_powr.cl index 0556ec97d6f3c..c35a3e2c382c5 100644 --- a/libclc/clc/lib/generic/math/clc_powr.cl +++ b/libclc/clc/lib/generic/math/clc_powr.cl @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/libclc/clc/lib/generic/math/clc_subnormal_config.cl b/libclc/clc/lib/generic/math/clc_subnormal_config.cl new file mode 100644 index 0000000000000..b4fd7e55ac1ce --- /dev/null +++ b/libclc/clc/lib/generic/math/clc_subnormal_config.cl @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include +#include + +#ifdef cl_khr_fp16 +#pragma OPENCL EXTENSION cl_khr_fp16 : enable +_CLC_DEF bool __clc_fp16_subnormals_supported() { +#ifdef CLC_SPIRV + half x = __clc_fabs(0x1p-24h); +#else + half x = __builtin_elementwise_canonicalize(0x1p-24h); +#endif + return !__builtin_isfpclass(x, __FPCLASS_POSZERO); +} +#endif // cl_khr_fp16 + +_CLC_DEF bool __clc_fp32_subnormals_supported() { +#ifdef CLC_SPIRV + float x = __clc_fabs(0x1p-149f); +#else + float x = __builtin_elementwise_canonicalize(0x1p-149f); +#endif + return !__builtin_isfpclass(x, __FPCLASS_POSZERO); +} + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable +_CLC_DEF bool __clc_fp64_subnormals_supported() { +#ifdef CLC_SPIRV + double x = __clc_fabs(0x1p-1074); +#else + double x = __builtin_elementwise_canonicalize(0x1p-1074); +#endif + return !__builtin_isfpclass(x, __FPCLASS_POSZERO); +} +#endif // cl_khr_fp64 diff --git a/libclc/opencl/lib/clspv/SOURCES b/libclc/opencl/lib/clspv/SOURCES index 8537d7c2d6b42..ccfea5bd16ea4 100644 --- a/libclc/opencl/lib/clspv/SOURCES +++ b/libclc/opencl/lib/clspv/SOURCES @@ -4,7 +4,6 @@ conversion/convert_int2float.cl conversion/convert_integer.cl math/fma.cl shared/vstore_half.cl -subnormal_config.cl ../generic/geometric/distance.cl ../generic/geometric/length.cl ../generic/math/acos.cl diff --git a/libclc/opencl/lib/clspv/subnormal_config.cl b/libclc/opencl/lib/clspv/subnormal_config.cl deleted file mode 100644 index 114aabb2e9435..0000000000000 --- a/libclc/opencl/lib/clspv/subnormal_config.cl +++ /dev/null @@ -1,16 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include - -_CLC_DEF bool __clc_fp16_subnormals_supported() { return false; } - -_CLC_DEF bool __clc_fp32_subnormals_supported() { return false; } - -_CLC_DEF bool __clc_fp64_subnormals_supported() { return false; } diff --git a/libclc/opencl/lib/generic/SOURCES b/libclc/opencl/lib/generic/SOURCES index a2c6af8b9252c..53ccc2c902cfd 100644 --- a/libclc/opencl/lib/generic/SOURCES +++ b/libclc/opencl/lib/generic/SOURCES @@ -1,5 +1,3 @@ -subnormal_config.cl -subnormal_helper_func.ll async/async_work_group_copy.cl async/async_work_group_strided_copy.cl async/prefetch.cl diff --git a/libclc/opencl/lib/generic/subnormal_config.cl b/libclc/opencl/lib/generic/subnormal_config.cl deleted file mode 100644 index aa2e30935e5f0..0000000000000 --- a/libclc/opencl/lib/generic/subnormal_config.cl +++ /dev/null @@ -1,18 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include - -_CLC_DEF bool __clc_fp16_subnormals_supported() { return false; } - -_CLC_DEF bool __clc_fp32_subnormals_supported() { return false; } - -_CLC_DEF bool __clc_fp64_subnormals_supported() { - return !__clc_subnormals_disabled(); -} diff --git a/libclc/opencl/lib/generic/subnormal_disable.ll b/libclc/opencl/lib/generic/subnormal_disable.ll deleted file mode 100644 index 732d09ff09ab4..0000000000000 --- a/libclc/opencl/lib/generic/subnormal_disable.ll +++ /dev/null @@ -1,9 +0,0 @@ -;;===----------------------------------------------------------------------===;; -; -; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -; See https://llvm.org/LICENSE.txt for license information. -; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -; -;;===----------------------------------------------------------------------===;; - -@__CLC_SUBNORMAL_DISABLE = unnamed_addr constant i1 true diff --git a/libclc/opencl/lib/generic/subnormal_helper_func.ll b/libclc/opencl/lib/generic/subnormal_helper_func.ll deleted file mode 100644 index 03beecf979260..0000000000000 --- a/libclc/opencl/lib/generic/subnormal_helper_func.ll +++ /dev/null @@ -1,16 +0,0 @@ -;;===----------------------------------------------------------------------===;; -; -; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -; See https://llvm.org/LICENSE.txt for license information. -; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -; -;;===----------------------------------------------------------------------===;; - -@__CLC_SUBNORMAL_DISABLE = external global i1 - -define i1 @__clc_subnormals_disabled() #0 { - %disable = load i1, i1* @__CLC_SUBNORMAL_DISABLE - ret i1 %disable -} - -attributes #0 = { alwaysinline } diff --git a/libclc/opencl/lib/generic/subnormal_use_default.ll b/libclc/opencl/lib/generic/subnormal_use_default.ll deleted file mode 100644 index c648cc0a8aded..0000000000000 --- a/libclc/opencl/lib/generic/subnormal_use_default.ll +++ /dev/null @@ -1,9 +0,0 @@ -;;===----------------------------------------------------------------------===;; -; -; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -; See https://llvm.org/LICENSE.txt for license information. -; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -; -;;===----------------------------------------------------------------------===;; - -@__CLC_SUBNORMAL_DISABLE = unnamed_addr constant i1 false diff --git a/libclc/opencl/lib/spirv/SOURCES b/libclc/opencl/lib/spirv/SOURCES index 0aa923978e9f1..aa7fcee0c4f4a 100644 --- a/libclc/opencl/lib/spirv/SOURCES +++ b/libclc/opencl/lib/spirv/SOURCES @@ -1,4 +1,3 @@ -subnormal_config.cl ../generic/async/async_work_group_strided_copy.cl ../generic/async/wait_group_events.cl ../generic/common/degrees.cl diff --git a/libclc/opencl/lib/spirv/subnormal_config.cl b/libclc/opencl/lib/spirv/subnormal_config.cl deleted file mode 100644 index 114aabb2e9435..0000000000000 --- a/libclc/opencl/lib/spirv/subnormal_config.cl +++ /dev/null @@ -1,16 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include -#include - -_CLC_DEF bool __clc_fp16_subnormals_supported() { return false; } - -_CLC_DEF bool __clc_fp32_subnormals_supported() { return false; } - -_CLC_DEF bool __clc_fp64_subnormals_supported() { return false; }