From 624877eb236e864903ed11117ecc64bfeda2bdff Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 1 Sep 2024 00:40:41 -0400 Subject: [PATCH 001/102] Cleanup runner configs --- .github/dependabot.yml | 13 +++++-------- .github/workflows/codeql.yml | 16 +++------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0d08e261..4a472a78 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,11 +1,8 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file - version: 2 updates: - - package-ecosystem: "github-actions" # See documentation for possible values - directory: "/" # Location of package manifests + - package-ecosystem: "github-actions" # Necessary to update action hashes. + directory: "/" schedule: - interval: "weekly" + interval: "monthly" + # Allow up to 3 opened pull requests for github-actions versions. + open-pull-requests-limit: 3 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index b097a3dd..3dd770e2 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,22 +1,12 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# + name: "CodeQL" on: push: - branches: ["main"] + branches: ["main", "dev"] pull_request: # The branches below must be a subset of the branches above - branches: ["main"] + branches: ["main", "dev"] schedule: - cron: "0 0 * * 1" From f450b58368e839384394a6e09a63f93299e56a18 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 1 Sep 2024 00:41:27 -0400 Subject: [PATCH 002/102] add workflow for automatic formatting with clang-format --- .github/workflows/lint.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..a3d9e76b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +name: lint + +on: + pull_request: + paths: + - '**.hpp' + +permissions: + contents: read + +jobs: + format_code: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + + - name: Install clang-format + uses: aminya/setup-cpp@290824452986e378826155f3379d31bce8753d76 # v0.37.0 + with: + clangformat: 17.0.5 + + - name: Run clang-format + run: | + find include -name '*.hpp' | xargs clang-format -i -style=file -fallback-style=none + git diff --exit-code From 28536b312ab2a95c990c8b990ca0a4aef7868c9e Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 1 Sep 2024 00:43:24 -0400 Subject: [PATCH 003/102] Setup initial work for pow implementation --- ccmath_core_headers.cmake | 8 +- ccmath_internal_headers.cmake | 91 +++--- .../math/generic/func/power/pow_gen.hpp | 56 +--- .../math/generic/func/power/pow_impl.hpp | 32 ++ .../math/generic/func/power/powf_impl.hpp | 32 ++ .../math/runtime/func/power/pow_rt.hpp | 73 +++++ .../math/runtime/simd/func/impl/avx/pow.hpp | 35 +++ .../math/runtime/simd/func/impl/avx2/pow.hpp | 36 +++ .../runtime/simd/func/impl/avx512/pow.hpp | 35 +++ .../math/runtime/simd/func/impl/neon/pow.hpp | 33 ++ .../runtime/simd/func/impl/scalar/pow.hpp | 23 ++ .../math/runtime/simd/func/impl/sse2/pow.hpp | 33 ++ .../math/runtime/simd/func/impl/sse3/pow.hpp | 33 ++ .../math/runtime/simd/func/impl/sse4/pow.hpp | 33 ++ .../math/runtime/simd/func/impl/ssse3/pow.hpp | 33 ++ .../simd/func/impl/vector_size/pow.hpp | 38 +++ .../internal/math/runtime/simd/func/pow.hpp | 14 + include/ccmath/math/power/impl/pow_impl.hpp | 294 ------------------ include/ccmath/math/power/pow.hpp | 55 +--- 19 files changed, 555 insertions(+), 432 deletions(-) create mode 100644 include/ccmath/internal/math/generic/func/power/pow_impl.hpp create mode 100644 include/ccmath/internal/math/generic/func/power/powf_impl.hpp create mode 100644 include/ccmath/internal/math/runtime/func/power/pow_rt.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/avx2/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/neon/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/vector_size/pow.hpp create mode 100644 include/ccmath/internal/math/runtime/simd/func/pow.hpp delete mode 100644 include/ccmath/math/power/impl/pow_impl.hpp diff --git a/ccmath_core_headers.cmake b/ccmath_core_headers.cmake index 1422a958..a5c8fb00 100644 --- a/ccmath_core_headers.cmake +++ b/ccmath_core_headers.cmake @@ -7,6 +7,7 @@ # Math Section ############################################################################## +# TODO: Remove all impls from here into the generic headers. ### Basic/Impl headers ########################################## @@ -152,13 +153,6 @@ set(ccmath_detail_nearest_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/nearest/trunc.hpp ) -### Power/Impl headers - TODO: Remove this an instead use the generic power headers -########################################## -set(ccmath_math_power_impl_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/power/impl/pow_impl.hpp -) - - ####################################### ## Power headers diff --git a/ccmath_internal_headers.cmake b/ccmath_internal_headers.cmake index 46a81a04..6e553360 100644 --- a/ccmath_internal_headers.cmake +++ b/ccmath_internal_headers.cmake @@ -2,6 +2,10 @@ # Internal Section ############################################################################## +########################################## +### Config Section +########################################## + ### Config/Arch/Targets headers ########################################## set(ccmath_internal_config_arch_targets_headers @@ -56,7 +60,12 @@ set(ccmath_internal_config_headers ) -#### Math/Generic Modules #### +########################################## +### Math Section +########################################## + +### Generic Module +########################################## ### Math/Generic/Func/Basic headers ########################################## @@ -75,9 +84,13 @@ set(ccmath_internal_math_generic_func_basic_headers ### Math/Generic/Func/Expo headers ########################################## set(ccmath_internal_math_generic_func_expo_headers + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/exp2_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/exp_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/expm1_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/log1p_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/log2_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/log10_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/log_gen.hpp ) @@ -129,37 +142,39 @@ set(ccmath_internal_math_generic_func_nearest_headers ### Math/Generic/Func/Power headers ########################################## set(ccmath_internal_math_generic_func_power_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/cbrt_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/hypot_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/pow_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/sqrt_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/cbrt_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/hypot_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/pow_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/pow_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/powf_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp ) ### Math/Generic/Func/Special headers ########################################## set(ccmath_internal_math_generic_func_special_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/assoc_laguerre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/assoc_legendre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/beta.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/comp_ellint_1.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/comp_ellint_2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/comp_ellint_3.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_bessel_i.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_bessel_j.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_bessel_k.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_neumann.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/ellint_1.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/ellint_2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/ellint_3.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/expint.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/hermite.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/laguerre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/legendre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/riemann_zeta.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/sph_bessel.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/sph_legendre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/sph_neumann.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/assoc_laguerre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/assoc_legendre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/beta_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/comp_ellint_1_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/comp_ellint_2_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/comp_ellint_3_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_bessel_i_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_bessel_j_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_bessel_k_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_neumann_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/ellint_1_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/ellint_2_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/ellint_3_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/expint_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/hermite_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/laguerre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/legendre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/riemann_zeta_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/sph_bessel_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/sph_legendre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/sph_neumann_gen.hpp ) @@ -197,18 +212,17 @@ set(ccmath_internal_math_generic_headers ) - -### Math/Runtime/func headers +### Math/Runtime/Func/Power headers ########################################## -set(ccmath_internal_math_runtime_func_headers - ${ccmath_internal_math_runtime_func_power_headers} +set(ccmath_internal_math_runtime_func_power_headers + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/func/power/sqrt_rt.hpp ) - -### Math/Runtime headers +### Math/Runtime/Func headers ########################################## -set(ccmath_internal_math_runtime_headers - ${ccmath_internal_math_runtime_func_headers} +set(ccmath_internal_math_runtime_func_headers + ${ccmath_internal_math_runtime_func_power_headers} ) @@ -297,6 +311,7 @@ set(ccmath_internal_math_runtime_simd_func_headers ${ccmath_internal_math_runtime_simd_func_impl_vector_size_headers} ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/sqrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/pow.hpp ) @@ -327,7 +342,8 @@ set(ccmath_internal_math_runtime_simd_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/simd.hpp ) - +### Math/Runtime headers +########################################## set(ccmath_internal_math_runtime_headers ${ccmath_internal_math_runtime_func_headers} ${ccmath_internal_math_runtime_simd_headers} @@ -480,11 +496,10 @@ set(ccmath_internal_types_headers set(ccmath_internal_headers ${ccmath_internal_config_headers} - ${ccmath_internal_generic_headers} + ${ccmath_internal_math_headers} ${ccmath_internal_predef_headers} - ${ccmath_internal_math_runtime_headers} ${ccmath_internal_support_headers} ${ccmath_internal_types_headers} ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/setup.hpp -) \ No newline at end of file +) diff --git a/include/ccmath/internal/math/generic/func/power/pow_gen.hpp b/include/ccmath/internal/math/generic/func/power/pow_gen.hpp index fc38e656..3a2d975e 100644 --- a/include/ccmath/internal/math/generic/func/power/pow_gen.hpp +++ b/include/ccmath/internal/math/generic/func/power/pow_gen.hpp @@ -10,59 +10,19 @@ #pragma once -#include - -#include "ccmath/math/exponential/exp2.hpp" -#include "ccmath/math/exponential/log2.hpp" - -#include "ccmath/math/power/impl/pow_impl.hpp" +#include "ccmath/internal/math/generic/func/power/pow_impl.hpp" +#include "ccmath/internal/math/generic/func/power/powf_impl.hpp" +#include -namespace ccm +namespace ccm::gen { - namespace internal::impl - { - template && std::is_unsigned_v, bool> = true> - constexpr T pow_expo_by_sqr(T base, T exp) noexcept - { - // Handle common cases - if (exp == 0) { return 1; } // Anything to the power of 0 is 1 - if (exp == 1) { return base; } // Anything to the power of 1 is itself - if (exp == 2) { return base * base; } // Anything to the power of 2 is itself squared - if (base == 0) { return 0; } // 0 to any power is 0 - if (base == 1) { return 1; } // 1 to any power is 1 - - // If the base is 2, we can use the bit shift operator to calculate the power. - if (base == 2) { return 1 << exp; } - - // This is pretty fast with smaller numbers, but is slower than the standard when dealing with large numbers. - // TODO: Find a way to optimize this for larger numbers. - T result = 1; - for (;;) - { - if (exp & 1) { result *= base; } - exp >>= 1; - if (!exp) { break; } - base *= base; - } - - return result; - } - - template , bool> = true> - constexpr T pow_generic(T base, T exp) noexcept - { - // This should work on all x86 platforms but may not work with other architectures. - // For now this is more of a hold over till I have time to implement a better generic version. - return ccm::exp2(exp * ccm::log2(base)); - } - } // namespace internal::impl - template - constexpr T pow(T base, T exp) noexcept + constexpr T pow_gen(T base, T exp) noexcept { - if constexpr (std::is_integral_v && std::is_unsigned_v) { return internal::impl::pow_expo_by_sqr(base, exp); } - return internal::impl::pow_generic(base, exp); + //if constexpr (std::is + + return 0; } } // namespace ccm diff --git a/include/ccmath/internal/math/generic/func/power/pow_impl.hpp b/include/ccmath/internal/math/generic/func/power/pow_impl.hpp new file mode 100644 index 00000000..0a883c4c --- /dev/null +++ b/include/ccmath/internal/math/generic/func/power/pow_impl.hpp @@ -0,0 +1,32 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include + +namespace ccm::gen::impl +{ + namespace internal::impl + { + template + constexpr T pow_impl(T base, T exp) noexcept + { + return 0; + } + } + + template + constexpr T pow_impl(T base, T exp) noexcept + { + return internal::impl::pow_impl(base, exp); + } + +} // namespace ccm diff --git a/include/ccmath/internal/math/generic/func/power/powf_impl.hpp b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp new file mode 100644 index 00000000..71d51bda --- /dev/null +++ b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include + +namespace ccm::gen::impl +{ + namespace internal::impl + { + template + constexpr T powf_impl(T base, T exp) noexcept + { + return 0; + } + } + + template + constexpr T powf_impl(T base, T exp) noexcept + { + return internal::impl::powf_impl(base, exp); + } + +} // namespace ccm diff --git a/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp new file mode 100644 index 00000000..b1fab829 --- /dev/null +++ b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/config/type_support.hpp" +#include "ccmath/internal/math/generic/func/power/pow_gen.hpp" +#include "ccmath/internal/math/runtime/simd/func/sqrt.hpp" +#include "ccmath/internal/support/always_false.hpp" +#include "ccmath/internal/support/bits.hpp" +#include "ccmath/internal/support/fenv/rounding_mode.hpp" +#include "ccmath/internal/support/fp/fp_bits.hpp" +#include "ccmath/internal/support/is_constant_evaluated.hpp" + +#include + +namespace ccm::rt::simd_impl +{ +#if defined(CCM_TYPES_LONG_DOUBLE_IS_FLOAT64) + template , bool> = true> +#else + template && !std::is_same_v, bool> = true> +#endif + [[nodiscard]] inline T pow_simd_impl(T num) noexcept; + +#ifdef CCMATH_HAS_SIMD + #if defined(CCM_TYPES_LONG_DOUBLE_IS_FLOAT64) + template , bool>> + #else + template && !std::is_same_v, bool>> + #endif + [[nodiscard]] inline T pow_simd_impl(T num) noexcept + { + intrin::simd const num_m(num); + intrin::simd const sqrt_m = intrin::sqrt(num_m); + return sqrt_m.convert(); + } +#endif +} // namespace ccm::rt::simd_impl + +namespace ccm::rt +{ + template , bool> = true> + T pow_rt(T num) + { +#if CCM_HAS_BUILTIN(__builtin_pow) || defined(__builtin_pow) // Prefer the builtins if available. + if constexpr (std::is_same_v) { return __builtin_powf(num); } + else if constexpr (std::is_same_v) { return __builtin_pow(num); } + else if constexpr (std::is_same_v) { return __builtin_powl(num); } + else { return static_cast(__builtin_powl(static_cast(num))); } +#elif defined(CCMATH_HAS_SIMD) + // In the unlikely event, the rounding mode is not the default, use the runtime implementation instead. + if (CCM_UNLIKELY(ccm::support::fenv::get_rounding_mode() != FE_TONEAREST)) { return gen::pow_gen(num); } + #if !defined(CCM_TYPES_LONG_DOUBLE_IS_FLOAT64) // If long double is different from double, use the generic implementation instead. + if constexpr (std::is_same_v || std::is_same_v) { return simd_impl::pow_simd_impl(num); } + else { return gen::pow_gen(num); } + #else // If long double is the same as double, we can use the SIMD implementation instead. + if constexpr (std::is_same_v || std::is_same_v) { return simd_impl::sqrt_simd_impl(num); } + else if constexpr (std::is_same_v) { return static_cast(simd_impl::sqrt_simd_impl(static_cast(num))); } + else { return ccm::gen::sqrt_gen(num); } + #endif +#else // If we don't have a builtin or SIMD, use the generic implementation. + return ccm::gen::pow_gen(num); +#endif + } +} // namespace ccm::rt diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp new file mode 100644 index 00000000..aff96b1b --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_AVX +namespace ccm::intrin +{ + + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm256_sqrt_ps(a.get())); + } + + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm256_sqrt_pd(a.get())); + } + +} // namespace ccm::intrin + + #endif // CCMATH_HAS_SIMD_AVX +#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx2/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/avx2/pow.hpp new file mode 100644 index 00000000..6bcdb788 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx2/pow.hpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_AVX2 +namespace ccm::intrin +{ + + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm256_pow_ps(a.get(), b.get())); + } + + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm256_pow_pd(a.get(), b.get())); + + } + +} // namespace ccm::intrin + + #endif // CCMATH_HAS_SIMD_AVX2 +#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp new file mode 100644 index 00000000..922d10b7 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_AVX512F +namespace ccm::intrin +{ + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm256_pow_ps(a.get(), b.get())); + } + + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm256_pow_pd(a.get(), b.get())); + + } + +} // namespace ccm::intrin + + #endif // CCMATH_HAS_SIMD_AVX512F +#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/neon/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/neon/pow.hpp new file mode 100644 index 00000000..3cabc66e --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/neon/pow.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_NEON +namespace ccm::intrin +{ + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(vsqrtq_f32(a.get())); + } + + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(vsqrtq_f64(a.get())); + } +} // namespace ccm::intrin + + #endif // CCMATH_HAS_SIMD_NEON +#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp new file mode 100644 index 00000000..63bc9b41 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/func/power/sqrt_gen.hpp" +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +namespace ccm::intrin +{ + template + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd sqrt(simd const& a) + { + return simd(ccm::gen::sqrt_gen(a.get())); + } +} // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp new file mode 100644 index 00000000..4478e56e --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_SSE2 +namespace ccm::intrin +{ + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm_sqrt_ps(a.get())); + } + + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm_sqrt_pd(a.get())); + } +} // namespace ccm::intrin + + #endif // CCMATH_HAS_SIMD_SSE2 +#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp new file mode 100644 index 00000000..c9e5a03f --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_SSE3 +namespace ccm::intrin +{ + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm_sqrt_ps(a.get())); + } + + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm_sqrt_pd(a.get())); + } +} // namespace ccm::intrin + + #endif // CCMATH_HAS_SIMD_SSE3 +#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp new file mode 100644 index 00000000..e2a782e1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_SSE4 +namespace ccm::intrin +{ + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm_sqrt_ps(a.get())); + } + + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm_sqrt_pd(a.get())); + } +} // namespace ccm::intrin + + #endif // CCMATH_HAS_SIMD_SSE4 +#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp new file mode 100644 index 00000000..9be19078 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_SSSE3 +namespace ccm::intrin +{ + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm_sqrt_ps(a.get())); + } + + CCM_ALWAYS_INLINE simd sqrt(simd const & a) + { + // NOLINTNEXTLINE(modernize-return-braced-init-list) + return simd(_mm_sqrt_pd(a.get())); + } +} // namespace ccm::intrin + + #endif // CCMATH_HAS_SIMD_SSSE3 +#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/pow.hpp new file mode 100644 index 00000000..81aecc7e --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/pow.hpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/runtime/simd/simd.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_ENABLE_VECTOR_SIZE + +namespace ccm::intrin +{ + + template + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd> sqrt(simd> const & a) + { + simd> result; + + // TODO: Implement a runtime vector_size sqrt that is optimized for runtime. + //CCM_SIMD_VECTORIZE for (int i = 0; i < a.size(); ++i) + //{ + // result.get()[i] = sqrt(a[i]); + //} + + return result; + } + +} // namespace ccm::intrin + + #endif // CCMATH_HAS_SIMD_ENABLE_VECTOR_SIZE +#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/pow.hpp new file mode 100644 index 00000000..c760adec --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/pow.hpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/config/arch/check_simd_support.hpp" + diff --git a/include/ccmath/math/power/impl/pow_impl.hpp b/include/ccmath/math/power/impl/pow_impl.hpp deleted file mode 100644 index a7224d04..00000000 --- a/include/ccmath/math/power/impl/pow_impl.hpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) Ian Pike - * Copyright (c) CCMath contributors - * - * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. - * See LICENSE for more information. - * - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#pragma once - -// turn on fenv access -// #pragma STDC FENV_ACCESS ON - -#include "ccmath/internal/support/floating_point_traits.hpp" -#include "ccmath/internal/support/fp/bit_mask_traits.hpp" -#include "ccmath/internal/support/fp/directional_rounding_utils.hpp" -#include "ccmath/internal/support/fp/fp_bits.hpp" -#include "ccmath/internal/support/unreachable.hpp" -#include "ccmath/internal/types/big_int.hpp" -#include "ccmath/math/basic/abs.hpp" -#include "ccmath/math/compare/isnan.hpp" -#include "ccmath/math/power/sqrt.hpp" - -#include - -namespace ccm::internal::impl -{ - template - constexpr T pow_exp_helper(T base, T exp) noexcept - { - return 0; - } - - template - constexpr T pow_log_helper(T base, T exp) noexcept - { - return 0; - } - - template - constexpr T pow_round_even(T x) noexcept - { - return ccm::support::fp::directional_round(x, FE_TONEAREST); - } - - template , bool> = true> - constexpr auto convert_fp_to_uint(T x) noexcept - { - using FPbits_t = support::fp::FPBits; - using Storage_t = typename FPbits_t::storage_type; - FPbits_t x_bits(x); - Storage_t x_abs = x_bits.abs().uintval(); - return x_abs; - } - - template - constexpr bool pow_impl_is_integer(T x) noexcept - { - return ccm::support::fp::directional_round(x, FE_TONEAREST) == x; - } - - template , bool> = true> - constexpr bool is_odd_integer(T x) - { - using FPBits_t = typename support::fp::FPBits; - using Storage_t = typename FPBits_t::storage_type; - using SignedStorage_t = support::float_signed_bits_t; - auto x_u = support::bit_cast(x); - auto x_e = static_cast((x_u & FPBits_t::exponent_mask) >> FPBits_t::fraction_length); - auto lsb = support::countr_zero(x_u | FPBits_t::exponent_mask); - constexpr auto UNIT_EXPONENT = FPBits_t::exponent_bias + static_cast(FPBits_t::fraction_length); - return (x_e + lsb == UNIT_EXPONENT); - } - - template , bool> = true> - constexpr bool is_integer(T x) - { - using FPBits_t = typename support::fp::FPBits; - using Storage_t = typename FPBits_t::storage_type; - using SignedStorage_t = support::float_signed_bits_t; - Storage_t x_u = support::bit_cast(x); - auto x_e = static_cast((x_u & FPBits_t::exponent_mask) >> FPBits_t::fraction_length); - SignedStorage_t lsb = support::countr_zero(x_u | FPBits_t::exponent_mask); - constexpr SignedStorage_t UNIT_EXPONENT = FPBits_t::exponent_bias + static_cast(FPBits_t::fraction_length); - return (x_e + lsb >= UNIT_EXPONENT); - } - - template - // NOLINTNEXTLINE(readability-function-cognitive-complexity) - Has a naturally high complexity. To avoid fracturing, we allow this. - constexpr std::enable_if_t, T> pow_impl_handle_special_cases(support::fp::FPBits & x_bits, support::fp::FPBits & y_bits, - T & x, T & y) noexcept - { - if (x_bits.is_nan()) - { - // IEEE 754-2019: pow(x, ±0) = 1 if x is not a signaling NaN - if (y == 0.0 && !x_bits.is_signaling_nan()) { return 1.0; } - - // For GCC based compilers, they do not account for signaling nan and just return 1.0 - // For clang, it will return 1.0 if the optimization flag is set. - // AppleClang always returns 1 no matter the optimization level. -#if (defined(__GNUC__) && !defined(__clang__)) || (defined(__clang__) && defined(__OPTIMIZE__)) || (defined(__clang__) && defined(__APPLE__)) || \ - (defined(__clang__) && defined(CCM_CONFIG_AGGRESSIVELY_OPTIMIZE)) || defined(__INTEL_LLVM_COMPILER) - if (y == 0.0 && x_bits.is_signaling_nan()) { return 1.0; } -#endif - - return x + x; - } - - if (y_bits.is_nan()) - { - // IEEE 754-2019: pow(1,y) = 1 for any y (even a quiet NaN) - if (x == 1.0 && !y_bits.is_signaling_nan()) { return 1.0; } - - // For GCC based compilers, they do not account for signaling nan and just return 1.0 - // For clang, it will return 1.0 if the optimization flag is set. - // AppleClang always returns 1 no matter the optimization level. -#if (defined(__GNUC__) && !defined(__clang__)) || (defined(__clang__) && defined(__OPTIMIZE__)) || (defined(__clang__) && defined(__APPLE__)) || \ - (defined(__clang__) && defined(CCM_CONFIG_AGGRESSIVELY_OPTIMIZE)) || defined(__INTEL_LLVM_COMPILER) - if (x == 1.0 && y_bits.is_signaling_nan()) { return 1.0; } -#endif - - return y + y; - } - - // Handle the special case where x is a positive infinity and y is not negative - // x = +inf - if (x_bits.is_inf() && !x_bits.is_neg()) - { - if (y == 0.0) { return 1.0; } - - if (y < 0.0) { return 0.0; } - - if (y > 0.0) { return std::numeric_limits::infinity(); } - } - - // Handle the special case where x is a negative infinity - // x = -inf - if (x_bits.is_inf() && x_bits.is_neg()) - { - // If y is an odd integer - if (pow_impl_is_integer(y) && !pow_impl_is_integer(y * std::numeric_limits::round_error())) - { - // y is a negative odd integer - if (y < 0.0) { return -0.0; } - - // y is a positive odd integer - return -std::numeric_limits::infinity(); - } - - // y is a negative even integer or a negative non-integer - if (y < 0.0) { return 0.0; } - - // y is a positive even integer or a positive non-integer - if (y > 0.0) { return std::numeric_limits::infinity(); } - } - - // y = +inf - if (y_bits.is_inf() && !y_bits.is_neg()) - { - if (x == 0.0) { return 0.0; } - - if (x == -1.0 || x == 1.0) { return 1.0; } - - if (-1.0 < x && x < 1.0) { return 0.0; } - - if (x < -1.0 || 1.0 < x) { return std::numeric_limits::infinity(); } - } - - // y = -inf - if (y_bits.is_inf() && y_bits.is_neg()) - { - if (x == 0.0) { return std::numeric_limits::infinity(); } - - if (x == -1.0 || x == 1.0) { return 1.0; } - - if (-1.0 < x && x < 1.0) { return std::numeric_limits::infinity(); } - - if (x < -1.0 || 1.0 < x) { return 0.0; } - } - - support::unreachable(); // Something went horribly wrong if we reach this point. - return 0.0; // This should never be reached. - } - - template - constexpr std::enable_if_t, T> pow_impl_handle_zero_or_less(support::fp::FPBits & x_bits, T & x, T & y, - T & current_sign_of_result) noexcept - { - const bool is_x_zero = x_bits.is_zero(); - const bool is_y_an_integer = pow_impl_is_integer(y); - // x = +0.0 - if (is_x_zero && !x_bits.is_neg()) - { - // y is an odd integer - if (is_y_an_integer && !pow_impl_is_integer(y * std::numeric_limits::round_error())) - { - // y is a negative odd integer - if (y < 0.0) - { - ccm::support::fenv::raise_except_if_required(FE_DIVBYZERO); - return std::numeric_limits::infinity(); - } - - // y is a positive odd integer - return 0.0; - } - - // y is positive even integer or a positive non-integer - if (y > 0.0) { return 0.0; } - - // y is a negative, even, and finite integer or non-integer - ccm::support::fenv::raise_except_if_required(FE_DIVBYZERO); - return std::numeric_limits::infinity(); - } - - // x = -0.0 - if (is_x_zero) - { - // y is an odd integer - if (is_y_an_integer && !pow_impl_is_integer(y * std::numeric_limits::round_error())) - { - // y is a negative odd integer - if (y < 0.0) - { - ccm::support::fenv::raise_except_if_required(FE_DIVBYZERO); - return -std::numeric_limits::infinity(); - } - - // y is a positive odd integer - return -0.0; - } - - // y is a positive even integer or a positive non-integer - if (y > 0.0) { return 0.0; } - - // y is a negative, even, and finite integer or non-integer - ccm::support::fenv::raise_except_if_required(FE_DIVBYZERO); - return -std::numeric_limits::infinity(); - } - - if (!is_y_an_integer) - { - ccm::support::fenv::raise_except_if_required(FE_INVALID); - return std::numeric_limits::quiet_NaN(); - } - - std::array copy_sign = {1.0, -1.0}; - - // set sign to 1 for even y and -1 for odd y - int y_parity = ccm::abs(y) >= support::floating_point_traits::max_safe_integer ? 0 : static_cast>(y) & 0x1; - current_sign_of_result = copy_sign.at(static_cast(y_parity)); - - // Set x to the absolute value of x for the remainder of the function - x = -x; - - // Indicate that we did not get a case that could've been handled, so we just set x above - // then signal this by returning a max value of our type which this function would never return. - // We have to do this as we are modifying x at this point but don't yet intend to return the full function. - return std::numeric_limits::min(); - } - - // make sure TStorage is of the type support::fp::FPBits::storage_type - template ::storage_type>, bool> = true> - constexpr std::enable_if_t, T> pow_check_over_under_flow(support::fp::FPBits & x_bits, support::fp::FPBits & y_bits, - TStorage & x_abs, TStorage & y_abs) noexcept - { - - return 0; - } - - template - constexpr std::enable_if_t, T> pow_impl(T x, T y) noexcept - { - support::fp::FPBits x_bits(x); - support::fp::FPBits y_bits(y); - double sign_of_result = 1.0; - - // Handle edge cases when x or y is a non-finite value - if (CCM_UNLIKELY(!x_bits.is_finite() || !y_bits.is_finite())) { return pow_impl_handle_special_cases(x_bits, y_bits, x, y); } - - // Handle edge cases when x is zero or lees than zero - if (x <= 0.0) - { - const auto handling_zero_or_less_result = pow_impl_handle_zero_or_less(x_bits, x, y, sign_of_result); - if (handling_zero_or_less_result != std::numeric_limits::min()) { return handling_zero_or_less_result; } - } - // Begin the actual calculation - - return 0; - } - -} // namespace ccm::internal::impl diff --git a/include/ccmath/math/power/pow.hpp b/include/ccmath/math/power/pow.hpp index d4fed718..6aeb4290 100644 --- a/include/ccmath/math/power/pow.hpp +++ b/include/ccmath/math/power/pow.hpp @@ -10,60 +10,25 @@ #pragma once -#include - -#include "ccmath/math/exponential/exp2.hpp" -#include "ccmath/math/exponential/log2.hpp" - -#include "ccmath/math/power/impl/pow_impl.hpp" +#include "ccmath/internal/math/generic/func/power/pow_gen.hpp" +#include "ccmath/internal/support/is_constant_evaluated.hpp" +#include namespace ccm { - // TODO: Much of this is going to be removed. New implementation is being worked on elsewhere. - namespace internal::impl - { - template && std::is_unsigned_v, bool> = true> - constexpr T pow_expo_by_sqr(T base, T exp) noexcept - { - // Handle common cases - if (exp == 0) { return 1; } // Anything to the power of 0 is 1 - if (exp == 1) { return base; } // Anything to the power of 1 is itself - if (exp == 2) { return base * base; } // Anything to the power of 2 is itself squared - if (base == 0) { return 0; } // 0 to any power is 0 - if (base == 1) { return 1; } // 1 to any power is 1 - - // If the base is 2, we can use the bit shift operator to calculate the power. - if (base == 2) { return 1 << exp; } - - // This is pretty fast with smaller numbers, but is slower than the standard when dealing with large numbers. - // TODO: Find a way to optimize this for larger numbers. - T result = 1; - for (;;) - { - if (exp & 1) { result *= base; } - exp >>= 1; - if (!exp) { break; } - base *= base; - } - return result; - } + template + constexpr T pow(T base, T exp) noexcept + { + // TODO: Add in usage of builtins that meet ccmath standards. - template , bool> = true> - constexpr T pow_generic(T base, T exp) noexcept + if (support::is_constant_evaluated()) { - // This should work on all x86 platforms but may not work with other architectures. - // For now this is more of a hold over till I have time to implement a better generic version. - return ccm::exp2(exp * ccm::log2(base)); + return gen::pow_gen(base, exp); } - } // namespace internal::impl - template - constexpr T pow(T base, T exp) noexcept - { - if constexpr (std::is_integral_v && std::is_unsigned_v) { return internal::impl::pow_expo_by_sqr(base, exp); } - return internal::impl::pow_generic(base, exp); + return gen::pow_gen(base, exp); // TODO: Replace once runtime implementation is hooked in. } } // namespace ccm From 389dd21e5c6f478cf2c959f63cc7793b0748d07f Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 1 Sep 2024 01:07:25 -0400 Subject: [PATCH 004/102] Setup simd intrinsic wrapper for pow --- ccmath_internal_headers.cmake | 16 ++++++++ .../math/runtime/simd/func/impl/avx/pow.hpp | 8 ++-- .../runtime/simd/func/impl/avx512/pow.hpp | 4 +- .../math/runtime/simd/func/impl/neon/pow.hpp | 2 + .../runtime/simd/func/impl/scalar/pow.hpp | 6 +-- .../math/runtime/simd/func/impl/sse2/pow.hpp | 8 ++-- .../math/runtime/simd/func/impl/sse3/pow.hpp | 8 ++-- .../math/runtime/simd/func/impl/sse4/pow.hpp | 8 ++-- .../math/runtime/simd/func/impl/ssse3/pow.hpp | 8 ++-- .../simd/func/impl/vector_size/pow.hpp | 38 ------------------ .../internal/math/runtime/simd/func/pow.hpp | 40 ++++++++++++++++++- 11 files changed, 82 insertions(+), 64 deletions(-) delete mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/vector_size/pow.hpp diff --git a/ccmath_internal_headers.cmake b/ccmath_internal_headers.cmake index 6e553360..4c03a84d 100644 --- a/ccmath_internal_headers.cmake +++ b/ccmath_internal_headers.cmake @@ -230,6 +230,7 @@ set(ccmath_internal_math_runtime_func_headers ########################################## set(ccmath_internal_math_runtime_simd_func_impl_avx_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx/sqrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp ) @@ -237,6 +238,8 @@ set(ccmath_internal_math_runtime_simd_func_impl_avx_headers ########################################## set(ccmath_internal_math_runtime_simd_func_impl_avx2_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx2/sqrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx2/pow.hpp + ) @@ -244,6 +247,8 @@ set(ccmath_internal_math_runtime_simd_func_impl_avx2_headers ########################################## set(ccmath_internal_math_runtime_simd_func_impl_avx512_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx512/sqrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp + ) @@ -258,6 +263,8 @@ set(ccmath_internal_math_runtime_simd_func_impl_neon_headers ########################################## set(ccmath_internal_math_runtime_simd_func_impl_scalar_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/scalar/sqrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp + ) @@ -265,6 +272,8 @@ set(ccmath_internal_math_runtime_simd_func_impl_scalar_headers ########################################## set(ccmath_internal_math_runtime_simd_func_impl_sse2_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse2/sqrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp + ) @@ -272,6 +281,8 @@ set(ccmath_internal_math_runtime_simd_func_impl_sse2_headers ########################################## set(ccmath_internal_math_runtime_simd_func_impl_sse3_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse3/sqrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp + ) @@ -279,6 +290,8 @@ set(ccmath_internal_math_runtime_simd_func_impl_sse3_headers ########################################## set(ccmath_internal_math_runtime_simd_func_impl_sse4_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse4/sqrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp + ) @@ -286,6 +299,8 @@ set(ccmath_internal_math_runtime_simd_func_impl_sse4_headers ########################################## set(ccmath_internal_math_runtime_simd_func_impl_ssse3_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/sqrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp + ) @@ -293,6 +308,7 @@ set(ccmath_internal_math_runtime_simd_func_impl_ssse3_headers ########################################## set(ccmath_internal_math_runtime_simd_func_impl_vector_size_headers ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/sqrt.hpp + ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp index aff96b1b..08ac3863 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp @@ -17,16 +17,16 @@ namespace ccm::intrin { - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm256_sqrt_ps(a.get())); + return simd(_mm256_pow_ps(a.get(), b.get())); } - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm256_sqrt_pd(a.get())); + return simd(_mm256_pow_pd(a.get(), b.get())); } } // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp index 922d10b7..4d9f9a61 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp @@ -19,13 +19,13 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm256_pow_ps(a.get(), b.get())); + return simd(_mm512_pow_ps(a.get(), b.get())); } CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm256_pow_pd(a.get(), b.get())); + return simd(_mm512_pow_pd(a.get(), b.get())); } diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/neon/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/neon/pow.hpp index 3cabc66e..38cafaed 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/neon/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/neon/pow.hpp @@ -10,6 +10,8 @@ #pragma once +// TODO: Implement pow for neon + #include "ccmath/internal/math/runtime/simd/simd.hpp" #ifdef CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp index 63bc9b41..633efbe9 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp @@ -10,14 +10,14 @@ #pragma once -#include "ccmath/internal/math/generic/func/power/sqrt_gen.hpp" +#include "ccmath/internal/math/generic/func/power/pow_gen.hpp" #include "ccmath/internal/math/runtime/simd/simd.hpp" namespace ccm::intrin { template - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd sqrt(simd const& a) + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd pow(simd const& a, simd const& b) { - return simd(ccm::gen::sqrt_gen(a.get())); + return simd(gen::pow_gen(a.get(), b.get())); } } // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp index 4478e56e..d6b34ee8 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp @@ -16,16 +16,16 @@ #ifdef CCMATH_HAS_SIMD_SSE2 namespace ccm::intrin { - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm_sqrt_ps(a.get())); + return simd(_mm_pow_ps(a.get(), b.get())); } - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm_sqrt_pd(a.get())); + return simd(_mm_pow_pd(a.get(), b.get())); } } // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp index c9e5a03f..f114f5ff 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp @@ -16,16 +16,16 @@ #ifdef CCMATH_HAS_SIMD_SSE3 namespace ccm::intrin { - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm_sqrt_ps(a.get())); + return simd(_mm_pow_ps(a.get(), b.get())); } - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm_sqrt_pd(a.get())); + return simd(_mm_pow_pd(a.get(), b.get())); } } // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp index e2a782e1..20e94e13 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp @@ -16,16 +16,16 @@ #ifdef CCMATH_HAS_SIMD_SSE4 namespace ccm::intrin { - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm_sqrt_ps(a.get())); + return simd(_mm_pow_ps(a.get(), b.get())); } - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm_sqrt_pd(a.get())); + return simd(_mm_pow_pd(a.get(), b.get())); } } // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp index 9be19078..235902f6 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp @@ -16,16 +16,16 @@ #ifdef CCMATH_HAS_SIMD_SSSE3 namespace ccm::intrin { - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm_sqrt_ps(a.get())); + return simd(_mm_pow_ps(a.get(), b.get())); } - CCM_ALWAYS_INLINE simd sqrt(simd const & a) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm_sqrt_pd(a.get())); + return simd(_mm_pow_pd(a.get(), b.get())); } } // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/pow.hpp deleted file mode 100644 index 81aecc7e..00000000 --- a/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/pow.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) Ian Pike - * Copyright (c) CCMath contributors - * - * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. - * See LICENSE for more information. - * - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#pragma once - -#include "ccmath/internal/math/runtime/simd/simd.hpp" - -#ifdef CCMATH_HAS_SIMD - #ifdef CCMATH_HAS_SIMD_ENABLE_VECTOR_SIZE - -namespace ccm::intrin -{ - - template - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd> sqrt(simd> const & a) - { - simd> result; - - // TODO: Implement a runtime vector_size sqrt that is optimized for runtime. - //CCM_SIMD_VECTORIZE for (int i = 0; i < a.size(); ++i) - //{ - // result.get()[i] = sqrt(a[i]); - //} - - return result; - } - -} // namespace ccm::intrin - - #endif // CCMATH_HAS_SIMD_ENABLE_VECTOR_SIZE -#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/pow.hpp index c760adec..24ae874a 100644 --- a/include/ccmath/internal/math/runtime/simd/func/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/pow.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) Ian Pike +* Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -12,3 +12,41 @@ #include "ccmath/internal/config/arch/check_simd_support.hpp" +// Generic scalar implementation +#include "impl/scalar/pow.hpp" + +#ifdef CCMATH_HAS_SIMD + #ifdef CCMATH_HAS_SIMD_SSE2 + #include "impl/sse2/pow.hpp" + #endif + + #ifdef CCMATH_HAS_SIMD_SSE3 + #include "impl/sse3/pow.hpp" + #endif + + #ifdef CCMATH_HAS_SIMD_SSSE3 + #include "impl/ssse3/pow.hpp" + #endif + + #ifdef CCMATH_HAS_SIMD_SSE4 + #include "impl/sse4/pow.hpp" + #endif + + #ifdef CCMATH_HAS_SIMD_AVX + #include "impl/avx/pow.hpp" + #endif + + #ifdef CCMATH_HAS_SIMD_AVX2 + #include "impl/avx2/pow.hpp" + #endif + + #ifdef CCMATH_HAS_SIMD_AVX512F + #include "impl/avx512/pow.hpp" + #endif + + // TODO: NEON does not have any builtin intrinsic for pow. + // Need to implement this later. + //#ifdef CCMATH_HAS_SIMD_NEON + // #include "impl/neon/pow.hpp" + //#endif +#endif From 6cf8c8ee1a7427e56d1f2088555b02b1990a46a5 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 1 Sep 2024 01:13:32 -0400 Subject: [PATCH 005/102] Setup layout for runtime pow --- .../math/runtime/func/power/pow_rt.hpp | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp index b1fab829..d2d3cda2 100644 --- a/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp +++ b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp @@ -10,9 +10,10 @@ #pragma once +#include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/config/type_support.hpp" #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" -#include "ccmath/internal/math/runtime/simd/func/sqrt.hpp" +#include "ccmath/internal/math/runtime/simd/func/pow.hpp" #include "ccmath/internal/support/always_false.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/support/fenv/rounding_mode.hpp" @@ -28,7 +29,7 @@ namespace ccm::rt::simd_impl #else template && !std::is_same_v, bool> = true> #endif - [[nodiscard]] inline T pow_simd_impl(T num) noexcept; + [[nodiscard]] inline T pow_simd_impl(T base, T exp) noexcept; #ifdef CCMATH_HAS_SIMD #if defined(CCM_TYPES_LONG_DOUBLE_IS_FLOAT64) @@ -36,11 +37,12 @@ namespace ccm::rt::simd_impl #else template && !std::is_same_v, bool>> #endif - [[nodiscard]] inline T pow_simd_impl(T num) noexcept + [[nodiscard]] inline T pow_simd_impl(T base, T exp) noexcept { - intrin::simd const num_m(num); - intrin::simd const sqrt_m = intrin::sqrt(num_m); - return sqrt_m.convert(); + intrin::simd const base_m(base); + intrin::simd const exp_m(exp); + intrin::simd const pow_m = intrin::sqrt(base_m, exp_m); + return pow_m.convert(); } #endif } // namespace ccm::rt::simd_impl @@ -48,26 +50,26 @@ namespace ccm::rt::simd_impl namespace ccm::rt { template , bool> = true> - T pow_rt(T num) + T pow_rt(T base, T exp) { #if CCM_HAS_BUILTIN(__builtin_pow) || defined(__builtin_pow) // Prefer the builtins if available. - if constexpr (std::is_same_v) { return __builtin_powf(num); } - else if constexpr (std::is_same_v) { return __builtin_pow(num); } - else if constexpr (std::is_same_v) { return __builtin_powl(num); } - else { return static_cast(__builtin_powl(static_cast(num))); } + if constexpr (std::is_same_v) { return __builtin_powf(base, exp); } + else if constexpr (std::is_same_v) { return __builtin_pow(base, exp); } + else if constexpr (std::is_same_v) { return __builtin_powl(base, exp); } + else { return static_cast(__builtin_powl(static_cast(base), static_cast(exp))); } #elif defined(CCMATH_HAS_SIMD) // In the unlikely event, the rounding mode is not the default, use the runtime implementation instead. - if (CCM_UNLIKELY(ccm::support::fenv::get_rounding_mode() != FE_TONEAREST)) { return gen::pow_gen(num); } + if (CCM_UNLIKELY(ccm::support::fenv::get_rounding_mode() != FE_TONEAREST)) { return gen::pow_gen(base, exp); } #if !defined(CCM_TYPES_LONG_DOUBLE_IS_FLOAT64) // If long double is different from double, use the generic implementation instead. - if constexpr (std::is_same_v || std::is_same_v) { return simd_impl::pow_simd_impl(num); } - else { return gen::pow_gen(num); } + if constexpr (std::is_same_v || std::is_same_v) { return simd_impl::pow_simd_impl(base, exp); } + else { return gen::pow_gen(base, exp); } #else // If long double is the same as double, we can use the SIMD implementation instead. if constexpr (std::is_same_v || std::is_same_v) { return simd_impl::sqrt_simd_impl(num); } else if constexpr (std::is_same_v) { return static_cast(simd_impl::sqrt_simd_impl(static_cast(num))); } else { return ccm::gen::sqrt_gen(num); } #endif #else // If we don't have a builtin or SIMD, use the generic implementation. - return ccm::gen::pow_gen(num); + return gen::pow_gen(num); #endif } } // namespace ccm::rt From 2269a070a5bd943fed28a531c1afbdb0d3809ca9 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 1 Sep 2024 01:13:52 -0400 Subject: [PATCH 006/102] Setup layout for runtime pow --- include/ccmath/internal/math/runtime/func/power/pow_rt.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp index d2d3cda2..fdc20c48 100644 --- a/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp +++ b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp @@ -41,7 +41,7 @@ namespace ccm::rt::simd_impl { intrin::simd const base_m(base); intrin::simd const exp_m(exp); - intrin::simd const pow_m = intrin::sqrt(base_m, exp_m); + intrin::simd const pow_m = intrin::pow(base_m, exp_m); return pow_m.convert(); } #endif From b1174e58cd40c945d186f60ce4c642108ffd49d2 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 1 Sep 2024 01:14:26 -0400 Subject: [PATCH 007/102] Setup layout for runtime pow --- include/ccmath/internal/math/runtime/func/power/pow_rt.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp index fdc20c48..f181f7ee 100644 --- a/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp +++ b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp @@ -14,11 +14,9 @@ #include "ccmath/internal/config/type_support.hpp" #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" #include "ccmath/internal/math/runtime/simd/func/pow.hpp" -#include "ccmath/internal/support/always_false.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/support/fenv/rounding_mode.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" -#include "ccmath/internal/support/is_constant_evaluated.hpp" #include From a0e64cc20cc4ee623b54481d0a2ac62171ec858d Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 1 Sep 2024 01:36:39 -0400 Subject: [PATCH 008/102] Setup generic for implementation of pow --- .../math/generic/func/power/pow_gen.hpp | 12 ++++++----- .../math/generic/func/power/pow_impl.hpp | 7 +++---- .../math/generic/func/power/powf_impl.hpp | 7 +++---- .../math/runtime/func/power/pow_rt.hpp | 10 ++++------ include/ccmath/math/power/pow.hpp | 20 ++++++++++--------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/ccmath/internal/math/generic/func/power/pow_gen.hpp b/include/ccmath/internal/math/generic/func/power/pow_gen.hpp index 3a2d975e..37433816 100644 --- a/include/ccmath/internal/math/generic/func/power/pow_gen.hpp +++ b/include/ccmath/internal/math/generic/func/power/pow_gen.hpp @@ -17,12 +17,14 @@ namespace ccm::gen { - template + template , bool> = true> constexpr T pow_gen(T base, T exp) noexcept { - //if constexpr (std::is - - return 0; + // TODO: Maybe add more specific optimizations for integers? + // Currently we only support float and double for all rounding modes + if constexpr (std::is_same_v) { return impl::powf_impl(base, exp); } + else if constexpr (std::is_same_v) { return impl::pow_impl(base, exp); } + else { return static_cast(impl::pow_impl(static_cast(base), static_cast(exp))); } } -} // namespace ccm +} // namespace ccm::gen diff --git a/include/ccmath/internal/math/generic/func/power/pow_impl.hpp b/include/ccmath/internal/math/generic/func/power/pow_impl.hpp index 0a883c4c..96acd6ac 100644 --- a/include/ccmath/internal/math/generic/func/power/pow_impl.hpp +++ b/include/ccmath/internal/math/generic/func/power/pow_impl.hpp @@ -16,15 +16,14 @@ namespace ccm::gen::impl { namespace internal::impl { - template - constexpr T pow_impl(T base, T exp) noexcept + constexpr double pow_impl(double base, double exp) noexcept { + // TODO: Implement this. return 0; } } - template - constexpr T pow_impl(T base, T exp) noexcept + constexpr double pow_impl(double base, double exp) noexcept { return internal::impl::pow_impl(base, exp); } diff --git a/include/ccmath/internal/math/generic/func/power/powf_impl.hpp b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp index 71d51bda..efdf1710 100644 --- a/include/ccmath/internal/math/generic/func/power/powf_impl.hpp +++ b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp @@ -16,15 +16,14 @@ namespace ccm::gen::impl { namespace internal::impl { - template - constexpr T powf_impl(T base, T exp) noexcept + constexpr float powf_impl(float base, float exp) noexcept { + // TODO: Implement this. return 0; } } - template - constexpr T powf_impl(T base, T exp) noexcept + constexpr float powf_impl(float base, float exp) noexcept { return internal::impl::powf_impl(base, exp); } diff --git a/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp index f181f7ee..171ecc32 100644 --- a/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp +++ b/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp @@ -11,10 +11,8 @@ #pragma once #include "ccmath/internal/predef/unlikely.hpp" -#include "ccmath/internal/config/type_support.hpp" #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" #include "ccmath/internal/math/runtime/simd/func/pow.hpp" -#include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/support/fenv/rounding_mode.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" @@ -62,12 +60,12 @@ namespace ccm::rt if constexpr (std::is_same_v || std::is_same_v) { return simd_impl::pow_simd_impl(base, exp); } else { return gen::pow_gen(base, exp); } #else // If long double is the same as double, we can use the SIMD implementation instead. - if constexpr (std::is_same_v || std::is_same_v) { return simd_impl::sqrt_simd_impl(num); } - else if constexpr (std::is_same_v) { return static_cast(simd_impl::sqrt_simd_impl(static_cast(num))); } - else { return ccm::gen::sqrt_gen(num); } + if constexpr (std::is_same_v || std::is_same_v) { return simd_impl::pow_simd_impl(base, exp); } + else if constexpr (std::is_same_v) { return static_cast(simd_impl::pow_simd_impl(static_cast(base), static_cast(exp))); } + else { return ccm::gen::pow_gen(base, exp); } #endif #else // If we don't have a builtin or SIMD, use the generic implementation. - return gen::pow_gen(num); + return gen::pow_gen(base, exp); #endif } } // namespace ccm::rt diff --git a/include/ccmath/math/power/pow.hpp b/include/ccmath/math/power/pow.hpp index 6aeb4290..fe777de6 100644 --- a/include/ccmath/math/power/pow.hpp +++ b/include/ccmath/math/power/pow.hpp @@ -11,24 +11,26 @@ #pragma once #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" +#include "ccmath/internal/math/runtime/func/power/pow_rt.hpp" #include "ccmath/internal/support/is_constant_evaluated.hpp" #include namespace ccm { - - template - constexpr T pow(T base, T exp) noexcept + template , bool> = true> + constexpr T pow(T base, T exp) { // TODO: Add in usage of builtins that meet ccmath standards. - if (support::is_constant_evaluated()) - { - return gen::pow_gen(base, exp); - } - - return gen::pow_gen(base, exp); // TODO: Replace once runtime implementation is hooked in. + if (support::is_constant_evaluated()) { return gen::pow_gen(base, exp); } + return rt::pow_rt(base, exp); } + template , bool> = true> + constexpr double pow(Integer base, Integer exp) + { + // TODO: Add integer specific optimization with exponentiation of a square + return ccm::pow(static_cast(base), static_cast(exp)); + } } // namespace ccm From a148cc05b50a34019fa5a2c0cc25deda18aa25bd Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 1 Sep 2024 02:42:12 -0400 Subject: [PATCH 009/102] Apply work around for SVML issues on Linux --- .../math/runtime/simd/func/impl/sse2/pow.hpp | 22 ++++++++++++++++- .../math/runtime/simd/func/impl/sse3/pow.hpp | 24 +++++++++++++++++-- .../math/runtime/simd/func/impl/sse4/pow.hpp | 20 ++++++++++++++++ .../math/runtime/simd/func/impl/ssse3/pow.hpp | 20 ++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp index d6b34ee8..7a8f4ada 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp @@ -14,18 +14,38 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSE2 + #include "ccmath/internal/config/platform/linux.hpp" + + #if defined(CCM_TARGET_PLATFORM_LINUX) + #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" + #endif + namespace ccm::intrin { CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) + // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler + // It appears Windows and macOS have SVML out the box so we only care about linux. + #if !defined(CCM_TARGET_PLATFORM_LINUX) return simd(_mm_pow_ps(a.get(), b.get())); + #else + // TODO: Replace this with a refined solution. For the time being this is temporary. + return simd(gen::pow_gen(a.convert(), b.convert())); + #endif } CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm_pow_pd(a.get(), b.get())); + // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler + // It appears Windows and macOS have SVML out the box so we only care about linux. + #if !defined(CCM_TARGET_PLATFORM_LINUX) + return simd(_mm_pow_pd(a.get(), b.get())); + #else + // TODO: Replace this with a refined solution. For the time being this is temporary. + return simd(gen::pow_gen(a.convert(), b.convert())); + #endif } } // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp index f114f5ff..daaacaaa 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp @@ -14,18 +14,38 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSE3 + #include "ccmath/internal/config/platform/linux.hpp" + + #if defined(CCM_TARGET_PLATFORM_LINUX) + #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" + #endif + namespace ccm::intrin { - CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) + CCM_ALWAYS_INLINE simd sqrt(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) + // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler + // It appears Windows and macOS have SVML out the box so we only care about linux. + #if !defined(CCM_TARGET_PLATFORM_LINUX) return simd(_mm_pow_ps(a.get(), b.get())); + #else + // TODO: Replace this with a refined solution. For the time being this is temporary. + return simd(gen::pow_gen(a.convert(), b.convert())); + #endif } - CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) + CCM_ALWAYS_INLINE simd sqrt(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) + // _mm_pow_pd is a part of SVML which is a part of intel's DPC++ compiler + // It appears Windows and macOS have SVML out the box so we only care about linux. + #if !defined(CCM_TARGET_PLATFORM_LINUX) return simd(_mm_pow_pd(a.get(), b.get())); + #else + // TODO: Replace this with a refined solution. For the time being this is temporary. + return simd(gen::pow_gen(a.convert(), b.convert())); + #endif } } // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp index 20e94e13..321565bd 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp @@ -14,18 +14,38 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSE4 + #include "ccmath/internal/config/platform/linux.hpp" + + #if defined(CCM_TARGET_PLATFORM_LINUX) + #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" + #endif + namespace ccm::intrin { CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) + // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler + // It appears Windows and macOS have SVML out the box so we only care about linux. + #if !defined(CCM_TARGET_PLATFORM_LINUX) return simd(_mm_pow_ps(a.get(), b.get())); + #else + // TODO: Replace this with a refined solution. For the time being this is temporary. + return simd(gen::pow_gen(a.convert(), b.convert())); + #endif } CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) + // _mm_pow_pd is a part of SVML which is a part of intel's DPC++ compiler + // It appears Windows and macOS have SVML out the box so we only care about linux. + #if !defined(CCM_TARGET_PLATFORM_LINUX) return simd(_mm_pow_pd(a.get(), b.get())); + #else + // TODO: Replace this with a refined solution. For the time being this is temporary. + return simd(gen::pow_gen(a.convert(), b.convert())); + #endif } } // namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp index 235902f6..e5a09908 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp @@ -14,18 +14,38 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSSE3 + #include "ccmath/internal/config/platform/linux.hpp" + + #if defined(CCM_TARGET_PLATFORM_LINUX) + #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" + #endif + namespace ccm::intrin { CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) + // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler + // It appears Windows and macOS have SVML out the box so we only care about linux. + #if !defined(CCM_TARGET_PLATFORM_LINUX) return simd(_mm_pow_ps(a.get(), b.get())); + #else + // TODO: Replace this with a refined solution. For the time being this is temporary. + return simd(gen::pow_gen(a.convert(), b.convert())); + #endif } CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) + // _mm_pow_pd is a part of SVML which is a part of intel's DPC++ compiler + // It appears Windows and macOS have SVML out the box so we only care about linux. + #if !defined(CCM_TARGET_PLATFORM_LINUX) return simd(_mm_pow_pd(a.get(), b.get())); + #else + // TODO: Replace this with a refined solution. For the time being this is temporary. + return simd(gen::pow_gen(a.convert(), b.convert())); + #endif } } // namespace ccm::intrin From 87637eb51e654a5de6c30e62758a75bab2dd1ab3 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 17 Oct 2024 22:45:57 -0400 Subject: [PATCH 010/102] Add initial work on reworking how sources are added along with major api changes --- CMakeLists.txt | 24 +- ccmath_core_headers.cmake | 276 ---------- ccmath_extensions_headers.cmake | 19 - ccmath_internal_headers.cmake | 521 ------------------ cmake/CcmAddHeaders.cmake | 3 + include/ccmath/CMakeLists.txt | 11 + include/ccmath/ccmath.hpp | 4 +- include/ccmath/ext/CMakeLists.txt | 19 + include/ccmath/internal/CMakeLists.txt | 13 + include/ccmath/internal/config/CMakeLists.txt | 13 + .../internal/config/arch/CMakeLists.txt | 10 + .../config/arch/targets/CMakeLists.txt | 8 + .../internal/config/builtin/CMakeLists.txt | 12 + .../internal/config/platform/CMakeLists.txt | 10 + include/ccmath/internal/math/CMakeLists.txt | 2 + .../internal/math/generic/CMakeLists.txt | 1 + .../internal/math/generic/func/CMakeLists.txt | 9 + .../math/generic/func/basic/CMakeLists.txt | 14 + .../math/generic/func/expo/CMakeLists.txt | 13 + .../math/generic/func/fmanip/CMakeLists.txt | 14 + .../math/generic/func/hyper/CMakeLists.txt | 12 + .../func/{hyperbolic => hyper}/acosh_gen.hpp | 0 .../func/{hyperbolic => hyper}/asinh_gen.hpp | 0 .../func/{hyperbolic => hyper}/atanh_gen.hpp | 0 .../func/{hyperbolic => hyper}/cosh_gen.hpp | 0 .../func/{hyperbolic => hyper}/sinh_gen.hpp | 0 .../func/{hyperbolic => hyper}/tanh_gen.hpp | 0 .../math/generic/func/misc/CMakeLists.txt | 7 + .../math/generic/func/nearest/CMakeLists.txt | 12 + .../math/generic/func/power/CMakeLists.txt | 16 + .../math/generic/func/power/pow_impl.hpp | 4 +- .../math/generic/func/power/powf_impl.hpp | 2 +- .../math/generic/func/special/CMakeLists.txt | 27 + .../math/generic/func/trig/CMakeLists.txt | 13 + .../internal/math/runtime/CMakeLists.txt | 2 + .../internal/math/runtime/func/CMakeLists.txt | 1 + .../math/runtime/func/power/CMakeLists.txt | 8 + .../internal/math/runtime/simd/CMakeLists.txt | 7 + include/ccmath/math/CMakeLists.txt | 26 + include/ccmath/math/basic/CMakeLists.txt | 17 + include/ccmath/math/basic/impl/CMakeLists.txt | 13 + .../math/basic/impl/runtime/fma_rt_impl.hpp | 34 -- include/ccmath/math/compare/CMakeLists.txt | 18 + .../ccmath/math/{exponential.hpp => expo.hpp} | 0 include/ccmath/math/expo/CMakeLists.txt | 15 + .../ccmath/math/{exponential => expo}/exp.hpp | 0 .../math/{exponential => expo}/exp2.hpp | 0 .../math/{exponential => expo}/expm1.hpp | 0 include/ccmath/math/expo/impl/CMakeLists.txt | 18 + .../{exponential => expo}/impl/exp2_data.hpp | 0 .../impl/exp2_double_impl.hpp | 0 .../impl/exp2_float_impl.hpp | 0 .../{exponential => expo}/impl/exp_data.hpp | 0 .../impl/exp_double_impl.hpp | 0 .../impl/exp_float_impl.hpp | 0 .../{exponential => expo}/impl/log2_data.hpp | 0 .../impl/log2_double_impl.hpp | 0 .../impl/log2_float_impl.hpp | 0 .../{exponential => expo}/impl/log_data.hpp | 0 .../impl/log_double_impl.hpp | 0 .../impl/log_float_impl.hpp | 0 .../ccmath/math/{exponential => expo}/log.hpp | 0 .../math/{exponential => expo}/log10.hpp | 0 .../math/{exponential => expo}/log1p.hpp | 0 .../math/{exponential => expo}/log2.hpp | 0 include/ccmath/math/fmanip/CMakeLists.txt | 17 + .../ccmath/math/fmanip/impl/CMakeLists.txt | 12 + .../ccmath/math/{hyperbolic.hpp => hyper.hpp} | 0 include/ccmath/math/hyper/CMakeLists.txt | 12 + .../math/{hyperbolic => hyper}/acosh.hpp | 0 .../math/{hyperbolic => hyper}/asinh.hpp | 0 .../math/{hyperbolic => hyper}/atanh.hpp | 0 .../math/{hyperbolic => hyper}/cosh.hpp | 0 .../math/{hyperbolic => hyper}/sinh.hpp | 0 .../math/{hyperbolic => hyper}/tanh.hpp | 0 include/ccmath/math/misc/CMakeLists.txt | 9 + include/ccmath/math/nearest/CMakeLists.txt | 12 + include/ccmath/math/power/CMakeLists.txt | 10 + include/ccmath/math/special/CMakeLists.txt | 27 + include/ccmath/math/trig/CMakeLists.txt | 13 + 80 files changed, 496 insertions(+), 864 deletions(-) delete mode 100644 ccmath_core_headers.cmake delete mode 100644 ccmath_extensions_headers.cmake delete mode 100644 ccmath_internal_headers.cmake create mode 100644 cmake/CcmAddHeaders.cmake create mode 100644 include/ccmath/CMakeLists.txt create mode 100644 include/ccmath/ext/CMakeLists.txt create mode 100644 include/ccmath/internal/CMakeLists.txt create mode 100644 include/ccmath/internal/config/CMakeLists.txt create mode 100644 include/ccmath/internal/config/arch/CMakeLists.txt create mode 100644 include/ccmath/internal/config/arch/targets/CMakeLists.txt create mode 100644 include/ccmath/internal/config/builtin/CMakeLists.txt create mode 100644 include/ccmath/internal/config/platform/CMakeLists.txt create mode 100644 include/ccmath/internal/math/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/func/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/func/basic/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/func/expo/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt rename include/ccmath/internal/math/generic/func/{hyperbolic => hyper}/acosh_gen.hpp (100%) rename include/ccmath/internal/math/generic/func/{hyperbolic => hyper}/asinh_gen.hpp (100%) rename include/ccmath/internal/math/generic/func/{hyperbolic => hyper}/atanh_gen.hpp (100%) rename include/ccmath/internal/math/generic/func/{hyperbolic => hyper}/cosh_gen.hpp (100%) rename include/ccmath/internal/math/generic/func/{hyperbolic => hyper}/sinh_gen.hpp (100%) rename include/ccmath/internal/math/generic/func/{hyperbolic => hyper}/tanh_gen.hpp (100%) create mode 100644 include/ccmath/internal/math/generic/func/misc/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/func/power/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/func/special/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/func/trig/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/func/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/func/power/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/CMakeLists.txt create mode 100644 include/ccmath/math/CMakeLists.txt create mode 100644 include/ccmath/math/basic/CMakeLists.txt create mode 100644 include/ccmath/math/basic/impl/CMakeLists.txt delete mode 100644 include/ccmath/math/basic/impl/runtime/fma_rt_impl.hpp create mode 100644 include/ccmath/math/compare/CMakeLists.txt rename include/ccmath/math/{exponential.hpp => expo.hpp} (100%) create mode 100644 include/ccmath/math/expo/CMakeLists.txt rename include/ccmath/math/{exponential => expo}/exp.hpp (100%) rename include/ccmath/math/{exponential => expo}/exp2.hpp (100%) rename include/ccmath/math/{exponential => expo}/expm1.hpp (100%) create mode 100644 include/ccmath/math/expo/impl/CMakeLists.txt rename include/ccmath/math/{exponential => expo}/impl/exp2_data.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/exp2_double_impl.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/exp2_float_impl.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/exp_data.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/exp_double_impl.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/exp_float_impl.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/log2_data.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/log2_double_impl.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/log2_float_impl.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/log_data.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/log_double_impl.hpp (100%) rename include/ccmath/math/{exponential => expo}/impl/log_float_impl.hpp (100%) rename include/ccmath/math/{exponential => expo}/log.hpp (100%) rename include/ccmath/math/{exponential => expo}/log10.hpp (100%) rename include/ccmath/math/{exponential => expo}/log1p.hpp (100%) rename include/ccmath/math/{exponential => expo}/log2.hpp (100%) create mode 100644 include/ccmath/math/fmanip/CMakeLists.txt create mode 100644 include/ccmath/math/fmanip/impl/CMakeLists.txt rename include/ccmath/math/{hyperbolic.hpp => hyper.hpp} (100%) create mode 100644 include/ccmath/math/hyper/CMakeLists.txt rename include/ccmath/math/{hyperbolic => hyper}/acosh.hpp (100%) rename include/ccmath/math/{hyperbolic => hyper}/asinh.hpp (100%) rename include/ccmath/math/{hyperbolic => hyper}/atanh.hpp (100%) rename include/ccmath/math/{hyperbolic => hyper}/cosh.hpp (100%) rename include/ccmath/math/{hyperbolic => hyper}/sinh.hpp (100%) rename include/ccmath/math/{hyperbolic => hyper}/tanh.hpp (100%) create mode 100644 include/ccmath/math/misc/CMakeLists.txt create mode 100644 include/ccmath/math/nearest/CMakeLists.txt create mode 100644 include/ccmath/math/power/CMakeLists.txt create mode 100644 include/ccmath/math/special/CMakeLists.txt create mode 100644 include/ccmath/math/trig/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b5acd83..96e6ad57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ option(CCMATH_FIND_GTEST_PACKAGE "Enable finding of gtest package" OFF) option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project}) option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project}) option(CCMATH_FIND_GBENCH_PACKAGE "Enable finding of google benchmark package" OFF) -option(CCMATH_INSTALL "Setup install and package steps" ${is_root_project}) +option(CCMATH_INSTALL "Setup install and package steps" OFF)#${is_root_project} option(CCMATH_ENABLE_EXTENSIONS "Enable the extended ccmath library that adds helpful additional methods that are not defined by the standard" ${is_root_project}) option(CCMATH_ENABLE_RUNTIME_SIMD "Enable SIMD optimization for runtime evaluation (does not effect compile time)" ON) option(CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS "Enable user defined optimization macros instead of having ccmath define its own internal ones in cmake" OFF) @@ -93,19 +93,25 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|IntelLLVM") ) endif () -include(ccmath_internal_headers.cmake) -include(ccmath_core_headers.cmake) +#include(ccmath_internal_headers.cmake) +#include(ccmath_core_headers.cmake) add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -target_sources(${PROJECT_NAME} INTERFACE "$") -target_sources(${PROJECT_NAME} INTERFACE "$") +# IanP: Begin initial work here -if (CCMATH_ENABLE_EXTENSIONS) - include(ccmath_extensions_headers.cmake) - target_sources(${PROJECT_NAME} INTERFACE "$") -endif () +add_subdirectory(include/ccmath) + +#message(STATUS "ccmath_internal_headers: ${ccmath_internal_headers}") + +#target_sources(${PROJECT_NAME} INTERFACE "$") +#target_sources(${PROJECT_NAME} INTERFACE "$") + +#if (CCMATH_ENABLE_EXTENSIONS) +# include(ccmath_extensions_headers.cmake) +# target_sources(${PROJECT_NAME} INTERFACE "$") +#endif () target_include_directories(${PROJECT_NAME} INTERFACE $) target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE $/include>) diff --git a/ccmath_core_headers.cmake b/ccmath_core_headers.cmake deleted file mode 100644 index a5c8fb00..00000000 --- a/ccmath_core_headers.cmake +++ /dev/null @@ -1,276 +0,0 @@ - - - - - -############################################################################## -# Math Section -############################################################################## - -# TODO: Remove all impls from here into the generic headers. - -### Basic/Impl headers -########################################## -set(ccmath_math_basic_impl_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/impl/nan_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/impl/nan_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/impl/nan_ldouble_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/impl/remquo_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/impl/remquo_double_impl.hpp -) - - - -####################################### -## Basic headers -####################################### - -set(ccmath_math_basic_headers - ${ccmath_math_basic_impl_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/abs.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/fdim.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/fma.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/fmod.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/max.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/min.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/remainder.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic/remquo.hpp -) - - - -####################################### -## Compare headers -####################################### - -set(ccmath_math_compare_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/fpclassify.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/isfinite.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/isgreater.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/isgreaterequal.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/isinf.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/isless.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/islessequal.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/islessgreater.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/isnan.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/isnormal.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/isunordered.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare/signbit.hpp -) - - -### Exponential/Impl headers -########################################## -set(ccmath_math_exponential_impl_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/exp_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/exp_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/exp_data.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/exp2_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/exp2_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/exp2_data.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/log_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/log_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/log_data.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/log2_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/log2_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/impl/log2_data.hpp -) - - - -####################################### -## Exponential headers -####################################### - -set(ccmath_math_exponential_headers - ${ccmath_math_exponential_impl_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/exp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/exp2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/expm1.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/log.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/log1p.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/log2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential/log10.hpp -) - - -### Fmanip/Impl headers -########################################## -set(ccmath_math_fmanip_impl_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/impl/modf_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/impl/modf_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/impl/scalbn_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp -) - - - -####################################### -## Fmanip headers -####################################### - -set(ccmath_math_fmanip_headers - ${ccmath_math_fmanip_impl_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/copysign.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/frexp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/ilogb.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/ldexp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/logb.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/modf.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/nextafter.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/nexttoward.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip/scalbn.hpp -) - - - -####################################### -## Hyperbolic headers -####################################### - -set(ccmath_math_hyperbolic_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/hyperbolic/acosh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/hyperbolic/asinh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/hyperbolic/atanh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/hyperbolic/cosh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/hyperbolic/sinh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/hyperbolic/tanh.hpp -) - - - -####################################### -## Nearest headers -####################################### - -set(ccmath_detail_nearest_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/nearest/ceil.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/nearest/floor.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/nearest/nearbyint.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/nearest/rint.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/nearest/round.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/nearest/trunc.hpp -) - - -####################################### -## Power headers -####################################### - -set(ccmath_math_power_headers - ${ccmath_math_power_impl_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/power/cbrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/power/hypot.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/power/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/power/sqrt.hpp -) - - - -####################################### -## Special headers -####################################### - -set(ccmath_math_special_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/assoc_laguerre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/assoc_legendre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/beta.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/comp_ellint_1.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/comp_ellint_2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/comp_ellint_3.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/cyl_bessel_i.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/cyl_bessel_j.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/cyl_bessel_k.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/cyl_neumann.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/ellint_1.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/ellint_2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/ellint_3.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/expint.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/hermite.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/laguerre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/legendre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/riemann_zeta.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/sph_bessel.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/sph_legendre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special/sph_neumann.hpp -) - - - -####################################### -## Trig headers -####################################### - -set(ccmath_math_trig_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/trig/acos.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/trig/asin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/trig/atan.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/trig/atan2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/trig/cos.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/trig/sin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/trig/tan.hpp -) - - - -####################################### -## Math headers (root) -####################################### -set(ccmath_math_misc_headers - # func without a specified category - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/misc/gamma.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/misc/lerp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/misc/lgamma.hpp -) - -set(ccmath_math_headers - ${ccmath_math_basic_headers} - ${ccmath_math_compare_headers} - ${ccmath_math_exponential_headers} - ${ccmath_math_fmanip_headers} - ${ccmath_math_hyperbolic_headers} - ${ccmath_math_nearest_headers} - ${ccmath_math_power_headers} - ${ccmath_math_trig_headers} - ${ccmath_math_misc_headers} -) - - - - -############################################################################## -# Root Section -############################################################################## - - - -####################################### -## CCMath headers Monolithic Headers -####################################### - -set(ccmath_monolithic_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/basic.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/compare.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/exponential.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/fmanip.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/hyperbolic.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/nearest.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/power.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/special.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/trig.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/math/numbers.hpp - - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ccmath.hpp -) - - - -####################################### -## CCMath headers (base) - all headers -####################################### - -set(ccmath_core_headers - ${ccmath_math_headers} - ${ccmath_monolithic_headers} -) diff --git a/ccmath_extensions_headers.cmake b/ccmath_extensions_headers.cmake deleted file mode 100644 index 40d21d19..00000000 --- a/ccmath_extensions_headers.cmake +++ /dev/null @@ -1,19 +0,0 @@ - - -set(ccmath_extensions_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/align.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/clamp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/cubic.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/degrees.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/fract.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/is_power_of_two.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/lerp_smooth.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/mix.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/normalize.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/ping_pong.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/radians.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/rcp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/ext/smoothstep.hpp - - -) diff --git a/ccmath_internal_headers.cmake b/ccmath_internal_headers.cmake deleted file mode 100644 index 4c03a84d..00000000 --- a/ccmath_internal_headers.cmake +++ /dev/null @@ -1,521 +0,0 @@ -############################################################################## -# Internal Section -############################################################################## - -########################################## -### Config Section -########################################## - -### Config/Arch/Targets headers -########################################## -set(ccmath_internal_config_arch_targets_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/arch/targets/aarch64.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/arch/targets/x86_64.hpp -) - - -### Config/Arch headers -########################################## -set(ccmath_internal_config_arch_headers - ${ccmath_internal_config_arch_targets_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/arch/check_arch_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/arch/check_simd_support.hpp -) - - -### Config/Builtin headers -########################################## -set(ccmath_internal_config_builtin_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/builtin/bit_cast_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/builtin/copysign_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/builtin/exp2_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/builtin/fma_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/builtin/ldexp_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/builtin/signbit_support.hpp -) - - -### Config/Platform headers -########################################## -set(ccmath_internal_config_platform_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/platform/android.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/platform/darwin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/platform/linux.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/platform/windows.hpp -) - - - -########################################## -## Config headers -########################################## - -set(ccmath_internal_config_headers - ${ccmath_internal_config_arch_headers} - ${ccmath_internal_config_builtin_headers} - ${ccmath_internal_config_platform_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/compiler.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/runtime_detection.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/type_support.hpp -) - - -########################################## -### Math Section -########################################## - -### Generic Module -########################################## - -### Math/Generic/Func/Basic headers -########################################## -set(ccmath_internal_math_generic_func_basic_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/basic/abs_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/basic/fdim_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/basic/fmod_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/basic/max_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/basic/min_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/basic/remainder_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/basic/remquo_gen.hpp -) - - -### Math/Generic/Func/Expo headers -########################################## -set(ccmath_internal_math_generic_func_expo_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/exp2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/exp_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/expm1_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/log1p_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/log2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/log10_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/expo/log_gen.hpp -) - - -### Math/Generic/Func/Fmanip headers -########################################## -set(ccmath_internal_math_generic_func_fmanip_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/fmanip/copysign_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/fmanip/frexp_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/fmanip/ilogb_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/fmanip/ldexp_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/fmanip/logb_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/fmanip/modf_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/fmanip/nextafter_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/fmanip/scalbn_gen.hpp -) - - -### Math/Generic/Func/Hyperbolic headers -########################################## -set(ccmath_internal_math_generic_func_hyperbolic_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/hyperbolic/acosh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/hyperbolic/asinh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/hyperbolic/atanh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/hyperbolic/cosh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/hyperbolic/sinh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/hyperbolic/tanh_gen.hpp -) - - -### Math/Generic/Func/Misc headers -########################################## -set(ccmath_internal_math_generic_func_misc_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/misc/lerp_gen.hpp -) - - -### Math/Generic/Func/Nearest headers -########################################## -set(ccmath_internal_math_generic_func_nearest_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/ceil_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/floor_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/nearbyint_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/rint_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/round_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/nearest/trunc_gen.hpp -) - - -### Math/Generic/Func/Power headers -########################################## -set(ccmath_internal_math_generic_func_power_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/cbrt_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/hypot_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/pow_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/pow_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/powf_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp -) - - -### Math/Generic/Func/Special headers -########################################## -set(ccmath_internal_math_generic_func_special_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/assoc_laguerre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/assoc_legendre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/beta_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/comp_ellint_1_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/comp_ellint_2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/comp_ellint_3_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_bessel_i_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_bessel_j_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_bessel_k_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/cyl_neumann_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/ellint_1_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/ellint_2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/ellint_3_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/expint_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/hermite_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/laguerre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/legendre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/riemann_zeta_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/sph_bessel_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/sph_legendre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/special/sph_neumann_gen.hpp -) - - -### Math/Generic/Func/Trig headers -########################################## -set(ccmath_internal_math_generic_func_trig_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/trig/acos_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/trig/asin_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/trig/atan2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/trig/cos_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/trig/sin_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/generic/func/trig/tan_gen.hpp -) - - -### Math/Generic/Func headers -########################################## -set(ccmath_internal_math_generic_func_headers - ${ccmath_internal_math_generic_func_basic_headers} - ${ccmath_internal_math_generic_func_expo_headers} - ${ccmath_internal_math_generic_func_fmanip_headers} - ${ccmath_internal_math_generic_func_hyperbolic_headers} - ${ccmath_internal_math_generic_func_misc_headers} - ${ccmath_internal_math_generic_func_nearest_headers} - ${ccmath_internal_math_generic_func_power_headers} - ${ccmath_internal_math_generic_func_special_headers} - ${ccmath_internal_math_generic_func_trig_headers} -) - - -### Math/Generic headers -########################################## -set(ccmath_internal_math_generic_headers - ${ccmath_internal_math_generic_func_headers} -) - - -### Math/Runtime/Func/Power headers -########################################## -set(ccmath_internal_math_runtime_func_power_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/func/power/pow_rt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/func/power/sqrt_rt.hpp -) - -### Math/Runtime/Func headers -########################################## -set(ccmath_internal_math_runtime_func_headers - ${ccmath_internal_math_runtime_func_power_headers} -) - - -### math/runtime/Simd/Func/Impl/Avx headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_avx_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx/sqrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx/pow.hpp -) - - -### math/runtime/Simd/Func/Impl/Avx2 headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_avx2_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx2/sqrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx2/pow.hpp - -) - - -### math/runtime/Simd/Func/Impl/Avx512 headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_avx512_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx512/sqrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp - -) - - -### math/runtime/Simd/Func/Impl/Neon headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_neon_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/neon/sqrt.hpp -) - - -### math/runtime/Simd/Func/Impl/Scalar headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_scalar_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/scalar/sqrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/scalar/pow.hpp - -) - - -### math/runtime/Simd/Func/Impl/Sse2 headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_sse2_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse2/sqrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp - -) - - -### math/runtime/Simd/Func/Impl/Sse3 headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_sse3_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse3/sqrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp - -) - - -### math/runtime/Simd/Func/Impl/Sse4 headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_sse4_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse4/sqrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp - -) - - -### math/runtime/Simd/Func/Impl/Ssse3 headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_ssse3_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/sqrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/pow.hpp - -) - - -### math/runtime/Simd/Func/Impl/Vector_Size headers -########################################## -set(ccmath_internal_math_runtime_simd_func_impl_vector_size_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/sqrt.hpp - -) - - -### math/runtime/Simd/Func headers -########################################## -set(ccmath_internal_math_runtime_simd_func_headers - ${ccmath_internal_math_runtime_simd_func_impl_avx_headers} - ${ccmath_internal_math_runtime_simd_func_impl_avx2_headers} - ${ccmath_internal_math_runtime_simd_func_impl_avx512_headers} - ${ccmath_internal_math_runtime_simd_func_impl_neon_headers} - ${ccmath_internal_math_runtime_simd_func_impl_scalar_headers} - ${ccmath_internal_math_runtime_simd_func_impl_sse2_headers} - ${ccmath_internal_math_runtime_simd_func_impl_sse3_headers} - ${ccmath_internal_math_runtime_simd_func_impl_ssse3_headers} - ${ccmath_internal_math_runtime_simd_func_impl_sse4_headers} - ${ccmath_internal_math_runtime_simd_func_impl_vector_size_headers} - - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/sqrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/func/pow.hpp -) - - -### math/runtime/Simd/Instructions headers -########################################## -set(ccmath_internal_math_runtime_simd_instructions_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/instructions/scalar.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/instructions/sse2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/instructions/sse3.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/instructions/ssse3.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/instructions/sse4.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/instructions/avx.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/instructions/avx2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/instructions/avx512.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/instructions/neon.hpp -) - - -### math/runtime/Simd headers -########################################## -set(ccmath_internal_math_runtime_simd_headers - ${ccmath_internal_math_runtime_simd_func_headers} - ${ccmath_internal_math_runtime_simd_instructions_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/common.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/pack.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/simd_vectorize.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/vector_size.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/math/runtime/simd/simd.hpp -) - -### Math/Runtime headers -########################################## -set(ccmath_internal_math_runtime_headers - ${ccmath_internal_math_runtime_func_headers} - ${ccmath_internal_math_runtime_simd_headers} -) - - -########################################## -## Math headers -########################################## - -set(ccmath_internal_math_headers - ${ccmath_internal_math_generic_headers} - ${ccmath_internal_math_runtime_headers} -) - - - -### Predef/Attributes headers -########################################## -set(ccmath_internal_predef_attributes_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/attributes/always_inline.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/attributes/never_inline.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/attributes/no_debug.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/attributes/optnone.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/attributes/gsl_suppress.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/attributes/gpu_device.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/attributes/gpu_host_device.hpp -) - - -### Predef/Compiler_Suppression headers -########################################## -set(ccmath_internal_predef_compiler_suppression_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/compiler_suppression/clang_compiler_suppression.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/compiler_suppression/gcc_compiler_suppression.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp -) - - -### Predef/Versioning headers -########################################## -set(ccmath_internal_predef_versioning_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/versioning/arm_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/versioning/clang_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/versioning/gcc_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/versioning/msvc_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/versioning/msvc_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/versioning/version_encode.hpp -) - - - -########################################## -## Predef headers -########################################## - -set(ccmath_internal_predef_headers - ${ccmath_internal_predef_attributes_headers} - ${ccmath_internal_predef_compiler_suppression_headers} - ${ccmath_internal_predef_versioning_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/expects_bool_condition.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/has_attribute.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/likely.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/has_builtin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/has_const_builtin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/assume.hpp -) - - - - -### Support/Fenv headers -########################################## -set(ccmath_internal_support_fenv_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/fenv/fenv_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/fenv/rounding_mode.hpp -) - - -### Support/FP headers -########################################## -set(ccmath_internal_support_fp_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/fp/bit_mask_traits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/fp/directional_rounding_utils.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/fp/fp_bits.hpp -) - -## Support/Helpers headers -########################################## - -set(ccmath_internal_support_helpers_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/helpers/digit_to_int.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/helpers/fpclassify_helper.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/helpers/exp_helpers.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/helpers/exp10.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/helpers/internal_ldexp.hpp -) - - - -####################################### -## Support headers -####################################### - -set(ccmath_internal_support_headers - ${ccmath_internal_support_fenv_headers} - ${ccmath_internal_support_fp_headers} - ${ccmath_internal_support_helpers_headers} - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/always_false.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/bits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/ctz.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/endian.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/floating_point_traits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/integer_literals.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/is_constant_evaluated.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/limits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/math_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/meta_compare.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/multiply_add.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/poly_eval.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/type_traits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/unreachable.hpp -) - - - -####################################### -## Types headers -####################################### - -set(ccmath_internal_types_headers - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/fp_types.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/number_pair.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/sign.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/float128.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/int128_types.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/double_double.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/triple_double.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/big_int.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/dyadic_float.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/normalized_float.hpp - -) - - - -############################################################################## -# Internal headers -############################################################################## - -set(ccmath_internal_headers - ${ccmath_internal_config_headers} - ${ccmath_internal_math_headers} - ${ccmath_internal_predef_headers} - ${ccmath_internal_support_headers} - ${ccmath_internal_types_headers} - - ${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/setup.hpp -) diff --git a/cmake/CcmAddHeaders.cmake b/cmake/CcmAddHeaders.cmake new file mode 100644 index 00000000..13326bca --- /dev/null +++ b/cmake/CcmAddHeaders.cmake @@ -0,0 +1,3 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() diff --git a/include/ccmath/CMakeLists.txt b/include/ccmath/CMakeLists.txt new file mode 100644 index 00000000..44340024 --- /dev/null +++ b/include/ccmath/CMakeLists.txt @@ -0,0 +1,11 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/ccmath.hpp +) + +add_subdirectory(ext) +add_subdirectory(internal) +add_subdirectory(math) diff --git a/include/ccmath/ccmath.hpp b/include/ccmath/ccmath.hpp index 408fa583..48391e38 100644 --- a/include/ccmath/ccmath.hpp +++ b/include/ccmath/ccmath.hpp @@ -17,13 +17,13 @@ #include "math/compare.hpp" /// Exponential func -#include "math/exponential.hpp" +#include "math/expo.hpp" /// Float manipulation func #include "math/fmanip.hpp" /// Hyperbolic func -#include "math/hyperbolic.hpp" +#include "math/hyper.hpp" /// Nearest func #include "math/nearest.hpp" diff --git a/include/ccmath/ext/CMakeLists.txt b/include/ccmath/ext/CMakeLists.txt new file mode 100644 index 00000000..b791d764 --- /dev/null +++ b/include/ccmath/ext/CMakeLists.txt @@ -0,0 +1,19 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/align.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/clamp.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cubic.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/degrees.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fract.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/is_power_of_two.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/lerp_smooth.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/mix.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/normalize.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ping_pong.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/radians.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/rcp.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/smoothstep.hpp +) diff --git a/include/ccmath/internal/CMakeLists.txt b/include/ccmath/internal/CMakeLists.txt new file mode 100644 index 00000000..c277ad81 --- /dev/null +++ b/include/ccmath/internal/CMakeLists.txt @@ -0,0 +1,13 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/setup.hpp +) + +add_subdirectory(config) +add_subdirectory(math) +#add_subdirectory(predef) +#add_subdirectory(support) +#add_subdirectory(types) diff --git a/include/ccmath/internal/config/CMakeLists.txt b/include/ccmath/internal/config/CMakeLists.txt new file mode 100644 index 00000000..08b5adac --- /dev/null +++ b/include/ccmath/internal/config/CMakeLists.txt @@ -0,0 +1,13 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/compiler.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/runtime_detection.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/type_support.hpp +) + +add_subdirectory(arch) +add_subdirectory(builtin) +add_subdirectory(platform) diff --git a/include/ccmath/internal/config/arch/CMakeLists.txt b/include/ccmath/internal/config/arch/CMakeLists.txt new file mode 100644 index 00000000..64f4dc1d --- /dev/null +++ b/include/ccmath/internal/config/arch/CMakeLists.txt @@ -0,0 +1,10 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/check_arch_support.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/check_simd_support.hpp +) + +add_subdirectory(targets) diff --git a/include/ccmath/internal/config/arch/targets/CMakeLists.txt b/include/ccmath/internal/config/arch/targets/CMakeLists.txt new file mode 100644 index 00000000..7a2aab12 --- /dev/null +++ b/include/ccmath/internal/config/arch/targets/CMakeLists.txt @@ -0,0 +1,8 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/aarch64.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/x86_64.hpp +) diff --git a/include/ccmath/internal/config/builtin/CMakeLists.txt b/include/ccmath/internal/config/builtin/CMakeLists.txt new file mode 100644 index 00000000..2cabfc24 --- /dev/null +++ b/include/ccmath/internal/config/builtin/CMakeLists.txt @@ -0,0 +1,12 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/bit_cast_support.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/copysign_support.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp2_support.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fma_support.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ldexp_support.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/signbit_support.hpp +) diff --git a/include/ccmath/internal/config/platform/CMakeLists.txt b/include/ccmath/internal/config/platform/CMakeLists.txt new file mode 100644 index 00000000..b4b84cd6 --- /dev/null +++ b/include/ccmath/internal/config/platform/CMakeLists.txt @@ -0,0 +1,10 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/android.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/darwin.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/linux.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/windows.hpp +) diff --git a/include/ccmath/internal/math/CMakeLists.txt b/include/ccmath/internal/math/CMakeLists.txt new file mode 100644 index 00000000..a8433b08 --- /dev/null +++ b/include/ccmath/internal/math/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(generic) +add_subdirectory(runtime) diff --git a/include/ccmath/internal/math/generic/CMakeLists.txt b/include/ccmath/internal/math/generic/CMakeLists.txt new file mode 100644 index 00000000..77809222 --- /dev/null +++ b/include/ccmath/internal/math/generic/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(func) diff --git a/include/ccmath/internal/math/generic/func/CMakeLists.txt b/include/ccmath/internal/math/generic/func/CMakeLists.txt new file mode 100644 index 00000000..2e820eba --- /dev/null +++ b/include/ccmath/internal/math/generic/func/CMakeLists.txt @@ -0,0 +1,9 @@ +add_subdirectory(basic) +add_subdirectory(expo) +add_subdirectory(fmanip) +add_subdirectory(hyper) +add_subdirectory(misc) +add_subdirectory(nearest) +add_subdirectory(power) +add_subdirectory(special) +add_subdirectory(trig) diff --git a/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt b/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt new file mode 100644 index 00000000..0d166f72 --- /dev/null +++ b/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt @@ -0,0 +1,14 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/abs_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fdim_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fma_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fmod_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/max_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/min_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/remainder_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/remquo_gen.hpp +) diff --git a/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt b/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt new file mode 100644 index 00000000..a1a07f04 --- /dev/null +++ b/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt @@ -0,0 +1,13 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/exp2_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/expm1_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log1p_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log2_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log10_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log_gen.hpp +) diff --git a/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt b/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt new file mode 100644 index 00000000..25776073 --- /dev/null +++ b/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt @@ -0,0 +1,14 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/copysign_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/frexp_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ilogb_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ldexp_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/logb_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/modf_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nextafter_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/scalbn_gen.hpp +) diff --git a/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt b/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt new file mode 100644 index 00000000..32f6c8c7 --- /dev/null +++ b/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt @@ -0,0 +1,12 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/acosh_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/asinh_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/atanh_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cosh_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sinh_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/tanh_gen.hpp +) diff --git a/include/ccmath/internal/math/generic/func/hyperbolic/acosh_gen.hpp b/include/ccmath/internal/math/generic/func/hyper/acosh_gen.hpp similarity index 100% rename from include/ccmath/internal/math/generic/func/hyperbolic/acosh_gen.hpp rename to include/ccmath/internal/math/generic/func/hyper/acosh_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/hyperbolic/asinh_gen.hpp b/include/ccmath/internal/math/generic/func/hyper/asinh_gen.hpp similarity index 100% rename from include/ccmath/internal/math/generic/func/hyperbolic/asinh_gen.hpp rename to include/ccmath/internal/math/generic/func/hyper/asinh_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/hyperbolic/atanh_gen.hpp b/include/ccmath/internal/math/generic/func/hyper/atanh_gen.hpp similarity index 100% rename from include/ccmath/internal/math/generic/func/hyperbolic/atanh_gen.hpp rename to include/ccmath/internal/math/generic/func/hyper/atanh_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/hyperbolic/cosh_gen.hpp b/include/ccmath/internal/math/generic/func/hyper/cosh_gen.hpp similarity index 100% rename from include/ccmath/internal/math/generic/func/hyperbolic/cosh_gen.hpp rename to include/ccmath/internal/math/generic/func/hyper/cosh_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/hyperbolic/sinh_gen.hpp b/include/ccmath/internal/math/generic/func/hyper/sinh_gen.hpp similarity index 100% rename from include/ccmath/internal/math/generic/func/hyperbolic/sinh_gen.hpp rename to include/ccmath/internal/math/generic/func/hyper/sinh_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/hyperbolic/tanh_gen.hpp b/include/ccmath/internal/math/generic/func/hyper/tanh_gen.hpp similarity index 100% rename from include/ccmath/internal/math/generic/func/hyperbolic/tanh_gen.hpp rename to include/ccmath/internal/math/generic/func/hyper/tanh_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt b/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt new file mode 100644 index 00000000..c0f53876 --- /dev/null +++ b/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt @@ -0,0 +1,7 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/lerp_gen.hpp +) diff --git a/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt b/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt new file mode 100644 index 00000000..5864e614 --- /dev/null +++ b/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt @@ -0,0 +1,12 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/ceil_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/floor_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nearbyint_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/rint_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/round_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/trunc_gen.hpp +) diff --git a/include/ccmath/internal/math/generic/func/power/CMakeLists.txt b/include/ccmath/internal/math/generic/func/power/CMakeLists.txt new file mode 100644 index 00000000..8fa8b4e5 --- /dev/null +++ b/include/ccmath/internal/math/generic/func/power/CMakeLists.txt @@ -0,0 +1,16 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/cbrt_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/hypot_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/pow_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt_gen.hpp +) + +# TODO: Move this to its own folder at some point +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/powf_impl.hpp +) diff --git a/include/ccmath/internal/math/generic/func/power/pow_impl.hpp b/include/ccmath/internal/math/generic/func/power/pow_impl.hpp index 96acd6ac..7777a9b1 100644 --- a/include/ccmath/internal/math/generic/func/power/pow_impl.hpp +++ b/include/ccmath/internal/math/generic/func/power/pow_impl.hpp @@ -21,11 +21,11 @@ namespace ccm::gen::impl // TODO: Implement this. return 0; } - } + } // namespace internal::impl constexpr double pow_impl(double base, double exp) noexcept { return internal::impl::pow_impl(base, exp); } -} // namespace ccm +} // namespace ccm::gen::impl diff --git a/include/ccmath/internal/math/generic/func/power/powf_impl.hpp b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp index efdf1710..98a84973 100644 --- a/include/ccmath/internal/math/generic/func/power/powf_impl.hpp +++ b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp @@ -28,4 +28,4 @@ namespace ccm::gen::impl return internal::impl::powf_impl(base, exp); } -} // namespace ccm +} // namespace ccm::gen::impl diff --git a/include/ccmath/internal/math/generic/func/special/CMakeLists.txt b/include/ccmath/internal/math/generic/func/special/CMakeLists.txt new file mode 100644 index 00000000..7b32d477 --- /dev/null +++ b/include/ccmath/internal/math/generic/func/special/CMakeLists.txt @@ -0,0 +1,27 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/assoc_laguerre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/assoc_legendre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/beta_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_1_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_2_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_3_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_i_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_j_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_k_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cyl_neumann_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ellint_1_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ellint_2_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ellint_3_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/expint_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/hermite_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/laguerre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/legendre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/riemann_zeta_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sph_bessel_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sph_legendre_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sph_neumann_gen.hpp +) diff --git a/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt b/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt new file mode 100644 index 00000000..3d598897 --- /dev/null +++ b/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt @@ -0,0 +1,13 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/acos_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/asin_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/atan2_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/atan_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cos_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sin_gen.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/tan_gen.hpp +) diff --git a/include/ccmath/internal/math/runtime/CMakeLists.txt b/include/ccmath/internal/math/runtime/CMakeLists.txt new file mode 100644 index 00000000..a0a34d09 --- /dev/null +++ b/include/ccmath/internal/math/runtime/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(func) +add_subdirectory(simd) diff --git a/include/ccmath/internal/math/runtime/func/CMakeLists.txt b/include/ccmath/internal/math/runtime/func/CMakeLists.txt new file mode 100644 index 00000000..21cfb14b --- /dev/null +++ b/include/ccmath/internal/math/runtime/func/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(power) diff --git a/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt b/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt new file mode 100644 index 00000000..bcd2cb5e --- /dev/null +++ b/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt @@ -0,0 +1,8 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow_rt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt_rt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt new file mode 100644 index 00000000..a140ae58 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt @@ -0,0 +1,7 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/common.hpp +) diff --git a/include/ccmath/math/CMakeLists.txt b/include/ccmath/math/CMakeLists.txt new file mode 100644 index 00000000..590c1724 --- /dev/null +++ b/include/ccmath/math/CMakeLists.txt @@ -0,0 +1,26 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/basic.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/compare.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/expo.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fmanip.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/hyper.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nearest.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/numbers.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/power.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/special.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/trig.hpp +) + +add_subdirectory(basic) +add_subdirectory(compare) +add_subdirectory(expo) +add_subdirectory(fmanip) +add_subdirectory(hyper) +add_subdirectory(nearest) +add_subdirectory(power) +add_subdirectory(special) +add_subdirectory(trig) diff --git a/include/ccmath/math/basic/CMakeLists.txt b/include/ccmath/math/basic/CMakeLists.txt new file mode 100644 index 00000000..be1d334d --- /dev/null +++ b/include/ccmath/math/basic/CMakeLists.txt @@ -0,0 +1,17 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/abs.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fdim.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fma.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fmod.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/max.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/min.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nan.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/remainder.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/remquo.hpp +) + +add_subdirectory(impl) diff --git a/include/ccmath/math/basic/impl/CMakeLists.txt b/include/ccmath/math/basic/impl/CMakeLists.txt new file mode 100644 index 00000000..2e41377c --- /dev/null +++ b/include/ccmath/math/basic/impl/CMakeLists.txt @@ -0,0 +1,13 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/nan_double_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nan_float_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nan_ldouble_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/remquo_double_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/remquo_float_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/remquo_ldouble_impl.hpp +) + diff --git a/include/ccmath/math/basic/impl/runtime/fma_rt_impl.hpp b/include/ccmath/math/basic/impl/runtime/fma_rt_impl.hpp deleted file mode 100644 index f0352f72..00000000 --- a/include/ccmath/math/basic/impl/runtime/fma_rt_impl.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) Ian Pike - * Copyright (c) CCMath contributors - * - * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. - * See LICENSE for more information. - * - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#pragma once - -#include // SSE2 - -namespace ccm::internal::rt::impl -{ - inline double fma_rt_double(double a, double b, double c) noexcept - { - // TODO: Apply generic implementation for non-SSE2 platforms - // Load a, b, and c into SSE2 registers - const __m128d va = _mm_set_sd(a); // Set the low double element and zero the upper element - const __m128d vb = _mm_set_sd(b); // Set the low double element and zero the upper element - const __m128d vc = _mm_set_sd(c); // Set the low double element and zero the upper element - - // Perform the multiplication and addition - const __m128d vmul = _mm_mul_sd(va, vb); // Multiply the low elements of va and vb - const __m128d vresult = _mm_add_sd(vmul, vc); // Add the low element of vc to the result of the multiplication - - // Extract the result - const double result = _mm_cvtsd_f64(vresult); // Convert the low double element to a double - - return result; - } -} // namespace ccm::internal::rt::impl diff --git a/include/ccmath/math/compare/CMakeLists.txt b/include/ccmath/math/compare/CMakeLists.txt new file mode 100644 index 00000000..babed0dd --- /dev/null +++ b/include/ccmath/math/compare/CMakeLists.txt @@ -0,0 +1,18 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/fpclassify.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/isfinite.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/isgreater.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/isgreaterequal.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/isinf.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/isless.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/islessequal.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/islessgreater.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/isnan.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/isnormal.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/isunordered.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/signbit.hpp +) diff --git a/include/ccmath/math/exponential.hpp b/include/ccmath/math/expo.hpp similarity index 100% rename from include/ccmath/math/exponential.hpp rename to include/ccmath/math/expo.hpp diff --git a/include/ccmath/math/expo/CMakeLists.txt b/include/ccmath/math/expo/CMakeLists.txt new file mode 100644 index 00000000..e2846346 --- /dev/null +++ b/include/ccmath/math/expo/CMakeLists.txt @@ -0,0 +1,15 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/exp.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp2.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/expm1.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log1p.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log2.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log10.hpp +) + +add_subdirectory(impl) diff --git a/include/ccmath/math/exponential/exp.hpp b/include/ccmath/math/expo/exp.hpp similarity index 100% rename from include/ccmath/math/exponential/exp.hpp rename to include/ccmath/math/expo/exp.hpp diff --git a/include/ccmath/math/exponential/exp2.hpp b/include/ccmath/math/expo/exp2.hpp similarity index 100% rename from include/ccmath/math/exponential/exp2.hpp rename to include/ccmath/math/expo/exp2.hpp diff --git a/include/ccmath/math/exponential/expm1.hpp b/include/ccmath/math/expo/expm1.hpp similarity index 100% rename from include/ccmath/math/exponential/expm1.hpp rename to include/ccmath/math/expo/expm1.hpp diff --git a/include/ccmath/math/expo/impl/CMakeLists.txt b/include/ccmath/math/expo/impl/CMakeLists.txt new file mode 100644 index 00000000..4d740219 --- /dev/null +++ b/include/ccmath/math/expo/impl/CMakeLists.txt @@ -0,0 +1,18 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/exp2_data.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp2_double_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp2_float_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp_data.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp_double_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp_float_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log2_data.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log2_double_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log2_float_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log_data.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log_double_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/log_float_impl.hpp +) diff --git a/include/ccmath/math/exponential/impl/exp2_data.hpp b/include/ccmath/math/expo/impl/exp2_data.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/exp2_data.hpp rename to include/ccmath/math/expo/impl/exp2_data.hpp diff --git a/include/ccmath/math/exponential/impl/exp2_double_impl.hpp b/include/ccmath/math/expo/impl/exp2_double_impl.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/exp2_double_impl.hpp rename to include/ccmath/math/expo/impl/exp2_double_impl.hpp diff --git a/include/ccmath/math/exponential/impl/exp2_float_impl.hpp b/include/ccmath/math/expo/impl/exp2_float_impl.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/exp2_float_impl.hpp rename to include/ccmath/math/expo/impl/exp2_float_impl.hpp diff --git a/include/ccmath/math/exponential/impl/exp_data.hpp b/include/ccmath/math/expo/impl/exp_data.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/exp_data.hpp rename to include/ccmath/math/expo/impl/exp_data.hpp diff --git a/include/ccmath/math/exponential/impl/exp_double_impl.hpp b/include/ccmath/math/expo/impl/exp_double_impl.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/exp_double_impl.hpp rename to include/ccmath/math/expo/impl/exp_double_impl.hpp diff --git a/include/ccmath/math/exponential/impl/exp_float_impl.hpp b/include/ccmath/math/expo/impl/exp_float_impl.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/exp_float_impl.hpp rename to include/ccmath/math/expo/impl/exp_float_impl.hpp diff --git a/include/ccmath/math/exponential/impl/log2_data.hpp b/include/ccmath/math/expo/impl/log2_data.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/log2_data.hpp rename to include/ccmath/math/expo/impl/log2_data.hpp diff --git a/include/ccmath/math/exponential/impl/log2_double_impl.hpp b/include/ccmath/math/expo/impl/log2_double_impl.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/log2_double_impl.hpp rename to include/ccmath/math/expo/impl/log2_double_impl.hpp diff --git a/include/ccmath/math/exponential/impl/log2_float_impl.hpp b/include/ccmath/math/expo/impl/log2_float_impl.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/log2_float_impl.hpp rename to include/ccmath/math/expo/impl/log2_float_impl.hpp diff --git a/include/ccmath/math/exponential/impl/log_data.hpp b/include/ccmath/math/expo/impl/log_data.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/log_data.hpp rename to include/ccmath/math/expo/impl/log_data.hpp diff --git a/include/ccmath/math/exponential/impl/log_double_impl.hpp b/include/ccmath/math/expo/impl/log_double_impl.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/log_double_impl.hpp rename to include/ccmath/math/expo/impl/log_double_impl.hpp diff --git a/include/ccmath/math/exponential/impl/log_float_impl.hpp b/include/ccmath/math/expo/impl/log_float_impl.hpp similarity index 100% rename from include/ccmath/math/exponential/impl/log_float_impl.hpp rename to include/ccmath/math/expo/impl/log_float_impl.hpp diff --git a/include/ccmath/math/exponential/log.hpp b/include/ccmath/math/expo/log.hpp similarity index 100% rename from include/ccmath/math/exponential/log.hpp rename to include/ccmath/math/expo/log.hpp diff --git a/include/ccmath/math/exponential/log10.hpp b/include/ccmath/math/expo/log10.hpp similarity index 100% rename from include/ccmath/math/exponential/log10.hpp rename to include/ccmath/math/expo/log10.hpp diff --git a/include/ccmath/math/exponential/log1p.hpp b/include/ccmath/math/expo/log1p.hpp similarity index 100% rename from include/ccmath/math/exponential/log1p.hpp rename to include/ccmath/math/expo/log1p.hpp diff --git a/include/ccmath/math/exponential/log2.hpp b/include/ccmath/math/expo/log2.hpp similarity index 100% rename from include/ccmath/math/exponential/log2.hpp rename to include/ccmath/math/expo/log2.hpp diff --git a/include/ccmath/math/fmanip/CMakeLists.txt b/include/ccmath/math/fmanip/CMakeLists.txt new file mode 100644 index 00000000..80e397d0 --- /dev/null +++ b/include/ccmath/math/fmanip/CMakeLists.txt @@ -0,0 +1,17 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/copysign.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/frexp.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ilogb.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ldexp.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/logb.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/modf.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nextafter.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nexttowards.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/scalbn.hpp +) + +add_subdirectory(impl) diff --git a/include/ccmath/math/fmanip/impl/CMakeLists.txt b/include/ccmath/math/fmanip/impl/CMakeLists.txt new file mode 100644 index 00000000..84172456 --- /dev/null +++ b/include/ccmath/math/fmanip/impl/CMakeLists.txt @@ -0,0 +1,12 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/modf_double_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/modf_float_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/scalbn_double_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/scalbn_float_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/scalbn_ldouble_impl.hpp +) + diff --git a/include/ccmath/math/hyperbolic.hpp b/include/ccmath/math/hyper.hpp similarity index 100% rename from include/ccmath/math/hyperbolic.hpp rename to include/ccmath/math/hyper.hpp diff --git a/include/ccmath/math/hyper/CMakeLists.txt b/include/ccmath/math/hyper/CMakeLists.txt new file mode 100644 index 00000000..2b430030 --- /dev/null +++ b/include/ccmath/math/hyper/CMakeLists.txt @@ -0,0 +1,12 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/acosh.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/asinh.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/atanh.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cosh.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sinh.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/tanh.hpp +) diff --git a/include/ccmath/math/hyperbolic/acosh.hpp b/include/ccmath/math/hyper/acosh.hpp similarity index 100% rename from include/ccmath/math/hyperbolic/acosh.hpp rename to include/ccmath/math/hyper/acosh.hpp diff --git a/include/ccmath/math/hyperbolic/asinh.hpp b/include/ccmath/math/hyper/asinh.hpp similarity index 100% rename from include/ccmath/math/hyperbolic/asinh.hpp rename to include/ccmath/math/hyper/asinh.hpp diff --git a/include/ccmath/math/hyperbolic/atanh.hpp b/include/ccmath/math/hyper/atanh.hpp similarity index 100% rename from include/ccmath/math/hyperbolic/atanh.hpp rename to include/ccmath/math/hyper/atanh.hpp diff --git a/include/ccmath/math/hyperbolic/cosh.hpp b/include/ccmath/math/hyper/cosh.hpp similarity index 100% rename from include/ccmath/math/hyperbolic/cosh.hpp rename to include/ccmath/math/hyper/cosh.hpp diff --git a/include/ccmath/math/hyperbolic/sinh.hpp b/include/ccmath/math/hyper/sinh.hpp similarity index 100% rename from include/ccmath/math/hyperbolic/sinh.hpp rename to include/ccmath/math/hyper/sinh.hpp diff --git a/include/ccmath/math/hyperbolic/tanh.hpp b/include/ccmath/math/hyper/tanh.hpp similarity index 100% rename from include/ccmath/math/hyperbolic/tanh.hpp rename to include/ccmath/math/hyper/tanh.hpp diff --git a/include/ccmath/math/misc/CMakeLists.txt b/include/ccmath/math/misc/CMakeLists.txt new file mode 100644 index 00000000..d1c688a2 --- /dev/null +++ b/include/ccmath/math/misc/CMakeLists.txt @@ -0,0 +1,9 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/gamma.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/lgamma.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/lerp.hpp +) diff --git a/include/ccmath/math/nearest/CMakeLists.txt b/include/ccmath/math/nearest/CMakeLists.txt new file mode 100644 index 00000000..907d8c3d --- /dev/null +++ b/include/ccmath/math/nearest/CMakeLists.txt @@ -0,0 +1,12 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/ceil.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/floor.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nearbyint.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/rint.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/round.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/trunc.hpp +) diff --git a/include/ccmath/math/power/CMakeLists.txt b/include/ccmath/math/power/CMakeLists.txt new file mode 100644 index 00000000..34354965 --- /dev/null +++ b/include/ccmath/math/power/CMakeLists.txt @@ -0,0 +1,10 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/cbrt.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/hypot.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/math/special/CMakeLists.txt b/include/ccmath/math/special/CMakeLists.txt new file mode 100644 index 00000000..88b4e4f6 --- /dev/null +++ b/include/ccmath/math/special/CMakeLists.txt @@ -0,0 +1,27 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/assoc_laguerre.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/assoc_legendre.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/beta.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_1.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_2.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_3.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_i.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_j.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_k.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cyl_neumann.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ellint_1.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ellint_2.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ellint_3.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/expint.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/hermite.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/laguerre.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/legendre.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/riemann_zeta.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sph_bessel.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sph_legendre.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sph_neumann.hpp +) diff --git a/include/ccmath/math/trig/CMakeLists.txt b/include/ccmath/math/trig/CMakeLists.txt new file mode 100644 index 00000000..d9c739aa --- /dev/null +++ b/include/ccmath/math/trig/CMakeLists.txt @@ -0,0 +1,13 @@ +macro(ccm_add_headers headers) + target_sources(${PROJECT_NAME} INTERFACE "$") +endmacro() + +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/acos.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/asin.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/atan.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/atan2.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/cos.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sin.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/tan.hpp +) From f4bb7a5df3a634faa4bac0ac3e82a98497cf6778 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 18 Oct 2024 19:07:54 -0400 Subject: [PATCH 011/102] Add links to project discord and additional badges --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index de7bcc4f..44fad83f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ -# CCMath - A C++17 constexpr-Compatible CMath Library +# CCMath - A C++17 Compile Time CMath Library [![image](https://github.com/Rinzii/ccmath/workflows/ci-windows/badge.svg)](https://github.com/Rinzii/ccmath/actions?query=workflow%3Aci-windows) [![image](https://github.com/Rinzii/ccmath/workflows/ci-linux/badge.svg)](https://github.com/Rinzii/ccmath/actions?query=workflow%3Aci-linux) [![image](https://github.com/Rinzii/ccmath/workflows/ci-macos/badge.svg)](https://github.com/Rinzii/ccmath/actions?query=workflow%3Aci-macos) [![image](https://api.securityscorecards.dev/projects/github.com/Rinzii/ccmath/badge)](https://securityscorecards.dev/viewer/?uri=github.com/Rinzii/ccmath) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/9402/badge)](https://www.bestpractices.dev/projects/9402) +[![License](https://img.shields.io/badge/License-Apache%202.0%20WITH%20LLVM--exception-blue.svg)]( +https://opensource.org/licenses/Apache-2.0) +[![Discord](https://img.shields.io/discord/1286067628456284244?label=Discord)](https://discord.gg/p3mVxAbdmc) **CCMath** is a C++17 library that provides a re-implementation of the standard `` library with all features made `constexpr`. @@ -77,6 +80,12 @@ CCMath is also designed with functions being freestanding and header only so you > [!NOTE] > Currently working on finding manners to lower these requirements. +## Join Our Discord! + +If you have any questions, suggestions, or just want to chat, feel free to join our Discord server! + +[![Discord Banner](https://discord.com/api/guilds/1286067628456284244/widget.png?style=banner2)](https://discord.gg/p3mVxAbdmc) + ## Contributing CCmath is an open-source project, and it needs your help to go on growing and improving. If you want to get involved and suggest some additional features, file a bug report or submit a patch, please have a look at the [contribution guidelines](CONTRIBUTING.md)! From 95d1a9ff07a8def95bb46c5291450ddbd3c1eede Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 18 Oct 2024 19:31:04 -0400 Subject: [PATCH 012/102] Continue major rewrite of cmake scripts along with significant changes to API --- CMakeLists.txt | 18 ++++++++++++++++++ include/ccmath/CMakeLists.txt | 4 ---- include/ccmath/internal/CMakeLists.txt | 4 ---- include/ccmath/internal/config/CMakeLists.txt | 4 ---- .../ccmath/internal/config/arch/CMakeLists.txt | 4 ---- .../config/arch/targets/CMakeLists.txt | 4 ---- .../internal/config/builtin/CMakeLists.txt | 4 ---- .../internal/config/platform/CMakeLists.txt | 4 ---- .../math/generic/func/basic/CMakeLists.txt | 4 ---- .../math/generic/func/expo/CMakeLists.txt | 4 ---- .../math/generic/func/fmanip/CMakeLists.txt | 4 ---- .../math/generic/func/hyper/CMakeLists.txt | 4 ---- .../math/generic/func/misc/CMakeLists.txt | 4 ---- .../math/generic/func/nearest/CMakeLists.txt | 4 ---- .../math/generic/func/power/CMakeLists.txt | 4 ---- .../math/generic/func/special/CMakeLists.txt | 4 ---- .../math/generic/func/trig/CMakeLists.txt | 4 ---- .../math/runtime/func/power/CMakeLists.txt | 4 ---- .../internal/math/runtime/simd/CMakeLists.txt | 4 ---- include/ccmath/math/CMakeLists.txt | 4 ---- include/ccmath/math/basic/CMakeLists.txt | 4 ---- include/ccmath/math/basic/impl/CMakeLists.txt | 4 ---- include/ccmath/math/compare/CMakeLists.txt | 4 ---- include/ccmath/math/expo.hpp | 14 +++++++------- include/ccmath/math/expo/CMakeLists.txt | 4 ---- include/ccmath/math/expo/exp.hpp | 4 ++-- include/ccmath/math/expo/exp2.hpp | 4 ++-- include/ccmath/math/expo/impl/CMakeLists.txt | 4 ---- .../ccmath/math/expo/impl/exp2_double_impl.hpp | 2 +- .../ccmath/math/expo/impl/exp2_float_impl.hpp | 2 +- .../ccmath/math/expo/impl/exp_double_impl.hpp | 2 +- .../ccmath/math/expo/impl/exp_float_impl.hpp | 2 +- .../ccmath/math/expo/impl/log2_double_impl.hpp | 2 +- .../ccmath/math/expo/impl/log2_float_impl.hpp | 2 +- .../ccmath/math/expo/impl/log_double_impl.hpp | 2 +- .../ccmath/math/expo/impl/log_float_impl.hpp | 2 +- include/ccmath/math/expo/log.hpp | 4 ++-- include/ccmath/math/expo/log2.hpp | 4 ++-- include/ccmath/math/fmanip/CMakeLists.txt | 4 ---- include/ccmath/math/fmanip/impl/CMakeLists.txt | 4 ---- include/ccmath/math/hyper.hpp | 12 ++++++------ include/ccmath/math/hyper/CMakeLists.txt | 4 ---- include/ccmath/math/misc/CMakeLists.txt | 4 ---- include/ccmath/math/nearest/CMakeLists.txt | 4 ---- include/ccmath/math/power/CMakeLists.txt | 4 ---- include/ccmath/math/special/CMakeLists.txt | 4 ---- include/ccmath/math/trig/CMakeLists.txt | 4 ---- 47 files changed, 47 insertions(+), 157 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96e6ad57..4895c95d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,8 +101,24 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) # IanP: Begin initial work here +# Initialize an empty list to hold all the source files +set(INTERNAL_CCMATH_SOURCES "") + +include(cmake/Macros.cmake) + +# Define a macro to add headers and append them to the source list +macro(ccm_add_headers headers) + list(APPEND INTERNAL_CCMATH_SOURCES "${headers}") + ccmath_message(COLOR yellow "Passed headers: ${headers}") + ccmath_message(COLOR yellow "Internal sources Currently: ${INTERNAL_CCMATH_SOURCES}") +endmacro() + add_subdirectory(include/ccmath) +target_sources(${PROJECT_NAME} INTERFACE "$") + +message(STATUS "Final Source files for target ${PROJECT_NAME}: ${SOURCES}") + #message(STATUS "ccmath_internal_headers: ${ccmath_internal_headers}") #target_sources(${PROJECT_NAME} INTERFACE "$") @@ -113,6 +129,8 @@ add_subdirectory(include/ccmath) # target_sources(${PROJECT_NAME} INTERFACE "$") #endif () + + target_include_directories(${PROJECT_NAME} INTERFACE $) target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE $/include>) diff --git a/include/ccmath/CMakeLists.txt b/include/ccmath/CMakeLists.txt index 44340024..53cd7465 100644 --- a/include/ccmath/CMakeLists.txt +++ b/include/ccmath/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/ccmath.hpp ) diff --git a/include/ccmath/internal/CMakeLists.txt b/include/ccmath/internal/CMakeLists.txt index c277ad81..89c5b5a1 100644 --- a/include/ccmath/internal/CMakeLists.txt +++ b/include/ccmath/internal/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/setup.hpp ) diff --git a/include/ccmath/internal/config/CMakeLists.txt b/include/ccmath/internal/config/CMakeLists.txt index 08b5adac..807683d5 100644 --- a/include/ccmath/internal/config/CMakeLists.txt +++ b/include/ccmath/internal/config/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/compiler.hpp ${CMAKE_CURRENT_SOURCE_DIR}/runtime_detection.hpp diff --git a/include/ccmath/internal/config/arch/CMakeLists.txt b/include/ccmath/internal/config/arch/CMakeLists.txt index 64f4dc1d..8a8e9d8c 100644 --- a/include/ccmath/internal/config/arch/CMakeLists.txt +++ b/include/ccmath/internal/config/arch/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/check_arch_support.hpp ${CMAKE_CURRENT_SOURCE_DIR}/check_simd_support.hpp diff --git a/include/ccmath/internal/config/arch/targets/CMakeLists.txt b/include/ccmath/internal/config/arch/targets/CMakeLists.txt index 7a2aab12..4378fa5e 100644 --- a/include/ccmath/internal/config/arch/targets/CMakeLists.txt +++ b/include/ccmath/internal/config/arch/targets/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/aarch64.hpp ${CMAKE_CURRENT_SOURCE_DIR}/x86_64.hpp diff --git a/include/ccmath/internal/config/builtin/CMakeLists.txt b/include/ccmath/internal/config/builtin/CMakeLists.txt index 2cabfc24..963b9507 100644 --- a/include/ccmath/internal/config/builtin/CMakeLists.txt +++ b/include/ccmath/internal/config/builtin/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/bit_cast_support.hpp ${CMAKE_CURRENT_SOURCE_DIR}/copysign_support.hpp diff --git a/include/ccmath/internal/config/platform/CMakeLists.txt b/include/ccmath/internal/config/platform/CMakeLists.txt index b4b84cd6..5877e355 100644 --- a/include/ccmath/internal/config/platform/CMakeLists.txt +++ b/include/ccmath/internal/config/platform/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/android.hpp ${CMAKE_CURRENT_SOURCE_DIR}/darwin.hpp diff --git a/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt b/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt index 0d166f72..627b561b 100644 --- a/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/abs_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/fdim_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt b/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt index a1a07f04..4a367450 100644 --- a/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/exp2_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/exp_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt b/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt index 25776073..9ea79bb6 100644 --- a/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/copysign_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/frexp_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt b/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt index 32f6c8c7..7aa035de 100644 --- a/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/acosh_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/asinh_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt b/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt index c0f53876..09b38858 100644 --- a/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/lerp_gen.hpp ) diff --git a/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt b/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt index 5864e614..965319b6 100644 --- a/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/ceil_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/floor_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/power/CMakeLists.txt b/include/ccmath/internal/math/generic/func/power/CMakeLists.txt index 8fa8b4e5..cd195b93 100644 --- a/include/ccmath/internal/math/generic/func/power/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/power/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/cbrt_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/hypot_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/special/CMakeLists.txt b/include/ccmath/internal/math/generic/func/special/CMakeLists.txt index 7b32d477..6f2b8ecf 100644 --- a/include/ccmath/internal/math/generic/func/special/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/special/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/assoc_laguerre_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/assoc_legendre_gen.hpp diff --git a/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt b/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt index 3d598897..22e1eedf 100644 --- a/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/acos_gen.hpp ${CMAKE_CURRENT_SOURCE_DIR}/asin_gen.hpp diff --git a/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt b/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt index bcd2cb5e..51d38ae6 100644 --- a/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/pow_rt.hpp ${CMAKE_CURRENT_SOURCE_DIR}/sqrt_rt.hpp diff --git a/include/ccmath/internal/math/runtime/simd/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt index a140ae58..70f9ae55 100644 --- a/include/ccmath/internal/math/runtime/simd/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/common.hpp ) diff --git a/include/ccmath/math/CMakeLists.txt b/include/ccmath/math/CMakeLists.txt index 590c1724..5bb71c3f 100644 --- a/include/ccmath/math/CMakeLists.txt +++ b/include/ccmath/math/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/basic.hpp ${CMAKE_CURRENT_SOURCE_DIR}/compare.hpp diff --git a/include/ccmath/math/basic/CMakeLists.txt b/include/ccmath/math/basic/CMakeLists.txt index be1d334d..4007659a 100644 --- a/include/ccmath/math/basic/CMakeLists.txt +++ b/include/ccmath/math/basic/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/abs.hpp ${CMAKE_CURRENT_SOURCE_DIR}/fdim.hpp diff --git a/include/ccmath/math/basic/impl/CMakeLists.txt b/include/ccmath/math/basic/impl/CMakeLists.txt index 2e41377c..1d13933b 100644 --- a/include/ccmath/math/basic/impl/CMakeLists.txt +++ b/include/ccmath/math/basic/impl/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/nan_double_impl.hpp ${CMAKE_CURRENT_SOURCE_DIR}/nan_float_impl.hpp diff --git a/include/ccmath/math/compare/CMakeLists.txt b/include/ccmath/math/compare/CMakeLists.txt index babed0dd..962be1fb 100644 --- a/include/ccmath/math/compare/CMakeLists.txt +++ b/include/ccmath/math/compare/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/fpclassify.hpp ${CMAKE_CURRENT_SOURCE_DIR}/isfinite.hpp diff --git a/include/ccmath/math/expo.hpp b/include/ccmath/math/expo.hpp index ac69461c..93cd7e87 100644 --- a/include/ccmath/math/expo.hpp +++ b/include/ccmath/math/expo.hpp @@ -10,10 +10,10 @@ #pragma once -#include "exponential/exp.hpp" -#include "exponential/exp2.hpp" -#include "exponential/expm1.hpp" -#include "exponential/log.hpp" -#include "exponential/log10.hpp" -#include "exponential/log1p.hpp" -#include "exponential/log2.hpp" +#include "expo/exp.hpp" +#include "expo/exp2.hpp" +#include "expo/expm1.hpp" +#include "expo/log.hpp" +#include "expo/log10.hpp" +#include "expo/log1p.hpp" +#include "expo/log2.hpp" diff --git a/include/ccmath/math/expo/CMakeLists.txt b/include/ccmath/math/expo/CMakeLists.txt index e2846346..57a51a62 100644 --- a/include/ccmath/math/expo/CMakeLists.txt +++ b/include/ccmath/math/expo/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/exp.hpp ${CMAKE_CURRENT_SOURCE_DIR}/exp2.hpp diff --git a/include/ccmath/math/expo/exp.hpp b/include/ccmath/math/expo/exp.hpp index 30f9c8f5..db56b205 100644 --- a/include/ccmath/math/expo/exp.hpp +++ b/include/ccmath/math/expo/exp.hpp @@ -10,8 +10,8 @@ #pragma once -#include "ccmath/math/exponential/impl/exp_double_impl.hpp" -#include "ccmath/math/exponential/impl/exp_float_impl.hpp" +#include "ccmath/math/expo/impl/exp_double_impl.hpp" +#include "ccmath/math/expo/impl/exp_float_impl.hpp" namespace ccm { diff --git a/include/ccmath/math/expo/exp2.hpp b/include/ccmath/math/expo/exp2.hpp index e61288d0..04d4d1b7 100644 --- a/include/ccmath/math/expo/exp2.hpp +++ b/include/ccmath/math/expo/exp2.hpp @@ -12,8 +12,8 @@ #include "ccmath/internal/config/builtin/exp2_support.hpp" #include "ccmath/internal/predef/has_const_builtin.hpp" -#include "ccmath/math/exponential/impl/exp2_double_impl.hpp" -#include "ccmath/math/exponential/impl/exp2_float_impl.hpp" +#include "ccmath/math/expo/impl/exp2_double_impl.hpp" +#include "ccmath/math/expo/impl/exp2_float_impl.hpp" #include diff --git a/include/ccmath/math/expo/impl/CMakeLists.txt b/include/ccmath/math/expo/impl/CMakeLists.txt index 4d740219..674f555e 100644 --- a/include/ccmath/math/expo/impl/CMakeLists.txt +++ b/include/ccmath/math/expo/impl/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/exp2_data.hpp ${CMAKE_CURRENT_SOURCE_DIR}/exp2_double_impl.hpp diff --git a/include/ccmath/math/expo/impl/exp2_double_impl.hpp b/include/ccmath/math/expo/impl/exp2_double_impl.hpp index cf5b7a3c..114f6281 100644 --- a/include/ccmath/math/expo/impl/exp2_double_impl.hpp +++ b/include/ccmath/math/expo/impl/exp2_double_impl.hpp @@ -14,7 +14,7 @@ #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/fp/bit_mask_traits.hpp" #include "ccmath/internal/types/fp_types.hpp" -#include "ccmath/math/exponential/impl/exp2_data.hpp" +#include "ccmath/math/expo/impl/exp2_data.hpp" #include diff --git a/include/ccmath/math/expo/impl/exp2_float_impl.hpp b/include/ccmath/math/expo/impl/exp2_float_impl.hpp index b32889d1..f8eee093 100644 --- a/include/ccmath/math/expo/impl/exp2_float_impl.hpp +++ b/include/ccmath/math/expo/impl/exp2_float_impl.hpp @@ -13,7 +13,7 @@ #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/types/fp_types.hpp" -#include "ccmath/math/exponential/impl/exp2_data.hpp" +#include "ccmath/math/expo/impl/exp2_data.hpp" #include #include diff --git a/include/ccmath/math/expo/impl/exp_double_impl.hpp b/include/ccmath/math/expo/impl/exp_double_impl.hpp index f231822d..eac4330e 100644 --- a/include/ccmath/math/expo/impl/exp_double_impl.hpp +++ b/include/ccmath/math/expo/impl/exp_double_impl.hpp @@ -13,7 +13,7 @@ #include "ccmath/internal/support/helpers/exp_helpers.hpp" #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/types/fp_types.hpp" -#include "ccmath/math/exponential/impl/exp_data.hpp" +#include "ccmath/math/expo/impl/exp_data.hpp" #include #include diff --git a/include/ccmath/math/expo/impl/exp_float_impl.hpp b/include/ccmath/math/expo/impl/exp_float_impl.hpp index 4666ea41..8a7f0e7b 100644 --- a/include/ccmath/math/expo/impl/exp_float_impl.hpp +++ b/include/ccmath/math/expo/impl/exp_float_impl.hpp @@ -13,7 +13,7 @@ #include "ccmath/internal/support/helpers/exp_helpers.hpp" #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/types/fp_types.hpp" -#include "ccmath/math/exponential/impl/exp_data.hpp" +#include "ccmath/math/expo/impl/exp_data.hpp" #include namespace ccm::internal::impl diff --git a/include/ccmath/math/expo/impl/log2_double_impl.hpp b/include/ccmath/math/expo/impl/log2_double_impl.hpp index 61de7040..9df5e220 100644 --- a/include/ccmath/math/expo/impl/log2_double_impl.hpp +++ b/include/ccmath/math/expo/impl/log2_double_impl.hpp @@ -13,7 +13,7 @@ #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/types/fp_types.hpp" -#include "ccmath/math/exponential/impl/log2_data.hpp" +#include "ccmath/math/expo/impl/log2_data.hpp" #include #include diff --git a/include/ccmath/math/expo/impl/log2_float_impl.hpp b/include/ccmath/math/expo/impl/log2_float_impl.hpp index 55ca54e5..238be336 100644 --- a/include/ccmath/math/expo/impl/log2_float_impl.hpp +++ b/include/ccmath/math/expo/impl/log2_float_impl.hpp @@ -13,7 +13,7 @@ #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/types/fp_types.hpp" -#include "ccmath/math/exponential/impl/log2_data.hpp" +#include "ccmath/math/expo/impl/log2_data.hpp" #include #include diff --git a/include/ccmath/math/expo/impl/log_double_impl.hpp b/include/ccmath/math/expo/impl/log_double_impl.hpp index 67ceaf96..da9528de 100644 --- a/include/ccmath/math/expo/impl/log_double_impl.hpp +++ b/include/ccmath/math/expo/impl/log_double_impl.hpp @@ -13,7 +13,7 @@ #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/types/fp_types.hpp" -#include "ccmath/math/exponential/impl/log_data.hpp" +#include "ccmath/math/expo/impl/log_data.hpp" #include #include diff --git a/include/ccmath/math/expo/impl/log_float_impl.hpp b/include/ccmath/math/expo/impl/log_float_impl.hpp index 26e9a8b6..1a335cd8 100644 --- a/include/ccmath/math/expo/impl/log_float_impl.hpp +++ b/include/ccmath/math/expo/impl/log_float_impl.hpp @@ -14,7 +14,7 @@ #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/types/fp_types.hpp" #include "ccmath/math/compare/isnan.hpp" -#include "ccmath/math/exponential/impl/log_data.hpp" +#include "ccmath/math/expo/impl/log_data.hpp" #include #include diff --git a/include/ccmath/math/expo/log.hpp b/include/ccmath/math/expo/log.hpp index 5aff8de4..f84dc078 100644 --- a/include/ccmath/math/expo/log.hpp +++ b/include/ccmath/math/expo/log.hpp @@ -10,8 +10,8 @@ #pragma once -#include "ccmath/math/exponential/impl/log_double_impl.hpp" -#include "ccmath/math/exponential/impl/log_float_impl.hpp" +#include "ccmath/math/expo/impl/log_double_impl.hpp" +#include "ccmath/math/expo/impl/log_float_impl.hpp" #include "ccmath/internal/math/generic/func/expo/log_gen.hpp" namespace ccm diff --git a/include/ccmath/math/expo/log2.hpp b/include/ccmath/math/expo/log2.hpp index a5b5f58c..3ce85d37 100644 --- a/include/ccmath/math/expo/log2.hpp +++ b/include/ccmath/math/expo/log2.hpp @@ -13,8 +13,8 @@ #include "ccmath/math/compare/isnan.hpp" #include "ccmath/internal/config/compiler.hpp" #include "ccmath/math/compare/signbit.hpp" -#include "ccmath/math/exponential/impl/log2_double_impl.hpp" -#include "ccmath/math/exponential/impl/log2_float_impl.hpp" +#include "ccmath/math/expo/impl/log2_double_impl.hpp" +#include "ccmath/math/expo/impl/log2_float_impl.hpp" #include #include diff --git a/include/ccmath/math/fmanip/CMakeLists.txt b/include/ccmath/math/fmanip/CMakeLists.txt index 80e397d0..f33c2f76 100644 --- a/include/ccmath/math/fmanip/CMakeLists.txt +++ b/include/ccmath/math/fmanip/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/copysign.hpp ${CMAKE_CURRENT_SOURCE_DIR}/frexp.hpp diff --git a/include/ccmath/math/fmanip/impl/CMakeLists.txt b/include/ccmath/math/fmanip/impl/CMakeLists.txt index 84172456..87d1c68e 100644 --- a/include/ccmath/math/fmanip/impl/CMakeLists.txt +++ b/include/ccmath/math/fmanip/impl/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/modf_double_impl.hpp ${CMAKE_CURRENT_SOURCE_DIR}/modf_float_impl.hpp diff --git a/include/ccmath/math/hyper.hpp b/include/ccmath/math/hyper.hpp index 31c5b623..99f96ba4 100644 --- a/include/ccmath/math/hyper.hpp +++ b/include/ccmath/math/hyper.hpp @@ -10,9 +10,9 @@ #pragma once -#include "hyperbolic/acosh.hpp" -#include "hyperbolic/asinh.hpp" -#include "hyperbolic/atanh.hpp" -#include "hyperbolic/cosh.hpp" -#include "hyperbolic/sinh.hpp" -#include "hyperbolic/tanh.hpp" +#include "hyper/acosh.hpp" +#include "hyper/asinh.hpp" +#include "hyper/atanh.hpp" +#include "hyper/cosh.hpp" +#include "hyper/sinh.hpp" +#include "hyper/tanh.hpp" diff --git a/include/ccmath/math/hyper/CMakeLists.txt b/include/ccmath/math/hyper/CMakeLists.txt index 2b430030..7c0290ab 100644 --- a/include/ccmath/math/hyper/CMakeLists.txt +++ b/include/ccmath/math/hyper/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/acosh.hpp ${CMAKE_CURRENT_SOURCE_DIR}/asinh.hpp diff --git a/include/ccmath/math/misc/CMakeLists.txt b/include/ccmath/math/misc/CMakeLists.txt index d1c688a2..1726e077 100644 --- a/include/ccmath/math/misc/CMakeLists.txt +++ b/include/ccmath/math/misc/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/gamma.hpp ${CMAKE_CURRENT_SOURCE_DIR}/lgamma.hpp diff --git a/include/ccmath/math/nearest/CMakeLists.txt b/include/ccmath/math/nearest/CMakeLists.txt index 907d8c3d..46c1f94d 100644 --- a/include/ccmath/math/nearest/CMakeLists.txt +++ b/include/ccmath/math/nearest/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/ceil.hpp ${CMAKE_CURRENT_SOURCE_DIR}/floor.hpp diff --git a/include/ccmath/math/power/CMakeLists.txt b/include/ccmath/math/power/CMakeLists.txt index 34354965..12918e59 100644 --- a/include/ccmath/math/power/CMakeLists.txt +++ b/include/ccmath/math/power/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/cbrt.hpp ${CMAKE_CURRENT_SOURCE_DIR}/hypot.hpp diff --git a/include/ccmath/math/special/CMakeLists.txt b/include/ccmath/math/special/CMakeLists.txt index 88b4e4f6..18e7c28f 100644 --- a/include/ccmath/math/special/CMakeLists.txt +++ b/include/ccmath/math/special/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/assoc_laguerre.hpp ${CMAKE_CURRENT_SOURCE_DIR}/assoc_legendre.hpp diff --git a/include/ccmath/math/trig/CMakeLists.txt b/include/ccmath/math/trig/CMakeLists.txt index d9c739aa..b0be016a 100644 --- a/include/ccmath/math/trig/CMakeLists.txt +++ b/include/ccmath/math/trig/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/acos.hpp ${CMAKE_CURRENT_SOURCE_DIR}/asin.hpp From 780778e6aa7885cfa9c136fa5e28d470dcf954ae Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 18 Oct 2024 20:50:43 -0400 Subject: [PATCH 013/102] Finish major rewrite of cmake script setup --- CMakeLists.txt | 217 +++++++++--------- include/ccmath/ext/CMakeLists.txt | 4 - .../internal/math/runtime/simd/CMakeLists.txt | 6 + .../math/runtime/simd/func/CMakeLists.txt | 6 + .../runtime/simd/func/impl/CMakeLists.txt | 10 + .../runtime/simd/func/impl/avx/CMakeLists.txt | 4 + .../simd/func/impl/avx2/CMakeLists.txt | 4 + .../simd/func/impl/avx512/CMakeLists.txt | 4 + .../simd/func/impl/neon/CMakeLists.txt | 4 + .../simd/func/impl/scalar/CMakeLists.txt | 4 + .../simd/func/impl/sse2/CMakeLists.txt | 4 + .../simd/func/impl/sse3/CMakeLists.txt | 4 + .../simd/func/impl/sse4/CMakeLists.txt | 4 + .../simd/func/impl/ssse3/CMakeLists.txt | 4 + .../simd/func/impl/vector_size/CMakeLists.txt | 3 + .../runtime/simd/instructions/CMakeLists.txt | 12 + include/ccmath/internal/predef/CMakeLists.txt | 13 ++ .../internal/predef/attributes/CMakeLists.txt | 9 + .../compiler_suppression/CMakeLists.txt | 5 + .../internal/predef/versioning/CMakeLists.txt | 9 + .../ccmath/internal/support/CMakeLists.txt | 20 ++ .../internal/support/fenv/CMakeLists.txt | 5 + .../ccmath/internal/support/fp/CMakeLists.txt | 6 + .../internal/support/helpers/CMakeLists.txt | 8 + include/ccmath/internal/types/CMakeLists.txt | 13 ++ include/ccmath/math/fmanip/CMakeLists.txt | 2 +- 26 files changed, 267 insertions(+), 117 deletions(-) create mode 100644 include/ccmath/internal/math/runtime/simd/func/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/avx/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/avx2/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/neon/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/scalar/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/sse2/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/sse3/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/sse4/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/ssse3/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/vector_size/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt create mode 100644 include/ccmath/internal/predef/CMakeLists.txt create mode 100644 include/ccmath/internal/predef/attributes/CMakeLists.txt create mode 100644 include/ccmath/internal/predef/compiler_suppression/CMakeLists.txt create mode 100644 include/ccmath/internal/predef/versioning/CMakeLists.txt create mode 100644 include/ccmath/internal/support/CMakeLists.txt create mode 100644 include/ccmath/internal/support/fenv/CMakeLists.txt create mode 100644 include/ccmath/internal/support/fp/CMakeLists.txt create mode 100644 include/ccmath/internal/support/helpers/CMakeLists.txt create mode 100644 include/ccmath/internal/types/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 4895c95d..42dd796b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,10 +12,10 @@ project( set(is_root_project OFF) # Identifies if this is the root project if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - set(is_root_project ON) + set(is_root_project ON) endif () -if(NOT CCMATH_SOURCE_DIR) - set(CCMATH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +if (NOT CCMATH_SOURCE_DIR) + set(CCMATH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) endif () set(CMAKE_CXX_STANDARD 17) @@ -47,50 +47,50 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME}-compile-options ALIAS ${PROJECT_NAM # Generic clang/gcc compiler options if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|IntelLLVM") - target_compile_options(${PROJECT_NAME}-compile-options INTERFACE - -Wall - -Wextra - -Wconversion - -Werror=return-type - - -Wno-pedantic + target_compile_options(${PROJECT_NAME}-compile-options INTERFACE + -Wall + -Wextra + -Wconversion + -Werror=return-type - # Allow FMA instructions - -ffp-contract=fast + -Wno-pedantic - # Macros to define - -DNOMINMAX - ) + # Allow FMA instructions + -ffp-contract=fast + # Macros to define + -DNOMINMAX + ) - if (CMAKE_CXX_COMPILER_ID STREQUAL MSVC) - target_compile_options(${PROJECT_NAME}-compile-options INTERFACE - /W3 - /WX - /permissive- - /Zc:__cplusplus - - # Macros to define - /DNOMINMAX - /D_ENABLE_EXTENDED_ALIGNED_STORAGE - ) - endif () + if (CMAKE_CXX_COMPILER_ID STREQUAL MSVC) + target_compile_options(${PROJECT_NAME}-compile-options INTERFACE + /W3 + /WX + /permissive- - # Disable intel specific warnings that don't apply to us. - if (CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM) - target_compile_options(${PROJECT_NAME}-compile-options INTERFACE - -Wno-tautological-constant-compare - ) - endif () + /Zc:__cplusplus + # Macros to define + /DNOMINMAX + /D_ENABLE_EXTENDED_ALIGNED_STORAGE + ) + endif () - # TODO: Remove this later. - # Some variables have been provided but are not currently being used, but it would not atm make sense to remove them. - # So to clean up the warnings we are just silencing these specific cases. + # Disable intel specific warnings that don't apply to us. + if (CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM) target_compile_options(${PROJECT_NAME}-compile-options INTERFACE - -Wno-unused-but-set-variable -Wno-unused-value -Wno-unused-parameter + -Wno-tautological-constant-compare ) + endif () + + + # TODO: Remove this later. + # Some variables have been provided but are not currently being used, but it would not atm make sense to remove them. + # So to clean up the warnings we are just silencing these specific cases. + target_compile_options(${PROJECT_NAME}-compile-options INTERFACE + -Wno-unused-but-set-variable -Wno-unused-value -Wno-unused-parameter + ) endif () #include(ccmath_internal_headers.cmake) @@ -99,36 +99,29 @@ endif () add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -# IanP: Begin initial work here - -# Initialize an empty list to hold all the source files -set(INTERNAL_CCMATH_SOURCES "") - include(cmake/Macros.cmake) -# Define a macro to add headers and append them to the source list -macro(ccm_add_headers headers) - list(APPEND INTERNAL_CCMATH_SOURCES "${headers}") - ccmath_message(COLOR yellow "Passed headers: ${headers}") - ccmath_message(COLOR yellow "Internal sources Currently: ${INTERNAL_CCMATH_SOURCES}") -endmacro() - -add_subdirectory(include/ccmath) - -target_sources(${PROJECT_NAME} INTERFACE "$") +# Initialize a global empty list to hold all the source files +set_property(GLOBAL PROPERTY INTERNAL_CCMATH_SOURCES "") -message(STATUS "Final Source files for target ${PROJECT_NAME}: ${SOURCES}") +# Helper function to add headers to the global source list +function(ccm_add_headers) + # Retrieve the current global property value + get_property(tmp GLOBAL PROPERTY INTERNAL_CCMATH_SOURCES) -#message(STATUS "ccmath_internal_headers: ${ccmath_internal_headers}") + foreach (arg ${ARGV}) + list(APPEND tmp "${arg}") + endforeach () -#target_sources(${PROJECT_NAME} INTERFACE "$") -#target_sources(${PROJECT_NAME} INTERFACE "$") + # Update the global property using APPEND + set_property(GLOBAL PROPERTY INTERNAL_CCMATH_SOURCES "${tmp}") +endfunction() -#if (CCMATH_ENABLE_EXTENSIONS) -# include(ccmath_extensions_headers.cmake) -# target_sources(${PROJECT_NAME} INTERFACE "$") -#endif () +add_subdirectory(include/ccmath) +# Add all the headers to the target interface +get_property(internal_ccmath_headers GLOBAL PROPERTY INTERNAL_CCMATH_SOURCES) +target_sources(${PROJECT_NAME} INTERFACE "$") target_include_directories(${PROJECT_NAME} INTERFACE $) @@ -139,81 +132,81 @@ target_link_libraries(${PROJECT_NAME} INTERFACE ) if (CCMATH_ENABLE_RUNTIME_SIMD) - target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_USE_RT_SIMD) + target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_USE_RT_SIMD) endif () if (NOT CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS) - # Set these definitions based on the build type to aid in identifying the optimization level. - # These are essential when dealing with compiler specific outcomes that are based on the optimization level. - target_compile_definitions(${PROJECT_NAME} - INTERFACE - $<$:CCM_CONFIG_DEBUG> # -O0 - $<$:CCM_CONFIG_OPTIMIZE> # -O2 - $<$:CCM_CONFIG_AGGRESSIVELY_OPTIMIZE> # -O3 - $<$:CCM_CONFIG_MINSIZE> # -Os - ) + # Set these definitions based on the build type to aid in identifying the optimization level. + # These are essential when dealing with compiler specific outcomes that are based on the optimization level. + target_compile_definitions(${PROJECT_NAME} + INTERFACE + $<$:CCM_CONFIG_DEBUG> # -O0 + $<$:CCM_CONFIG_OPTIMIZE> # -O2 + $<$:CCM_CONFIG_AGGRESSIVELY_OPTIMIZE> # -O3 + $<$:CCM_CONFIG_MINSIZE> # -Os + ) endif () if (CCMATH_DISABLE_ERRNO) - target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_DISABLE_ERRNO) + target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_DISABLE_ERRNO) endif () configure_file(cmake/version.hpp.in "${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/version.hpp" @ONLY) if (CCMATH_BUILD_EXAMPLES OR CCMATH_BUILD_BENCHMARKS OR CCMATH_BUILD_TESTS) - add_subdirectory(thirdparty) + add_subdirectory(thirdparty) endif () if (CCMATH_BUILD_EXAMPLES) - add_subdirectory(example) + add_subdirectory(example) endif () if (CCMATH_BUILD_BENCHMARKS) - add_subdirectory(benchmark) + add_subdirectory(benchmark) endif () if (CCMATH_BUILD_TESTS) - enable_testing() - add_subdirectory(test) + enable_testing() + add_subdirectory(test) endif () if (CCMATH_INSTALL) - include(GNUInstallDirs) - include(CMakePackageConfigHelpers) - - install(TARGETS - ${PROJECT_NAME} - ${PROJECT_NAME}-compile-options - EXPORT ${PROJECT_NAME}-targets - ) - - # Manually specify the headers to install - install(DIRECTORY - "${CMAKE_CURRENT_SOURCE_DIR}/include/" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - FILES_MATCHING PATTERN "*.hpp" - ) - - install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/version.hpp" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}" - ) - - install(EXPORT ${PROJECT_NAME}-targets - FILE ${PROJECT_NAME}-targets.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" - ) - - configure_package_config_file( - cmake/${PROJECT_NAME}-config.cmake.in - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" - INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" - ) - - install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + + install(TARGETS + ${PROJECT_NAME} + ${PROJECT_NAME}-compile-options + EXPORT ${PROJECT_NAME}-targets + ) + + # Manually specify the headers to install + install(DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}/include/" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING PATTERN "*.hpp" + ) + + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/version.hpp" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}" + ) + + install(EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}-targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + ) + + configure_package_config_file( + cmake/${PROJECT_NAME}-config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + ) + + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") endif () diff --git a/include/ccmath/ext/CMakeLists.txt b/include/ccmath/ext/CMakeLists.txt index b791d764..3493955f 100644 --- a/include/ccmath/ext/CMakeLists.txt +++ b/include/ccmath/ext/CMakeLists.txt @@ -1,7 +1,3 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() - ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/align.hpp ${CMAKE_CURRENT_SOURCE_DIR}/clamp.hpp diff --git a/include/ccmath/internal/math/runtime/simd/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt index 70f9ae55..58d2077e 100644 --- a/include/ccmath/internal/math/runtime/simd/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt @@ -1,3 +1,9 @@ ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/common.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/pack.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/simd.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/simd_vectorize.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/vector_size.hpp ) + +add_subdirectory(func) diff --git a/include/ccmath/internal/math/runtime/simd/func/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/CMakeLists.txt new file mode 100644 index 00000000..0c12929f --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/CMakeLists.txt @@ -0,0 +1,6 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) + +add_subdirectory(impl) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/CMakeLists.txt new file mode 100644 index 00000000..cf1ce420 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/CMakeLists.txt @@ -0,0 +1,10 @@ +add_subdirectory(avx) +add_subdirectory(avx2) +add_subdirectory(avx512) +add_subdirectory(neon) +add_subdirectory(scalar) +add_subdirectory(sse2) +add_subdirectory(sse3) +add_subdirectory(sse4) +add_subdirectory(ssse3) +add_subdirectory(vector_size) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/avx/CMakeLists.txt new file mode 100644 index 00000000..7ed3a7d1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx2/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/avx2/CMakeLists.txt new file mode 100644 index 00000000..7ed3a7d1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx2/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt new file mode 100644 index 00000000..7ed3a7d1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/neon/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/neon/CMakeLists.txt new file mode 100644 index 00000000..7ed3a7d1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/neon/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/scalar/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/CMakeLists.txt new file mode 100644 index 00000000..7ed3a7d1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/CMakeLists.txt new file mode 100644 index 00000000..7ed3a7d1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/CMakeLists.txt new file mode 100644 index 00000000..7ed3a7d1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/CMakeLists.txt new file mode 100644 index 00000000..7ed3a7d1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/CMakeLists.txt new file mode 100644 index 00000000..7ed3a7d1 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/CMakeLists.txt new file mode 100644 index 00000000..c66b35a8 --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/CMakeLists.txt @@ -0,0 +1,3 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp +) diff --git a/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt new file mode 100644 index 00000000..02ddf8ef --- /dev/null +++ b/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt @@ -0,0 +1,12 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/avx.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/avx2.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/avx512.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/neon.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sse2.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sse3.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sse4.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ssse3.hpp +) + +add_subdirectory(func) diff --git a/include/ccmath/internal/predef/CMakeLists.txt b/include/ccmath/internal/predef/CMakeLists.txt new file mode 100644 index 00000000..0db29860 --- /dev/null +++ b/include/ccmath/internal/predef/CMakeLists.txt @@ -0,0 +1,13 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/assume.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/expects_bool_condition.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/has_attribute.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/has_builtin.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/has_const_builtin.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/likely.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/unlikely.hpp +) + +add_subdirectory(attributes) +add_subdirectory(compiler_suppression) +add_subdirectory(versioning) diff --git a/include/ccmath/internal/predef/attributes/CMakeLists.txt b/include/ccmath/internal/predef/attributes/CMakeLists.txt new file mode 100644 index 00000000..0e858d29 --- /dev/null +++ b/include/ccmath/internal/predef/attributes/CMakeLists.txt @@ -0,0 +1,9 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/always_inline.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/gpu_device.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/gpu_host_device.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/gsl_suppress.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/never_inline.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/no_debug.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/optnone.hpp +) diff --git a/include/ccmath/internal/predef/compiler_suppression/CMakeLists.txt b/include/ccmath/internal/predef/compiler_suppression/CMakeLists.txt new file mode 100644 index 00000000..b57712da --- /dev/null +++ b/include/ccmath/internal/predef/compiler_suppression/CMakeLists.txt @@ -0,0 +1,5 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/clang_compiler_suppression.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/gcc_compiler_suppression.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/msvc_compiler_suppression.hpp +) diff --git a/include/ccmath/internal/predef/versioning/CMakeLists.txt b/include/ccmath/internal/predef/versioning/CMakeLists.txt new file mode 100644 index 00000000..c72c8021 --- /dev/null +++ b/include/ccmath/internal/predef/versioning/CMakeLists.txt @@ -0,0 +1,9 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/arm_version.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/clang_version.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/gcc_version.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/intel_version.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/msvc_version.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/version_encode.hpp + +) diff --git a/include/ccmath/internal/support/CMakeLists.txt b/include/ccmath/internal/support/CMakeLists.txt new file mode 100644 index 00000000..216a84bf --- /dev/null +++ b/include/ccmath/internal/support/CMakeLists.txt @@ -0,0 +1,20 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/always_false.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/bits.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ctz.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/endian.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/floating_point_traits.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/integer_literals.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/is_constant_evaluated.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/limits.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/math_support.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/meta_compare.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/multiply_add.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/poly_eval.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/type_traits.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/unreachable.hpp +) + +add_subdirectory(fenv) +add_subdirectory(fp) +add_subdirectory(helpers) diff --git a/include/ccmath/internal/support/fenv/CMakeLists.txt b/include/ccmath/internal/support/fenv/CMakeLists.txt new file mode 100644 index 00000000..a90ef78f --- /dev/null +++ b/include/ccmath/internal/support/fenv/CMakeLists.txt @@ -0,0 +1,5 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/fenv_support.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/rounding_mode.hpp +) + diff --git a/include/ccmath/internal/support/fp/CMakeLists.txt b/include/ccmath/internal/support/fp/CMakeLists.txt new file mode 100644 index 00000000..edbace57 --- /dev/null +++ b/include/ccmath/internal/support/fp/CMakeLists.txt @@ -0,0 +1,6 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/bit_mask_traits.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/directional_rounding_utils.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fp_bits.hpp +) + diff --git a/include/ccmath/internal/support/helpers/CMakeLists.txt b/include/ccmath/internal/support/helpers/CMakeLists.txt new file mode 100644 index 00000000..16613039 --- /dev/null +++ b/include/ccmath/internal/support/helpers/CMakeLists.txt @@ -0,0 +1,8 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/digit_to_int.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp10.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/exp_helpers.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fpclassify_helpers.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/internal_ldexp.hpp +) + diff --git a/include/ccmath/internal/types/CMakeLists.txt b/include/ccmath/internal/types/CMakeLists.txt new file mode 100644 index 00000000..6cad760c --- /dev/null +++ b/include/ccmath/internal/types/CMakeLists.txt @@ -0,0 +1,13 @@ +ccm_add_headers( + ${CMAKE_CURRENT_SOURCE_DIR}/big_int.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/double_double.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/dyadic_float.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/float128.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fp_types.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/int128_types.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/normalized_float.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/number_pair.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/sign.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/triple_double.hpp +) + diff --git a/include/ccmath/math/fmanip/CMakeLists.txt b/include/ccmath/math/fmanip/CMakeLists.txt index f33c2f76..76a8fc3f 100644 --- a/include/ccmath/math/fmanip/CMakeLists.txt +++ b/include/ccmath/math/fmanip/CMakeLists.txt @@ -6,7 +6,7 @@ ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/logb.hpp ${CMAKE_CURRENT_SOURCE_DIR}/modf.hpp ${CMAKE_CURRENT_SOURCE_DIR}/nextafter.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nexttowards.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/nexttoward.hpp ${CMAKE_CURRENT_SOURCE_DIR}/scalbn.hpp ) From cda8706bddac9c7aa96886e52ebad85fe326573b Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 18 Oct 2024 20:50:51 -0400 Subject: [PATCH 014/102] Formatting --- test/fmanip/nexttoward_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/fmanip/nexttoward_test.cpp b/test/fmanip/nexttoward_test.cpp index cffd0531..9bc8f21a 100644 --- a/test/fmanip/nexttoward_test.cpp +++ b/test/fmanip/nexttoward_test.cpp @@ -10,9 +10,10 @@ #include +#include "ccmath/ccmath.hpp" + #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathFmanipTests, Nexttoward) { From f051b0e30fcbb93c960d98ee4ae5263ddd51b402 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 18 Oct 2024 20:59:26 -0400 Subject: [PATCH 015/102] Final cleanup --- CMakeLists.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42dd796b..df8cd621 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,14 +25,16 @@ set(CMAKE_CXX_EXTENSIONS OFF) message(STATUS "CCMath version: ${PROJECT_VERSION}") # TO THE IMPLEMENTOR: If CCMATH_BUILD_TESTS is set to OFF then googletest can be deleted from the ext folder. +option(CCMATH_INSTALL "Setup install and package steps" ${is_root_project}) + option(CCMATH_BUILD_TESTS "Build ccmath tests" ${is_root_project}) option(CCMATH_FIND_GTEST_PACKAGE "Enable finding of gtest package" OFF) -option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project}) option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project}) option(CCMATH_FIND_GBENCH_PACKAGE "Enable finding of google benchmark package" OFF) -option(CCMATH_INSTALL "Setup install and package steps" OFF)#${is_root_project} +option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project}) + option(CCMATH_ENABLE_EXTENSIONS "Enable the extended ccmath library that adds helpful additional methods that are not defined by the standard" ${is_root_project}) -option(CCMATH_ENABLE_RUNTIME_SIMD "Enable SIMD optimization for runtime evaluation (does not effect compile time)" ON) +option(CCMATH_ENABLE_RUNTIME_SIMD "Enable SIMD optimization for runtime evaluation (does not effect compile time)" ON) # By default we want SIMD to be enabled option(CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS "Enable user defined optimization macros instead of having ccmath define its own internal ones in cmake" OFF) option(CCMATH_DISABLE_ERRNO "Disable the use of errno in ccmath during runtime" OFF) @@ -93,9 +95,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|IntelLLVM") ) endif () -#include(ccmath_internal_headers.cmake) -#include(ccmath_core_headers.cmake) - add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) From 1e53230bc9464e01ec9af541fe8ec57685f2f894 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 18 Oct 2024 22:15:38 -0400 Subject: [PATCH 016/102] Simplify header adding function --- CMakeLists.txt | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index df8cd621..3647811c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,29 +100,14 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) include(cmake/Macros.cmake) -# Initialize a global empty list to hold all the source files -set_property(GLOBAL PROPERTY INTERNAL_CCMATH_SOURCES "") - # Helper function to add headers to the global source list function(ccm_add_headers) - # Retrieve the current global property value - get_property(tmp GLOBAL PROPERTY INTERNAL_CCMATH_SOURCES) - - foreach (arg ${ARGV}) - list(APPEND tmp "${arg}") - endforeach () - - # Update the global property using APPEND - set_property(GLOBAL PROPERTY INTERNAL_CCMATH_SOURCES "${tmp}") + # Append all the passed arguments (headers) to the target's sources + target_sources(${PROJECT_NAME} INTERFACE "$") endfunction() add_subdirectory(include/ccmath) -# Add all the headers to the target interface -get_property(internal_ccmath_headers GLOBAL PROPERTY INTERNAL_CCMATH_SOURCES) -target_sources(${PROJECT_NAME} INTERFACE "$") - - target_include_directories(${PROJECT_NAME} INTERFACE $) target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE $/include>) From 63fd16b5dc2f1148f0b9c39efe97dc39c808b3c3 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 19 Oct 2024 00:05:03 -0400 Subject: [PATCH 017/102] Bug fixing for intel OneAPI DPC++ --- CMakeLists.txt | 2 +- include/ccmath/internal/config/compiler.hpp | 21 ++++++++++--------- .../math/runtime/simd/func/impl/sse2/pow.hpp | 6 +++++- .../support/helpers/fpclassify_helper.hpp | 6 ++++++ test/basic/nan_test.cpp | 7 ++++++- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3647811c..2dc7e480 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.18) +cmake_minimum_required(VERSION 3.23.0) set(CCMATH_BUILD_VERSION 0.2.0) diff --git a/include/ccmath/internal/config/compiler.hpp b/include/ccmath/internal/config/compiler.hpp index e4c29cbd..66bf732c 100644 --- a/include/ccmath/internal/config/compiler.hpp +++ b/include/ccmath/internal/config/compiler.hpp @@ -28,6 +28,17 @@ #define CCMATH_COMPILER_MSVC #define CCMATH_COMPILER_MSVC_VER _MSC_VER +/// Intel DPC++ Compiler +#elif defined(SYCL_LANGUAGE_VERSION) || defined(__INTEL_LLVM_COMPILER) && !defined(CCMATH_COMPILER_INTEL) + #define CCMATH_COMPILER_INTEL + #define CCMATH_COMPILER_INTEL_VER __INTEL_LLVM_COMPILER + + #ifndef CCMATH_COMPILER_CLANG_BASED + #define CCMATH_COMPILER_CLANG_BASED + #endif + +// TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler + #elif defined(_MSC_VER) && defined(__clang__) && !defined(CCMATH_COMPILER_CLANG_CL) #define CCMATH_COMPILER_CLANG_CL @@ -42,16 +53,6 @@ // TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler -/// Intel DPC++ Compiler -#elif defined(SYCL_LANGUAGE_VERSION) || defined(__INTEL_LLVM_COMPILER) && !defined(CCMATH_COMPILER_INTEL) - #define CCMATH_COMPILER_INTEL - #define CCMATH_COMPILER_INTEL_VER __INTEL_LLVM_COMPILER - - #ifndef CCMATH_COMPILER_CLANG_BASED - #define CCMATH_COMPILER_CLANG_BASED - #endif - -// TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler /// Nvidia HPC SDK diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp index 7a8f4ada..e6c52596 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp @@ -16,6 +16,10 @@ #ifdef CCMATH_HAS_SIMD_SSE2 #include "ccmath/internal/config/platform/linux.hpp" +#if !defined(CCM_TARGET_PLATFORM_LINUX) + #include +#endif // !CCM_TARGET_PLATFORM_LINUX + #if defined(CCM_TARGET_PLATFORM_LINUX) #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" #endif @@ -41,7 +45,7 @@ namespace ccm::intrin // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler // It appears Windows and macOS have SVML out the box so we only care about linux. #if !defined(CCM_TARGET_PLATFORM_LINUX) - return simd(_mm_pow_pd(a.get(), b.get())); + return simd(_mm_pow_pd(a.get(), b.get())); #else // TODO: Replace this with a refined solution. For the time being this is temporary. return simd(gen::pow_gen(a.convert(), b.convert())); diff --git a/include/ccmath/internal/support/helpers/fpclassify_helper.hpp b/include/ccmath/internal/support/helpers/fpclassify_helper.hpp index 5a3cbd43..032eb159 100644 --- a/include/ccmath/internal/support/helpers/fpclassify_helper.hpp +++ b/include/ccmath/internal/support/helpers/fpclassify_helper.hpp @@ -45,6 +45,12 @@ namespace ccm::support::helpers static constexpr int eFP_ZERO = 2; static constexpr int eFP_SUBNORMAL = 2; static constexpr int eFP_NORMAL = 4; +#elif defined(CCMATH_COMPILER_INTEL) // Intel OneAPI DPC++ has a different set of defines than Clang + static constexpr int eFP_NAN = 2; + static constexpr int eFP_INFINITE = 1; + static constexpr int eFP_ZERO = 0; + static constexpr int eFP_SUBNORMAL = -2; + static constexpr int eFP_NORMAL = -1; #elif defined(CCMATH_COMPILER_CLANG) || defined(CCMATH_COMPILER_GCC) || defined(CCMATH_COMPILER_CLANG_BASED) // Clang and GCC have the same defines static constexpr int eFP_NAN = 0; static constexpr int eFP_INFINITE = 1; diff --git a/test/basic/nan_test.cpp b/test/basic/nan_test.cpp index 5042d3c8..a28ae8c4 100644 --- a/test/basic/nan_test.cpp +++ b/test/basic/nan_test.cpp @@ -105,7 +105,11 @@ TEST(CcmathBasicTests, Nan_Double) */ } -#if LDBL_MANT_DIG == 53 +// TODO: Currently, the testing for 64 bit long doubles on intel DPC++ is causing a SEH exception. +// I need to investigate this further but I don't yet have the time. +// Return to this later, but for now, I will disable the test for DPC++. +#if !(defined(SYCL_LANGUAGE_VERSION) || defined(__INTEL_LLVM_COMPILER)) +#if (LDBL_MANT_DIG == 53) TEST(CcmathBasicTests, Nan_LDouble64bit) { @@ -312,3 +316,4 @@ TEST(CcmathBasicTests, Nan_LDoubleUnknownBits) FAIL() << "We do not know how to handle long doubles with an unknown number of bits. Please report this if you see this failure."; } #endif +#endif // !(defined(SYCL_LANGUAGE_VERSION) || defined(__INTEL_LLVM_COMPILER)) From 012a23a95eb96469cc84632bb3522a55dbd360f9 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 19 Oct 2024 00:10:17 -0400 Subject: [PATCH 018/102] Revert cmake version to 3.18 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dc7e480..b499eb8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.23.0) +cmake_minimum_required(VERSION 3.18.0) set(CCMATH_BUILD_VERSION 0.2.0) From 133776659013c6dcf9cdae51b2f6a5e61da57dc7 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 21 Oct 2024 16:01:11 -0400 Subject: [PATCH 019/102] Minor cleanup --- include/ccmath/ext/clamp.hpp | 2 +- include/ccmath/ext/cubic.hpp | 2 +- include/ccmath/ext/lerp_smooth.hpp | 2 +- include/ccmath/ext/mix.hpp | 2 +- include/ccmath/ext/normalize.hpp | 2 +- include/ccmath/ext/ping_pong.hpp | 2 +- .../ccmath/internal/math/generic/func/fmanip/ldexp_gen.hpp | 5 +++-- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/ccmath/ext/clamp.hpp b/include/ccmath/ext/clamp.hpp index 626ddd63..0e870292 100644 --- a/include/ccmath/ext/clamp.hpp +++ b/include/ccmath/ext/clamp.hpp @@ -20,7 +20,7 @@ namespace ccm::ext /** * @brief Clamps a value between a minimum and maximum value. * @tparam T Type of the input and output. - * @param x Value to clamp. + * @param v Value to clamp. * @param lo Minimum value. * @param hi Maximum value. * @return The clamped value. diff --git a/include/ccmath/ext/cubic.hpp b/include/ccmath/ext/cubic.hpp index ccbaea71..67b0764d 100644 --- a/include/ccmath/ext/cubic.hpp +++ b/include/ccmath/ext/cubic.hpp @@ -34,6 +34,6 @@ namespace ccm::ext const T t2 = t * t; - return a0 * t * t2 + a1 * t2 + a2 * t + a3; + return (a0 * t * t2) + (a1 * t2) + (a2 * t) + a3; } } // namespace ccm::ext diff --git a/include/ccmath/ext/lerp_smooth.hpp b/include/ccmath/ext/lerp_smooth.hpp index 66919ff8..941f403a 100644 --- a/include/ccmath/ext/lerp_smooth.hpp +++ b/include/ccmath/ext/lerp_smooth.hpp @@ -10,7 +10,7 @@ #pragma once -#include "ccmath/math/exponential/exp2.hpp" +#include "ccmath/math/expo/exp2.hpp" namespace ccm::ext { diff --git a/include/ccmath/ext/mix.hpp b/include/ccmath/ext/mix.hpp index 153eb42c..dc78a607 100644 --- a/include/ccmath/ext/mix.hpp +++ b/include/ccmath/ext/mix.hpp @@ -41,6 +41,6 @@ namespace ccm::ext template constexpr std::common_type_t mix(TStart x, TEnd y, TAplha a) noexcept { - return x * (1 - a) + y * a; + return (x * (1 - a)) + (y * a); } } // namespace ccm::ext diff --git a/include/ccmath/ext/normalize.hpp b/include/ccmath/ext/normalize.hpp index 29abf887..bbb73e1c 100644 --- a/include/ccmath/ext/normalize.hpp +++ b/include/ccmath/ext/normalize.hpp @@ -27,6 +27,6 @@ namespace ccm::ext template, bool> = true> constexpr T normalize(T value, T min = T(0), T max = T(1)) { - return ccm::ext::clamp((value - min) / (max - min), static_cast(0), static_cast(1)); + return ext::clamp((value - min) / (max - min), static_cast(0), static_cast(1)); } } // namespace ccm::ext diff --git a/include/ccmath/ext/ping_pong.hpp b/include/ccmath/ext/ping_pong.hpp index b6655b37..065e75bc 100644 --- a/include/ccmath/ext/ping_pong.hpp +++ b/include/ccmath/ext/ping_pong.hpp @@ -32,7 +32,7 @@ namespace ccm::ext return T(0); } - return ccm::abs(ccm::ext::fract((a - b) / (b * 2.0)) * b * 2.0 - b); + return ccm::abs((ccm::ext::fract((a - b) / (b * 2.0)) * b * 2.0) - b); } } // namespace ccm::ext diff --git a/include/ccmath/internal/math/generic/func/fmanip/ldexp_gen.hpp b/include/ccmath/internal/math/generic/func/fmanip/ldexp_gen.hpp index 52aca0bc..8d8e8669 100644 --- a/include/ccmath/internal/math/generic/func/fmanip/ldexp_gen.hpp +++ b/include/ccmath/internal/math/generic/func/fmanip/ldexp_gen.hpp @@ -12,8 +12,8 @@ #include "ccmath/internal/config/builtin/bit_cast_support.hpp" #include "ccmath/internal/config/builtin/ldexp_support.hpp" -#include "ccmath/internal/support/helpers/internal_ldexp.hpp" #include "ccmath/internal/predef/has_const_builtin.hpp" +#include "ccmath/internal/support/helpers/internal_ldexp.hpp" /* TODO: Move, remove, or change this to not use bit_cast. #include "ccmath/internal/support/bits.hpp" @@ -38,13 +38,14 @@ namespace ccm template , bool> = true> constexpr T ldexp(T num, int exp) noexcept { + //NOLINTNEXTLINE #if defined(CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP) || CCM_HAS_CONST_BUILTIN(__builtin_ldexp) if constexpr (std::is_same_v) { return __builtin_ldexpf(num, exp); } if constexpr (std::is_same_v) { return __builtin_ldexp(num, exp); } if constexpr (std::is_same_v) { return __builtin_ldexpl(num, exp); } return static_cast(__builtin_ldexpl(num, exp)); #else - return helpers::internal_ldexp(num, exp); + return support::helpers::internal_ldexp(num, exp); /* TODO: Move, remove, or change this to not use bit_cast. // Fallback option. Does not give perfect results, but generally good enough. int old_exp = static_cast(support::get_exponent_of_floating_point(num)); From 23e1b4d3d7efb46a366f1f941d363061a83c06c3 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 21 Oct 2024 16:01:43 -0400 Subject: [PATCH 020/102] Add type-specific optimizations for popcount --- include/ccmath/internal/support/bits.hpp | 44 +++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/include/ccmath/internal/support/bits.hpp b/include/ccmath/internal/support/bits.hpp index 71e7526c..49efa64d 100644 --- a/include/ccmath/internal/support/bits.hpp +++ b/include/ccmath/internal/support/bits.hpp @@ -302,7 +302,7 @@ namespace ccm::support { return __builtin_popcountg(value); // NOLINT } -#else // !CCM_HAS_BUILTIN(__builtin_popcountg) +#else // !CCM_HAS_BUILTIN(__builtin_popcountg) template [[nodiscard]] constexpr std::enable_if_t, int> popcount(T value) { @@ -323,6 +323,48 @@ namespace ccm::support } return count; } + + // Specific optimizations for known types + constexpr int popcount(std::uint8_t n) + { + // The algorithm is specific to 8-bit input, and avoids using 64-bit register for code size. + std::uint32_t r = static_cast(n * 0x08040201U); + r = static_cast(((r >> 3) & 0x11111111U) * 0x11111111U) >> 28; + return r; + } + + // We don't want these overloads to be defined if the builtins are available, so we check for the builtins first. + + #if !CCM_HAS_BUILTIN(__builtin_popcount) + constexpr int popcount(unsigned int n) // Assume int is 32 bit and not 16. + { + n = n - (n >> 1) & 0x55555555; + n = (n & 0x33333333) + (n >> 2) & 0x33333333; + n = (n + n >> 4) & 0x0F0F0F0F; + return (n * 0x01010101) >> 24; + } + #endif // !CCM_HAS_BUILTIN(__builtin_popcount) + + #if !CCM_HAS_BUILTIN(__builtin_popcountl) + constexpr int popcount(unsigned long n) + { + n = n - (n >> 1) & 0x55555555; + n = (n & 0x33333333) + (n >> 2) & 0x33333333; + n = (n + n >> 4) & 0x0F0F0F0F; + return (n * 0x01010101) >> 24; + } + #endif // !CCM_HAS_BUILTIN(__builtin_popcount) + + #if !CCM_HAS_BUILTIN(__builtin_popcountll) + constexpr int popcount(unsigned long long n) + { + n = n - ((n >> 1) & 0x5555555555555555); + n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333); + n = (n + (n >> 4)) & 0xF0F0F0F0F0F0F0F; + return (n * 0x101010101010101) >> 56; + } + #endif // !CCM_HAS_BUILTIN(__builtin_popcountll) + #endif // CCM_HAS_BUILTIN(__builtin_popcountg) // Macro to allow simplified creation of specializations From 0bfd90ea0118eb94e9c9a8c05ae341b0d1d94c81 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 21 Oct 2024 16:17:12 -0400 Subject: [PATCH 021/102] Minor bug fix --- include/ccmath/internal/CMakeLists.txt | 6 +++--- include/ccmath/internal/support/helpers/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ccmath/internal/CMakeLists.txt b/include/ccmath/internal/CMakeLists.txt index 89c5b5a1..c056b1c7 100644 --- a/include/ccmath/internal/CMakeLists.txt +++ b/include/ccmath/internal/CMakeLists.txt @@ -4,6 +4,6 @@ ccm_add_headers( add_subdirectory(config) add_subdirectory(math) -#add_subdirectory(predef) -#add_subdirectory(support) -#add_subdirectory(types) +add_subdirectory(predef) +add_subdirectory(support) +add_subdirectory(types) diff --git a/include/ccmath/internal/support/helpers/CMakeLists.txt b/include/ccmath/internal/support/helpers/CMakeLists.txt index 16613039..e44bc0ea 100644 --- a/include/ccmath/internal/support/helpers/CMakeLists.txt +++ b/include/ccmath/internal/support/helpers/CMakeLists.txt @@ -2,7 +2,7 @@ ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/digit_to_int.hpp ${CMAKE_CURRENT_SOURCE_DIR}/exp10.hpp ${CMAKE_CURRENT_SOURCE_DIR}/exp_helpers.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fpclassify_helpers.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/fpclassify_helper.hpp ${CMAKE_CURRENT_SOURCE_DIR}/internal_ldexp.hpp ) From d1d6b8367c48db5c852c2686d13375b91044b208 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 21 Oct 2024 21:18:33 -0400 Subject: [PATCH 022/102] Finalize popcount optimization --- include/ccmath/internal/support/bits.hpp | 109 ++++++++++++++++------- 1 file changed, 75 insertions(+), 34 deletions(-) diff --git a/include/ccmath/internal/support/bits.hpp b/include/ccmath/internal/support/bits.hpp index 49efa64d..acf09796 100644 --- a/include/ccmath/internal/support/bits.hpp +++ b/include/ccmath/internal/support/bits.hpp @@ -324,45 +324,20 @@ namespace ccm::support return count; } - // Specific optimizations for known types - constexpr int popcount(std::uint8_t n) - { - // The algorithm is specific to 8-bit input, and avoids using 64-bit register for code size. - std::uint32_t r = static_cast(n * 0x08040201U); - r = static_cast(((r >> 3) & 0x11111111U) * 0x11111111U) >> 28; - return r; - } - // We don't want these overloads to be defined if the builtins are available, so we check for the builtins first. - + // Provides optimizations for common types. + // All provided optimizations are based on the Hammering Weight algorithm except for unsigned char. + // https://en.wikipedia.org/wiki/Hamming_weight #if !CCM_HAS_BUILTIN(__builtin_popcount) - constexpr int popcount(unsigned int n) // Assume int is 32 bit and not 16. - { - n = n - (n >> 1) & 0x55555555; - n = (n & 0x33333333) + (n >> 2) & 0x33333333; - n = (n + n >> 4) & 0x0F0F0F0F; - return (n * 0x01010101) >> 24; - } + #endif // !CCM_HAS_BUILTIN(__builtin_popcount) #if !CCM_HAS_BUILTIN(__builtin_popcountl) - constexpr int popcount(unsigned long n) - { - n = n - (n >> 1) & 0x55555555; - n = (n & 0x33333333) + (n >> 2) & 0x33333333; - n = (n + n >> 4) & 0x0F0F0F0F; - return (n * 0x01010101) >> 24; - } + #endif // !CCM_HAS_BUILTIN(__builtin_popcount) #if !CCM_HAS_BUILTIN(__builtin_popcountll) - constexpr int popcount(unsigned long long n) - { - n = n - ((n >> 1) & 0x5555555555555555); - n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333); - n = (n + (n >> 4)) & 0xF0F0F0F0F0F0F0F; - return (n * 0x101010101010101) >> 56; - } + #endif // !CCM_HAS_BUILTIN(__builtin_popcountll) #endif // CCM_HAS_BUILTIN(__builtin_popcountg) @@ -376,21 +351,87 @@ namespace ccm::support static_assert(ccm::support::traits::ccm_is_unsigned_v); \ return BUILTIN(value); \ } + // NOLINTEND(bugprone-macro-parentheses) // If the compiler has builtins for popcount, then create specializations that use the builtins. #if CCM_HAS_BUILTIN(__builtin_popcount) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned char, __builtin_popcount) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned short, __builtin_popcount) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned, __builtin_popcount) -#endif // CCM_HAS_BUILTIN(__builtin_popcount) +#else + // If we don't have builtins, then provide optimizations for common types. + // All provided optimizations are based on the Hamming Weight algorithm except for unsigned char. + // https://en.wikipedia.org/wiki/Hamming_weight + constexpr int popcount(unsigned char n) + { + // The algorithm is specific to 8-bit input, and avoids using 64-bit register for code size. + std::uint32_t r = static_cast(n * 0x08040201U); + r = static_cast(((r >> 3) & 0x11111111U) * 0x11111111U) >> 28; + return r; + } + + constexpr int popcount(unsigned short n) + { + n = n - (n >> 1) & 0x5555; + n = (n & 0x3333) + (n >> 2) & 0x3333; + n = (n + n >> 4) & 0x0F0F; + return (n * 0x0101) >> 16; + } + + constexpr int popcount(unsigned int n) + { + // int can be 32 or 16 bits, so we need to check. + if constexpr (constexpr int bits = std::numeric_limits::digits; bits == 32) // 32 bit int + { + n = n - (n >> 1) & 0x55555555; + n = (n & 0x33333333) + (n >> 2) & 0x33333333; + n = (n + n >> 4) & 0x0F0F0F0F; + return (n * 0x01010101) >> 24; + } + else // 16 bit int + { + n = n - (n >> 1) & 0x5555; + n = (n & 0x3333) + (n >> 2) & 0x3333; + n = (n + n >> 4) & 0x0F0F; + return (n * 0x0101) >> 16; + } + } +#endif #if CCM_HAS_BUILTIN(__builtin_popcountl) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned long, __builtin_popcountl) -#endif // CCM_HAS_BUILTIN(__builtin_popcountl) +#else + constexpr int popcount(unsigned long n) + { + // long can be 32 or 64 bits, so we need to check. + if constexpr (constexpr long bits = std::numeric_limits::digits; bits == 32) // 32 bit long + { + n = n - (n >> 1) & 0x55555555; + n = (n & 0x33333333) + (n >> 2) & 0x33333333; + n = (n + n >> 4) & 0x0F0F0F0F; + return (n * 0x01010101) >> 24; + } + else // 64-bit long + { + n = n - ((n >> 1) & 0x5555555555555555); + n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333); + n = (n + (n >> 4)) & 0xF0F0F0F0F0F0F0F; + return (n * 0x101010101010101) >> 56; + } + } +#endif #if CCM_HAS_BUILTIN(__builtin_popcountll) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned long long, __builtin_popcountll) -#endif // CCM_HAS_BUILTIN(__builtin_popcountll) +#else + constexpr int popcount(unsigned long long n) + { + n = n - ((n >> 1) & 0x5555555555555555); + n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333); + n = (n + (n >> 4)) & 0xF0F0F0F0F0F0F0F; + return (n * 0x101010101010101) >> 56; + } +#endif #undef INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION From 406c404524a4148d1b1adc11eda60f4c69127377 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 18:16:02 -0400 Subject: [PATCH 023/102] Minor cleanup --- cmake/CcmAddHeaders.cmake | 3 -- cmake/Macros.cmake | 49 ------------------------ cmake/functions/CcmAddHeaders.cmake | 5 +++ cmake/functions/CcmathMessage.cmake | 59 +++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 52 deletions(-) delete mode 100644 cmake/CcmAddHeaders.cmake delete mode 100644 cmake/Macros.cmake create mode 100644 cmake/functions/CcmAddHeaders.cmake create mode 100644 cmake/functions/CcmathMessage.cmake diff --git a/cmake/CcmAddHeaders.cmake b/cmake/CcmAddHeaders.cmake deleted file mode 100644 index 13326bca..00000000 --- a/cmake/CcmAddHeaders.cmake +++ /dev/null @@ -1,3 +0,0 @@ -macro(ccm_add_headers headers) - target_sources(${PROJECT_NAME} INTERFACE "$") -endmacro() diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake deleted file mode 100644 index 24147244..00000000 --- a/cmake/Macros.cmake +++ /dev/null @@ -1,49 +0,0 @@ -macro ( ccmath_message_color NAME ) - ccmath_message ( COLOR ${NAME} " ${NAME}" ) -endmacro () - -function ( text ) - cmake_parse_arguments ( PARSE_ARGV 0 "_TEXT" "BOLD" "COLOR" "" ) - - set ( _TEXT_OPTIONS -E cmake_echo_color --no-newline ) - - if ( _TEXT_COLOR ) - string ( TOLOWER "${_TEXT_COLOR}" _TEXT_COLOR_LOWER ) - if( _TEXT_COLOR_LOWER STREQUAL "warning" ) - set ( _TEXT_COLOR_LOWER "yellow" ) - endif () - if ( NOT ${_TEXT_COLOR_LOWER} MATCHES "^default|black|red|green|yellow|warning|blue|magenta|cyan|white" ) - ccmath_message ( "Only these colours are supported:" ) - ccmath_message_color ( DEFAULT ) - ccmath_message_color ( BLACK ) - ccmath_message_color ( RED ) - ccmath_message_color ( GREEN ) - ccmath_message_color ( YELLOW ) - ccmath_message_color ( WARNING ) - ccmath_message_color ( BLUE ) - ccmath_message_color ( MAGENTA ) - ccmath_message_color ( CYAN ) - ccmath_message_color ( WHITE ) - TEXT ( WARING "Color ${_TEXT_COLOR} is not support." ) - else () - list ( APPEND _TEXT_OPTIONS --${_TEXT_COLOR_LOWER} ) - endif () - endif () - - if ( _TEXT_BOLD ) - list ( APPEND _TEXT_OPTIONS --bold ) - endif () - - execute_process ( COMMAND ${CMAKE_COMMAND} -E env CLICOLOR_FORCE=1 ${CMAKE_COMMAND} ${_TEXT_OPTIONS} "-- " ${_TEXT_UNPARSED_ARGUMENTS} - OUTPUT_VARIABLE _TEXT_RESULT - ECHO_ERROR_VARIABLE - ) - - set ( TEXT_RESULT ${_TEXT_RESULT} PARENT_SCOPE ) -endfunction () -unset ( ccmath_message_color ) - -function ( ccmath_message ) - text ( ${ARGN} ) - message ( ${TEXT_RESULT} ) -endfunction () diff --git a/cmake/functions/CcmAddHeaders.cmake b/cmake/functions/CcmAddHeaders.cmake new file mode 100644 index 00000000..c2d7cf38 --- /dev/null +++ b/cmake/functions/CcmAddHeaders.cmake @@ -0,0 +1,5 @@ +# Helper function to add headers to the global source list +function(ccm_add_headers) + # Append all the passed arguments (headers) to the target's sources + target_sources(${PROJECT_NAME} INTERFACE "$") +endfunction() diff --git a/cmake/functions/CcmathMessage.cmake b/cmake/functions/CcmathMessage.cmake new file mode 100644 index 00000000..2dc632eb --- /dev/null +++ b/cmake/functions/CcmathMessage.cmake @@ -0,0 +1,59 @@ +macro(ccmath_message_color NAME) + ccmath_message(COLOR ${NAME} " ${NAME}") +endmacro() + +function(internal_ccmath_colored_text) + cmake_parse_arguments(PARSE_ARGV 0 "_TEXT" "BOLD" "COLOR" "") + + set(_TEXT_OPTIONS -E cmake_echo_color --no-newline) + + if (_TEXT_COLOR) + string(TOLOWER "${_TEXT_COLOR}" _TEXT_COLOR_LOWER) + if (_TEXT_COLOR_LOWER STREQUAL "warning") + set(_TEXT_COLOR_LOWER "yellow") + endif () + if (NOT ${_TEXT_COLOR_LOWER} MATCHES "^default|black|red|green|yellow|warning|blue|magenta|cyan|white") + ccmath_message("Only these colours are supported:") + ccmath_message_color(DEFAULT) + ccmath_message_color(BLACK) + ccmath_message_color(RED) + ccmath_message_color(GREEN) + ccmath_message_color(YELLOW) + ccmath_message_color(WARNING) + ccmath_message_color(BLUE) + ccmath_message_color(MAGENTA) + ccmath_message_color(CYAN) + ccmath_message_color(WHITE) + TEXT(WARING "Color ${_TEXT_COLOR} is not support.") + else () + list(APPEND _TEXT_OPTIONS --${_TEXT_COLOR_LOWER}) + endif () + endif () + + if (_TEXT_BOLD) + list(APPEND _TEXT_OPTIONS --bold) + endif () + + execute_process(COMMAND ${CMAKE_COMMAND} -E env CLICOLOR_FORCE=1 ${CMAKE_COMMAND} ${_TEXT_OPTIONS} "-- " ${_TEXT_UNPARSED_ARGUMENTS} + OUTPUT_VARIABLE _TEXT_RESULT + ECHO_ERROR_VARIABLE + ) + + set(TEXT_RESULT ${_TEXT_RESULT} PARENT_SCOPE) +endfunction() +unset(ccmath_message_color) + +function(internal_ccmath_normal_text) + cmake_parse_arguments(PARSE_ARGV 0 "_TEXT" "BOLD" "COLOR" "") + set(TEXT_RESULT ${_TEXT_UNPARSED_ARGUMENTS} PARENT_SCOPE) +endfunction() + +function(ccmath_message) + if (DEFINED CCMATH_CMAKE_DEBUG AND CCMATH_CMAKE_DEBUG STREQUAL "ON") + internal_ccmath_colored_text(${ARGN}) + message(${TEXT_RESULT}) + else () + internal_ccmath_normal_text(${ARGN}) + message(STATUS ${TEXT_RESULT}) + endif () +endfunction() From 979b5addc7be50d351991ba63a0072e43cc2e9ac Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 18:16:58 -0400 Subject: [PATCH 024/102] Add feature checking for simd --- CMakeLists.txt | 33 ++++--- .../features/CheckAllSupportedFeatures.cmake | 0 .../CheckAllSupportedSimdFeatures.cmake | 17 ++++ .../features/simd/CheckAVX2Support.cmake | 13 +++ .../features/simd/CheckAVX512Support.cmake | 90 +++++++++++++++++++ .../features/simd/CheckAVXSupport.cmake | 13 +++ .../features/simd/CheckFMASupport.cmake | 13 +++ .../features/simd/CheckNEONSupport.cmake | 13 +++ .../features/simd/CheckSSE2Support.cmake | 13 +++ .../features/simd/CheckSSE3Support.cmake | 13 +++ .../features/simd/CheckSSE4Support.cmake | 31 +++++++ .../features/simd/CheckSSSE3Support.cmake | 13 +++ .../features/simd/CheckSVMLSupport.cmake | 14 +++ 13 files changed, 263 insertions(+), 13 deletions(-) create mode 100644 cmake/config/features/CheckAllSupportedFeatures.cmake create mode 100644 cmake/config/features/CheckAllSupportedSimdFeatures.cmake create mode 100644 cmake/config/features/simd/CheckAVX2Support.cmake create mode 100644 cmake/config/features/simd/CheckAVX512Support.cmake create mode 100644 cmake/config/features/simd/CheckAVXSupport.cmake create mode 100644 cmake/config/features/simd/CheckFMASupport.cmake create mode 100644 cmake/config/features/simd/CheckNEONSupport.cmake create mode 100644 cmake/config/features/simd/CheckSSE2Support.cmake create mode 100644 cmake/config/features/simd/CheckSSE3Support.cmake create mode 100644 cmake/config/features/simd/CheckSSE4Support.cmake create mode 100644 cmake/config/features/simd/CheckSSSE3Support.cmake create mode 100644 cmake/config/features/simd/CheckSVMLSupport.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b499eb8b..c5aca007 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,19 +27,26 @@ message(STATUS "CCMath version: ${PROJECT_VERSION}") # TO THE IMPLEMENTOR: If CCMATH_BUILD_TESTS is set to OFF then googletest can be deleted from the ext folder. option(CCMATH_INSTALL "Setup install and package steps" ${is_root_project}) -option(CCMATH_BUILD_TESTS "Build ccmath tests" ${is_root_project}) +## CCMath specific user defined options +option(CCMATH_BUILD_TESTS "Build ccmath tests" ${is_root_project}) # If disabled then gtest will not be fetched. option(CCMATH_FIND_GTEST_PACKAGE "Enable finding of gtest package" OFF) -option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project}) +option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project}) # If disabled then gbench will not be fetched. option(CCMATH_FIND_GBENCH_PACKAGE "Enable finding of google benchmark package" OFF) option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project}) - -option(CCMATH_ENABLE_EXTENSIONS "Enable the extended ccmath library that adds helpful additional methods that are not defined by the standard" ${is_root_project}) -option(CCMATH_ENABLE_RUNTIME_SIMD "Enable SIMD optimization for runtime evaluation (does not effect compile time)" ON) # By default we want SIMD to be enabled option(CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS "Enable user defined optimization macros instead of having ccmath define its own internal ones in cmake" OFF) -option(CCMATH_DISABLE_ERRNO "Disable the use of errno in ccmath during runtime" OFF) + +## Standard changing user defined options +# Most options here are by default set to OFF. Setting them to ON will violate the standard, but generally +# provide better performance or get rid of extra bloat that the standard requires. +option(CCMATH_ENABLE_EXTENSIONS "Enable the extended ccmath library that adds helpful additional methods that are not defined by the standard" OFF) +option(CCMATH_DISABLE_ERRNO "Disable the use of errno in ccmath during runtime (this will allow compile time evaluation of edge cases that normally can not be evaluated at compile time)" OFF) + +## Simd specific user defined options +option(CCMATH_ENABLE_RUNTIME_SIMD "Enable SIMD optimization for runtime evaluation (does not effect compile time)" ON) # By default we want SIMD to be enabled to allow faster runtime evaluation. +option(CCMATH_DISABLE_SVML_USAGE "Disable the use of SVML functions in ccmath. (This only effects compilers that use SVML)" OFF) # include the global configuration file -include(cmake/GlobalConfig.cmake) +include(cmake/config/GlobalConfig.cmake) add_library(${PROJECT_NAME}-compile-options INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME}-compile-options ALIAS ${PROJECT_NAME}-compile-options) @@ -98,13 +105,9 @@ endif () add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -include(cmake/Macros.cmake) +include(cmake/functions/CcmathMessage.cmake) -# Helper function to add headers to the global source list -function(ccm_add_headers) - # Append all the passed arguments (headers) to the target's sources - target_sources(${PROJECT_NAME} INTERFACE "$") -endfunction() +include(cmake/functions/CcmAddHeaders.cmake) add_subdirectory(include/ccmath) @@ -117,6 +120,10 @@ target_link_libraries(${PROJECT_NAME} INTERFACE if (CCMATH_ENABLE_RUNTIME_SIMD) target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_USE_RT_SIMD) + + if (NOT CCMATH_DISABLE_SVML_USAGE) + include(cmake/config/features/CheckAllSupportedSimdFeatures.cmake) # Checks for specific SIMD features and sets the appropriate macros. + endif () endif () if (NOT CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS) diff --git a/cmake/config/features/CheckAllSupportedFeatures.cmake b/cmake/config/features/CheckAllSupportedFeatures.cmake new file mode 100644 index 00000000..e69de29b diff --git a/cmake/config/features/CheckAllSupportedSimdFeatures.cmake b/cmake/config/features/CheckAllSupportedSimdFeatures.cmake new file mode 100644 index 00000000..b1c8f8f8 --- /dev/null +++ b/cmake/config/features/CheckAllSupportedSimdFeatures.cmake @@ -0,0 +1,17 @@ +if (NOT DEFINED CCMATH_SOURCE_DIR) + message(FATAL_ERROR "CCMATH_SOURCE_DIR is not defined. Did you forget to include the main CMakeLists.txt?") +endif () + +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckFMASupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckAVXSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckAVX2Support.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckAVX512Support.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSE2Support.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSE3Support.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSSE3Support.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSE4Support.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSVMLSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckNEONSupport.cmake) + + + diff --git a/cmake/config/features/simd/CheckAVX2Support.cmake b/cmake/config/features/simd/CheckAVX2Support.cmake new file mode 100644 index 00000000..c74c34e3 --- /dev/null +++ b/cmake/config/features/simd/CheckAVX2Support.cmake @@ -0,0 +1,13 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + #include + int main() { + __m256i avx2_test = _mm256_add_epi32(_mm256_set1_epi32(1), _mm256_set1_epi32(2)); + return 0; + } + " CCMATH_SIMD_HAS_AVX2_SUPPORT) + +if (CCMATH_SIMD_HAS_AVX2_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX2) +endif () diff --git a/cmake/config/features/simd/CheckAVX512Support.cmake b/cmake/config/features/simd/CheckAVX512Support.cmake new file mode 100644 index 00000000..7ec03547 --- /dev/null +++ b/cmake/config/features/simd/CheckAVX512Support.cmake @@ -0,0 +1,90 @@ +include(CheckCXXSourceCompiles) + +# Check for AVX-512-F (Foundation) +check_cxx_source_compiles(" + #include + int main() { + __m512d avx512f_test = _mm512_set1_pd(1.0); + return 0; + } + " CCMATH_SIMD_HAS_AVX512F_SUPPORT) + +if (CCMATH_SIMD_HAS_AVX512F_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512F) +endif () + +# Check for AVX-512-DQ (Double and Quadword) +check_cxx_source_compiles(" + #include + int main() { + __m512i avx512dq_test = _mm512_mul_epu32(_mm512_set1_epi64(1), _mm512_set1_epi64(2)); + return 0; + } + " CCMATH_SIMD_HAS_AVX512DQ_SUPPORT) + +if (CCMATH_SIMD_HAS_AVX512DQ_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512DQ) +endif () + +# Check for AVX-512-IFMA (Integer Fused Multiply-Add) +check_cxx_source_compiles(" + #include + int main() { + __m512i avx512ifma_test = _mm512_madd52hi_epu64(_mm512_set1_epi64(1), _mm512_set1_epi64(2), _mm512_set1_epi64(3)); + return 0; + } + " CCMATH_SIMD_HAS_AVX512IFMA_SUPPORT) + +if (CCMATH_SIMD_HAS_AVX512IFMA_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512IFMA) +endif () + +# Check for AVX-512-CD (Conflict Detection) +check_cxx_source_compiles(" + #include + int main() { + __m512i avx512cd_test = _mm512_conflict_epi64(_mm512_set1_epi64(1)); + return 0; + } + " CCMATH_SIMD_HAS_AVX512CD_SUPPORT) + +if (CCMATH_SIMD_HAS_AVX512CD_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512CD) +endif () + +# Check for AVX-512-BW (Byte and Word) +check_cxx_source_compiles(" + #include + int main() { + __m512i avx512bw_test = _mm512_cvtepi16_epi8(_mm512_set1_epi16(1)); + return 0; + } + " CCMATH_SIMD_HAS_AVX512BW_SUPPORT) + +if (CCMATH_SIMD_HAS_AVX512BW_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512BW) +endif () + +# Check for AVX-512-VL (Vector Length Extensions) +check_cxx_source_compiles(" + #include + int main() { + __m256i avx512vl_test = _mm256_abs_epi16(_mm256_set1_epi16(-1)); + return 0; + } + " CCMATH_SIMD_HAS_AVX512VL_SUPPORT) + +if (CCMATH_SIMD_HAS_AVX512VL_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512VL) +endif () + + +# Check if we have full AVX-512 support +if (CCMATH_SIMD_HAS_AVX512F_SUPPORT AND + CCMATH_SIMD_HAS_AVX512DQ_SUPPORT AND + CCMATH_SIMD_HAS_AVX512IFMA_SUPPORT AND + CCMATH_SIMD_HAS_AVX512CD_SUPPORT AND + CCMATH_SIMD_HAS_AVX512BW_SUPPORT AND + CCMATH_SIMD_HAS_AVX512VL_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512) +endif () diff --git a/cmake/config/features/simd/CheckAVXSupport.cmake b/cmake/config/features/simd/CheckAVXSupport.cmake new file mode 100644 index 00000000..3c84107a --- /dev/null +++ b/cmake/config/features/simd/CheckAVXSupport.cmake @@ -0,0 +1,13 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + #include + int main() { + __m256d avx_test = _mm256_set1_pd(1.0); + return 0; + } + " CCMATH_SIMD_HAS_AVX_SUPPORT) + +if (CCMATH_SIMD_HAS_AVX_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX) +endif () diff --git a/cmake/config/features/simd/CheckFMASupport.cmake b/cmake/config/features/simd/CheckFMASupport.cmake new file mode 100644 index 00000000..67817e49 --- /dev/null +++ b/cmake/config/features/simd/CheckFMASupport.cmake @@ -0,0 +1,13 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + #include + int main() { + __m128 fma_test = _mm_fmadd_ps(_mm_set1_ps(1.0f), _mm_set1_ps(2.0f), _mm_set1_ps(3.0f)); + return 0; + } + " CCMATH_SIMD_HAS_FMA_SUPPORT) + +if (CCMATH_SIMD_HAS_FMA_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_FMA) +endif () diff --git a/cmake/config/features/simd/CheckNEONSupport.cmake b/cmake/config/features/simd/CheckNEONSupport.cmake new file mode 100644 index 00000000..d0049aa1 --- /dev/null +++ b/cmake/config/features/simd/CheckNEONSupport.cmake @@ -0,0 +1,13 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + #include + int main() { + int32x4_t neon_test = vdupq_n_s32(1); + return 0; + } + " CCMATH_SIMD_HAS_NEON_SUPPORT) + +if (CCMATH_SIMD_HAS_NEON_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_NEON) +endif () diff --git a/cmake/config/features/simd/CheckSSE2Support.cmake b/cmake/config/features/simd/CheckSSE2Support.cmake new file mode 100644 index 00000000..859fd597 --- /dev/null +++ b/cmake/config/features/simd/CheckSSE2Support.cmake @@ -0,0 +1,13 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + #include + int main() { + __m128d sse2_test = _mm_set1_pd(1.0); + return 0; + } + " CCMATH_SIMD_HAS_SSE2_SUPPORT) + +if (CCMATH_SIMD_HAS_SSE2_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_SSE2) +endif () diff --git a/cmake/config/features/simd/CheckSSE3Support.cmake b/cmake/config/features/simd/CheckSSE3Support.cmake new file mode 100644 index 00000000..dfb3f9cc --- /dev/null +++ b/cmake/config/features/simd/CheckSSE3Support.cmake @@ -0,0 +1,13 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + #include + int main() { + __m128d sse3_test = _mm_addsub_pd(_mm_set1_pd(1.0), _mm_set1_pd(2.0)); + return 0; + } + " CCMATH_SIMD_HAS_SSE3_SUPPORT) + +if (CCMATH_SIMD_HAS_SSE3_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_SSE3) +endif () diff --git a/cmake/config/features/simd/CheckSSE4Support.cmake b/cmake/config/features/simd/CheckSSE4Support.cmake new file mode 100644 index 00000000..ca8523cc --- /dev/null +++ b/cmake/config/features/simd/CheckSSE4Support.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check for SSE4.1 support +check_cxx_source_compiles(" + #include + int main() { + __m128i sse4_1_test = _mm_min_epi32(_mm_set1_epi32(1), _mm_set1_epi32(2)); + return 0; + } + " CCMATH_SIMD_HAS_SSE4_1_SUPPORT) + +# Check for SSE4.2 support +check_cxx_source_compiles(" + #include + int main() { + __m128i sse4_2_test = _mm_cmpestra(_mm_set1_epi32(1), 1, _mm_set1_epi32(2), 1, 0); + return 0; + } + " CCMATH_SIMD_HAS_SSE4_2_SUPPORT) + +if (CCMATH_SIMD_HAS_SSE4_1_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_SSE4_1) +endif () + +if (CCMATH_SIMD_HAS_SSE4_2_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_SSE4_2) +endif () + +if (CCMATH_SIMD_HAS_SSE4_1_SUPPORT AND CCMATH_SIMD_HAS_SSE4_2_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_SSE4) +endif () diff --git a/cmake/config/features/simd/CheckSSSE3Support.cmake b/cmake/config/features/simd/CheckSSSE3Support.cmake new file mode 100644 index 00000000..4c42e319 --- /dev/null +++ b/cmake/config/features/simd/CheckSSSE3Support.cmake @@ -0,0 +1,13 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + #include + int main() { + __m128i ssse3_test = _mm_abs_epi8(_mm_set1_epi8(-1)); + return 0; + } + " CCMATH_SIMD_HAS_SSSE3_SUPPORT) + +if (CCMATH_SIMD_HAS_SSSE3_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_SSSE3) +endif () diff --git a/cmake/config/features/simd/CheckSVMLSupport.cmake b/cmake/config/features/simd/CheckSVMLSupport.cmake new file mode 100644 index 00000000..e830055b --- /dev/null +++ b/cmake/config/features/simd/CheckSVMLSupport.cmake @@ -0,0 +1,14 @@ +include(CheckCXXSourceCompiles) + +# Try to compile a small piece of code that uses an SVML function +check_cxx_source_compiles(" + #include + int main() { + _mm_sin_pd(_mm_set1_pd(1.0)); + return 0; + } + " CCMATH_SIMD_HAS_SVML_SUPPORT) + +if (CCMATH_SIMD_HAS_SVML_SUPPORT) + add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_SVML) +endif () From c7022ecca3fb05019a75482aa7357ec0ab431349 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 18:19:15 -0400 Subject: [PATCH 025/102] Minor cleanup & bug fixing --- cmake/{ => config}/GlobalConfig.cmake | 2 +- .../config/arch/check_simd_support.hpp | 76 +++++++++---------- .../internal/math/runtime/simd/CMakeLists.txt | 1 + .../runtime/simd/instructions/CMakeLists.txt | 2 - 4 files changed, 36 insertions(+), 45 deletions(-) rename cmake/{ => config}/GlobalConfig.cmake (98%) diff --git a/cmake/GlobalConfig.cmake b/cmake/config/GlobalConfig.cmake similarity index 98% rename from cmake/GlobalConfig.cmake rename to cmake/config/GlobalConfig.cmake index 0de848cd..39d59d7a 100644 --- a/cmake/GlobalConfig.cmake +++ b/cmake/config/GlobalConfig.cmake @@ -1,4 +1,4 @@ -include(cmake/Macros.cmake) +include(cmake/functions/CcmathMessage.cmake) # detect our OS if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") diff --git a/include/ccmath/internal/config/arch/check_simd_support.hpp b/include/ccmath/internal/config/arch/check_simd_support.hpp index 42894c33..5ac372b3 100644 --- a/include/ccmath/internal/config/arch/check_simd_support.hpp +++ b/include/ccmath/internal/config/arch/check_simd_support.hpp @@ -29,146 +29,138 @@ #ifdef CCM_CONFIG_USE_RT_SIMD - // Streaming SIMD Extensions (SSE) - #if defined(__SSE__) || (defined(_M_IX86_FP) && _M_IX86_FP >= 1) - #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD - #endif - #define CCMATH_HAS_SIMD_SSE 1 - #endif - // Streaming SIMD Extensions 2 (SSE2) - #if defined(__SSE2__) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2) + #if defined(__SSE2__) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2) || defined(CCM_CONFIG_RT_SIMD_HAS_SSE2) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_SSE2 1 #endif // Streaming SIMD Extensions 3 (SSE3) - #if defined(__SSE3__) + #if defined(__SSE3__) || defined(CCM_CONFIG_RT_SIMD_HAS_SSE3) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_SSE3 1 #endif // Supplemental Streaming SIMD Extensions 3 (SSSE3) - #if defined(__SSSE3__) + #if defined(__SSSE3__) || defined(CCM_CONFIG_RT_SIMD_HAS_SSSE3) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_SSSE3 1 #endif // Streaming SIMD Extensions 4.1 (SSE4.1) - #if defined(__SSE4_1__) + #if defined(__SSE4_1__) || defined(CCM_CONFIG_RT_SIMD_HAS_SSE4_1) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_SSE4_1 1 #endif // Streaming SIMD Extensions 4.2 (SSE4.2) - #if defined(__SSE4_2__) + #if defined(__SSE4_2__) || defined(CCM_CONFIG_RT_SIMD_HAS_SSE4_2) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_SSE4_2 1 #endif // Streaming SIMD Extensions 4 (SSE4) - #if defined(CCMATH_HAS_SIMD_SSE4_1) || defined(CCMATH_HAS_SIMD_SSE4_2) + #if (defined(CCMATH_HAS_SIMD_SSE4_1) && defined(CCMATH_HAS_SIMD_SSE4_2)) || defined(CCM_CONFIG_RT_SIMD_HAS_SSE4) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_SSE4 1 #endif // Advanced Vector Extensions (AVX) - #if defined(__AVX__) + #if defined(__AVX__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX 1 #endif // Advanced Vector Extensions 2 (AVX2) - #if defined(__AVX2__) + #if defined(__AVX2__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX2) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX2 1 #endif // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Byte and Word instructions. - #if defined(__AVX512BW__) + #if defined(__AVX512BW__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512BW) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX512BW 1 #endif // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Conflict Detection instructions. - #if defined(__AVX512CD__) + #if defined(__AVX512CD__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512CD) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX512CD 1 #endif // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Doubleword and Quadword instructions. - #if defined(__AVX512DQ__) + #if defined(__AVX512DQ__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512DQ) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX512DQ 1 #endif // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Exponential and Reciprocal instructions. - #if defined(__AVX512ER__) + #if defined(__AVX512ER__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512ER) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX512ER 1 #endif // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Foundation instructions. - #if defined(__AVX512F__) + #if defined(__AVX512F__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512F) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX512F 1 #endif // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Prefetch instructions. - #if defined(__AVX512PF__) + #if defined(__AVX512PF__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512PF) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX512PF 1 #endif // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Vector Length extensions. - #if defined(__AVX512VL__) + #if defined(__AVX512VL__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512VL) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX512VL 1 #endif // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Byte and Word instructions. - #if defined(__AVX512F__) && defined(__AVX512VL__) && defined(__AVX512BW__) && defined(__AVX512DQ__) + #if (defined(__AVX512F__) && defined(__AVX512VL__) && defined(__AVX512BW__) && defined(__AVX512DQ__)) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_AVX512 1 #endif // ARM Advanced SIMD (NEON) - #if defined(__ARM_NEON) || defined(__ARM_NEON__) + #if defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(CCM_CONFIG_RT_SIMD_HAS_NEON) #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 #endif #define CCMATH_HAS_SIMD_NEON 1 #endif diff --git a/include/ccmath/internal/math/runtime/simd/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt index 58d2077e..55a401c7 100644 --- a/include/ccmath/internal/math/runtime/simd/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt @@ -7,3 +7,4 @@ ccm_add_headers( ) add_subdirectory(func) +add_subdirectory(instructions) diff --git a/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt index 02ddf8ef..ad2041ce 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt @@ -8,5 +8,3 @@ ccm_add_headers( ${CMAKE_CURRENT_SOURCE_DIR}/sse4.hpp ${CMAKE_CURRENT_SOURCE_DIR}/ssse3.hpp ) - -add_subdirectory(func) From 8416e907e7b0a110ad0fb106e099137cb1cdae42 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 18:19:46 -0400 Subject: [PATCH 026/102] Fix incorrect abi usage --- .../internal/math/runtime/simd/func/impl/avx512/pow.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp index 4d9f9a61..bc0154b7 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp @@ -19,13 +19,13 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm512_pow_ps(a.get(), b.get())); + return simd(_mm512_pow_ps(a.get(), b.get())); } CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm512_pow_pd(a.get(), b.get())); + return simd(_mm512_pow_pd(a.get(), b.get())); } From be0e44f60cd53e9cb5764c2bf14af089cb9c3ecf Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 18:20:40 -0400 Subject: [PATCH 027/102] Minor cleanup --- include/ccmath/internal/support/fenv/rounding_mode.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ccmath/internal/support/fenv/rounding_mode.hpp b/include/ccmath/internal/support/fenv/rounding_mode.hpp index 2fd82bcd..bc0f15ee 100644 --- a/include/ccmath/internal/support/fenv/rounding_mode.hpp +++ b/include/ccmath/internal/support/fenv/rounding_mode.hpp @@ -114,6 +114,6 @@ namespace ccm::support::fenv default: return FE_TONEAREST; // Default rounding mode. } } - else { return internal::rt_get_rounding_mode(); } + return internal::rt_get_rounding_mode(); } } // namespace ccm::support::fenv From 4e6764391e1aba62cf1df09a85c161f259fc16c5 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 18:21:16 -0400 Subject: [PATCH 028/102] Change fenv exception handling to now enforce runtime evaluation --- .../internal/support/fenv/fenv_support.hpp | 62 ++++++++++++------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/include/ccmath/internal/support/fenv/fenv_support.hpp b/include/ccmath/internal/support/fenv/fenv_support.hpp index 3cbf37a4..f6e2262b 100644 --- a/include/ccmath/internal/support/fenv/fenv_support.hpp +++ b/include/ccmath/internal/support/fenv/fenv_support.hpp @@ -22,12 +22,12 @@ namespace ccm::support::fenv::internal { - inline int clear_except(int err_code) + inline int clear_except(const int err_code) { return std::feclearexcept(err_code); } - inline int test_except(int err_code) + inline int test_except(const int err_code) { return std::fetestexcept(err_code); } @@ -42,7 +42,7 @@ namespace ccm::support::fenv::internal #endif } - inline int set_except(int err_code) + inline int set_except([[maybe_unused]] int err_code) { // Only GNU-based compilers support this function. #ifdef __USE_GNU @@ -52,12 +52,12 @@ namespace ccm::support::fenv::internal #endif } - inline int raise_except(int err_code) + inline int raise_except(const int err_code) { return std::feraiseexcept(err_code); } - inline int enable_except(int err_code) + inline int enable_except([[maybe_unused]] int err_code) { // Only GNU-based compilers support this function. #ifdef __USE_GNU @@ -66,7 +66,7 @@ namespace ccm::support::fenv::internal return 0; #endif } - inline int disable_except(int err_code) + inline int disable_except([[maybe_unused]] int err_code) { // Only GNU-based compilers support this function. #ifdef __USE_GNU @@ -78,10 +78,10 @@ namespace ccm::support::fenv::internal inline int get_round() { - return ccm::support::fenv::get_rounding_mode(); + return get_rounding_mode(); } - inline int set_round(int rounding_mode) + inline int set_round(const int rounding_mode) { return std::fesetround(rounding_mode); } @@ -105,12 +105,23 @@ namespace ccm::support::fenv eErrnoExcept = 2, }; + constexpr bool is_errno_enabled() + { + #if defined(__FAST_MATH__) || defined(CCM_CONFIG_DISABLE_ERRNO) + return false; + #else + return true; + #endif + } + // Helper function to convert the enum class to an integer to enable bitwise operations. constexpr int get_mode(ccm_math_err_mode mode) { return static_cast(mode); } + + constexpr int ccm_math_err_handling() { #if defined(__FAST_MATH__) || defined(CCM_CONFIG_DISABLE_ERRNO) @@ -124,31 +135,36 @@ namespace ccm::support::fenv #endif } - constexpr int set_except_if_required(int excepts) + // ReSharper disable once CppDFAConstantFunctionResult + inline int set_except_if_required(const int excepts) { - if (is_constant_evaluated()) { return 0; } // We cannot raise fenv exceptions in a constexpr context. So we return. - if ((ccm_math_err_handling() & get_mode(ccm_math_err_mode::eErrnoExcept)) != 0) { return internal::set_except(excepts); } + // Now following the mentality that fenv exceptions will enforce a constexpr function must be evaluated at runtime. + //if (is_constant_evaluated()) { return 0; } // We cannot raise fenv exceptions in a constexpr context. So we return. + if constexpr (is_errno_enabled()) + { + if constexpr ((ccm_math_err_handling() & get_mode(ccm_math_err_mode::eErrnoExcept)) != 0) { return internal::set_except(excepts); } + } + // ReSharper disable once CppDFAUnreachableCode // This is unreachable code if the above constexpr if statement is true which is desired. return 0; } - constexpr int raise_except_if_required(int excepts) + inline int raise_except_if_required(const int excepts) { - if (is_constant_evaluated()) { return 0; } // We cannot raise fenv exceptions in a constexpr context. So we return. - - if ((ccm_math_err_handling() & get_mode(ccm_math_err_mode::eErrnoExcept)) != 0) { return internal::raise_except(excepts); } + // Now following the mentality that fenv exceptions will enforce a constexpr function must be evaluated at runtime. + //if (is_constant_evaluated()) { return 0; } // We cannot raise fenv exceptions in a constexpr context. So we return. + if constexpr (is_errno_enabled()) + { + if constexpr ((ccm_math_err_handling() & get_mode(ccm_math_err_mode::eErrnoExcept)) != 0) { return internal::raise_except(excepts); } + } + // ReSharper disable once CppDFAUnreachableCode // This is unreachable code if the above constexpr if statement is true which is desired. return 0; } - constexpr void set_errno_if_required(int err) + inline void set_errno_if_required(const int err) { - // NOLINTNEXTLINE(bugprone-branch-clone) - if (is_constant_evaluated()) // We cannot raise fenv exceptions in a constexpr context. So we return. - { - // Do nothing - } - else + if constexpr (is_errno_enabled()) { - if ((ccm_math_err_handling() & get_mode(ccm_math_err_mode::eErrnoExcept)) != 0) { errno = err; } + if constexpr ((ccm_math_err_handling() & get_mode(ccm_math_err_mode::eErrnoExcept)) != 0) { errno = err; } } } } // namespace ccm::support::fenv From 205944fd10e4c9ef70013fa912abe998202df00f Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 18:21:55 -0400 Subject: [PATCH 029/102] Add a windows-specific lint script --- lint.bat | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lint.bat diff --git a/lint.bat b/lint.bat new file mode 100644 index 00000000..30793f8d --- /dev/null +++ b/lint.bat @@ -0,0 +1,21 @@ +@echo off + +REM +REM Copyright (c) Ian Pike +REM Copyright (c) CCMath contributors +REM +REM CCMath is provided under the Apache-2.0 License WITH LLVM-exception. +REM See LICENSE for more information. +REM +REM SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +REM + +set status=0 + +for /r "include\ccmath" %%f in (*.hpp) do ( + echo Checking %%f + clang-tidy %%f -p=out/clang-tidy + if errorlevel 1 set status=1 +) + +exit /b %status% From ab4ae1bccda7075868d3cf1fd2c02e18e3036ea8 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 18:22:58 -0400 Subject: [PATCH 030/102] Add cmake specific SVML detection for pow --- .../math/runtime/simd/func/impl/sse2/pow.hpp | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp index e6c52596..57f140a5 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp @@ -14,13 +14,10 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSE2 - #include "ccmath/internal/config/platform/linux.hpp" -#if !defined(CCM_TARGET_PLATFORM_LINUX) - #include -#endif // !CCM_TARGET_PLATFORM_LINUX - - #if defined(CCM_TARGET_PLATFORM_LINUX) + #if defined(CCM_CONFIG_RT_SIMD_HAS_SVML) + #include + #else #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" #endif @@ -28,27 +25,25 @@ namespace ccm::intrin { CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler - // It appears Windows and macOS have SVML out the box so we only care about linux. - #if !defined(CCM_TARGET_PLATFORM_LINUX) - return simd(_mm_pow_ps(a.get(), b.get())); + // The cmake performs a test validating if the compiler supports SVML. + // As far as I'm aware, this is the only reliable way to check. + #if defined(CCM_CONFIG_RT_SIMD_HAS_SVML) + return {_mm_pow_ps(a.get(), b.get())}; #else // TODO: Replace this with a refined solution. For the time being this is temporary. - return simd(gen::pow_gen(a.convert(), b.convert())); + return {gen::pow_gen(a.convert(), b.convert())}; #endif } CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler - // It appears Windows and macOS have SVML out the box so we only care about linux. - #if !defined(CCM_TARGET_PLATFORM_LINUX) - return simd(_mm_pow_pd(a.get(), b.get())); + // The cmake performs a test validating if the compiler supports SVML. + // As far as I'm aware, this is the only reliable way to check. + #if defined(CCM_CONFIG_RT_SIMD_HAS_SVML) + return {_mm_pow_pd(a.get(), b.get())}; #else // TODO: Replace this with a refined solution. For the time being this is temporary. - return simd(gen::pow_gen(a.convert(), b.convert())); + return {gen::pow_gen(a.convert(), b.convert())}; #endif } } // namespace ccm::intrin From a6137cd756d550b695a732a41d0dd74d114ef0b9 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 18:24:14 -0400 Subject: [PATCH 031/102] Add --no-install-recommends to install command --- .github/workflows/ci-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 06f8c572..656fb4b1 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -39,7 +39,7 @@ jobs: ${{ runner.os }}-cmake-${{ matrix.compiler }}- - name: install dependencies - run: sudo apt install -yqq ninja-build + run: sudo apt install -yqq --no-install-recommends ninja-build - name: configure cmake run: cmake -S . --preset=${{matrix.compiler}} -B build -DCMAKE_CXX_STANDARD=${{matrix.cxx_version}} From 3436be5bf360f4eebf251fb5a3ac17b3af2b421a Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 19:46:10 -0400 Subject: [PATCH 032/102] Apply multiple adjustments and minor fixes based on linting work along with silencing false positives --- .../config/arch/check_simd_support.hpp | 18 ++++++ .../math/generic/func/power/powf_impl.hpp | 2 +- .../math/generic/func/power/sqrt_gen.hpp | 2 +- .../math/runtime/simd/func/impl/sse2/pow.hpp | 6 +- .../math/runtime/simd/func/impl/sse3/pow.hpp | 35 +++++------ .../math/runtime/simd/func/impl/sse4/pow.hpp | 31 +++++---- .../math/runtime/simd/instructions/avx.hpp | 26 ++++---- .../math/runtime/simd/instructions/avx2.hpp | 26 ++++---- .../math/runtime/simd/instructions/avx512.hpp | 2 + .../math/runtime/simd/instructions/scalar.hpp | 7 ++- .../math/runtime/simd/instructions/sse2.hpp | 22 +++---- .../math/runtime/simd/instructions/sse3.hpp | 4 -- .../math/runtime/simd/instructions/sse4.hpp | 7 +-- .../math/runtime/simd/instructions/ssse3.hpp | 63 +++++++++---------- .../support/floating_point_traits.hpp | 29 +++------ .../ccmath/internal/support/fp/fp_bits.hpp | 2 +- .../internal/support/helpers/digit_to_int.hpp | 2 +- .../ccmath/internal/support/helpers/exp10.hpp | 6 +- .../internal/support/helpers/exp_helpers.hpp | 2 +- .../support/helpers/fpclassify_helper.hpp | 2 +- .../support/helpers/internal_ldexp.hpp | 15 +++-- include/ccmath/internal/types/big_int.hpp | 33 +++++----- include/ccmath/math/expo/log.hpp | 2 +- lint.bat | 10 ++- lint.sh | 12 ++-- 25 files changed, 186 insertions(+), 180 deletions(-) diff --git a/include/ccmath/internal/config/arch/check_simd_support.hpp b/include/ccmath/internal/config/arch/check_simd_support.hpp index 5ac372b3..0613ddf6 100644 --- a/include/ccmath/internal/config/arch/check_simd_support.hpp +++ b/include/ccmath/internal/config/arch/check_simd_support.hpp @@ -157,6 +157,22 @@ #define CCMATH_HAS_SIMD_AVX512 1 #endif +// Intel Short Vector Math Library (SVML) + #if defined(__FMA__) || defined(CCM_CONFIG_RT_SIMD_HAS_FMA) + #ifndef CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 + #endif + #define CCMATH_HAS_SIMD_FMA 1 + #endif + +// Intel Short Vector Math Library (SVML) + #if defined(CCM_CONFIG_RT_SIMD_HAS_SVML) + #ifndef CCMATH_HAS_SIMD + #define CCMATH_HAS_SIMD 1 + #endif + #define CCMATH_HAS_SIMD_SVML 1 + #endif + // ARM Advanced SIMD (NEON) #if defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(CCM_CONFIG_RT_SIMD_HAS_NEON) #ifndef CCMATH_HAS_SIMD @@ -165,6 +181,8 @@ #define CCMATH_HAS_SIMD_NEON 1 #endif + + // ARM Scalable Vector Extension (SVE) /* TODO: At some point add proper SVE support. #if defined(__ARM_FEATURE_SVE) diff --git a/include/ccmath/internal/math/generic/func/power/powf_impl.hpp b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp index 98a84973..bb3166ad 100644 --- a/include/ccmath/internal/math/generic/func/power/powf_impl.hpp +++ b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp @@ -21,7 +21,7 @@ namespace ccm::gen::impl // TODO: Implement this. return 0; } - } + } // namespace internal::impl constexpr float powf_impl(float base, float exp) noexcept { diff --git a/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp b/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp index a9b61cd5..362c4ff0 100644 --- a/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp +++ b/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp @@ -11,8 +11,8 @@ #pragma once #include "ccmath/internal/config/type_support.hpp" -#include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/math/runtime/simd/simd_vectorize.hpp" +#include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/always_false.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/support/fenv/rounding_mode.hpp" diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp index 57f140a5..a47a8b05 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/pow.hpp @@ -15,7 +15,7 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSE2 - #if defined(CCM_CONFIG_RT_SIMD_HAS_SVML) + #if CCMATH_HAS_SIMD_SVML #include #else #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" @@ -27,7 +27,7 @@ namespace ccm::intrin { // The cmake performs a test validating if the compiler supports SVML. // As far as I'm aware, this is the only reliable way to check. - #if defined(CCM_CONFIG_RT_SIMD_HAS_SVML) + #if CCMATH_HAS_SIMD_SVML return {_mm_pow_ps(a.get(), b.get())}; #else // TODO: Replace this with a refined solution. For the time being this is temporary. @@ -39,7 +39,7 @@ namespace ccm::intrin { // The cmake performs a test validating if the compiler supports SVML. // As far as I'm aware, this is the only reliable way to check. - #if defined(CCM_CONFIG_RT_SIMD_HAS_SVML) + #if CCMATH_HAS_SIMD_SVML return {_mm_pow_pd(a.get(), b.get())}; #else // TODO: Replace this with a refined solution. For the time being this is temporary. diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp index daaacaaa..f094830e 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/pow.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) Ian Pike +* Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -14,40 +14,39 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSE3 - #include "ccmath/internal/config/platform/linux.hpp" - #if defined(CCM_TARGET_PLATFORM_LINUX) + #if CCMATH_HAS_SIMD_SVML + #include + #else #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" #endif namespace ccm::intrin { - CCM_ALWAYS_INLINE simd sqrt(simd const & a, simd const & b) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler - // It appears Windows and macOS have SVML out the box so we only care about linux. - #if !defined(CCM_TARGET_PLATFORM_LINUX) - return simd(_mm_pow_ps(a.get(), b.get())); + // The cmake performs a test validating if the compiler supports SVML. + // As far as I'm aware, this is the only reliable way to check. + #if CCMATH_HAS_SIMD_SVML + return {_mm_pow_ps(a.get(), b.get())}; #else // TODO: Replace this with a refined solution. For the time being this is temporary. - return simd(gen::pow_gen(a.convert(), b.convert())); + return {gen::pow_gen(a.convert(), b.convert())}; #endif } - CCM_ALWAYS_INLINE simd sqrt(simd const & a, simd const & b) + CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - // _mm_pow_pd is a part of SVML which is a part of intel's DPC++ compiler - // It appears Windows and macOS have SVML out the box so we only care about linux. - #if !defined(CCM_TARGET_PLATFORM_LINUX) - return simd(_mm_pow_pd(a.get(), b.get())); + // The cmake performs a test validating if the compiler supports SVML. + // As far as I'm aware, this is the only reliable way to check. + #if CCMATH_HAS_SIMD_SVML + return {_mm_pow_pd(a.get(), b.get())}; #else // TODO: Replace this with a refined solution. For the time being this is temporary. - return simd(gen::pow_gen(a.convert(), b.convert())); + return {gen::pow_gen(a.convert(), b.convert())}; #endif } } // namespace ccm::intrin - #endif // CCMATH_HAS_SIMD_SSE3 +#endif // CCMATH_HAS_SIMD_SSE3 #endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp index 321565bd..2af02622 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/pow.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) Ian Pike +* Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -14,9 +14,10 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSE4 - #include "ccmath/internal/config/platform/linux.hpp" - #if defined(CCM_TARGET_PLATFORM_LINUX) + #if CCMATH_HAS_SIMD_SVML + #include + #else #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" #endif @@ -24,30 +25,28 @@ namespace ccm::intrin { CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - // _mm_pow_ps is a part of SVML which is a part of intel's DPC++ compiler - // It appears Windows and macOS have SVML out the box so we only care about linux. - #if !defined(CCM_TARGET_PLATFORM_LINUX) - return simd(_mm_pow_ps(a.get(), b.get())); + // The cmake performs a test validating if the compiler supports SVML. + // As far as I'm aware, this is the only reliable way to check. + #if CCMATH_HAS_SIMD_SVML + return {_mm_pow_ps(a.get(), b.get())}; #else // TODO: Replace this with a refined solution. For the time being this is temporary. - return simd(gen::pow_gen(a.convert(), b.convert())); + return {gen::pow_gen(a.convert(), b.convert())}; #endif } CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - // _mm_pow_pd is a part of SVML which is a part of intel's DPC++ compiler - // It appears Windows and macOS have SVML out the box so we only care about linux. - #if !defined(CCM_TARGET_PLATFORM_LINUX) - return simd(_mm_pow_pd(a.get(), b.get())); + // The cmake performs a test validating if the compiler supports SVML. + // As far as I'm aware, this is the only reliable way to check. + #if defined(CCMATH_HAS_SIMD_SVML) + return {_mm_pow_pd(a.get(), b.get())}; #else // TODO: Replace this with a refined solution. For the time being this is temporary. - return simd(gen::pow_gen(a.convert(), b.convert())); + return {gen::pow_gen(a.convert(), b.convert())}; #endif } } // namespace ccm::intrin - #endif // CCMATH_HAS_SIMD_SSE4 +#endif // CCMATH_HAS_SIMD_sse4 #endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/instructions/avx.hpp b/include/ccmath/internal/math/runtime/simd/instructions/avx.hpp index f5d69200..985dfe14 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/avx.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/avx.hpp @@ -36,9 +36,9 @@ namespace ccm::intrin using simd_type = simd; using abi_type = abi::avx; CCM_ALWAYS_INLINE simd_mask() = default; - CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(_mm256_castsi256_ps(_mm256_set1_epi32(-static_cast(value)))) { } + CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(_mm256_castsi256_ps(_mm256_set1_epi32(-static_cast(value)))) { } // NOLINT static constexpr int size() { return 8; } - CCM_ALWAYS_INLINE constexpr simd_mask(__m256 const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE constexpr simd_mask(__m256 const & value_in) : m_value(value_in) {} // NOLINT [[nodiscard]] constexpr __m256 get() const { return m_value; } CCM_ALWAYS_INLINE simd_mask operator||(simd_mask const & other) const { return {_mm256_or_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd_mask operator&&(simd_mask const & other) const { return {_mm256_and_ps(m_value, other.m_value)}; } @@ -68,11 +68,11 @@ namespace ccm::intrin using storage_type = simd_storage; CCM_ALWAYS_INLINE simd() = default; static constexpr int size() { return 8; } - CCM_ALWAYS_INLINE simd(float value) : m_value(_mm256_set1_ps(value)) {} + CCM_ALWAYS_INLINE simd(float value) : m_value(_mm256_set1_ps(value)) {} // NOLINT CCM_ALWAYS_INLINE simd(float a, float b, float c, float d, float e, float f, float g, float h) : m_value(_mm256_setr_ps(a, b, c, d, e, f, g, h)) { } - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -83,10 +83,10 @@ namespace ccm::intrin { } CCM_ALWAYS_INLINE simd(float const * ptr, int stride) - : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride], ptr[4 * stride], ptr[5 * stride], ptr[6 * stride], ptr[7 * stride]) + : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride], ptr[4 * stride], ptr[5 * stride], ptr[6 * stride], ptr[7 * stride]) // NOLINT { } - CCM_ALWAYS_INLINE constexpr simd(__m256 const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE constexpr simd(__m256 const & value_in) : m_value(value_in) {} // NOLINT CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return {_mm256_mul_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return {_mm256_div_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return {_mm256_add_ps(m_value, other.m_value)}; } @@ -122,9 +122,9 @@ namespace ccm::intrin using simd_type = simd; using abi_type = abi::avx; CCM_ALWAYS_INLINE simd_mask() = default; - CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(_mm256_castsi256_pd(_mm256_set1_epi64x(-static_cast(value)))) { } + CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(_mm256_castsi256_pd(_mm256_set1_epi64x(-static_cast(value)))) { } // NOLINT CCM_ALWAYS_INLINE static constexpr int size() { return 4; } - CCM_ALWAYS_INLINE constexpr simd_mask(__m256d const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE constexpr simd_mask(__m256d const & value_in) : m_value(value_in) {} // NOLINT [[nodiscard]] constexpr __m256d get() const { return m_value; } CCM_ALWAYS_INLINE simd_mask operator||(simd_mask const & other) const { return {_mm256_or_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd_mask operator&&(simd_mask const & other) const { return {_mm256_and_pd(m_value, other.m_value)}; } @@ -145,7 +145,7 @@ namespace ccm::intrin } template <> - struct simd + struct simd // NOLINT { public: @@ -159,9 +159,9 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd & operator=(simd const &) = default; CCM_ALWAYS_INLINE simd & operator=(simd &&) = default; CCM_ALWAYS_INLINE static constexpr int size() { return 4; } - CCM_ALWAYS_INLINE simd(double value) : m_value(_mm256_set1_pd(value)) {} + CCM_ALWAYS_INLINE simd(double value) : m_value(_mm256_set1_pd(value)) {} // NOLINT CCM_ALWAYS_INLINE simd(double a, double b, double c, double d) : m_value(_mm256_setr_pd(a, b, c, d)) {} - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -171,8 +171,8 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd(double const * ptr, Flags flags) : m_value(_mm256_loadu_pd(ptr)) { } - CCM_ALWAYS_INLINE simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride]) {} - CCM_ALWAYS_INLINE constexpr simd(__m256d const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride]) {} // NOLINT + CCM_ALWAYS_INLINE constexpr simd(__m256d const & value_in) : m_value(value_in) {} // NOLINT CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return {_mm256_mul_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return {_mm256_div_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return {_mm256_add_pd(m_value, other.m_value)}; } diff --git a/include/ccmath/internal/math/runtime/simd/instructions/avx2.hpp b/include/ccmath/internal/math/runtime/simd/instructions/avx2.hpp index cf43637f..89b773bc 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/avx2.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/avx2.hpp @@ -36,9 +36,9 @@ namespace ccm::intrin using simd_type = simd; using abi_type = abi::avx2; CCM_ALWAYS_INLINE simd_mask() = default; - CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(_mm256_castsi256_ps(_mm256_set1_epi32(-static_cast(value)))) { } + CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(_mm256_castsi256_ps(_mm256_set1_epi32(-static_cast(value)))) { } // NOLINT static constexpr int size() { return 8; } - CCM_ALWAYS_INLINE constexpr simd_mask(__m256 const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE constexpr simd_mask(__m256 const & value_in) : m_value(value_in) {} // NOLINT [[nodiscard]] constexpr __m256 get() const { return m_value; } CCM_ALWAYS_INLINE simd_mask operator||(simd_mask const & other) const { return {_mm256_or_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd_mask operator&&(simd_mask const & other) const { return {_mm256_and_ps(m_value, other.m_value)}; } @@ -68,11 +68,11 @@ namespace ccm::intrin using storage_type = simd_storage; CCM_ALWAYS_INLINE simd() = default; static constexpr int size() { return 8; } - CCM_ALWAYS_INLINE simd(float value) : m_value(_mm256_set1_ps(value)) {} + CCM_ALWAYS_INLINE simd(float value) : m_value(_mm256_set1_ps(value)) {} // NOLINT CCM_ALWAYS_INLINE simd(float a, float b, float c, float d, float e, float f, float g, float h) : m_value(_mm256_setr_ps(a, b, c, d, e, f, g, h)) { } - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -83,10 +83,10 @@ namespace ccm::intrin { } CCM_ALWAYS_INLINE simd(float const * ptr, int stride) - : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride], ptr[4 * stride], ptr[5 * stride], ptr[6 * stride], ptr[7 * stride]) + : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride], ptr[4 * stride], ptr[5 * stride], ptr[6 * stride], ptr[7 * stride]) // NOLINT { } - CCM_ALWAYS_INLINE constexpr simd(__m256 const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE constexpr simd(__m256 const & value_in) : m_value(value_in) {} // NOLINT CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return {_mm256_mul_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return {_mm256_div_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return {_mm256_add_ps(m_value, other.m_value)}; } @@ -122,9 +122,9 @@ namespace ccm::intrin using simd_type = simd; using abi_type = abi::avx2; CCM_ALWAYS_INLINE simd_mask() = default; - CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(_mm256_castsi256_pd(_mm256_set1_epi64x(-static_cast(value)))) { } + CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(_mm256_castsi256_pd(_mm256_set1_epi64x(-static_cast(value)))) { } // NOLINT CCM_ALWAYS_INLINE static constexpr int size() { return 4; } - CCM_ALWAYS_INLINE constexpr simd_mask(__m256d const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE constexpr simd_mask(__m256d const & value_in) : m_value(value_in) {} // NOLINT [[nodiscard]] constexpr __m256d get() const { return m_value; } CCM_ALWAYS_INLINE simd_mask operator||(simd_mask const & other) const { return {_mm256_or_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd_mask operator&&(simd_mask const & other) const { return {_mm256_and_pd(m_value, other.m_value)}; } @@ -145,7 +145,7 @@ namespace ccm::intrin } template <> - struct simd + struct simd // NOLINT { public: @@ -159,9 +159,9 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd & operator=(simd const &) = default; CCM_ALWAYS_INLINE simd & operator=(simd &&) = default; CCM_ALWAYS_INLINE static constexpr int size() { return 4; } - CCM_ALWAYS_INLINE simd(double value) : m_value(_mm256_set1_pd(value)) {} + CCM_ALWAYS_INLINE simd(double value) : m_value(_mm256_set1_pd(value)) {} // NOLINT CCM_ALWAYS_INLINE simd(double a, double b, double c, double d) : m_value(_mm256_setr_pd(a, b, c, d)) {} - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -171,8 +171,8 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd(double const * ptr, Flags flags) : m_value(_mm256_loadu_pd(ptr)) { } - CCM_ALWAYS_INLINE simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride]) {} - CCM_ALWAYS_INLINE constexpr simd(__m256d const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride]) {} // NOLINT + CCM_ALWAYS_INLINE constexpr simd(__m256d const & value_in) : m_value(value_in) {} // NOLINT CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return {_mm256_mul_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return {_mm256_div_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return {_mm256_add_pd(m_value, other.m_value)}; } diff --git a/include/ccmath/internal/math/runtime/simd/instructions/avx512.hpp b/include/ccmath/internal/math/runtime/simd/instructions/avx512.hpp index c7809019..3e1ec5c4 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/avx512.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/avx512.hpp @@ -18,6 +18,7 @@ #include +// NOLINTBEGIN namespace ccm::intrin { namespace abi @@ -214,6 +215,7 @@ namespace ccm::intrin } } // namespace ccm::intrin +// NOLINTEND #endif // CCMATH_HAS_SIMD_AVX512F #endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/instructions/scalar.hpp b/include/ccmath/internal/math/runtime/simd/instructions/scalar.hpp index 5ae2f91c..ef00ca5a 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/scalar.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/scalar.hpp @@ -83,6 +83,7 @@ namespace ccm::intrin } template + // NOLINTNEXTLINE struct simd { using value_type = T; @@ -95,8 +96,8 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd & operator=(simd const &) = default; CCM_ALWAYS_INLINE simd & operator=(simd &&) = default; CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE static constexpr int size() { return 1; } - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd(T value) : m_value(value) {} - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd(T value) : m_value(value) {} // NOLINT(google-explicit-constructor) + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } // NOLINT(google-explicit-constructor) CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -107,7 +108,7 @@ namespace ccm::intrin { copy_from(ptr, flags); } - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd(T const * ptr, int /*stride*/) : m_value(ptr[0]) {} + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd(T const * ptr, int /*stride*/) : m_value(ptr[0]) {} // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd operator*(simd const & other) const { return simd(m_value * other.m_value); } CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd operator/(simd const & other) const { return simd(m_value / other.m_value); } CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd operator+(simd const & other) const { return simd(m_value + other.m_value); } diff --git a/include/ccmath/internal/math/runtime/simd/instructions/sse2.hpp b/include/ccmath/internal/math/runtime/simd/instructions/sse2.hpp index b347758f..f0ec9547 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/sse2.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/sse2.hpp @@ -18,10 +18,6 @@ #include // SSE #endif - #if defined(__FMA__) || defined(CCMATH_HAS_SIMD_AVX2) - #include - #endif - #ifdef CCMATH_HAS_SIMD_SSE2 namespace ccm::intrin @@ -73,9 +69,9 @@ namespace ccm::intrin using storage_type = simd_storage; CCM_ALWAYS_INLINE simd() = default; static constexpr int size() { return 4; } - CCM_ALWAYS_INLINE simd(float value) : m_value(_mm_set1_ps(value)) {} + CCM_ALWAYS_INLINE simd(float value) : m_value(_mm_set1_ps(value)) {} // NOLINT(google-explicit-constructor) CCM_ALWAYS_INLINE simd(float a, float b, float c, float d) : m_value(_mm_setr_ps(a, b, c, d)) {} - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -85,8 +81,8 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd(float const * ptr, Flags /*flags*/) : m_value(_mm_loadu_ps(ptr)) { } - CCM_ALWAYS_INLINE simd(float const * ptr, int stride) : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride]) {} - CCM_ALWAYS_INLINE constexpr simd(__m128 const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE simd(float const * ptr, int stride) : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride]) {} // NOLINT + CCM_ALWAYS_INLINE constexpr simd(__m128 const & value_in) : m_value(value_in) {} // NOLINT(google-explicit-constructor) CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return {_mm_mul_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return {_mm_div_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return {_mm_add_ps(m_value, other.m_value)}; } @@ -146,7 +142,7 @@ namespace ccm::intrin } template <> - struct simd + struct simd // NOLINT { using value_type = double; using abi_type = abi::sse2; @@ -158,9 +154,9 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd & operator=(simd const &) = default; CCM_ALWAYS_INLINE simd & operator=(simd &&) = default; static constexpr int size() { return 2; } - CCM_ALWAYS_INLINE simd(double value) : m_value(_mm_set1_pd(value)) {} + CCM_ALWAYS_INLINE simd(double value) : m_value(_mm_set1_pd(value)) {} // NOLINT(google-explicit-constructor) CCM_ALWAYS_INLINE simd(double a, double b) : m_value(_mm_setr_pd(a, b)) {} - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } // NOLINT(google-explicit-constructor, cppcoreguidelines-pro-type-member-init) CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -170,8 +166,8 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd(double const * ptr, Flags /*flags*/) : m_value(_mm_loadu_pd(ptr)) { } - CCM_ALWAYS_INLINE simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride]) {} - CCM_ALWAYS_INLINE constexpr simd(__m128d const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride]) {} // NOLINT + CCM_ALWAYS_INLINE constexpr simd(__m128d const & value_in) : m_value(value_in) {} // NOLINT(google-explicit-constructor) CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return {_mm_mul_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return {_mm_div_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return {_mm_add_pd(m_value, other.m_value)}; } diff --git a/include/ccmath/internal/math/runtime/simd/instructions/sse3.hpp b/include/ccmath/internal/math/runtime/simd/instructions/sse3.hpp index e98b3b04..dc1a7e7b 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/sse3.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/sse3.hpp @@ -18,10 +18,6 @@ #include // SSE3 #endif - #if defined(__FMA__) || defined(CCMATH_HAS_SIMD_AVX2) - #include - #endif - #ifdef CCMATH_HAS_SIMD_SSE3 namespace ccm::intrin diff --git a/include/ccmath/internal/math/runtime/simd/instructions/sse4.hpp b/include/ccmath/internal/math/runtime/simd/instructions/sse4.hpp index 3ab03014..bceb2ea9 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/sse4.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/sse4.hpp @@ -15,11 +15,8 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSE4 - #include // SSE4 - #endif - - #if defined(__FMA__) || defined(CCMATH_HAS_SIMD_AVX2) - #include + #include // SSE4.1 + #include // SSE4.2 #endif #ifdef CCMATH_HAS_SIMD_SSE4 diff --git a/include/ccmath/internal/math/runtime/simd/instructions/ssse3.hpp b/include/ccmath/internal/math/runtime/simd/instructions/ssse3.hpp index 876b72dd..ecb764e6 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/ssse3.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/ssse3.hpp @@ -15,13 +15,10 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSSE3 + // NOLINTNEXTLINE #include // SSSE3 #endif - #if defined(__FMA__) || defined(CCMATH_HAS_SIMD_AVX2) - #include - #endif - #ifdef CCMATH_HAS_SIMD_SSSE3 namespace ccm::intrin @@ -38,9 +35,9 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::ssse3; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::ssse3; CCM_ALWAYS_INLINE simd_mask() = default; CCM_ALWAYS_INLINE explicit simd_mask(bool value) : m_value(_mm_castsi128_ps(_mm_set1_epi32(-static_cast(value)))) {} static constexpr int size() { return 4; } @@ -67,15 +64,15 @@ namespace ccm::intrin template <> struct simd { - using value_type = float; - using abi_type = abi::ssse3; - using mask_type = simd_mask; - using storage_type = simd_storage; + using value_type = float; + using abi_type = abi::ssse3; + using mask_type = simd_mask; + using storage_type = simd_storage; CCM_ALWAYS_INLINE simd() = default; static constexpr int size() { return 4; } - CCM_ALWAYS_INLINE simd(float value) : m_value(_mm_set1_ps(value)) {} + CCM_ALWAYS_INLINE simd(float value) : m_value(_mm_set1_ps(value)) {} // NOLINT CCM_ALWAYS_INLINE simd(float a, float b, float c, float d) : m_value(_mm_setr_ps(a, b, c, d)) {} - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -85,8 +82,8 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd(float const * ptr, Flags /*flags*/) : m_value(_mm_loadu_ps(ptr)) { } - CCM_ALWAYS_INLINE simd(float const * ptr, int stride) : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride]) {} - CCM_ALWAYS_INLINE constexpr simd(__m128 const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE simd(float const * ptr, int stride) : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride]) {} // NOLINT + CCM_ALWAYS_INLINE constexpr simd(__m128 const & value_in) : m_value(value_in) {} // NOLINT CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return {_mm_mul_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return {_mm_div_ps(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return {_mm_add_ps(m_value, other.m_value)}; } @@ -110,7 +107,7 @@ namespace ccm::intrin }; CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + simd const & c) { // NOLINTNEXTLINE(modernize-return-braced-init-list) return simd(_mm_add_ps(_mm_and_ps(a.get(), b.get()), _mm_andnot_ps(a.get(), c.get()))); @@ -119,9 +116,9 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::ssse3; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::ssse3; CCM_ALWAYS_INLINE simd_mask() = default; CCM_ALWAYS_INLINE explicit simd_mask(bool value) : m_value(_mm_castsi128_pd(_mm_set1_epi64x(-static_cast(value)))) {} static constexpr int size() { return 4; } @@ -146,21 +143,21 @@ namespace ccm::intrin } template <> - struct simd + struct simd // NOLINT { - using value_type = double; - using abi_type = abi::ssse3; - using mask_type = simd_mask; - using storage_type = simd_storage; - CCM_ALWAYS_INLINE simd() = default; - CCM_ALWAYS_INLINE simd(simd const &) = default; - CCM_ALWAYS_INLINE simd(simd &&) = default; + using value_type = double; + using abi_type = abi::ssse3; + using mask_type = simd_mask; + using storage_type = simd_storage; + CCM_ALWAYS_INLINE simd() = default; + CCM_ALWAYS_INLINE simd(simd const &) = default; + CCM_ALWAYS_INLINE simd(simd &&) = default; CCM_ALWAYS_INLINE simd & operator=(simd const &) = default; - CCM_ALWAYS_INLINE simd & operator=(simd &&) = default; + CCM_ALWAYS_INLINE simd & operator=(simd &&) = default; static constexpr int size() { return 2; } - CCM_ALWAYS_INLINE simd(double value) : m_value(_mm_set1_pd(value)) {} + CCM_ALWAYS_INLINE simd(double value) : m_value(_mm_set1_pd(value)) {} // NOLINT CCM_ALWAYS_INLINE simd(double a, double b) : m_value(_mm_setr_pd(a, b)) {} - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -170,8 +167,8 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd(double const * ptr, Flags /*flags*/) : m_value(_mm_loadu_pd(ptr)) { } - CCM_ALWAYS_INLINE simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride]) {} - CCM_ALWAYS_INLINE constexpr simd(__m128d const & value_in) : m_value(value_in) {} + CCM_ALWAYS_INLINE simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride]) {} // NOLINT + CCM_ALWAYS_INLINE constexpr simd(__m128d const & value_in) : m_value(value_in) {} // NOLINT CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return {_mm_mul_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return {_mm_div_pd(m_value, other.m_value)}; } CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return {_mm_add_pd(m_value, other.m_value)}; } @@ -196,7 +193,7 @@ namespace ccm::intrin }; CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + simd const & c) { // NOLINTNEXTLINE(modernize-return-braced-init-list) return simd(_mm_add_pd(_mm_and_pd(a.get(), b.get()), _mm_andnot_pd(a.get(), c.get()))); diff --git a/include/ccmath/internal/support/floating_point_traits.hpp b/include/ccmath/internal/support/floating_point_traits.hpp index aad4de20..1637aeb5 100644 --- a/include/ccmath/internal/support/floating_point_traits.hpp +++ b/include/ccmath/internal/support/floating_point_traits.hpp @@ -100,9 +100,9 @@ namespace ccm::support using int_type = ccm::types::int128_t; - static constexpr int_type mantissa_bits = 112; // LDBL_MANT_DIG - static constexpr int_type exponent_bits = 15; // sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG - static constexpr int_type maximum_binary_exponent = 16383; // LDBL_MAX_EXP - 1 + static constexpr int_type mantissa_bits = 112; // LDBL_MANT_DIG + static constexpr int_type exponent_bits = 15; // sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG + static constexpr int_type maximum_binary_exponent = 16383; // LDBL_MAX_EXP - 1 static constexpr int_type minimum_binary_exponent = -16382; // LDBL_MIN_EXP - 1 static constexpr int_type exponent_bias = 16383; static constexpr int_type sign_shift = 79; // exponent_bits + mantissa_bits - 1 @@ -120,20 +120,18 @@ namespace ccm::support static constexpr long double normalize_factor = 340282366920938463463374607431768211456.0L; // 2^128 static constexpr long double max_safe_integer = 0x1p+112; // 5192296858534827628530496329220096.0L (2^112) - - }; #elif defined(CCM_TYPES_LONG_DOUBLE_IS_FLOAT80) template <> -struct floating_point_traits + struct floating_point_traits { using upgraded_floating_type = ccm::types::DyadicFloat<256>; using int_type = ccm::types::int128_t; - static constexpr int_type mantissa_bits = 64; // LDBL_MANT_DIG - static constexpr int_type exponent_bits = 15; // sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG - static constexpr int_type maximum_binary_exponent = 16383; // LDBL_MAX_EXP - 1 + static constexpr int_type mantissa_bits = 64; // LDBL_MANT_DIG + static constexpr int_type exponent_bits = 15; // sizeof(long double) * CHAR_BIT - LDBL_MANT_DIG + static constexpr int_type maximum_binary_exponent = 16383; // LDBL_MAX_EXP - 1 static constexpr int_type minimum_binary_exponent = -16382; // LDBL_MIN_EXP - 1 static constexpr int_type exponent_bias = 16383; static constexpr int_type sign_shift = 79; // exponent_bits + mantissa_bits - 1 @@ -154,21 +152,13 @@ struct floating_point_traits static constexpr long double max_safe_integer = 0x1p+64L; // 18446744073709551616.0L (2^64) }; - #else // long double is the same as double +#else // long double is the same as double template <> struct floating_point_traits { - #if defined(CCM_TYPES_LONG_DOUBLE_IS_FLOAT128) - using upgraded_floating_type = long double - #elif defined(CCM_TYPES_HAS_FLOAT128) - using upgraded_floating_type = ccm::types::float128; - #elif defined(CCM_TYPES_LONG_DOUBLE_IS_FLOAT80) using upgraded_floating_type = ccm::types::DyadicFloat<128>; - #else - using upgraded_floating_type = ccm::types::DyadicFloat<128>; - #endif - using int_type = std::int64_t; + using int_type = std::int64_t; static constexpr int_type mantissa_bits = 53; // DBL_MANT_DIG static constexpr int_type exponent_bits = 11; // sizeof(double) * CHAR_BIT - DBL_MANT_DIG @@ -207,7 +197,6 @@ struct floating_point_traits template inline constexpr typename floating_point_traits::uint_type sign_mask_v = floating_point_traits::shifted_sign_mask; - // TODO: Possible remove these func from floating_point_traits as they are more so there own things and not really traits. // All func below that use bit_cast have to use the __builtin_bit_cast as bit_cast itself includes floating_point_traits.hpp diff --git a/include/ccmath/internal/support/fp/fp_bits.hpp b/include/ccmath/internal/support/fp/fp_bits.hpp index 5b17bab6..f1423f31 100644 --- a/include/ccmath/internal/support/fp/fp_bits.hpp +++ b/include/ccmath/internal/support/fp/fp_bits.hpp @@ -188,7 +188,7 @@ namespace ccm::support::fp * @tparam T The type of the integer. */ template - struct TypedInt + struct TypedInt // NOLINT(cppcoreguidelines-special-member-functions) { using value_type = T; constexpr explicit TypedInt(T value) : value(value) {} diff --git a/include/ccmath/internal/support/helpers/digit_to_int.hpp b/include/ccmath/internal/support/helpers/digit_to_int.hpp index eb6b09c8..97ebb434 100644 --- a/include/ccmath/internal/support/helpers/digit_to_int.hpp +++ b/include/ccmath/internal/support/helpers/digit_to_int.hpp @@ -28,4 +28,4 @@ namespace ccm::support::helpers } return 0; } -} // namespace ccm::helpers +} // namespace ccm::support::helpers diff --git a/include/ccmath/internal/support/helpers/exp10.hpp b/include/ccmath/internal/support/helpers/exp10.hpp index f0b00790..5e3ca3b4 100644 --- a/include/ccmath/internal/support/helpers/exp10.hpp +++ b/include/ccmath/internal/support/helpers/exp10.hpp @@ -13,13 +13,13 @@ #include "ccmath/internal/support/multiply_add.hpp" #include "ccmath/internal/types/double_double.hpp" #include "ccmath/internal/types/triple_double.hpp" -#include "ccmath/math/exponential/log2.hpp" +#include "ccmath/math/expo/log2.hpp" #include #include "ccmath/internal/support/poly_eval.hpp" -namespace ccm::internal +namespace ccm::support::helpers { namespace impl { @@ -109,4 +109,4 @@ namespace ccm::internal { return impl::exp10_float_impl(exp); } -} // namespace ccm::internal +} // namespace ccm::support::helpers diff --git a/include/ccmath/internal/support/helpers/exp_helpers.hpp b/include/ccmath/internal/support/helpers/exp_helpers.hpp index 64567e39..68992d52 100644 --- a/include/ccmath/internal/support/helpers/exp_helpers.hpp +++ b/include/ccmath/internal/support/helpers/exp_helpers.hpp @@ -42,4 +42,4 @@ namespace ccm::support::helpers return math_narrow_eval_tmp; #endif } -} // namespace ccm::helpers +} // namespace ccm::support::helpers diff --git a/include/ccmath/internal/support/helpers/fpclassify_helper.hpp b/include/ccmath/internal/support/helpers/fpclassify_helper.hpp index 032eb159..818b0425 100644 --- a/include/ccmath/internal/support/helpers/fpclassify_helper.hpp +++ b/include/ccmath/internal/support/helpers/fpclassify_helper.hpp @@ -61,4 +61,4 @@ namespace ccm::support::helpers #error "FP_* macros are extremely implementation specific and are not defined for this compiler. Please add support for this compiler." #endif }; -} // namespace ccm::helpers +} // namespace ccm::support::helpers diff --git a/include/ccmath/internal/support/helpers/internal_ldexp.hpp b/include/ccmath/internal/support/helpers/internal_ldexp.hpp index 3475e88c..b4107cb8 100644 --- a/include/ccmath/internal/support/helpers/internal_ldexp.hpp +++ b/include/ccmath/internal/support/helpers/internal_ldexp.hpp @@ -36,14 +36,17 @@ namespace ccm::support::helpers if ((sign == types::Sign::POS && rounding_mode == FE_DOWNWARD) || (sign == types::Sign::NEG && rounding_mode == FE_UPWARD) || (rounding_mode == FE_TOWARDZERO)) { - return support::fp::FPBits::max_normal(sign).get_val(); + return fp::FPBits::max_normal(sign).get_val(); } - // These func do nothing at compile time, but at runtime will set errno and raise exceptions if required. - support::fenv::set_errno_if_required(ERANGE); - support::fenv::raise_except_if_required(FE_OVERFLOW); + if constexpr (fenv::is_errno_enabled()) + { + // These func do nothing at compile time, but at runtime will set errno and raise exceptions if required. + fenv::set_errno_if_required(ERANGE); + fenv::raise_except_if_required(FE_OVERFLOW); + } - return support::fp::FPBits::inf(sign).get_val(); + return fp::FPBits::inf(sign).get_val(); } if (CCM_UNLIKELY(exp < -EXP_LIMIT)) @@ -68,4 +71,4 @@ namespace ccm::support::helpers normal.exponent += exp; return static_cast(normal); } -} // namespace ccm::helpers +} // namespace ccm::support::helpers diff --git a/include/ccmath/internal/types/big_int.hpp b/include/ccmath/internal/types/big_int.hpp index 75ff1ef6..27671078 100644 --- a/include/ccmath/internal/types/big_int.hpp +++ b/include/ccmath/internal/types/big_int.hpp @@ -13,19 +13,18 @@ #pragma once +// ReSharper disable once CppUnusedIncludeDirective - compiler.hpp is used in the code below. #include "ccmath/internal/config/compiler.hpp" #include "ccmath/internal/config/type_support.hpp" -#include "ccmath/internal/predef/assume.hpp" +#ifdef CCMATH_COMPILER_CLANG + #include "ccmath/internal/predef/assume.hpp" +#endif #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/support/fenv/fenv_support.hpp" #include "ccmath/internal/support/math_support.hpp" #include "ccmath/internal/support/type_traits.hpp" -//#include "ccmath/internal/math/runtime/simd/simd_vectorize.hpp" -//#include "ccmath/internal/support/is_constant_evaluated.hpp" - - #include #include #include @@ -567,7 +566,7 @@ namespace ccm::types } // namespace multiword template - struct BigInt + struct BigInt // NOLINT(cppcoreguidelines-special-member-functions) { private: static_assert(ccm::support::traits::ccm_is_integral_v && ccm::support::traits::ccm_is_unsigned_v, @@ -610,7 +609,7 @@ namespace ccm::types * @param other The source BigInt to construct from. */ template - constexpr BigInt(const BigInt & other) + constexpr BigInt(const BigInt & other) // NOLINT(google-explicit-constructor) { if (OtherBits >= Bits) { @@ -632,8 +631,8 @@ namespace ccm::types * @param nums The input array of WordType values. */ template - constexpr BigInt( - const WordType (&nums)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays) - We are intentionally using C-style arrays here. + // NOLINTNEXTLINE(google-explicit-constructor) - Cannot be marked explicit. + constexpr BigInt(const WordType (&nums)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays) - We are intentionally using C-style arrays here. { static_assert(N == WORD_COUNT); for (std::size_t i = 0; i < WORD_COUNT; ++i) { val[i] = nums[i]; } @@ -815,7 +814,7 @@ namespace ccm::types */ constexpr BigInt operator+(BigInt && other) const { - std::move(other); // We ignore the moved value here. + std::move(other); // We ignore the moved value here. other.add_overflow(*this); // We ignore the returned carry value here. return other; } @@ -1183,11 +1182,11 @@ namespace ccm::types return *this; } - constexpr BigInt operator++(int) + constexpr BigInt operator++(int) // NOLINT(cert-dcl21-cpp) { - BigInt oldval(*this); + BigInt old_val(*this); increment(); - return oldval; + return old_val; } constexpr BigInt & operator--() @@ -1196,11 +1195,11 @@ namespace ccm::types return *this; } - constexpr BigInt operator--(int) + constexpr BigInt operator--(int) // NOLINT(cert-dcl21-cpp) { - BigInt oldval(*this); + BigInt old_val(*this); decrement(); - return oldval; + return old_val; } constexpr const WordType & operator[](std::size_t i) const { return val[i]; } @@ -1358,6 +1357,7 @@ namespace ccm::types namespace std { template <> + // ReSharper disable once CppMismatchedClassTags - Compilers are inconsistent with struct or class. Functionally the selection does not matter. struct numeric_limits> { public: @@ -1368,6 +1368,7 @@ namespace std }; template <> + // ReSharper disable once CppMismatchedClassTags - Compilers are inconsistent with struct or class. Functionally the selection does not matter. struct numeric_limits> { public: diff --git a/include/ccmath/math/expo/log.hpp b/include/ccmath/math/expo/log.hpp index f84dc078..261ee56e 100644 --- a/include/ccmath/math/expo/log.hpp +++ b/include/ccmath/math/expo/log.hpp @@ -11,8 +11,8 @@ #pragma once #include "ccmath/math/expo/impl/log_double_impl.hpp" -#include "ccmath/math/expo/impl/log_float_impl.hpp" #include "ccmath/internal/math/generic/func/expo/log_gen.hpp" +#include "ccmath/math/expo/impl/log_float_impl.hpp" namespace ccm { diff --git a/lint.bat b/lint.bat index 30793f8d..adc09c2f 100644 --- a/lint.bat +++ b/lint.bat @@ -12,10 +12,14 @@ REM set status=0 +echo Beginning linting... for /r "include\ccmath" %%f in (*.hpp) do ( - echo Checking %%f - clang-tidy %%f -p=out/clang-tidy - if errorlevel 1 set status=1 + clang-tidy %%f -p=out/clang-tidy --quiet 2>nul + if errorlevel 1 ( + echo Error in %%f + set status=1 + ) ) +echo Linting complete. exit /b %status% diff --git a/lint.sh b/lint.sh index 063d251b..6990602e 100644 --- a/lint.sh +++ b/lint.sh @@ -10,14 +10,18 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # +echo "Beginning linting..." + status=0 -while read f +while read -r f do - echo checking $f - clang-tidy $f -p=out/clang-tidy + clang-tidy "$f" -p=out/clang-tidy --quiet 2>/dev/null ret=$? if [ $ret -ne 0 ]; then + echo "Error in $f" status=1 fi -done <<< $(find include/ccmath -name "*.hpp") +done <<< "$(find include/ccmath -name "*.hpp")" + +echo "Done linting." exit $status From 7f8036927a47a3f2f61260bdc55c247d39642bcb Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 30 Oct 2024 19:46:23 -0400 Subject: [PATCH 033/102] Enable color in clang tidy --- .clang-tidy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 428f6d18..83214b57 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -65,4 +65,6 @@ openmp-use-default-none, CheckOptions: cppcoreguidelines-avoid-do-while.IgnoreMacros: 'true' - readability-function-cognitive-complexity.Threshold: 35 \ No newline at end of file + readability-function-cognitive-complexity.Threshold: 35 + +UseColor: true From 4488e307aef2cb42d20e5d2e95a52f25aeb8d64c Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 11 Dec 2024 13:33:31 -0500 Subject: [PATCH 034/102] typo --- include/ccmath/internal/math/generic/func/basic/fma_gen.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp b/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp index edbcafdd..b4eda434 100644 --- a/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp +++ b/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp @@ -41,7 +41,7 @@ namespace ccm #else if (CCM_UNLIKELY(x == 0 || y == 0 || z == 0)) { return x * y + z; } - // If x is zero and y is infinity, or if y is zero and x is infinity and... + // If x is zero, and y is infinity, or if y is zero and x is infinity and... if ((x == static_cast(0) && ccm::isinf(y)) || (y == T{0} && ccm::isinf(x))) { // ...z is NaN, return +NaN... From a70b3c690759eeb00b25d932ed7fe1f157395319 Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 11 Dec 2024 13:33:56 -0500 Subject: [PATCH 035/102] clang-tidy cleanup --- include/ccmath/ext/lerp_smooth.hpp | 3 ++- include/ccmath/ext/mix.hpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/ccmath/ext/lerp_smooth.hpp b/include/ccmath/ext/lerp_smooth.hpp index 941f403a..bec558a7 100644 --- a/include/ccmath/ext/lerp_smooth.hpp +++ b/include/ccmath/ext/lerp_smooth.hpp @@ -28,6 +28,7 @@ namespace ccm::ext template constexpr T lerp_smooth(T a, T b, T t, T h) { - return b + (a - b) * ccm::exp2(-t / h); + // ReSharper disable once CppRedundantParentheses + return b + ((a - b) * ccm::exp2(-t / h)); } } // namespace ccm::ext diff --git a/include/ccmath/ext/mix.hpp b/include/ccmath/ext/mix.hpp index dc78a607..f809d201 100644 --- a/include/ccmath/ext/mix.hpp +++ b/include/ccmath/ext/mix.hpp @@ -25,7 +25,8 @@ namespace ccm::ext template constexpr T mix(T x, T y, T a) noexcept { - return x * (1 - a) + y * a; + // ReSharper disable once CppRedundantParentheses + return (x * (1 - a)) + (y * a); } /** From 2e352a6ff9fecc84c26f1ed3cd67def30fa8d92f Mon Sep 17 00:00:00 2001 From: Ian Date: Wed, 11 Dec 2024 13:35:59 -0500 Subject: [PATCH 036/102] Add major feature validation to cmake scripts --- CMakeLists.txt | 206 ++++++++++++------ .../CheckAllSupportedBuiltinFeatures.cmake | 70 ++++++ .../features/CheckAllSupportedFeatures.cmake | 0 .../CheckAllSupportedSimdFeatures.cmake | 5 +- .../features/GetAllSupportedFeatures.cmake | 5 + .../math/basic/CheckBuiltinNanSupport.cmake | 32 +++ .../compare/CheckBuiltinIsInfSupport.cmake | 13 ++ .../compare/CheckBuiltinIsNanSupport.cmake | 13 ++ .../compare/CheckBuiltinSignbitSupport.cmake | 26 +++ .../math/expo/CheckBuiltinExp2Support.cmake | 31 +++ .../math/expo/CheckBuiltinExpSupport.cmake | 31 +++ .../math/expo/CheckBuiltinExpm1Support.cmake | 31 +++ .../math/expo/CheckBuiltinLog10Support.cmake | 31 +++ .../math/expo/CheckBuiltinLog1pSupport.cmake | 31 +++ .../math/expo/CheckBuiltinLog2Support.cmake | 31 +++ .../math/expo/CheckBuiltinLogSupport.cmake | 31 +++ .../fmanip/CheckBuiltinCopysignSupport.cmake | 26 +++ .../fmanip/CheckBuiltinFrexpSupport.cmake | 26 +++ .../fmanip/CheckBuiltinIlogbSupport.cmake | 26 +++ .../fmanip/CheckBuiltinLdexpSupport.cmake | 26 +++ .../math/fmanip/CheckBuiltinLogbSupport.cmake | 26 +++ .../math/fmanip/CheckBuiltinModfSupport.cmake | 26 +++ .../fmanip/CheckBuiltinScalbnSupport.cmake | 3 + .../math/hyper/CheckBuiltinAcoshSupport.cmake | 31 +++ .../math/hyper/CheckBuiltinAsinhSupport.cmake | 31 +++ .../math/hyper/CheckBuiltinAtanhSupport.cmake | 31 +++ .../math/hyper/CheckBuiltinCoshSupport.cmake | 31 +++ .../math/hyper/CheckBuiltinSinhSupport.cmake | 31 +++ .../math/hyper/CheckBuiltinTanhSupport.cmake | 31 +++ .../math/power/CheckBuiltinCbrtSupport.cmake | 31 +++ .../math/power/CheckBuiltinHypotSupport.cmake | 31 +++ .../math/power/CheckBuiltinPowSupport.cmake | 31 +++ .../math/power/CheckBuiltinSqrtSupport.cmake | 31 +++ .../math/trig/CheckBuiltinAcosSupport.cmake | 31 +++ .../math/trig/CheckBuiltinAsinSupport.cmake | 31 +++ .../math/trig/CheckBuiltinAtan2Support.cmake | 31 +++ .../math/trig/CheckBuiltinAtanSupport.cmake | 31 +++ .../math/trig/CheckBuiltinCosSupport.cmake | 31 +++ .../math/trig/CheckBuiltinSinSupport.cmake | 31 +++ .../math/trig/CheckBuiltinTanSupport.cmake | 31 +++ .../support/CheckBuiltinBitCastSupport.cmake | 22 ++ .../support/CheckBuiltinFmaSupport.cmake | 31 +++ thirdparty/CMakeLists.txt | 76 +++---- 43 files changed, 1288 insertions(+), 114 deletions(-) create mode 100644 cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake delete mode 100644 cmake/config/features/CheckAllSupportedFeatures.cmake create mode 100644 cmake/config/features/GetAllSupportedFeatures.cmake create mode 100644 cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake create mode 100644 cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake create mode 100644 cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake create mode 100644 cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake create mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake create mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake create mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake create mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake create mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake create mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake create mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake create mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake create mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake create mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake create mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake create mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake create mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake create mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake create mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake create mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake create mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake create mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake create mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake create mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake create mode 100644 cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake create mode 100644 cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake create mode 100644 cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake create mode 100644 cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake create mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake create mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake create mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake create mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake create mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake create mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake create mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake create mode 100644 cmake/config/features/builtin/support/CheckBuiltinBitCastSupport.cmake create mode 100644 cmake/config/features/builtin/support/CheckBuiltinFmaSupport.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c5aca007..44e7a526 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,8 @@ project( LANGUAGES CXX ) -set(is_root_project OFF) # Identifies if this is the root project +# Determine if this is the root project or a subproject. +set(is_root_project OFF) if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(is_root_project ON) endif () @@ -18,101 +19,158 @@ if (NOT CCMATH_SOURCE_DIR) set(CCMATH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) endif () +# TODO: Change this to instead use cmakes more modern target_compile_features set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) message(STATUS "CCMath version: ${PROJECT_VERSION}") -# TO THE IMPLEMENTOR: If CCMATH_BUILD_TESTS is set to OFF then googletest can be deleted from the ext folder. +# +# User-facing options +# + +# CCMATH_INSTALL: +# Controls whether installation and packaging steps are configured. +# If this is the root project (standalone), default to ON. +# If this project is included as a subproject, default to OFF. option(CCMATH_INSTALL "Setup install and package steps" ${is_root_project}) -## CCMath specific user defined options -option(CCMATH_BUILD_TESTS "Build ccmath tests" ${is_root_project}) # If disabled then gtest will not be fetched. +# CCMATH_BUILD_TESTS: +# Enable building of ccmath tests. If OFF, tests are skipped. Should only be used by ccmath developers. +option(CCMATH_BUILD_TESTS "Build ccmath tests" ${is_root_project}) + +# CCMATH_FIND_GTEST_PACKAGE: +# Look for gtest package rather than downloading it if needed. option(CCMATH_FIND_GTEST_PACKAGE "Enable finding of gtest package" OFF) -option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project}) # If disabled then gbench will not be fetched. -option(CCMATH_FIND_GBENCH_PACKAGE "Enable finding of google benchmark package" OFF) -option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project}) -option(CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS "Enable user defined optimization macros instead of having ccmath define its own internal ones in cmake" OFF) -## Standard changing user defined options -# Most options here are by default set to OFF. Setting them to ON will violate the standard, but generally -# provide better performance or get rid of extra bloat that the standard requires. -option(CCMATH_ENABLE_EXTENSIONS "Enable the extended ccmath library that adds helpful additional methods that are not defined by the standard" OFF) -option(CCMATH_DISABLE_ERRNO "Disable the use of errno in ccmath during runtime (this will allow compile time evaluation of edge cases that normally can not be evaluated at compile time)" OFF) +# CCMATH_BUILD_BENCHMARKS: +# Enable building of ccmath benchmarks. If OFF, benchmarks are skipped. +option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project}) + +# CCMATH_FIND_GBENCH_PACKAGE: +# Look for google benchmark package rather than downloading it if needed. Should only be used by ccmath developers. +option(CCMATH_FIND_GBENCH_PACKAGE "Enable finding of google benchmark package" OFF) -## Simd specific user defined options -option(CCMATH_ENABLE_RUNTIME_SIMD "Enable SIMD optimization for runtime evaluation (does not effect compile time)" ON) # By default we want SIMD to be enabled to allow faster runtime evaluation. -option(CCMATH_DISABLE_SVML_USAGE "Disable the use of SVML functions in ccmath. (This only effects compilers that use SVML)" OFF) +# CCMATH_BUILD_EXAMPLES: +# Build example code demonstrating usage of ccmath. +option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project}) -# include the global configuration file +# CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS: +# Allow users to supply their own optimization macros rather than CCMath defining them itself. +option(CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS + "Enable user defined optimization macros instead of having ccmath define its own" + OFF) + +# CCMATH_ENABLE_EXTENSIONS: +# Enable non-standard extensions that go beyond the interface. +option(CCMATH_ENABLE_EXTENSIONS + "Enable the extended ccmath library that adds additional methods beyond the standard" + OFF) + +# CCMATH_DISABLE_ERRNO: +# Disable usage of errno during runtime breaking standard compliance, but may lead to faster evaluation and smaller binaries. +option(CCMATH_DISABLE_ERRNO + "Disable the use of errno in ccmath during runtime (may lead to faster evaluations but is non-standard)" + OFF) + +# CCMATH_ENABLE_RUNTIME_SIMD: +# Enable runtime SIMD optimizations for faster evaluations at runtime. +option(CCMATH_ENABLE_RUNTIME_SIMD + "Enable SIMD optimization for runtime evaluation (does not affect compile-time)" + ON) + +# CCMATH_DISABLE_SVML_USAGE: +# Disable the use of SVML (Short Vector Math Library) if supported by the compiler. +option(CCMATH_DISABLE_SVML_USAGE + "Disable the use of SVML functions in ccmath (if supported by compiler)" + OFF) + +# CCMATH_STRICT_WARNINGS: +# Enable strict warning handling, turning certain warnings into errors. +# This might be intrusive for downstream users, so disable if we are not the root project. +option(CCMATH_STRICT_WARNINGS + "Enable strict warnings and treat certain warnings as errors. May be intrusive downstream." + ${is_root_project}) + +# Include global configuration include(cmake/config/GlobalConfig.cmake) add_library(${PROJECT_NAME}-compile-options INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME}-compile-options ALIAS ${PROJECT_NAME}-compile-options) +# +# Compiler Flags and Conditions +# +if (MSVC) + # MSVC-specific options + target_compile_options(${PROJECT_NAME}-compile-options INTERFACE + /W3 + /permissive- + /Zc:__cplusplus + /D_ENABLE_EXTENDED_ALIGNED_STORAGE + ) + # Only define NOMINMAX on Windows platforms + if (WIN32) + target_compile_definitions(${PROJECT_NAME}-compile-options INTERFACE NOMINMAX) + endif() + + if (CCMATH_STRICT_WARNINGS) + target_compile_options(${PROJECT_NAME}-compile-options INTERFACE /WX) + endif() -##### ccmath specified compiler options +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" + OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" + OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") -# Generic clang/gcc compiler options -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|IntelLLVM") + # Generic clang/gcc/intel options + # Consider making some of these suppressions configurable if requested by users. target_compile_options(${PROJECT_NAME}-compile-options INTERFACE -Wall -Wextra -Wconversion - -Werror=return-type - -Wno-pedantic - - # Allow FMA instructions -ffp-contract=fast - - # Macros to define - -DNOMINMAX + # Define NOMINMAX only on Windows to avoid conflicts with min/max macros + $<$:-DNOMINMAX> + -Wno-unused-but-set-variable + -Wno-unused-value + -Wno-unused-parameter ) - - if (CMAKE_CXX_COMPILER_ID STREQUAL MSVC) - target_compile_options(${PROJECT_NAME}-compile-options INTERFACE - /W3 - /WX - /permissive- - - /Zc:__cplusplus - - # Macros to define - /DNOMINMAX - /D_ENABLE_EXTENDED_ALIGNED_STORAGE - ) + if (CCMATH_STRICT_WARNINGS) + target_compile_options(${PROJECT_NAME}-compile-options INTERFACE -Werror=return-type) endif () - # Disable intel specific warnings that don't apply to us. - if (CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM) + if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") target_compile_options(${PROJECT_NAME}-compile-options INTERFACE -Wno-tautological-constant-compare ) - endif () + endif() - - # TODO: Remove this later. - # Some variables have been provided but are not currently being used, but it would not atm make sense to remove them. - # So to clean up the warnings we are just silencing these specific cases. - target_compile_options(${PROJECT_NAME}-compile-options INTERFACE - -Wno-unused-but-set-variable -Wno-unused-value -Wno-unused-parameter - ) -endif () +else() + message(WARNING "CCMath: Unknown compiler. No specific flags applied.") +endif() add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) include(cmake/functions/CcmathMessage.cmake) - include(cmake/functions/CcmAddHeaders.cmake) +# Add public headers through a directory-level CMakeLists that sets variables, etc. add_subdirectory(include/ccmath) -target_include_directories(${PROJECT_NAME} INTERFACE $) -target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE $/include>) + +# CCMath configuration and detection files +include(cmake/config/features/GetAllSupportedFeatures.cmake) + + +# Ensure proper include directories for consumers +target_include_directories(${PROJECT_NAME} INTERFACE + $ + $ +) target_link_libraries(${PROJECT_NAME} INTERFACE ${PROJECT_NAME}::${PROJECT_NAME}-compile-options @@ -120,21 +178,14 @@ target_link_libraries(${PROJECT_NAME} INTERFACE if (CCMATH_ENABLE_RUNTIME_SIMD) target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_USE_RT_SIMD) - - if (NOT CCMATH_DISABLE_SVML_USAGE) - include(cmake/config/features/CheckAllSupportedSimdFeatures.cmake) # Checks for specific SIMD features and sets the appropriate macros. - endif () endif () if (NOT CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS) - # Set these definitions based on the build type to aid in identifying the optimization level. - # These are essential when dealing with compiler specific outcomes that are based on the optimization level. - target_compile_definitions(${PROJECT_NAME} - INTERFACE - $<$:CCM_CONFIG_DEBUG> # -O0 - $<$:CCM_CONFIG_OPTIMIZE> # -O2 - $<$:CCM_CONFIG_AGGRESSIVELY_OPTIMIZE> # -O3 - $<$:CCM_CONFIG_MINSIZE> # -Os + target_compile_definitions(${PROJECT_NAME} INTERFACE + $<$:CCM_CONFIG_DEBUG> + $<$:CCM_CONFIG_OPTIMIZE> + $<$:CCM_CONFIG_AGGRESSIVELY_OPTIMIZE> + $<$:CCM_CONFIG_MINSIZE> ) endif () @@ -142,10 +193,17 @@ if (CCMATH_DISABLE_ERRNO) target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_DISABLE_ERRNO) endif () +# Generate version header configure_file(cmake/version.hpp.in "${CMAKE_CURRENT_BINARY_DIR}/include/${PROJECT_NAME}/version.hpp" @ONLY) +# Add optional subdirectories only if requested if (CCMATH_BUILD_EXAMPLES OR CCMATH_BUILD_BENCHMARKS OR CCMATH_BUILD_TESTS) - add_subdirectory(thirdparty) + # Use SYSTEM to suppress warnings from thirdparty code if supported by the CMake version. + if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.25) + add_subdirectory(thirdparty SYSTEM) + else () + add_subdirectory(thirdparty) + endif () endif () if (CCMATH_BUILD_EXAMPLES) @@ -161,7 +219,7 @@ if (CCMATH_BUILD_TESTS) add_subdirectory(test) endif () - +# Installation and Packaging if (CCMATH_INSTALL) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -172,7 +230,6 @@ if (CCMATH_INSTALL) EXPORT ${PROJECT_NAME}-targets ) - # Manually specify the headers to install install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" @@ -196,8 +253,15 @@ if (CCMATH_INSTALL) INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) + # Write a version file for strict version checking + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + COMPATIBILITY SameMajorVersion + ) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + ) endif () diff --git a/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake b/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake new file mode 100644 index 00000000..fee276c5 --- /dev/null +++ b/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake @@ -0,0 +1,70 @@ +# Monolithic feature checking script +# +# All of these included cmake files perform compilation tests to determine if we have support for +# internally used builtin functions. If the tests pass, we add a compile definition to the project +# to indicate that the feature is supported. We should only use cmake to perform these checks if +# and only if we are actually using the feature in the codebase. If not then don't bother checking. +# +# NOTE: Be aware these scripts WILL create macros definitions that the project may use internally. +# NOTE: The check for __builtin_bit_cast will cause a cmake error as the library has a hard dependency on it. + + +# Common Support Builtins +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/support/CheckBuiltinBitCastSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/support/CheckBuiltinFmaSupport.cmake) + + +# Basic +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake) + + +# Compare +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake) + + +# Exponential +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake) + + +# Fmanip +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake) + + +# Hyperbolic +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake) + + +# Power +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake) + + +# Trigonometric +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake) diff --git a/cmake/config/features/CheckAllSupportedFeatures.cmake b/cmake/config/features/CheckAllSupportedFeatures.cmake deleted file mode 100644 index e69de29b..00000000 diff --git a/cmake/config/features/CheckAllSupportedSimdFeatures.cmake b/cmake/config/features/CheckAllSupportedSimdFeatures.cmake index b1c8f8f8..43d3129f 100644 --- a/cmake/config/features/CheckAllSupportedSimdFeatures.cmake +++ b/cmake/config/features/CheckAllSupportedSimdFeatures.cmake @@ -10,8 +10,9 @@ include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSE2Support.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSE3Support.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSSE3Support.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSE4Support.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSVMLSupport.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckNEONSupport.cmake) - +if (NOT CCMATH_DISABLE_SVML_USAGE) + include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSVMLSupport.cmake) +endif () diff --git a/cmake/config/features/GetAllSupportedFeatures.cmake b/cmake/config/features/GetAllSupportedFeatures.cmake new file mode 100644 index 00000000..5be2b4eb --- /dev/null +++ b/cmake/config/features/GetAllSupportedFeatures.cmake @@ -0,0 +1,5 @@ +include(${CCMATH_SOURCE_DIR}/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake) + +if (CCMATH_ENABLE_RUNTIME_SIMD) + include(${CCMATH_SOURCE_DIR}/cmake/config/features/CheckAllSupportedSimdFeatures.cmake) +endif () diff --git a/cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake b/cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake new file mode 100644 index 00000000..5696d64b --- /dev/null +++ b/cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake @@ -0,0 +1,32 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_nan is supported +check_cxx_source_compiles(" + int main() { + float fr = __builtin_nanf(); + double dr = __builtin_nan(); + long double lr = __builtin_nanl(); + return 0; + } +" CCMATH_BUILTIN_NAN_SUPPORT) + +if (CCMATH_BUILTIN_NAN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_NAN) +endif () + +# Check if __builtin_nan can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr float fr = __builtin_nanf(); + constexpr double dr = __builtin_nan(); + constexpr long double lr = __builtin_nanl(); + static_assert(fr != fr); + static_assert(dr != dr); + static_assert(lr != lr); + return 0; + } +" CCMATH_BUILTIN_NAN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_NAN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_NAN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake b/cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake new file mode 100644 index 00000000..71215d27 --- /dev/null +++ b/cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake @@ -0,0 +1,13 @@ +include(CheckCXXSourceCompiles) + +# We only care about the constexpr support for isinf +check_cxx_source_compiles(" + int main() { + static_assert(__builtin_isinf(1.0 / 0.0)); + return 0; + } +" CCMATH_BUILTIN_ISINF_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_ISINF_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ISINF_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake b/cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake new file mode 100644 index 00000000..d393146f --- /dev/null +++ b/cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake @@ -0,0 +1,13 @@ +include(CheckCXXSourceCompiles) + +# We only care about the constexpr support for isnan +check_cxx_source_compiles(" + int main() { + static_assert(__builtin_isnan(0.0 / 0.0)); + return 0; + } +" CCMATH_BUILTIN_ISNAN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_ISNAN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ISNAN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake b/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake new file mode 100644 index 00000000..f177015f --- /dev/null +++ b/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake @@ -0,0 +1,26 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + int main() { + return __builtin_signbit(1.0) + + __builtin_signbitf(1.0f) + + __builtin_signbitl(1.0l); + } +" CCMATH_BUILTIN_SIGNBIT_SUPPORT) + +if (CCMATH_BUILTIN_SIGNBIT_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SIGNBIT) +endif () + +check_cxx_source_compiles(" + int main() { + static_assert(__builtin_signbit(-1.0)); + static_assert(__builtin_signbitf(-1.0f)); + static_assert(__builtin_signbitl(-1.0l)); + return 0; + } +" CCMATH_BUILTIN_SIGNBIT_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_SIGNBIT_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SIGNBIT_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake new file mode 100644 index 00000000..ea1cf0e4 --- /dev/null +++ b/cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_exp2 is supported +check_cxx_source_compiles(" + int main() { + double x = 2.0; + float fr = __builtin_exp2f(x); + double dr = __builtin_exp2(x); + long double lr = __builtin_exp2l(x); + return 0; + } +" CCMATH_BUILTIN_EXP2_SUPPORT) + +if (CCMATH_BUILTIN_EXP2_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXP2) +endif () + +# Check if __builtin_exp2 can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 2.0; + static_assert(__builtin_exp2f(x) == __builtin_exp2f(x)); + static_assert(__builtin_exp2(x) == __builtin_exp2(x)); + static_assert(__builtin_exp2l(x) == __builtin_exp2l(x)); + return 0; + } +" CCMATH_BUILTIN_EXP2_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_EXP2_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXP2_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake new file mode 100644 index 00000000..f46fd9e2 --- /dev/null +++ b/cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_exp is supported +check_cxx_source_compiles(" + int main() { + double x = 2.0; + float fr = __builtin_expf(x); + double dr = __builtin_exp(x); + long double lr = __builtin_expl(x); + return 0; + } +" CCMATH_BUILTIN_EXP_SUPPORT) + +if (CCMATH_BUILTIN_EXP_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXP) +endif () + +# Check if __builtin_exp can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 2.0; + static_assert(__builtin_expf(x) == __builtin_expf(x)); + static_assert(__builtin_exp(x) == __builtin_exp(x)); + static_assert(__builtin_expl(x) == __builtin_expl(x)); + return 0; + } +" CCMATH_BUILTIN_EXP_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_EXP_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXP_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake new file mode 100644 index 00000000..7c476660 --- /dev/null +++ b/cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_expm1 is supported +check_cxx_source_compiles(" + int main() { + double x = 2.0; + float fr = __builtin_expm1f(x); + double dr = __builtin_expm1(x); + long double lr = __builtin_expm1l(x); + return 0; + } +" CCMATH_BUILTIN_EXPM1_SUPPORT) + +if (CCMATH_BUILTIN_EXPM1_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXPM1) +endif () + +# Check if __builtin_expm1 can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 2.0; + static_assert(__builtin_expm1f(x) == __builtin_expm1f(x)); + static_assert(__builtin_expm1(x) == __builtin_expm1(x)); + static_assert(__builtin_expm1l(x) == __builtin_expm1l(x)); + return 0; + } +" CCMATH_BUILTIN_EXPM1_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_EXPM1_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXPM1_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake new file mode 100644 index 00000000..443f5bc9 --- /dev/null +++ b/cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_log10 is supported +check_cxx_source_compiles(" + int main() { + double x = 2.0; + float fr = __builtin_log10f(x); + double dr = __builtin_log10(x); + long double lr = __builtin_log10l(x); + return 0; + } +" CCMATH_BUILTIN_LOG10_SUPPORT) + +if (CCMATH_BUILTIN_LOG10_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG10) +endif () + +# Check if __builtin_log10 can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 2.0; + static_assert(__builtin_log10f(x) == __builtin_log10f(x)); + static_assert(__builtin_log10(x) == __builtin_log10(x)); + static_assert(__builtin_log10l(x) == __builtin_log10l(x)); + return 0; + } +" CCMATH_BUILTIN_LOG10_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_LOG10_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG10_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake new file mode 100644 index 00000000..c946b720 --- /dev/null +++ b/cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_log1p is supported +check_cxx_source_compiles(" + int main() { + double x = 2.0; + float fr = __builtin_log1pf(x); + double dr = __builtin_log1p(x); + long double lr = __builtin_log1pl(x); + return 0; + } +" CCMATH_BUILTIN_LOG1P_SUPPORT) + +if (CCMATH_BUILTIN_LOG1P_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG1P) +endif () + +# Check if __builtin_log1p can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 2.0; + static_assert(__builtin_log1pf(x) == __builtin_log1pf(x)); + static_assert(__builtin_log1p(x) == __builtin_log1p(x)); + static_assert(__builtin_log1pl(x) == __builtin_log1pl(x)); + return 0; + } +" CCMATH_BUILTIN_LOG1P_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_LOG1P_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG1P_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake new file mode 100644 index 00000000..8ce1ab09 --- /dev/null +++ b/cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_log2 is supported +check_cxx_source_compiles(" + int main() { + double x = 2.0; + float fr = __builtin_log2f(x); + double dr = __builtin_log2(x); + long double lr = __builtin_log2l(x); + return 0; + } +" CCMATH_BUILTIN_LOG2_SUPPORT) + +if (CCMATH_BUILTIN_LOG2_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG2) +endif () + +# Check if __builtin_log2 can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 2.0; + static_assert(__builtin_log2f(x) == __builtin_log2f(x)); + static_assert(__builtin_log2(x) == __builtin_log2(x)); + static_assert(__builtin_log2l(x) == __builtin_log2l(x)); + return 0; + } +" CCMATH_BUILTIN_LOG2_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_LOG2_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG2_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake new file mode 100644 index 00000000..1cd9781a --- /dev/null +++ b/cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_log is supported +check_cxx_source_compiles(" + int main() { + double x = 2.0; + float fr = __builtin_logf(x); + double dr = __builtin_log(x); + long double lr = __builtin_logl(x); + return 0; + } +" CCMATH_BUILTIN_LOG_SUPPORT) + +if (CCMATH_BUILTIN_LOG_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG) +endif () + +# Check if __builtin_log can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 2.0; + static_assert(__builtin_logf(x) == __builtin_logf(x)); + static_assert(__builtin_log(x) == __builtin_log(x)); + static_assert(__builtin_logl(x) == __builtin_logl(x)); + return 0; + } +" CCMATH_BUILTIN_LOG_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_LOG_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake new file mode 100644 index 00000000..e3932c69 --- /dev/null +++ b/cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake @@ -0,0 +1,26 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + int main() { + return __builtin_copysign(1.0, -1.0) + + __builtin_copysignf(1.0f, -1.0f) + + __builtin_copysignl(1.0l, -1.0l); + } +" CCMATH_BUILTIN_COPYSIGN_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) +endif () + +check_cxx_source_compiles(" + int main() { + static_assert(__builtin_copysign(1.0, -1.0) == -1.0); + static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); + static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); + return 0; + } +" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake new file mode 100644 index 00000000..e3932c69 --- /dev/null +++ b/cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake @@ -0,0 +1,26 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + int main() { + return __builtin_copysign(1.0, -1.0) + + __builtin_copysignf(1.0f, -1.0f) + + __builtin_copysignl(1.0l, -1.0l); + } +" CCMATH_BUILTIN_COPYSIGN_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) +endif () + +check_cxx_source_compiles(" + int main() { + static_assert(__builtin_copysign(1.0, -1.0) == -1.0); + static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); + static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); + return 0; + } +" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake new file mode 100644 index 00000000..e3932c69 --- /dev/null +++ b/cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake @@ -0,0 +1,26 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + int main() { + return __builtin_copysign(1.0, -1.0) + + __builtin_copysignf(1.0f, -1.0f) + + __builtin_copysignl(1.0l, -1.0l); + } +" CCMATH_BUILTIN_COPYSIGN_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) +endif () + +check_cxx_source_compiles(" + int main() { + static_assert(__builtin_copysign(1.0, -1.0) == -1.0); + static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); + static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); + return 0; + } +" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake new file mode 100644 index 00000000..e3932c69 --- /dev/null +++ b/cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake @@ -0,0 +1,26 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + int main() { + return __builtin_copysign(1.0, -1.0) + + __builtin_copysignf(1.0f, -1.0f) + + __builtin_copysignl(1.0l, -1.0l); + } +" CCMATH_BUILTIN_COPYSIGN_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) +endif () + +check_cxx_source_compiles(" + int main() { + static_assert(__builtin_copysign(1.0, -1.0) == -1.0); + static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); + static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); + return 0; + } +" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake new file mode 100644 index 00000000..e3932c69 --- /dev/null +++ b/cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake @@ -0,0 +1,26 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + int main() { + return __builtin_copysign(1.0, -1.0) + + __builtin_copysignf(1.0f, -1.0f) + + __builtin_copysignl(1.0l, -1.0l); + } +" CCMATH_BUILTIN_COPYSIGN_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) +endif () + +check_cxx_source_compiles(" + int main() { + static_assert(__builtin_copysign(1.0, -1.0) == -1.0); + static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); + static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); + return 0; + } +" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake new file mode 100644 index 00000000..e3932c69 --- /dev/null +++ b/cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake @@ -0,0 +1,26 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + int main() { + return __builtin_copysign(1.0, -1.0) + + __builtin_copysignf(1.0f, -1.0f) + + __builtin_copysignl(1.0l, -1.0l); + } +" CCMATH_BUILTIN_COPYSIGN_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) +endif () + +check_cxx_source_compiles(" + int main() { + static_assert(__builtin_copysign(1.0, -1.0) == -1.0); + static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); + static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); + return 0; + } +" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake new file mode 100644 index 00000000..d727c3eb --- /dev/null +++ b/cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake @@ -0,0 +1,3 @@ +include(CheckCXXSourceCompiles) + +# TODO: For now I'm not implementing checks for scalbn as checking it for constexpr is a little trickier. diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake new file mode 100644 index 00000000..16dde682 --- /dev/null +++ b/cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_acosh is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_acoshf(x); + double dr = __builtin_acosh(x); + long double lr = __builtin_acoshl(x); + return 0; + } +" CCMATH_BUILTIN_ACOSH_SUPPORT) + +if (CCMATH_BUILTIN_ACOSH_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ACOSH) +endif () + +# Check if __builtin_acosh can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_acoshf(x) == __builtin_acoshf(x)); + static_assert(__builtin_acosh(x) == __builtin_acosh(x)); + static_assert(__builtin_acoshl(x) == __builtin_acoshl(x)); + return 0; + } +" CCMATH_BUILTIN_ACOSH_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_ACOSH_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ACOSH_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake new file mode 100644 index 00000000..89280eb7 --- /dev/null +++ b/cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_asinh is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_asinhf(x); + double dr = __builtin_asinh(x); + long double lr = __builtin_asinhl(x); + return 0; + } +" CCMATH_BUILTIN_ASINH_SUPPORT) + +if (CCMATH_BUILTIN_ASINH_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ASINH) +endif () + +# Check if __builtin_asinh can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_asinhf(x) == __builtin_asinhf(x)); + static_assert(__builtin_asinh(x) == __builtin_asinh(x)); + static_assert(__builtin_asinhl(x) == __builtin_asinhl(x)); + return 0; + } +" CCMATH_BUILTIN_ASINH_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_ASINH_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ASINH_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake new file mode 100644 index 00000000..6b6b4151 --- /dev/null +++ b/cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_atanh is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_atanhf(x); + double dr = __builtin_atanh(x); + long double lr = __builtin_atanhl(x); + return 0; + } +" CCMATH_BUILTIN_ATANH_SUPPORT) + +if (CCMATH_BUILTIN_ATANH_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATANH) +endif () + +# Check if __builtin_atanh can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_atanhf(x) == __builtin_atanhf(x)); + static_assert(__builtin_atanh(x) == __builtin_atanh(x)); + static_assert(__builtin_atanhl(x) == __builtin_atanhl(x)); + return 0; + } +" CCMATH_BUILTIN_ATANH_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_ATANH_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATANH_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake new file mode 100644 index 00000000..e063a2ab --- /dev/null +++ b/cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_cosh is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_coshf(x); + double dr = __builtin_cosh(x); + long double lr = __builtin_coshl(x); + return 0; + } +" CCMATH_BUILTIN_COSH_SUPPORT) + +if (CCMATH_BUILTIN_COSH_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COSH) +endif () + +# Check if __builtin_cosh can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_coshf(x) == __builtin_coshf(x)); + static_assert(__builtin_cosh(x) == __builtin_cosh(x)); + static_assert(__builtin_coshl(x) == __builtin_coshl(x)); + return 0; + } +" CCMATH_BUILTIN_COSH_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_COSH_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COSH_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake new file mode 100644 index 00000000..3f8faf4f --- /dev/null +++ b/cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_sinh is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_sinhf(x); + double dr = __builtin_sinh(x); + long double lr = __builtin_sinhl(x); + return 0; + } +" CCMATH_BUILTIN_SINH_SUPPORT) + +if (CCMATH_BUILTIN_SINH_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SINH) +endif () + +# Check if __builtin_sinh can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_sinhf(x) == __builtin_sinhf(x)); + static_assert(__builtin_sinh(x) == __builtin_sinh(x)); + static_assert(__builtin_sinhl(x) == __builtin_sinhl(x)); + return 0; + } +" CCMATH_BUILTIN_SINH_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_SINH_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SINH_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake new file mode 100644 index 00000000..36abaac5 --- /dev/null +++ b/cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_tanh is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_tanhf(x); + double dr = __builtin_tanh(x); + long double lr = __builtin_tanhl(x); + return 0; + } +" CCMATH_BUILTIN_TANH_SUPPORT) + +if (CCMATH_BUILTIN_TANH_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_TANH) +endif () + +# Check if __builtin_tanh can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_tanhf(x) == __builtin_tanhf(x)); + static_assert(__builtin_tanh(x) == __builtin_tanh(x)); + static_assert(__builtin_tanhl(x) == __builtin_tanhl(x)); + return 0; + } +" CCMATH_BUILTIN_TANH_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_TANH_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_TANH_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake b/cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake new file mode 100644 index 00000000..239f1a55 --- /dev/null +++ b/cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_cbrt is supported +check_cxx_source_compiles(" + int main() { + double x = 2.0; + float fr = __builtin_cbrtf(x); + double dr = __builtin_cbrt(x); + long double lr = __builtin_cbrtl(x); + return 0; + } +" CCMATH_BUILTIN_CBRT_SUPPORT) + +if (CCMATH_BUILTIN_CBRT_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_CBRT) +endif () + +# Check if __builtin_cbrt can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 2.0; + static_assert(__builtin_cbrtf(x) == __builtin_cbrtf(x)); + static_assert(__builtin_cbrt(x) == __builtin_cbrt(x)); + static_assert(__builtin_cbrtl(x) == __builtin_cbrtl(x)); + return 0; + } +" CCMATH_BUILTIN_CBRT_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_CBRT_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_CBRT_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake b/cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake new file mode 100644 index 00000000..f1e260f8 --- /dev/null +++ b/cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_hypot is supported +check_cxx_source_compiles(" + int main() { + double x = 3.0, y = 4.0; + float fr = __builtin_hypotf(x, y); + double dr = __builtin_hypot(x, y); + long double lr = __builtin_hypotl(x, y); + return 0; + } +" CCMATH_BUILTIN_HYPOT_SUPPORT) + +if (CCMATH_BUILTIN_HYPOT_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_HYPOT) +endif () + +# Check if __builtin_hypot can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 3.0, y = 4.0; + static_assert(__builtin_hypotf(x, y) == __builtin_hypotf(x, y)); + static_assert(__builtin_hypot(x, y) == __builtin_hypot(x, y)); + static_assert(__builtin_hypotl(x, y) == __builtin_hypotl(x, y)); + return 0; + } +" CCMATH_BUILTIN_HYPOT_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_HYPOT_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_HYPOT_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake b/cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake new file mode 100644 index 00000000..1ed9178a --- /dev/null +++ b/cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_pow is supported +check_cxx_source_compiles(" + int main() { + double x = 3.0, y = 2.0; + float fr = __builtin_powf(x, y); + double dr = __builtin_pow(x, y); + long double lr = __builtin_powl(x, y); + return 0; + } +" CCMATH_BUILTIN_POW_SUPPORT) + +if (CCMATH_BUILTIN_POW_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_POW) +endif () + +# Check if __builtin_pow can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 3.0, y = 2.0; + static_assert(__builtin_powf(x, y) == __builtin_powf(x, y)); + static_assert(__builtin_pow(x, y) == __builtin_pow(x, y)); + static_assert(__builtin_powl(x, y) == __builtin_powl(x, y)); + return 0; + } +" CCMATH_BUILTIN_POW_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_POW_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_POW_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake b/cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake new file mode 100644 index 00000000..4f24e011 --- /dev/null +++ b/cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_sqrt is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_sqrtf(x); + double dr = __builtin_sqrt(x); + long double lr = __builtin_sqrtl(x); + return 0; + } +" CCMATH_BUILTIN_SQRT_SUPPORT) + +if (CCMATH_BUILTIN_SQRT_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SQRT) +endif () + +# Check if __builtin_sqrt can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_sqrtf(x) == __builtin_sqrtf(x)); + static_assert(__builtin_sqrt(x) == __builtin_sqrt(x)); + static_assert(__builtin_sqrtl(x) == __builtin_sqrtl(x)); + return 0; + } +" CCMATH_BUILTIN_SQRT_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_SQRT_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SQRT_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake new file mode 100644 index 00000000..ee1a7d48 --- /dev/null +++ b/cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_acos is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_acosf(x); + double dr = __builtin_acos(x); + long double lr = __builtin_acosl(x); + return 0; + } +" CCMATH_BUILTIN_ACOS_SUPPORT) + +if (CCMATH_BUILTIN_ACOS_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ACOS) +endif () + +# Check if __builtin_acos can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_acosf(x) == __builtin_acosf(x)); + static_assert(__builtin_acos(x) == __builtin_acos(x)); + static_assert(__builtin_acosl(x) == __builtin_acosl(x)); + return 0; + } +" CCMATH_BUILTIN_ACOS_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_ACOS_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ACOS_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake new file mode 100644 index 00000000..1391625c --- /dev/null +++ b/cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_asin is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_asinf(x); + double dr = __builtin_asin(x); + long double lr = __builtin_asinl(x); + return 0; + } +" CCMATH_BUILTIN_ASIN_SUPPORT) + +if (CCMATH_BUILTIN_ASIN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ASIN) +endif () + +# Check if __builtin_asin can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_asinf(x) == __builtin_asinf(x)); + static_assert(__builtin_asin(x) == __builtin_asin(x)); + static_assert(__builtin_asinl(x) == __builtin_asinl(x)); + return 0; + } +" CCMATH_BUILTIN_ASIN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_ASIN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ASIN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake new file mode 100644 index 00000000..635ce981 --- /dev/null +++ b/cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_atan2 is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0, y = 2.0; + float fr = __builtin_atan2f(x, y); + double dr = __builtin_atan2(x, y); + long double lr = __builtin_atan2l(x, y); + return 0; + } +" CCMATH_BUILTIN_ATAN2_SUPPORT) + +if (CCMATH_BUILTIN_ATAN2_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATAN2) +endif () + +# Check if __builtin_atan2 can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0, y = 2.0; + static_assert(__builtin_atan2f(x, y) == __builtin_atan2f(x, y)); + static_assert(__builtin_atan2(x, y) == __builtin_atan2(x, y)); + static_assert(__builtin_atan2l(x, y) == __builtin_atan2l(x, y)); + return 0; + } +" CCMATH_BUILTIN_ATAN2_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_ATAN2_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATAN2_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake new file mode 100644 index 00000000..1a4140de --- /dev/null +++ b/cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_atan is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_atanf(x); + double dr = __builtin_atan(x); + long double lr = __builtin_atanl(x); + return 0; + } +" CCMATH_BUILTIN_ATAN_SUPPORT) + +if (CCMATH_BUILTIN_ATAN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATAN) +endif () + +# Check if __builtin_atan can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_atanf(x) == __builtin_atanf(x)); + static_assert(__builtin_atan(x) == __builtin_atan(x)); + static_assert(__builtin_atanl(x) == __builtin_atanl(x)); + return 0; + } +" CCMATH_BUILTIN_ATAN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_ATAN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATAN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake new file mode 100644 index 00000000..b926d21f --- /dev/null +++ b/cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_cos is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_cosf(x); + double dr = __builtin_cos(x); + long double lr = __builtin_cosl(x); + return 0; + } +" CCMATH_BUILTIN_COS_SUPPORT) + +if (CCMATH_BUILTIN_COS_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COS) +endif () + +# Check if __builtin_cos can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_cosf(x) == __builtin_cosf(x)); + static_assert(__builtin_cos(x) == __builtin_cos(x)); + static_assert(__builtin_cosl(x) == __builtin_cosl(x)); + return 0; + } +" CCMATH_BUILTIN_COS_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_COS_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COS_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake new file mode 100644 index 00000000..459ebb26 --- /dev/null +++ b/cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_sin is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_sinf(x); + double dr = __builtin_sin(x); + long double lr = __builtin_sinl(x); + return 0; + } +" CCMATH_BUILTIN_SIN_SUPPORT) + +if (CCMATH_BUILTIN_SIN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SIN) +endif () + +# Check if __builtin_sin can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_sinf(x) == __builtin_sinf(x)); + static_assert(__builtin_sin(x) == __builtin_sin(x)); + static_assert(__builtin_sinl(x) == __builtin_sinl(x)); + return 0; + } +" CCMATH_BUILTIN_SIN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_SIN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SIN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake new file mode 100644 index 00000000..3f6b77b6 --- /dev/null +++ b/cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_tan is supported +check_cxx_source_compiles(" + int main() { + double x = 4.0; + float fr = __builtin_tanf(x); + double dr = __builtin_tan(x); + long double lr = __builtin_tanl(x); + return 0; + } +" CCMATH_BUILTIN_TAN_SUPPORT) + +if (CCMATH_BUILTIN_TAN_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_TAN) +endif () + +# Check if __builtin_tan can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 4.0; + static_assert(__builtin_tanf(x) == __builtin_tanf(x)); + static_assert(__builtin_tan(x) == __builtin_tan(x)); + static_assert(__builtin_tanl(x) == __builtin_tanl(x)); + return 0; + } +" CCMATH_BUILTIN_TAN_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_TAN_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_TAN_CONSTEXPR) +endif () diff --git a/cmake/config/features/builtin/support/CheckBuiltinBitCastSupport.cmake b/cmake/config/features/builtin/support/CheckBuiltinBitCastSupport.cmake new file mode 100644 index 00000000..0ef8bc96 --- /dev/null +++ b/cmake/config/features/builtin/support/CheckBuiltinBitCastSupport.cmake @@ -0,0 +1,22 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_bit_cast is supported +check_cxx_source_compiles(" + #include + + int main() { + struct A { int x; }; + struct B { int y; }; + B b = __builtin_bit_cast(B, A{42}); + return 0; + } +" CCMATH_BUILTIN_BIT_CAST_SUPPORT) + +if (CCMATH_BUILTIN_BIT_CAST_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_BIT_CAST) +else () + message(FATAL_ERROR " + CCMath: __builtin_bit_cast is not supported by the compiler. + CCmath MANDATES you have a compiler that supports __builtin_bit_cast! +") +endif () diff --git a/cmake/config/features/builtin/support/CheckBuiltinFmaSupport.cmake b/cmake/config/features/builtin/support/CheckBuiltinFmaSupport.cmake new file mode 100644 index 00000000..7726be88 --- /dev/null +++ b/cmake/config/features/builtin/support/CheckBuiltinFmaSupport.cmake @@ -0,0 +1,31 @@ +include(CheckCXXSourceCompiles) + +# Check if __builtin_fma is supported +check_cxx_source_compiles(" + int main() { + double x = 1.0, y = 2.0, z = 3.0; + float fr = __builtin_fmaf(x, y, z); + double dr = __builtin_fma(x, y, z); + long double lr = __builtin_fmal(x, y, z); + return 0; + } +" CCMATH_BUILTIN_FMA_SUPPORT) + +if (CCMATH_BUILTIN_FMA_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_FMA) +endif () + +# Check if __builtin_fma can be used as a constexpr in C++17 +check_cxx_source_compiles(" + int main() { + constexpr double x = 1.0, y = 2.0, z = 3.0; + static_assert(__builtin_fmaf(x, y, z) == __builtin_fmaf(x, y, z)); + static_assert(__builtin_fma(x, y, z) == __builtin_fma(x, y, z)); + static_assert(__builtin_fmal(x, y, z) == __builtin_fmal(x, y, z)); + return 0; + } +" CCMATH_BUILTIN_FMA_CONSTEXPR_SUPPORT) + +if (CCMATH_BUILTIN_FMA_CONSTEXPR_SUPPORT) + add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_FMA_CONSTEXPR) +endif () diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 88ffe58f..b1504eb6 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -2,67 +2,61 @@ project(ccmath-ext) include(FetchContent) +set(CCMATH_BENCHMARK_VERSION v1.8.3) +set(CCMATH_GTEST_VERSION v1.14.0) + if (CCMATH_BUILD_BENCHMARKS) - # Intel does implement the regex library but google test is unable to detect this. - # Lets help them out and set the var ourselves. - if (CCMATH_COMPILER_INTEL) - set(HAVE_STD_REGEX ON CACHE BOOL "" FORCE) - endif () + if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + set(HAVE_STD_REGEX ON) + endif() set(BENCHMARK_ENABLE_TESTING NO) FetchContent_Declare( benchmark GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG v1.8.3 + GIT_TAG ${CCMATH_BENCHMARK_VERSION} ) - FetchContent_MakeAvailable(benchmark) -endif () +endif() if (CCMATH_BUILD_TESTS) - # Intel does implement the regex library but google test is unable to detect this. - # Lets help them out and set the var ourselves. - if (CCMATH_COMPILER_INTEL) - set(HAVE_STD_REGEX ON CACHE BOOL "" FORCE) - endif () - - # PThreads are not available on Windows - # So tell gtest to not use them. - if(CCMATH_WINDOWS) - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - set(gtest_disable_pthreads ON CACHE BOOL "" FORCE) + if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + set(HAVE_STD_REGEX ON) endif() + if (WIN32) + set(gtest_force_shared_crt ON) + set(gtest_disable_pthreads ON) + endif() + set(BUILD_GMOCK OFF) + set(INSTALL_GTEST OFF) + set(gtest_build_samples OFF) + set(gtest_build_tests OFF) - set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) - set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) - set(gtest_build_samples OFF CACHE BOOL "" FORCE) - set(gtest_build_tests OFF CACHE BOOL "" FORCE) - - if(CCMATH_FIND_GTEST_PACKAGE) + if (CCMATH_FIND_GTEST_PACKAGE) find_package(GTest REQUIRED) else() FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 + GIT_TAG ${CCMATH_GTEST_VERSION} ) - FetchContent_MakeAvailable(googletest) - endif () - - add_library(gtest::gtest ALIAS gtest) + FetchContent_MakeAvailable(googletest) + if (NOT TARGET gtest::gtest) + add_library(gtest::gtest ALIAS gtest) + endif() + endif() endif() +FetchContent_MakeAvailable(benchmark) +# Create the INTERFACE library add_library(${PROJECT_NAME} INTERFACE) add_library(ccmath::ext ALIAS ${PROJECT_NAME}) -if(CCMATH_BUILD_TESTS) - target_link_libraries(${PROJECT_NAME} INTERFACE - gtest::gtest - ) -endif () - -if(CCMATH_BUILD_BENCHMARKS) - target_link_libraries(${PROJECT_NAME} INTERFACE - benchmark::benchmark - ) -endif () +# Link GTest only if tests are enabled +if (CCMATH_BUILD_TESTS) + target_link_libraries(${PROJECT_NAME} INTERFACE gtest::gtest) +endif() +# Link Google Benchmark only if benchmarks are enabled +if (CCMATH_BUILD_BENCHMARKS) + target_link_libraries(${PROJECT_NAME} INTERFACE benchmark::benchmark) +endif() From d6ebf917e453441a6743da3fed762d2d31d918f0 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 15:30:22 -0500 Subject: [PATCH 037/102] Major rework of cmake scripts and ci --- .github/workflows/ci-linux.yml | 121 +++-- .github/workflows/ci-macos.yml | 112 +++-- .github/workflows/ci-windows.yml | 78 +-- CMakeLists.txt | 96 +--- CMakePresets.json | 460 +++++++++++++----- cmake/config/GlobalConfig.cmake | 66 --- cmake/config/UserOptions.cmake | 80 +++ cmake/functions/CcmathMessage.cmake | 59 --- .../CcmAddHeaders.cmake | 0 9 files changed, 623 insertions(+), 449 deletions(-) delete mode 100644 cmake/config/GlobalConfig.cmake create mode 100644 cmake/config/UserOptions.cmake delete mode 100644 cmake/functions/CcmathMessage.cmake rename cmake/{functions => helpers}/CcmAddHeaders.cmake (100%) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 656fb4b1..6551e8c8 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -1,4 +1,5 @@ name: ci-linux + on: push: tags-ignore: @@ -18,57 +19,97 @@ jobs: strategy: fail-fast: false matrix: - compiler: [ninja-gcc, ninja-clang, ninja-clang-libcpp] - cxx_version: [17, 20] - target: [Debug, Release] - steps: - - name: Harden Runner - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 - with: - egress-policy: audit + include: + # GCC Debug + - name: gcc-debug + configurePreset: ninja-gcc-debug + buildPreset: build-ninja-gcc-debug + testPreset: test-ninja-gcc-debug + cxx_version: 17 - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - name: gcc-debug-cxx20 + configurePreset: ninja-gcc-debug + buildPreset: build-ninja-gcc-debug + testPreset: test-ninja-gcc-debug + cxx_version: 20 - - name: Cache CMake build files - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - with: - path: build - key: ${{ runner.os }}-cmake-${{ matrix.compiler }}-${{ matrix.cxx_version }}-${{ matrix.target }} - restore-keys: | - ${{ runner.os }}-cmake-${{ matrix.compiler }}-${{ matrix.cxx_version }}- - ${{ runner.os }}-cmake-${{ matrix.compiler }}- + # GCC Release + - name: gcc-release + configurePreset: ninja-gcc-release + buildPreset: build-ninja-gcc-release + testPreset: test-ninja-gcc-release + cxx_version: 17 - - name: install dependencies - run: sudo apt install -yqq --no-install-recommends ninja-build + - name: gcc-release-cxx20 + configurePreset: ninja-gcc-release + buildPreset: build-ninja-gcc-release + testPreset: test-ninja-gcc-release + cxx_version: 20 - - name: configure cmake - run: cmake -S . --preset=${{matrix.compiler}} -B build -DCMAKE_CXX_STANDARD=${{matrix.cxx_version}} + # Clang Debug + - name: clang-debug + configurePreset: ninja-clang-debug + buildPreset: build-ninja-clang-debug + testPreset: test-ninja-clang-debug + cxx_version: 17 - - name: build - run: cmake --build build --config=${{matrix.target}} + - name: clang-debug-cxx20 + configurePreset: ninja-clang-debug + buildPreset: build-ninja-clang-debug + testPreset: test-ninja-clang-debug + cxx_version: 20 + + # Clang Release + - name: clang-release + configurePreset: ninja-clang-release + buildPreset: build-ninja-clang-release + testPreset: test-ninja-clang-release + cxx_version: 17 + + - name: clang-release-cxx20 + configurePreset: ninja-clang-release + buildPreset: build-ninja-clang-release + testPreset: test-ninja-clang-release + cxx_version: 20 + + # Clang libcpp Release + - name: clang-libcpp-release + configurePreset: ninja-clang-libcpp-relwithdebinfo + buildPreset: build-ninja-clang-libcpp-relwithdebinfo + testPreset: test-ninja-clang-libcpp-relwithdebinfo + cxx_version: 17 + + - name: clang-libcpp-release-cxx20 + configurePreset: ninja-clang-libcpp-relwithdebinfo + buildPreset: build-ninja-clang-libcpp-relwithdebinfo + testPreset: test-ninja-clang-libcpp-relwithdebinfo + cxx_version: 20 - test: - runs-on: ubuntu-22.04 - needs: build - strategy: - fail-fast: false - matrix: - compiler: [ninja-gcc, ninja-clang, ninja-clang-libcpp] - cxx_version: [17, 20] - target: [Debug, Release] steps: - name: Harden Runner - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@v2.9.1 with: egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@v4 - - name: Cache CMake build files - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 + - name: Cache build + uses: actions/cache@v4 with: - path: build - key: ${{ runner.os }}-cmake-${{ matrix.compiler }}-${{ matrix.cxx_version }}-${{ matrix.target }} + path: | + ./**/CMakeFiles + ./**/CMakeCache.txt + ./**/out + key: ${{ runner.os }}-${{ matrix.name }} + + - name: Install dependencies + run: sudo apt-get update -qq && sudo apt-get install -yqq --no-install-recommends ninja-build + + - name: Configure + run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" + + - name: Build + run: cmake --build --preset="${{ matrix.buildPreset }}" - - name: test - run: cd build && ctest -C ${{matrix.target}} --output-on-failure + - name: Test + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index caf533c1..853e6c32 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -1,4 +1,5 @@ name: ci-macos + on: push: tags-ignore: @@ -18,63 +19,86 @@ jobs: strategy: fail-fast: false matrix: - compiler: [ninja-clang, ninja-gcc] - cxx_version: [17, 20] - target: [Debug, Release] - steps: - - name: Harden Runner - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 - with: - egress-policy: audit + include: + - name: clang-debug-cxx17 + configurePreset: ninja-clang-debug + buildPreset: build-ninja-clang-debug + testPreset: test-ninja-clang-debug + cxx_version: 17 - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - name: clang-debug-cxx20 + configurePreset: ninja-clang-debug + buildPreset: build-ninja-clang-debug + testPreset: test-ninja-clang-debug + cxx_version: 20 - - name: Cache CMake build files - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - with: - path: build - key: ${{ runner.os }}-cmake-${{ matrix.compiler }}-${{ matrix.cxx_version }}-${{ matrix.target }} - restore-keys: | - ${{ runner.os }}-cmake-${{ matrix.compiler }}-${{ matrix.cxx_version }}- - ${{ runner.os }}-cmake-${{ matrix.compiler }}- + - name: clang-release-cxx17 + configurePreset: ninja-clang-release + buildPreset: build-ninja-clang-release + testPreset: test-ninja-clang-release + cxx_version: 17 - - name: install homebrew formulae - run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + - name: clang-release-cxx20 + configurePreset: ninja-clang-release + buildPreset: build-ninja-clang-release + testPreset: test-ninja-clang-release + cxx_version: 20 - - name: install ninja - run: brew install ninja + - name: gcc-debug-cxx17 + configurePreset: ninja-gcc-debug + buildPreset: build-ninja-gcc-debug + testPreset: test-ninja-gcc-debug + cxx_version: 17 - - name: update AppleClang to 14.0.3 - run: sudo xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer + - name: gcc-debug-cxx20 + configurePreset: ninja-gcc-debug + buildPreset: build-ninja-gcc-debug + testPreset: test-ninja-gcc-debug + cxx_version: 20 - - name: configure - run: cmake -S . --preset=${{matrix.compiler}} -B build -DCMAKE_CXX_STANDARD=${{matrix.cxx_version}} + - name: gcc-release-cxx17 + configurePreset: ninja-gcc-release + buildPreset: build-ninja-gcc-release + testPreset: test-ninja-gcc-release + cxx_version: 17 - - name: build - run: cmake --build build --config=${{matrix.target}} + - name: gcc-release-cxx20 + configurePreset: ninja-gcc-release + buildPreset: build-ninja-gcc-release + testPreset: test-ninja-gcc-release + cxx_version: 20 - test: - runs-on: macos-14 - needs: build - strategy: - fail-fast: false - matrix: - compiler: [ninja-clang, ninja-gcc] - cxx_version: [17, 20] - target: [Debug, Release] steps: - name: Harden Runner - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@v2.9.1 with: egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@v4 - - name: Cache CMake build files - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 + - name: Cache build + uses: actions/cache@v4 with: - path: build - key: ${{ runner.os }}-cmake-${{ matrix.compiler }}-${{ matrix.cxx_version }}-${{ matrix.target }} + path: | + ./**/CMakeFiles + ./**/CMakeCache.txt + ./**/out + key: ${{ runner.os }}-${{ matrix.name }} + + - name: Install Homebrew + run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + - name: Install Ninja + run: brew install ninja + + - name: Update AppleClang to 14.0.3 + run: sudo xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer + + - name: Configure + run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" + + - name: Build + run: cmake --build --preset="${{ matrix.buildPreset }}" - - name: test - run: cd build && ctest -C ${{matrix.target}} --output-on-failure + - name: Test + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index cbc4c3b2..c3006528 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -1,4 +1,5 @@ name: ci-windows + on: push: tags-ignore: @@ -18,54 +19,53 @@ jobs: strategy: fail-fast: false matrix: - compiler: [vs22] - cxx_version: [17, 20] - target: [Debug, Release] - steps: - - name: Harden Runner - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 - with: - egress-policy: audit - - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + include: + - name: vs22-debug-cxx17 + configurePreset: vs22-debug + buildPreset: build-vs22-debug + testPreset: test-vs22-debug + cxx_version: 17 - - name: Cache CMake build files - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 - with: - path: build - key: ${{ runner.os }}-cmake-${{ matrix.compiler }}-${{ matrix.cxx_version }}-${{ matrix.target }} - restore-keys: | - ${{ runner.os }}-cmake-${{ matrix.compiler }}-${{ matrix.cxx_version }}- - ${{ runner.os }}-cmake-${{ matrix.compiler }}- + - name: vs22-debug-cxx20 + configurePreset: vs22-debug + buildPreset: build-vs22-debug + testPreset: test-vs22-debug + cxx_version: 20 - - name: configure - run: cmake -S . --preset=${{matrix.compiler}} -B build -DCMAKE_CXX_STANDARD=${{matrix.cxx_version}} + - name: vs22-release-cxx17 + configurePreset: vs22-release + buildPreset: build-vs22-release + testPreset: test-vs22-release + cxx_version: 17 - - name: build - run: cmake --build build --config=${{matrix.target}} + - name: vs22-release-cxx20 + configurePreset: vs22-release + buildPreset: build-vs22-release + testPreset: test-vs22-release + cxx_version: 20 - test: - runs-on: windows-2022 - needs: build - strategy: - fail-fast: false - matrix: - compiler: [vs22] - cxx_version: [17, 20] - target: [Debug, Release] steps: - name: Harden Runner - uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1 + uses: step-security/harden-runner@v2.9.1 with: egress-policy: audit - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/checkout@v4 - - name: Cache CMake build files - uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 + - name: Cache build + uses: actions/cache@v4 with: - path: build - key: ${{ runner.os }}-cmake-${{ matrix.compiler }}-${{ matrix.cxx_version }}-${{ matrix.target }} + path: | + ./**/CMakeFiles + ./**/CMakeCache.txt + ./**/out + key: ${{ runner.os }}-${{ matrix.name }} + + - name: Configure + run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" + + - name: Build + run: cmake --build --preset="${{ matrix.buildPreset }}" - - name: test - run: cd build && ctest -C ${{matrix.target}} --output-on-failure + - name: Test + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure diff --git a/CMakeLists.txt b/CMakeLists.txt index 44e7a526..dd4d9500 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,82 +19,18 @@ if (NOT CCMATH_SOURCE_DIR) set(CCMATH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) endif () -# TODO: Change this to instead use cmakes more modern target_compile_features +# TODO: Possibly change this to instead use cmakes more modern target_compile_features +# TODO: Changing this to use target_compile_features will require adjustments of the CI set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -message(STATUS "CCMath version: ${PROJECT_VERSION}") +message(STATUS "CCMath: Version: ${PROJECT_VERSION}") # # User-facing options # - -# CCMATH_INSTALL: -# Controls whether installation and packaging steps are configured. -# If this is the root project (standalone), default to ON. -# If this project is included as a subproject, default to OFF. -option(CCMATH_INSTALL "Setup install and package steps" ${is_root_project}) - -# CCMATH_BUILD_TESTS: -# Enable building of ccmath tests. If OFF, tests are skipped. Should only be used by ccmath developers. -option(CCMATH_BUILD_TESTS "Build ccmath tests" ${is_root_project}) - -# CCMATH_FIND_GTEST_PACKAGE: -# Look for gtest package rather than downloading it if needed. -option(CCMATH_FIND_GTEST_PACKAGE "Enable finding of gtest package" OFF) - -# CCMATH_BUILD_BENCHMARKS: -# Enable building of ccmath benchmarks. If OFF, benchmarks are skipped. -option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project}) - -# CCMATH_FIND_GBENCH_PACKAGE: -# Look for google benchmark package rather than downloading it if needed. Should only be used by ccmath developers. -option(CCMATH_FIND_GBENCH_PACKAGE "Enable finding of google benchmark package" OFF) - -# CCMATH_BUILD_EXAMPLES: -# Build example code demonstrating usage of ccmath. -option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project}) - -# CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS: -# Allow users to supply their own optimization macros rather than CCMath defining them itself. -option(CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS - "Enable user defined optimization macros instead of having ccmath define its own" - OFF) - -# CCMATH_ENABLE_EXTENSIONS: -# Enable non-standard extensions that go beyond the interface. -option(CCMATH_ENABLE_EXTENSIONS - "Enable the extended ccmath library that adds additional methods beyond the standard" - OFF) - -# CCMATH_DISABLE_ERRNO: -# Disable usage of errno during runtime breaking standard compliance, but may lead to faster evaluation and smaller binaries. -option(CCMATH_DISABLE_ERRNO - "Disable the use of errno in ccmath during runtime (may lead to faster evaluations but is non-standard)" - OFF) - -# CCMATH_ENABLE_RUNTIME_SIMD: -# Enable runtime SIMD optimizations for faster evaluations at runtime. -option(CCMATH_ENABLE_RUNTIME_SIMD - "Enable SIMD optimization for runtime evaluation (does not affect compile-time)" - ON) - -# CCMATH_DISABLE_SVML_USAGE: -# Disable the use of SVML (Short Vector Math Library) if supported by the compiler. -option(CCMATH_DISABLE_SVML_USAGE - "Disable the use of SVML functions in ccmath (if supported by compiler)" - OFF) - -# CCMATH_STRICT_WARNINGS: -# Enable strict warning handling, turning certain warnings into errors. -# This might be intrusive for downstream users, so disable if we are not the root project. -option(CCMATH_STRICT_WARNINGS - "Enable strict warnings and treat certain warnings as errors. May be intrusive downstream." - ${is_root_project}) - -# Include global configuration -include(cmake/config/GlobalConfig.cmake) +include(cmake/config/UserOptions.cmake) # To see the options, look at this file add_library(${PROJECT_NAME}-compile-options INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME}-compile-options ALIAS ${PROJECT_NAME}-compile-options) @@ -105,7 +41,7 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME}-compile-options ALIAS ${PROJECT_NAM if (MSVC) # MSVC-specific options target_compile_options(${PROJECT_NAME}-compile-options INTERFACE - /W3 + /W4 /permissive- /Zc:__cplusplus /D_ENABLE_EXTENDED_ALIGNED_STORAGE @@ -129,24 +65,23 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" -Wall -Wextra -Wconversion - -Wno-pedantic - -ffp-contract=fast + -Wpedantic # Define NOMINMAX only on Windows to avoid conflicts with min/max macros $<$:-DNOMINMAX> - -Wno-unused-but-set-variable - -Wno-unused-value - -Wno-unused-parameter + #-Wno-unused-but-set-variable + #-Wno-unused-value + #-Wno-unused-parameter ) if (CCMATH_STRICT_WARNINGS) target_compile_options(${PROJECT_NAME}-compile-options INTERFACE -Werror=return-type) endif () - if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") - target_compile_options(${PROJECT_NAME}-compile-options INTERFACE - -Wno-tautological-constant-compare - ) - endif() +# if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") +# target_compile_options(${PROJECT_NAME}-compile-options INTERFACE +# -Wno-tautological-constant-compare +# ) +# endif() else() message(WARNING "CCMath: Unknown compiler. No specific flags applied.") @@ -155,8 +90,7 @@ endif() add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -include(cmake/functions/CcmathMessage.cmake) -include(cmake/functions/CcmAddHeaders.cmake) +include(cmake/helpers/CcmAddHeaders.cmake) # Add public headers through a directory-level CMakeLists that sets variables, etc. add_subdirectory(include/ccmath) diff --git a/CMakePresets.json b/CMakePresets.json index 09152f76..adb249eb 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,216 +2,436 @@ "version": 2, "cmakeMinimumRequired": { "major": 3, - "minor": 20, + "minor": 18, "patch": 0 }, "configurePresets": [ { - "name": "default", - "description": "Build configuration using Ninja Multi-config", + "name": "base", + "description": "Base configuration using Ninja Multi-config", "generator": "Ninja Multi-Config", - "binaryDir": "${sourceDir}/out/default", + "hidden": true, + "binaryDir": "${sourceDir}/out/build/ninja/${presetName}", "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", + "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", + "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;MinSizeRel", + "CMAKE_CXX_STANDARD": "17" } }, { - "name": "ninja-gcc", - "description": "Build configuration using Ninja Multi-config / gcc", - "inherits": "default", - "binaryDir": "${sourceDir}/out/gcc", + "name": "base-vs19", + "description": "Base configuration using Visual Studio 16 (2019)", + "generator": "Visual Studio 16 2019", + "hidden": true, + "binaryDir": "${sourceDir}/out/build/vs19/${presetName}", + "architecture": { + "value": "x64", + "strategy": "external" + }, "cacheVariables": { - "CMAKE_C_COMPILER": "gcc", - "CMAKE_CXX_COMPILER": "g++" + "CMAKE_CXX_STANDARD": "17" } }, { - "name": "ninja-gcc-minsize", - "description": "Build configuration using Ninja Multi-config / gcc", - "inherits": "ninja-gcc", - "binaryDir": "${sourceDir}/out/gcc-minsize", + "name": "base-vs22", + "description": "Base configuration using Visual Studio 17 (2022)", + "generator": "Visual Studio 17 2022", + "hidden": true, + "binaryDir": "${sourceDir}/out/build/vs22/${presetName}", + "architecture": { + "value": "x64", + "strategy": "external" + }, "cacheVariables": { - "CMAKE_C_COMPILER": "gcc", - "CMAKE_CXX_COMPILER": "g++", - "CMAKE_CXX_FLAGS": "-Os" + "CMAKE_CXX_STANDARD": "17" } }, { - "name": "ninja-clang", - "description": "Build configuration using Ninja Multi-config / clang", - "inherits": "default", - "binaryDir": "${sourceDir}/out/clang", + "name": "Debug", + "hidden": true, "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++" + "CMAKE_BUILD_TYPE": "Debug" } }, { - "name": "ninja-clang-minsize", - "description": "Build configuration using Ninja Multi-config / clang", - "inherits": "ninja-clang", - "binaryDir": "${sourceDir}/out/clang-minsize", + "name": "Release", + "hidden": true, "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++", - "CMAKE_CXX_FLAGS": "-Os" + "CMAKE_BUILD_TYPE": "RelWithDebInfo" } }, { - "name": "ninja-clang-libcpp", - "description": "Build configuration using Ninja Multi-config / clang", - "inherits": "default", - "binaryDir": "${sourceDir}/out/clang-libcpp", + "name": "MinSizeRel", + "hidden": true, "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++", - "CMAKE_CXX_FLAGS": "-stdlib=libc++", - "CMAKE_EXE_LINKER_FLAGS": "-lc++abi" + "CMAKE_BUILD_TYPE": "MinSizeRel" } }, { - "name": "ninja-intel", - "description": "Build configuration using Ninja Multi-config / intel", - "inherits": "default", - "binaryDir": "${sourceDir}/out/intel", + "name": "RelWithDebInfo", + "hidden": true, "cacheVariables": { - "CMAKE_C_COMPILER": "icx", - "CMAKE_CXX_COMPILER": "icpx" + "CMAKE_BUILD_TYPE": "RelWithDebInfo" } }, { - "name": "ninja-nvidia-hpc", - "description": "Build configuration using Ninja Multi-config / nvidia-hpc", - "inherits": "default", - "binaryDir": "${sourceDir}/out/nvidia-hpc", + "name": "ccache", + "hidden": true, "cacheVariables": { - "CMAKE_C_COMPILER": "nvc", - "CMAKE_CXX_COMPILER": "nvc++" + "CMAKE_C_COMPILER_LAUNCHER": "ccache", + "CMAKE_CXX_COMPILER_LAUNCHER": "ccache" } }, { - "name": "ninja-ubsan", - "description": "UBSan build configuration using Ninja Multi-config", - "inherits": "default", - "binaryDir": "${sourceDir}/out/ubsan", + "name": "gcc", + "hidden": true, "cacheVariables": { - "CMAKE_CXX_FLAGS": "-fsanitize=undefined" + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" } }, { - "name": "clang-tidy", - "description": "UBSan build configuration using Ninja Multi-config", - "inherits": "ninja-clang", - "binaryDir": "${sourceDir}/out/clang-tidy", + "name": "clang", + "hidden": true, "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "On" + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" } }, { - "name": "vs19", - "description": "Build configuration using Visual Studio 16 (2019)", - "generator": "Visual Studio 16 2019", - "binaryDir": "${sourceDir}/out/vs", - "architecture": { - "value": "x64", - "strategy": "external" + "name": "clang-libcpp", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_CXX_FLAGS": "-stdlib=libc++", + "CMAKE_EXE_LINKER_FLAGS": "-lc++abi" } }, { - "name": "vs22", - "description": "Build configuration using Visual Studio 17 (2022)", - "inherits": "vs19", - "generator": "Visual Studio 17 2022" + "name": "msvc", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl" + } }, { - "name": "benchmark-default", - "description": "Benchmark build configuration using Ninja Multi-config", - "inherits": "default", - "binaryDir": "${sourceDir}/out/benchmark", + "name": "msvc-clang", + "hidden": true, "cacheVariables": { - "CCMATH_BUILD_BENCHMARKS": "ON", - "CCMATH_BUILD_TESTS": "OFF", - "CCMATH_BUILD_EXAMPLES": "OFF" + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" } + }, + { + "name": "intel", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "icx", + "CMAKE_CXX_COMPILER": "icpx" + } + }, + { + "name": "ninja-gcc-debug", + "inherits": [ + "base", + "gcc", + "Debug" + ], + "description": "Ninja Multi-config + GCC (Debug)" + }, + { + "name": "ninja-gcc-release", + "inherits": [ + "base", + "gcc", + "Release" + ], + "description": "Ninja Multi-config + GCC (RelWithDebInfo)" + }, + { + "name": "ninja-gcc-ccache-debug", + "inherits": [ + "base", + "ccache", + "gcc", + "Debug" + ], + "description": "Ninja Multi-config + GCC + ccache (Debug)" + }, + { + "name": "ninja-clang-debug", + "inherits": [ + "base", + "clang", + "Debug" + ], + "description": "Ninja Multi-config + Clang (Debug)" + }, + { + "name": "ninja-clang-release", + "inherits": [ + "base", + "clang", + "Release" + ], + "description": "Ninja Multi-config + Clang (RelWithDebInfo)" + }, + { + "name": "ninja-clang-minsizerel", + "inherits": [ + "base", + "clang", + "MinSizeRel" + ], + "description": "Ninja Multi-config + Clang (MinSizeRel)" + }, + { + "name": "ninja-clang-libcpp-relwithdebinfo", + "inherits": [ + "base", + "clang-libcpp", + "RelWithDebInfo" + ], + "description": "Ninja + Clang + libc++ (RelWithDebInfo)" + }, + { + "name": "ninja-intel-relwithdebinfo", + "inherits": [ + "base", + "intel", + "RelWithDebInfo" + ], + "description": "Ninja + Intel (RelWithDebInfo)" + }, + { + "name": "vs19-debug", + "inherits": [ + "base-vs19", + "Debug" + ], + "description": "VS2019 + Debug" + }, + { + "name": "vs19-release", + "inherits": [ + "base-vs19", + "Release" + ], + "description": "VS2019 + RelWithDebInfo" + }, + { + "name": "vs22-debug", + "inherits": [ + "base-vs22", + "Debug" + ], + "description": "VS2022 + Debug" + }, + { + "name": "vs22-release", + "inherits": [ + "base-vs22", + "Release" + ], + "description": "VS2022 + RelWithDebInfo" + }, + { + "name": "vs22-clang-debug", + "inherits": [ + "base-vs22", + "msvc-clang", + "Debug" + ], + "description": "VS2022 + clang-cl (Debug)" } ], "buildPresets": [ { - "name": "Debug", - "configurePreset": "default", - "configuration": "Debug" + "name": "build-ninja-gcc-debug", + "configurePreset": "ninja-gcc-debug", + "configuration": "Debug", + "targets": [ + "all" + ] }, { - "name": "Debug-gcc", - "configurePreset": "ninja-gcc", - "configuration": "Debug" + "name": "build-ninja-gcc-release", + "configurePreset": "ninja-gcc-release", + "configuration": "RelWithDebInfo", + "targets": [ + "all" + ] }, { - "name": "Debug-clang", - "configurePreset": "ninja-clang", - "configuration": "Debug" + "name": "build-ninja-gcc-ccache-debug", + "configurePreset": "ninja-gcc-ccache-debug", + "configuration": "Debug", + "targets": [ + "all" + ] }, { - "name": "Release", - "configurePreset": "default", - "configuration": "Release" + "name": "build-ninja-clang-debug", + "configurePreset": "ninja-clang-debug", + "configuration": "Debug", + "targets": [ + "all" + ] }, { - "name": "Release-gcc", - "configurePreset": "ninja-gcc", - "configuration": "Release" + "name": "build-ninja-clang-release", + "configurePreset": "ninja-clang-release", + "configuration": "RelWithDebInfo", + "targets": [ + "all" + ] }, { - "name": "Release-clang", - "configurePreset": "ninja-clang", - "configuration": "Release" + "name": "build-ninja-clang-minsizerel", + "configurePreset": "ninja-clang-minsizerel", + "configuration": "MinSizeRel", + "targets": [ + "all" + ] }, { - "name": "RelWithDebInfo", - "configurePreset": "default", - "configuration": "RelWithDebInfo" + "name": "build-ninja-clang-libcpp-relwithdebinfo", + "configurePreset": "ninja-clang-libcpp-relwithdebinfo", + "configuration": "RelWithDebInfo", + "targets": [ + "all" + ] }, { - "name": "RelWithDebInfo-gcc", - "configurePreset": "ninja-gcc", - "configuration": "RelWithDebInfo" + "name": "build-ninja-intel-relwithdebinfo", + "configurePreset": "ninja-intel-relwithdebinfo", + "configuration": "RelWithDebInfo", + "targets": [ + "all" + ] }, { - "name": "RelWithDebInfo-clang", - "configurePreset": "ninja-clang", - "configuration": "RelWithDebInfo" + "name": "build-vs19-debug", + "configurePreset": "vs19-debug", + "configuration": "Debug", + "targets": [ + "ALL_BUILD" + ] }, { - "name": "Benchmark", - "configurePreset": "benchmark-default", - "configuration": "Release" + "name": "build-vs19-release", + "configurePreset": "vs19-release", + "configuration": "RelWithDebInfo", + "targets": [ + "ALL_BUILD" + ] + }, + { + "name": "build-vs22-debug", + "configurePreset": "vs22-debug", + "configuration": "Debug", + "targets": [ + "ALL_BUILD" + ] + }, + { + "name": "build-vs22-release", + "configurePreset": "vs22-release", + "configuration": "RelWithDebInfo", + "targets": [ + "ALL_BUILD" + ] + }, + { + "name": "build-vs22-clang-debug", + "configurePreset": "vs22-clang-debug", + "configuration": "Debug", + "targets": [ + "ALL_BUILD" + ] } - ], "testPresets": [ { - "name": "Debug", - "configurePreset": "default", + "name": "test-ninja-gcc-debug", + "configurePreset": "ninja-gcc-debug", "configuration": "Debug", "inheritConfigureEnvironment": true }, { - "name": "Release", - "configurePreset": "default", - "configuration": "Release", + "name": "test-ninja-gcc-release", + "configurePreset": "ninja-gcc-release", + "configuration": "RelWithDebInfo", "inheritConfigureEnvironment": true }, { - "name": "Release-clang", - "configurePreset": "ninja-clang", - "configuration": "Release", + "name": "test-ninja-gcc-ccache-debug", + "configurePreset": "ninja-gcc-ccache-debug", + "configuration": "Debug", "inheritConfigureEnvironment": true }, { - "name": "RelWithDebInfo", - "configurePreset": "default", + "name": "test-ninja-clang-debug", + "configurePreset": "ninja-clang-debug", + "configuration": "Debug", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-clang-release", + "configurePreset": "ninja-clang-release", + "configuration": "RelWithDebInfo", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-clang-minsizerel", + "configurePreset": "ninja-clang-minsizerel", + "configuration": "MinSizeRel", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-clang-libcpp-relwithdebinfo", + "configurePreset": "ninja-clang-libcpp-relwithdebinfo", + "configuration": "RelWithDebInfo", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-intel-relwithdebinfo", + "configurePreset": "ninja-intel-relwithdebinfo", + "configuration": "RelWithDebInfo", + "inheritConfigureEnvironment": true + }, + { + "name": "test-vs19-debug", + "configurePreset": "vs19-debug", + "configuration": "Debug", + "inheritConfigureEnvironment": true + }, + { + "name": "test-vs19-release", + "configurePreset": "vs19-release", + "configuration": "RelWithDebInfo", + "inheritConfigureEnvironment": true + }, + { + "name": "test-vs22-debug", + "configurePreset": "vs22-debug", + "configuration": "Debug", + "inheritConfigureEnvironment": true + }, + { + "name": "test-vs22-release", + "configurePreset": "vs22-release", "configuration": "RelWithDebInfo", "inheritConfigureEnvironment": true + }, + { + "name": "test-vs22-clang-debug", + "configurePreset": "vs22-clang-debug", + "configuration": "Debug", + "inheritConfigureEnvironment": true } ] } diff --git a/cmake/config/GlobalConfig.cmake b/cmake/config/GlobalConfig.cmake deleted file mode 100644 index 39d59d7a..00000000 --- a/cmake/config/GlobalConfig.cmake +++ /dev/null @@ -1,66 +0,0 @@ -include(cmake/functions/CcmathMessage.cmake) - -# detect our OS -if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - set(CCMATH_OS_WINDOWS 1) -elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - set(CCMATH_OS_LINUX 1) -elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - set(CCMATH_OS_MACOS 1) -elseif(CMAKE_SYSTEM_NAME MATCHES "^k?FreeBSD$") - set(CCMATH_OS_FREEBSD 1) -elseif(CMAKE_SYSTEM_NAME MATCHES "^OpenBSD$") - set(CCMATH_OS_OPENBSD 1) -elseif(CMAKE_SYSTEM_NAME MATCHES "^NetBSD$") - set(CCMATH_OS_NETBSD 1) -else() - message(WARNING "Mim could not detected a know supported OS you may experience UB or crashes: ${CMAKE_SYSTEM_NAME}") - message(WARNING "Please report any bugs you encounter and the OS you are using to the ccmath developers!") -endif() - - -# detect the compiler -# Note: The detection order is important because: -# - Visual Studio can both use MSVC and Clang -# - GNUCXX can still be set on macOS when using Clang -if(MSVC) - set(CCMATH_COMPILER_MSVC 1) - # Identify if we are using clang-CL - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CCMATH_COMPILER_CLANG_CL 1) - endif() - -elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CCMATH_COMPILER_CLANG 1) -elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") - set(CCMATH_COMPILER_INTEL 1) -elseif (CMAKE_CXX_COMPILER_ID MATCHES "NVHPC") - set(CCMATH_COMPILER_NVIDIA_HPC 1) -elseif(CMAKE_COMPILER_IS_GNUCXX) - set(CCMATH_COMPILER_GCC 1) - - execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "--version" OUTPUT_VARIABLE GCC_COMPILER_VERSION) - string(REGEX MATCHALL ".*(tdm[64]*-[1-9]).*" CCMATH_COMPILER_GCC_TDM "${GCC_COMPILER_VERSION}") -else() - message(WARNING "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}") - return() -endif() - - -# detect the architecture (note: this test won't work for cross-compilation) -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(CCMATH_ARCH_X64 1) -elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(CCMATH_ARCH_X86 1) -elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^armv7") - set(CCMATH_ARCH_ARM 1) -elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") - set(CCMATH_ARCH_ARM64 1) -else() - message(FATAL_ERROR "Unsupported architecture") - return() -endif() - -message(STATUS "CCMake Detected OS: ${CMAKE_SYSTEM_NAME}") -message(STATUS "CCMake Detected Compiler: ${CMAKE_CXX_COMPILER_ID}") -message(STATUS "CCMake Detected Architecture: ${CMAKE_SYSTEM_PROCESSOR}") diff --git a/cmake/config/UserOptions.cmake b/cmake/config/UserOptions.cmake new file mode 100644 index 00000000..ba91db49 --- /dev/null +++ b/cmake/config/UserOptions.cmake @@ -0,0 +1,80 @@ +# CCMATH_INSTALL: +# Controls whether installation and packaging steps are configured. +# If this is the root project (standalone), default to ON. +# If this project is included as a subproject, default to OFF. +option(CCMATH_INSTALL "Setup install and package steps" ${is_root_project}) + +# CCMATH_BUILD_TESTS: +# Enable building of ccmath tests. If OFF, tests are skipped. Should only be used by ccmath developers. +option(CCMATH_BUILD_TESTS "Build ccmath tests" ${is_root_project}) + +# CCMATH_FIND_GTEST_PACKAGE: +# Look for gtest package rather than downloading it if needed. +option(CCMATH_FIND_GTEST_PACKAGE "Enable finding of gtest package" OFF) + +# CCMATH_BUILD_BENCHMARKS: +# Enable building of ccmath benchmarks. If OFF, benchmarks are skipped. +option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project}) + +# CCMATH_FIND_GBENCH_PACKAGE: +# Look for google benchmark package rather than downloading it if needed. Should only be used by ccmath developers. +option(CCMATH_FIND_GBENCH_PACKAGE "Enable finding of google benchmark package" OFF) + +# CCMATH_BUILD_EXAMPLES: +# Build example code demonstrating usage of ccmath. +option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project}) + +# CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS: +# Allow users to supply their own optimization macros rather than CCMath defining them itself. +option(CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS + "Enable user defined optimization macros instead of having ccmath define its own" + OFF) + +# CCMATH_ENABLE_EXTENSIONS: +# Enable non-standard extensions that go beyond the interface. +option(CCMATH_ENABLE_EXTENSIONS + "Enable the extended ccmath library that adds additional methods beyond the standard" + OFF) + +# CCMATH_DISABLE_ERRNO: +# Disable usage of errno during runtime breaking standard compliance, but may lead to faster evaluation and smaller binaries. +option(CCMATH_DISABLE_ERRNO + "Disable the use of errno in ccmath during runtime (may lead to faster evaluations but is non-standard)" + OFF) + +# CCMATH_ENABLE_RUNTIME_SIMD: +# Enable runtime SIMD optimizations for faster evaluations at runtime. +option(CCMATH_ENABLE_RUNTIME_SIMD + "Enable SIMD optimization for runtime evaluation (does not affect compile-time)" + ON) + +# CCMATH_DISABLE_SVML_USAGE: +# Disable the use of SVML (Short Vector Math Library) if supported by the compiler. +option(CCMATH_DISABLE_SVML_USAGE + "Disable the use of SVML functions in ccmath (if supported by compiler)" + OFF) + +# CCMATH_DISABLE_CMAKE_FEATURE_CHECKS: +# Disable cmakes ability to check for certain features at the CMake level. +option(CCMATH_DISABLE_CMAKE_FEATURE_CHECKS + "Disable the ability for CCMath to check for certain features at the CMake level" + OFF) + +# CCMATH_DISABLE_CMAKE_SIMD_CHECKS: +# Disable cmakes ability to check for certain SIMD features at the CMake level. +option(CCMATH_DISABLE_CMAKE_SIMD_CHECKS + "Disable the ability for CCMath to check for SIMD features at the CMake level" + OFF) + +# CCMATH_DISABLE_CMAKE_BUILTIN_CHECKS: +# Disable cmakes ability to check for certain builtin functions at the CMake level. +option(CCMATH_DISABLE_CMAKE_BUILTIN_CHECKS + "Disable the ability for CCMath to check for builtin functions at the CMake level" + OFF) + +# CCMATH_STRICT_WARNINGS: +# Enable strict warning handling, turning certain warnings into errors. +# This might be intrusive for downstream users, so disable if we are not the root project. +option(CCMATH_STRICT_WARNINGS + "Enable strict warnings and treat certain warnings as errors. May be intrusive downstream." + ${is_root_project}) diff --git a/cmake/functions/CcmathMessage.cmake b/cmake/functions/CcmathMessage.cmake deleted file mode 100644 index 2dc632eb..00000000 --- a/cmake/functions/CcmathMessage.cmake +++ /dev/null @@ -1,59 +0,0 @@ -macro(ccmath_message_color NAME) - ccmath_message(COLOR ${NAME} " ${NAME}") -endmacro() - -function(internal_ccmath_colored_text) - cmake_parse_arguments(PARSE_ARGV 0 "_TEXT" "BOLD" "COLOR" "") - - set(_TEXT_OPTIONS -E cmake_echo_color --no-newline) - - if (_TEXT_COLOR) - string(TOLOWER "${_TEXT_COLOR}" _TEXT_COLOR_LOWER) - if (_TEXT_COLOR_LOWER STREQUAL "warning") - set(_TEXT_COLOR_LOWER "yellow") - endif () - if (NOT ${_TEXT_COLOR_LOWER} MATCHES "^default|black|red|green|yellow|warning|blue|magenta|cyan|white") - ccmath_message("Only these colours are supported:") - ccmath_message_color(DEFAULT) - ccmath_message_color(BLACK) - ccmath_message_color(RED) - ccmath_message_color(GREEN) - ccmath_message_color(YELLOW) - ccmath_message_color(WARNING) - ccmath_message_color(BLUE) - ccmath_message_color(MAGENTA) - ccmath_message_color(CYAN) - ccmath_message_color(WHITE) - TEXT(WARING "Color ${_TEXT_COLOR} is not support.") - else () - list(APPEND _TEXT_OPTIONS --${_TEXT_COLOR_LOWER}) - endif () - endif () - - if (_TEXT_BOLD) - list(APPEND _TEXT_OPTIONS --bold) - endif () - - execute_process(COMMAND ${CMAKE_COMMAND} -E env CLICOLOR_FORCE=1 ${CMAKE_COMMAND} ${_TEXT_OPTIONS} "-- " ${_TEXT_UNPARSED_ARGUMENTS} - OUTPUT_VARIABLE _TEXT_RESULT - ECHO_ERROR_VARIABLE - ) - - set(TEXT_RESULT ${_TEXT_RESULT} PARENT_SCOPE) -endfunction() -unset(ccmath_message_color) - -function(internal_ccmath_normal_text) - cmake_parse_arguments(PARSE_ARGV 0 "_TEXT" "BOLD" "COLOR" "") - set(TEXT_RESULT ${_TEXT_UNPARSED_ARGUMENTS} PARENT_SCOPE) -endfunction() - -function(ccmath_message) - if (DEFINED CCMATH_CMAKE_DEBUG AND CCMATH_CMAKE_DEBUG STREQUAL "ON") - internal_ccmath_colored_text(${ARGN}) - message(${TEXT_RESULT}) - else () - internal_ccmath_normal_text(${ARGN}) - message(STATUS ${TEXT_RESULT}) - endif () -endfunction() diff --git a/cmake/functions/CcmAddHeaders.cmake b/cmake/helpers/CcmAddHeaders.cmake similarity index 100% rename from cmake/functions/CcmAddHeaders.cmake rename to cmake/helpers/CcmAddHeaders.cmake From 2511661abb70bdd2713b0fd4f19ac9980cf35695 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 15:32:36 -0500 Subject: [PATCH 038/102] Remove explicit setting of appleclang version --- .github/workflows/ci-macos.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 853e6c32..180ee2dd 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -91,9 +91,6 @@ jobs: - name: Install Ninja run: brew install ninja - - name: Update AppleClang to 14.0.3 - run: sudo xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer - - name: Configure run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" From f1189277be770a0f828072df4d86c63a362014b1 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 16:04:23 -0500 Subject: [PATCH 039/102] Update licensing to include LLVM licensing --- LICENSE | 288 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) diff --git a/LICENSE b/LICENSE index 5bed1467..96d01e5c 100644 --- a/LICENSE +++ b/LICENSE @@ -217,3 +217,291 @@ conflicts with the conditions of the GPLv2, you may retroactively and prospectively choose to deem waived or otherwise exclude such Section(s) of the License, but only in their entirety and only with respect to the Combined Software. + +================================================================================================================================================================== +PORTIONS OF CCMATH ARE BASED ON OR DERIVED FROM THE WORK OF THE LLVM TEAM AS SUCH THE FOLLOWING LICENSE ALSO APPLIES: +CCMATH AND LLVM ARE BOTH UNDER THE APACHE LICENSE V2.0 WITH LLVM EXCEPTION SO THIS HAS NO FUNCTIONAL CHANGE TO LICENSE TERMS: +CCMATH WOULD ALSO LIKE TO THANK THE LLVM TEAM FOR THEIR WORK AND CONTRIBUTIONS TO THE OPEN SOURCE COMMUNITY. +MUCH OF THE WORK IN CCMATH WOULD NOT OF BEEN POSSIBLE WITHOUT THE LLVM TEAM'S WORK AND CONTRIBUTIONS WITHOUT SIGNIFICANTLY MORE EFFORT FROM THE CCMATH TEAM. +THIRD PARTY LICENSES THAT APPLY TO LLVM LIKELY WON'T APPLY TO CCMATH DUE TO LIMITED USE OF LLVM CODE IN CCMATH. +MAJORITY OF WORK FROM LLVM USED IN CCMATH IS DERIVED FROM LIBC. +================================================================================================================================================================== + +============================================================================== +The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: +============================================================================== + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + +============================================================================== +Software from third parties included in the LLVM Project: +============================================================================== +The LLVM Project contains third party software which is under different license +terms. All such code will be identified clearly using at least one of two +mechanisms: +1) It will be in a separate directory tree with its own `LICENSE.txt` or + `LICENSE` file at the top containing the specific license and restrictions + which apply to that software, or +2) It will contain specific license and restriction terms at the top of every + file. + +============================================================================== +Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): +============================================================================== +University of Illinois/NCSA +Open Source License + +Copyright (c) 2003-2019 University of Illinois at Urbana-Champaign. +All rights reserved. + +Developed by: + + LLVM Team + + University of Illinois at Urbana-Champaign + + http://llvm.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimers. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimers in the + documentation and/or other materials provided with the distribution. + + * Neither the names of the LLVM Team, University of Illinois at + Urbana-Champaign, nor the names of its contributors may be used to + endorse or promote products derived from this Software without specific + prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +SOFTWARE. From 510b9c610431d15c0acd3e812886b065f6debc09 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 16:04:46 -0500 Subject: [PATCH 040/102] Improve contributing doc --- CONTRIBUTING.md | 214 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 157 insertions(+), 57 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 353f93d0..640fb772 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,29 +3,30 @@ > [!IMPORTANT] > Currently the contribution guidelines are a work in progress. Please check back later for more information. - # Contributing to CCMath First off, thanks for taking the time to contribute! ❤️ All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions. 🎉 -> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about: -> - Star the project -> - Refer this project in your project's readme -> - Mention the project at local meetups and tell your friends/colleagues +If you enjoy this project but don’t have the time or ability to contribute code, you can still show your support in the following ways: +- Star the repository +- Mention this project in your own project's documentation +- Share this project on social media or at community meetups + - ## Table of Contents - [I Have a Question](#i-have-a-question) - [I Want To Contribute](#i-want-to-contribute) -- [Your First Code Contribution](#your-first-code-contribution) + - [Core Tenets of CCMath](#core-tenets-of-ccmath) + - [Your First Code Contribution](#your-first-code-contribution) - [How to manually build CCMath with the command line](#how-to-manually-build-ccmath-with-the-command-line) - [Prerequisites](#prerequisites) - [How to clone project from GitHub](#how-to-clone-project-from-github) - [How to build the project](#how-to-build-the-project) - [How to run tests](#how-to-run-tests) +- [Additional Notes](#additional-notes) ## I Have a Question @@ -45,28 +46,93 @@ We will then take care of the issue as soon as possible. ## I Want To Contribute -> ### Legal Notice -> When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license. +> **Legal Notice** +> By contributing to this project, you agree that: +> - You have authored 100% of the content, or the content is compatible with the project’s license and is marked as such +> - You have the rights necessary to share the content +> - The content may be provided under the project’s license -***Before any code can be written consider these core tenets of CCMath as you work on the project.*** +***Before any code can be written, consider these core tenets of CCMath as you work on the project.*** ### Core Tenets of CCMath -* At all times should code produced for CCMath be evaluable at compile time. (e.g. `constexpr` & `static_assert`) -* Always aim to have the same output as the standard. Never compromise on accuracy. -* Always aim to have speed's comparable to the standard. (Aim for being no slower than 1/2 the speed of the standard if possible) -* Always aim to have your code work with `static_assert`. -* At all times should you prefer a generic solution over a platform dependent solution if possible. -* You should always mimic the behavior of every compiler we support. (This is most visible in `ccm::fpclassify`) -* Always have a comprehensive test suite for your implementation that covers all edge cases. -* Ensure your code is always properly documented with doxygen in a detailed manner. -* Always have the same API layout as the standard. (This can be cross-referenced from [cppreference](https://en.cppreference.com/w/)) +1. Code should be evaluable at compile time when possible and great effort should be taken to comply with this (e.g., `constexpr` and `static_assert`). +2. Match the behavior of the standard library as closely as possible, with no compromises on accuracy. +3. Strive for performance comparable to (or no worse than half the speed of) the standard library. +4. Ensure code can work with `static_assert`. +5. Favor generic solutions over platform-specific ones, when possible. +6. Mimic the behavior of compilers we support (particularly relevant for `ccm::fpclassify`). +7. Provide comprehensive tests covering all edge cases for any new code. +8. Document thoroughly with Doxygen, ensuring clarity and completeness. +9. Follow the same API layout as the standard library. Refer to [cppreference](https://en.cppreference.com/w/cpp/header/cmath) for guidance on `'s api. ### Your First Code Contribution - -WIP + +If you’re ready to make your first contribution to CCMath, here’s a basic workflow you can follow: + +1. **Fork and Clone** + - Fork the CCMath repository on GitHub to your personal account. + - Clone your fork locally: + ```bash + git clone https://github.com//ccmath.git + cd ccmath + ``` + +2. **Check Out the `dev` Branch** + - We recommend making changes off of the `dev` branch: + ```bash + git checkout dev + ``` + +3. **Set Up Your Environment** + - Make sure you have the prerequisites installed (CMake, Ninja, Git, and a compatible compiler). + - Install any other dependencies specific to your platform (for example, using `apt`, `brew`, or `choco`). + +4. **Create a Feature Branch** + - Create a new branch for your proposed changes: + ```bash + git checkout -b feature/my-new-feature + ``` + +5. **Implement Your Changes** + - Edit or add source/header files under `ccmath/`. + - Remember the [Core Tenets of CCMath](#core-tenets-of-ccmath)—aim for constexpr-friendly, standards-compliant, well-documented, and well-tested code. + +6. **Build and Test Locally** + - Use the provided CMake Presets to configure, build, and test: + ```bash + cmake --preset=ninja-gcc-debug + cmake --build --preset=build-ninja-gcc-debug + ctest --preset=test-ninja-gcc-debug --output-on-failure + ``` + - If you encounter any build or test failures, consult the project’s [Issues](https://github.com/Rinzii/ccmath/issues) or open a new one if needed. + +7. **Document Your Code** + - Add or update Doxygen comments where appropriate to ensure comprehensive coverage of new or modified functions. + - If applicable, include references or code examples in docstrings. + +8. **Commit and Push** + - Once your changes pass locally, commit them with a meaningful message: + ```bash + git add . + git commit -m "Implement new math function with tests" + ``` + - Push your branch to your fork: + ```bash + git push -u origin feature/my-new-feature + ``` + +9. **Open a Pull Request** + - On GitHub, open a Pull Request (PR) from your branch to `Rinzii/ccmath`’s `dev` branch. + - Provide a clear title and description of your changes. + - Describe any related issue references (if applicable) and how you tested your changes. + +10. **Code Review** +- A maintainer will review your PR. If changes are requested, address them and push updates to the same feature branch. +- Once everything is approved, your PR will be merged into `dev`. + +That’s it! Thank you for contributing to CCMath. If you have any questions or run into any problems, don’t hesitate to open an issue or add a comment in your PR. We appreciate your help in making CCMath a robust, efficient, and user-friendly math library. + ## How to manually build CCMath with the command line @@ -89,37 +155,71 @@ Step 2: (recommended) Check out the dev branch git checkout dev ``` -### How to build the project - -For Linux & macOS: -```bash -# Run commands in the project root directory - -# Configure cmake to use default compiler -# Preset can alternatively be set to ninja-gcc or ninja-clang for use with gcc or clang -cmake -S . --preset=default -B build - -# Build the project -# --config= can be set to Debug, Release, or RelWithDebInfo -cmake --build build --config=Debug -``` - -For Windows: -```bash -# Run commands in the project root directory - -# Configure cmake to use Visual Studio -cmake -S . --preset=vs22 -B build - -# Build the project -# --config= can be set to Debug, Release, or RelWithDebInfo -cmake --build build --config=Debug -``` - -### How to run tests -```bash -# Run commands from the project root directory -# Must have built the project before running tests -cd build -ctest -C Debug -``` +## Building on Linux & macOS + +1. Pick a preset for your compiler and configuration. + - Examples (see `CMakePresets.json` for the full list): + - `ninja-gcc-debug` + - `ninja-gcc-release` + - `ninja-clang-debug` + - `ninja-clang-release` + - `ninja-clang-libcpp-relwithdebinfo` + - If you need a specific C++ standard, pass `-DCMAKE_CXX_STANDARD=17` (or 20, etc.) after specifying the preset. +2. Configure using one of the presets (example shown uses GCC Debug with C++17): + ```bash + cmake --preset=ninja-gcc-debug -DCMAKE_CXX_STANDARD=17 + ``` +3. Build the project + ```bash + cmake --preset=ninja-gcc-debug -DCMAKE_CXX_STANDARD=17 + ``` + Or, if you prefer a single step after configuring: + ```bash + cmake --preset=ninja-gcc-debug -DCMAKE_CXX_STANDARD=17 + ``` + You can also specify `--config Debug` or `--config Release` if needed +4. Run the tests + ```bash + ctest --preset=test-ninja-gcc-debug --output-on-failure + ``` + Or, if you prefer a one-liner after configuring and building: + ```bash + ctest -C Debug --output-on-failure + ``` + (Ensure you built a Debug config if you’re testing Debug.) + +## Building on Windows (Visual Studio 2022) + +1. Choose a preset, for example: + - `vs22-debug` + - `vs22-release` + - `vs22-clang-debug` + +2. Configure: + ```powershell + cmake --preset=vs22-debug -DCMAKE_CXX_STANDARD=17 + ``` +3. Build using the corresponding build preset: + ```powershell + cmake --build --preset=vs22-debug + ``` + Or, if you prefer a single step after configuring: + ```powershell + # In the same directory where you ran cmake --preset=... + cmake --build . --config Debug + ``` +4. Run the tests + ```powershell + ctest --preset=test-vs22-debug --output-on-failure + ``` + Or, if you prefer a one-liner after configuring and building: + ```powershell + ctest -C Debug --output-on-failure + ``` + +## Additional Notes + +- The exact preset names may differ in your local `CMakePresets.json`. Check that file for the list of available presets. +- Presets for coverage, sanitizer builds, or specialized compilers like Intel may also be available (for example, `ninja-intel-relwithdebinfo` or `ninja-gcc-ccache-debug`). +- If you run into issues, confirm that your CMake, Ninja, and compiler versions are current and supported. +- See our [Contribution Guidelines](CONTRIBUTING.md) for more detailed information on contributing and troubleshooting. From 70f6bb370a928b372113eb09e1bac726607d5336 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 16:05:19 -0500 Subject: [PATCH 041/102] Increase gtest version --- thirdparty/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index b1504eb6..51bd8902 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -2,7 +2,7 @@ project(ccmath-ext) include(FetchContent) -set(CCMATH_BENCHMARK_VERSION v1.8.3) +set(CCMATH_BENCHMARK_VERSION v1.9.1) set(CCMATH_GTEST_VERSION v1.14.0) if (CCMATH_BUILD_BENCHMARKS) From 2f4594ed67498416cb8135e8f52a55aa7860e7b7 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 16:06:05 -0500 Subject: [PATCH 042/102] Change folder from scripts to tools --- {scripts => tools}/plot.py | 2 +- {scripts => tools}/run_benchmark_and_plot.bat | 0 {scripts => tools}/run_benchmark_and_plot.sh | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename {scripts => tools}/plot.py (98%) rename {scripts => tools}/run_benchmark_and_plot.bat (100%) mode change 100755 => 100644 rename {scripts => tools}/run_benchmark_and_plot.sh (100%) mode change 100755 => 100644 diff --git a/scripts/plot.py b/tools/plot.py similarity index 98% rename from scripts/plot.py rename to tools/plot.py index 09095eec..56fb33c7 100644 --- a/scripts/plot.py +++ b/tools/plot.py @@ -3,7 +3,7 @@ # Original script from here: # https://github.com/lakshayg/google_benchmark_plot/ # Script has been modified to meet the needs of ccmath - +# TODO: Replace this with new script able to handle averaged data. """Script to visualize google-benchmark output""" import argparse diff --git a/scripts/run_benchmark_and_plot.bat b/tools/run_benchmark_and_plot.bat old mode 100755 new mode 100644 similarity index 100% rename from scripts/run_benchmark_and_plot.bat rename to tools/run_benchmark_and_plot.bat diff --git a/scripts/run_benchmark_and_plot.sh b/tools/run_benchmark_and_plot.sh old mode 100755 new mode 100644 similarity index 100% rename from scripts/run_benchmark_and_plot.sh rename to tools/run_benchmark_and_plot.sh From 3bad88e184a6e8844d4da3811a7a46c2d8b43838 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 16:10:51 -0500 Subject: [PATCH 043/102] Fix issue where windows builds of clang output a million warnings --- include/ccmath/internal/predef/attributes/always_inline.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ccmath/internal/predef/attributes/always_inline.hpp b/include/ccmath/internal/predef/attributes/always_inline.hpp index 55ebeeab..6e7b7ce5 100644 --- a/include/ccmath/internal/predef/attributes/always_inline.hpp +++ b/include/ccmath/internal/predef/attributes/always_inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) Ian Pike +* Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -16,7 +16,7 @@ #ifndef CCM_ALWAYS_INLINE #if defined(CCM_CONFIG_NO_FORCED_INLINE) #define CCM_ALWAYS_INLINE inline - #elif defined(__GNUC__) || defined(__clang__) + #elif defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER)) #define CCM_ALWAYS_INLINE __attribute__((always_inline)) inline #elif defined(_MSC_VER) #define CCM_ALWAYS_INLINE __forceinline From 208cbaf61b872d01409fb3e5139e559600d7a427 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 20:47:00 -0500 Subject: [PATCH 044/102] Minor adjustments to functionality --- include/ccmath/internal/support/fenv/rounding_mode.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/ccmath/internal/support/fenv/rounding_mode.hpp b/include/ccmath/internal/support/fenv/rounding_mode.hpp index bc0f15ee..9bba0a8d 100644 --- a/include/ccmath/internal/support/fenv/rounding_mode.hpp +++ b/include/ccmath/internal/support/fenv/rounding_mode.hpp @@ -21,19 +21,19 @@ namespace ccm::support::fenv { inline bool rt_rounding_mode_is_round_up() { - volatile constexpr float x = 0x1.0p-25F; + static volatile const float x = 0x1.0p-25F; return (1.0F + x != 1.0F); } inline bool rt_rounding_mode_is_round_down() { - volatile constexpr float x = 0x1.0p-25F; + static volatile const float x = 0x1.0p-25F; return (-1.0F - x != -1.0F); } inline bool rt_rounding_mode_is_round_to_nearest() { - static volatile constexpr float x = 0x1.0p-24F; + static volatile const float x = 0x1.0p-24F; float const y = x; return (1.5F + y == 1.5F - y); } @@ -41,14 +41,14 @@ namespace ccm::support::fenv inline bool rt_rounding_mode_is_round_to_zero() { - static volatile float const x = 0x1.0p-24F; + static volatile const float x = 0x1.0p-24F; const float y = x; return ((0x1.000002p0F + y) + (-1.0F - y) == 0x1.0p-23F); } inline int rt_get_rounding_mode() { - static volatile float const x = 0x1.0p-24F; + static volatile const float x = 0x1.0p-24F; float const y = x; float const z = (0x1.000002p0F + y) + (-1.0F - y); From 5ca8e577ef57050e9552e18244ce6615a27537aa Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 20:51:23 -0500 Subject: [PATCH 045/102] Clean up headers to take advantage of cmake --- include/ccmath/math/compare/isinf.hpp | 2 +- include/ccmath/math/compare/isnan.hpp | 2 +- include/ccmath/math/compare/signbit.hpp | 38 +++++++++---------------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/include/ccmath/math/compare/isinf.hpp b/include/ccmath/math/compare/isinf.hpp index 55422708..3744fa91 100644 --- a/include/ccmath/math/compare/isinf.hpp +++ b/include/ccmath/math/compare/isinf.hpp @@ -26,7 +26,7 @@ namespace ccm template , bool> = true> constexpr bool isinf(T num) noexcept { -#if defined(__GNUC__) || defined(__clang__) +#if defined(__GNUC__) || defined(__clang__) || defined(CCM_CONFIG_HAS_BUILTIN_ISINF_CONSTEXPR) return __builtin_isinf(num); // GCC and Clang implement this as constexpr #else // If we can't use the builtin, fallback to this comparison and hope for the best. using FPBits_t = typename ccm::support::fp::FPBits; diff --git a/include/ccmath/math/compare/isnan.hpp b/include/ccmath/math/compare/isnan.hpp index 8d8a7b7e..75237797 100644 --- a/include/ccmath/math/compare/isnan.hpp +++ b/include/ccmath/math/compare/isnan.hpp @@ -23,7 +23,7 @@ namespace ccm template , bool> = true> [[nodiscard]] constexpr bool isnan(T num) noexcept { -#if defined(__GNUC__) || defined(__clang__) +#if defined(__GNUC__) || defined(__clang__) || defined(CCM_CONFIG_HAS_BUILTIN_ISNAN_CONSTEXPR) return __builtin_isnan(num); // GCC and Clang implement this as constexpr #else // If we can't use the builtin, fallback to this comparison and hope for the best. using FPBits_t = typename ccm::support::fp::FPBits; diff --git a/include/ccmath/math/compare/signbit.hpp b/include/ccmath/math/compare/signbit.hpp index 1d5992f9..15f4959c 100644 --- a/include/ccmath/math/compare/signbit.hpp +++ b/include/ccmath/math/compare/signbit.hpp @@ -9,21 +9,20 @@ */ #pragma once - - +#if defined(CCM_CONFIG_HAS_BUILTIN_BIT_CAST) || defined(CCM_CONFIG_HAS_BUILTIN_SIGNBIT_CONSTEXPR) #include "ccmath/internal/config/builtin/bit_cast_support.hpp" #include "ccmath/internal/config/builtin/copysign_support.hpp" #include "ccmath/internal/config/builtin/signbit_support.hpp" +#endif + // Include the necessary headers for each different fallback -#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN +#if defined(CCM_CONFIG_HAS_BUILTIN_SIGNBIT_CONSTEXPR) || defined(CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN) #include "ccmath/math/compare/isnan.hpp" -#endif -#ifdef CCMATH_HAS_BUILTIN_BIT_CAST +#elif defined(CCM_CONFIG_HAS_BUILTIN_BIT_CAST) || defined(CCMATH_HAS_BUILTIN_BIT_CAST) #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/support/floating_point_traits.hpp" -#endif -#if !defined(CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT) && !defined(CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN) && !defined(CCMATH_HAS_BUILTIN_BIT_CAST) +#else #include "ccmath/internal/support/always_false.hpp" #endif @@ -35,25 +34,19 @@ namespace ccm * @param num A floating-point number. * @return true if \p x is negative, false otherwise. * - * @note This function has multiple implementations based on the compiler and the version of - * the the compiler used. With nearly all implementations, this function is fully constexpr and will return + * @note This function has multiple implementations based on the compiler and the version of the compiler used. + * With nearly all implementations, this function is fully constexpr and will return * the same values as std::signbit along with being static_assert-able. * - * @warning ccm::signbit currently is only ensured to work on little-endian systems. There is currently no guarantee this it will work on big-endian - * systems. - * - * @attention Implementing signbit is a non-trivial task and requires a lot of compiler magic to allow for ccm::signbit to be - * fully constexpr and static_assert-able while also conforming to the standard. CCMath has done its best to provide - * a constexpr signbit for all compilers, but we feel that not covering edge cases would be unacceptable and as such - * if your compiler is not supported a static assertion will be triggered. If this happens to you please report it to - * the dev team and we will try to bring support to your compiler ASAP if we are able to! + * @warning ccm::signbit may fail + * to compile if you are not using the cmake build for ccmath or do not have access to __builtin_bit_cast. */ template , bool> = true> [[nodiscard]] constexpr bool signbit(T num) noexcept { -#if defined(CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT) +#if defined(CCM_CONFIG_HAS_BUILTIN_SIGNBIT_CONSTEXPR) return __builtin_signbit(num); -#elif defined(CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN) +#elif defined(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) // use __builtin_copysign to check for the sign of zero if (num == static_cast(0) || ccm::isnan(num)) { @@ -66,8 +59,8 @@ namespace ccm } return num < static_cast(0); -#elif defined(CCMATH_HAS_BUILTIN_BIT_CAST) - // Check for the sign of +0.0 and -0.0 withbit_cast +#else + // Check for the sign of +0.0 and -0.0 with bit_cast if (num == static_cast(0) || ccm::isnan(num)) { const auto bits = support::bit_cast>(num); @@ -75,9 +68,6 @@ namespace ccm } return num < static_cast(0); -#else - static_assert(ccm::support::always_false, "ccm::signbit is not implemented for this compiler. Please report this issue to the ccmath dev team!"); - return false; #endif } From a8ce844220a1dd9678f85eb7deaf32840020018f Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 20:52:18 -0500 Subject: [PATCH 046/102] Minor bug fixes --- include/ccmath/internal/support/bits.hpp | 112 +++++++++++------------ 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/include/ccmath/internal/support/bits.hpp b/include/ccmath/internal/support/bits.hpp index acf09796..9777f6ba 100644 --- a/include/ccmath/internal/support/bits.hpp +++ b/include/ccmath/internal/support/bits.hpp @@ -38,7 +38,7 @@ namespace ccm::support } template && traits::ccm_is_unsigned_v && !traits::is_char_v && !std::is_same_v, bool> = true> + std::enable_if_t && traits::ccm_is_unsigned_v && !traits::is_char_v && !std::is_same_v, bool> = true> constexpr bool has_single_bit(T x) noexcept { return x && !(x & (x - 1)); @@ -46,7 +46,7 @@ namespace ccm::support // TODO: Have the below function replace all other top_bits func. - template && !std::is_same_v, bool> = true> + template && !std::is_same_v, bool> = true> constexpr std::uint32_t top_bits(T x) noexcept { // This function does not work with long double. May support it later though. @@ -121,10 +121,10 @@ namespace ccm::support * @brief Rotates unsigned integer bits to the right. * https://en.cppreference.com/w/cpp/numeric/rotr */ - template , bool> = true> + template , bool> = true> constexpr T rotr(T t, int cnt) noexcept { -#if defined(_MSC_VER) && !defined(__clang__) + #if defined(_MSC_VER) && !defined(__clang__) // Allow for the use of compiler intrinsics if we are not being evaluated at compile time in msvc. if (!is_constant_evaluated()) { @@ -132,7 +132,7 @@ namespace ccm::support if constexpr (std::is_same_v) { return _rotr(t, cnt); } else if constexpr (std::is_same_v) { return _rotr64(t, cnt); } } -#endif + #endif const unsigned int dig = std::numeric_limits::digits; if ((static_cast(cnt) % dig) == 0) { return t; } @@ -141,7 +141,7 @@ namespace ccm::support { cnt *= -1; return (t << (static_cast(cnt) % dig)) | - (t >> (dig - (static_cast(cnt) % dig))); // rotr with negative cnt is similar to rotl + (t >> (dig - (static_cast(cnt) % dig))); // rotr with negative cnt is similar to rotl } return (t >> (static_cast(cnt) % dig)) | (t << (dig - (static_cast(cnt) % dig))); @@ -151,10 +151,10 @@ namespace ccm::support * @brief Rotates unsigned integer bits to the left. * https://en.cppreference.com/w/cpp/numeric/rotl */ - template , bool> = true> + template , bool> = true> constexpr T rotl(T t, int cnt) noexcept { -#if defined(_MSC_VER) && !defined(__clang__) + #if defined(_MSC_VER) && !defined(__clang__) // Allow for the use of compiler intrinsics if we are not being evaluated at compile time in msvc. if (!is_constant_evaluated()) { @@ -162,13 +162,13 @@ namespace ccm::support if constexpr (std::is_same_v) { return _rotl(t, cnt); } else if constexpr (std::is_same_v) { return _rotl64(t, cnt); } } -#endif + #endif return rotr(t, -cnt); } -// Macro to allow simplified creation of specializations -// NOLINTBEGIN(bugprone-macro-parentheses) -#define INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(FUNC, TYPE, BUILTIN) \ + // Macro to allow simplified creation of specializations + // NOLINTBEGIN(bugprone-macro-parentheses) + #define INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(FUNC, TYPE, BUILTIN) \ template <> \ [[nodiscard]] constexpr int FUNC(TYPE value) \ { \ @@ -177,7 +177,7 @@ namespace ccm::support } // NOLINTEND(bugprone-macro-parentheses) -#if CCM_HAS_BUILTIN(__builtin_ctzg) + #if CCM_HAS_BUILTIN(__builtin_ctzg) /** * @brief Returns the number of consecutive 0 bits in the value of x, starting from the least significant bit ("right"). * https://en.cppreference.com/w/cpp/numeric/countr_zero @@ -187,7 +187,7 @@ namespace ccm::support { return __builtin_ctzg(value, std::numeric_limits::digits); // NOLINT } -#else // !CCM_HAS_BUILTIN(__builtin_ctzg) + #else // !CCM_HAS_BUILTIN(__builtin_ctzg) /** * @brief Returns the number of consecutive 0 bits in the value of x, starting from the least significant bit ("right"). * https://en.cppreference.com/w/cpp/numeric/countr_zero @@ -199,8 +199,8 @@ namespace ccm::support if (value & 0x1) { return 0; } // Bisection method unsigned zero_bits = 0; - unsigned shift = std::numeric_limits::digits >> 1; - T mask = std::numeric_limits::max() >> shift; + unsigned shift = std::numeric_limits::digits >> 1; + T mask = std::numeric_limits::max() >> shift; while (shift) { if ((value & mask) == 0) @@ -213,28 +213,28 @@ namespace ccm::support } return zero_bits; } -#endif // CCM_HAS_BUILTIN(__builtin_ctzg) + #endif // CCM_HAS_BUILTIN(__builtin_ctzg) -#if CCM_HAS_BUILTIN(__builtin_ctzs) + #if CCM_HAS_BUILTIN(__builtin_ctzs) INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(countr_zero, unsigned short, __builtin_ctzs) -#endif // CCM_HAS_BUILTIN(__builtin_ctzs) -#if CCM_HAS_BUILTIN(__builtin_ctz) + #endif // CCM_HAS_BUILTIN(__builtin_ctzs) + #if CCM_HAS_BUILTIN(__builtin_ctz) INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(countr_zero, unsigned int, __builtin_ctz) -#endif // CCM_HAS_BUILTIN(__builtin_ctz) -#if CCM_HAS_BUILTIN(__builtin_ctzl) + #endif // CCM_HAS_BUILTIN(__builtin_ctz) + #if CCM_HAS_BUILTIN(__builtin_ctzl) INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(countr_zero, unsigned long, __builtin_ctzl) -#endif // CCM_HAS_BUILTIN(__builtin_ctzl) -#if CCM_HAS_BUILTIN(__builtin_ctzll) + #endif // CCM_HAS_BUILTIN(__builtin_ctzl) + #if CCM_HAS_BUILTIN(__builtin_ctzll) INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(countr_zero, unsigned long long, __builtin_ctzll) -#endif // CCM_HAS_BUILTIN(__builtin_ctzll) + #endif // CCM_HAS_BUILTIN(__builtin_ctzll) -#if CCM_HAS_BUILTIN(__builtin_clzg) + #if CCM_HAS_BUILTIN(__builtin_clzg) template [[nodiscard]] constexpr std::enable_if_t, int> countl_zero(T value) { return __builtin_clzg(value, std::numeric_limits::digits); // NOLINT } -#else // !CCM_HAS_BUILTIN(__builtin_clzg) + #else // !CCM_HAS_BUILTIN(__builtin_clzg) template [[nodiscard]] constexpr std::enable_if_t, int> countl_zero(T value) { @@ -261,22 +261,22 @@ namespace ccm::support } return zero_bits; } -#endif // CCM_HAS_BUILTIN(__builtin_clzg) + #endif // CCM_HAS_BUILTIN(__builtin_clzg) -#if CCM_HAS_BUILTIN(__builtin_clzs) + #if CCM_HAS_BUILTIN(__builtin_clzs) INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(countl_zero, unsigned short, __builtin_clzs) -#endif // CCM_HAS_BUILTIN(__builtin_clzs) -#if CCM_HAS_BUILTIN(__builtin_clz) + #endif // CCM_HAS_BUILTIN(__builtin_clzs) + #if CCM_HAS_BUILTIN(__builtin_clz) INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(countl_zero, unsigned int, __builtin_clz) -#endif // CCM_HAS_BUILTIN(__builtin_clz) -#if CCM_HAS_BUILTIN(__builtin_clzl) + #endif // CCM_HAS_BUILTIN(__builtin_clz) + #if CCM_HAS_BUILTIN(__builtin_clzl) INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(countl_zero, unsigned long, __builtin_clzl) -#endif // CCM_HAS_BUILTIN(__builtin_clzl) -#if CCM_HAS_BUILTIN(__builtin_clzll) + #endif // CCM_HAS_BUILTIN(__builtin_clzl) + #if CCM_HAS_BUILTIN(__builtin_clzll) INTERNAL_CCM_ADD_CTZ_SPECIALIZATION(countl_zero, unsigned long long, __builtin_clzll) -#endif // CCM_HAS_BUILTIN(__builtin_clzll) + #endif // CCM_HAS_BUILTIN(__builtin_clzll) -#undef INTERNAL_CCM_ADD_CTZ_SPECIALIZATION + #undef INTERNAL_CCM_ADD_CTZ_SPECIALIZATION template [[nodiscard]] constexpr std::enable_if_t, int> countr_one(T value) @@ -284,7 +284,7 @@ namespace ccm::support return support::countr_zero(~value); } - template , bool> = true> + template , bool> = true> [[nodiscard]] constexpr std::enable_if_t, int> countl_one(T value) { return value != std::numeric_limits::max() ? countl_zero(static_cast(~value)) : std::numeric_limits::digits; @@ -296,13 +296,13 @@ namespace ccm::support return std::numeric_limits::digits - countl_zero(value); } -#if CCM_HAS_BUILTIN(__builtin_popcountg) + #if CCM_HAS_BUILTIN(__builtin_popcountg) template [[nodiscard]] constexpr std::enable_if_t, int> popcount(T value) { return __builtin_popcountg(value); // NOLINT } -#else // !CCM_HAS_BUILTIN(__builtin_popcountg) + #else // !CCM_HAS_BUILTIN(__builtin_popcountg) template [[nodiscard]] constexpr std::enable_if_t, int> popcount(T value) { @@ -340,11 +340,11 @@ namespace ccm::support #endif // !CCM_HAS_BUILTIN(__builtin_popcountll) -#endif // CCM_HAS_BUILTIN(__builtin_popcountg) + #endif // CCM_HAS_BUILTIN(__builtin_popcountg) -// Macro to allow simplified creation of specializations -// NOLINTBEGIN(bugprone-macro-parentheses) -#define INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(FUNC, TYPE, BUILTIN) \ + // Macro to allow simplified creation of specializations + // NOLINTBEGIN(bugprone-macro-parentheses) + #define INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(FUNC, TYPE, BUILTIN) \ template <> \ [[nodiscard]] constexpr int FUNC(TYPE value) \ { \ @@ -352,13 +352,13 @@ namespace ccm::support return BUILTIN(value); \ } -// NOLINTEND(bugprone-macro-parentheses) -// If the compiler has builtins for popcount, then create specializations that use the builtins. -#if CCM_HAS_BUILTIN(__builtin_popcount) + // NOLINTEND(bugprone-macro-parentheses) + // If the compiler has builtins for popcount, then create specializations that use the builtins. + #if CCM_HAS_BUILTIN(__builtin_popcount) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned char, __builtin_popcount) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned short, __builtin_popcount) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned, __builtin_popcount) -#else + #else // If we don't have builtins, then provide optimizations for common types. // All provided optimizations are based on the Hamming Weight algorithm except for unsigned char. // https://en.wikipedia.org/wiki/Hamming_weight @@ -396,11 +396,11 @@ namespace ccm::support return (n * 0x0101) >> 16; } } -#endif + #endif -#if CCM_HAS_BUILTIN(__builtin_popcountl) + #if CCM_HAS_BUILTIN(__builtin_popcountl) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned long, __builtin_popcountl) -#else + #else constexpr int popcount(unsigned long n) { // long can be 32 or 64 bits, so we need to check. @@ -419,11 +419,11 @@ namespace ccm::support return (n * 0x101010101010101) >> 56; } } -#endif + #endif -#if CCM_HAS_BUILTIN(__builtin_popcountll) + #if CCM_HAS_BUILTIN(__builtin_popcountll) INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION(popcount, unsigned long long, __builtin_popcountll) -#else + #else constexpr int popcount(unsigned long long n) { n = n - ((n >> 1) & 0x5555555555555555); @@ -431,8 +431,8 @@ namespace ccm::support n = (n + (n >> 4)) & 0xF0F0F0F0F0F0F0F; return (n * 0x101010101010101) >> 56; } -#endif + #endif -#undef INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION + #undef INTERNAL_CCM_ADD_POPCOUNT_SPECIALIZATION } // namespace ccm::support From 79471e7810dd4f09d2bfe8474d52feea3969c4f8 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 20:52:55 -0500 Subject: [PATCH 047/102] Initial support for benchmarking trunc --- benchmark/CMakeLists.txt | 15 +- benchmark/benchmarks/nearest/trunc.bench.cpp | 22 +++ benchmark/benchmarks/nearest/trunc.bench.hpp | 149 +++++++++++++++++++ 3 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 benchmark/benchmarks/nearest/trunc.bench.cpp create mode 100644 benchmark/benchmarks/nearest/trunc.bench.hpp diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 8e816120..ad4f43be 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -6,7 +6,8 @@ project(ccmath-benchmark) option(CCM_BENCH_BASIC "Enable basic benchmarks" OFF) option(CCM_BENCH_COMPARE "Enable comparison benchmarks" OFF) -option(CCM_BENCH_POWER "Enable power benchmarks" ON) +option(CCM_BENCH_POWER "Enable power benchmarks" OFF) +option(CCM_BENCH_NEAREST "Enable nearest benchmarks" ON) option(CCM_BENCH_ALL "Enable all benchmarks" OFF) @@ -19,12 +20,6 @@ if(NOT TARGET ccmath) find_package(ccmath CONFIG REQUIRED) endif() -#if (CMAKE_CXX_COMPILER_ID STREQUAL Clang OR CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM) -# target_compile_options(ccm_benchmark_${function_name} INTERFACE -# -S -# ) -#endif() - function(add_benchmark function_name source_files) add_executable(ccm_benchmark_${function_name} helpers/randomizers.hpp ${source_files}) target_link_libraries(ccm_benchmark_${function_name} PRIVATE ccmath::ccmath benchmark::benchmark) @@ -40,4 +35,8 @@ endif () if(CCM_BENCH_POWER) add_benchmark(sqrt benchmarks/power/sqrt.bench.cpp benchmarks/power/sqrt.bench.hpp) -endif () \ No newline at end of file +endif () + +if(CCM_BENCH_NEAREST) + add_benchmark(trunc benchmarks/nearest/trunc.bench.cpp benchmarks/nearest/trunc.bench.hpp) +endif () diff --git a/benchmark/benchmarks/nearest/trunc.bench.cpp b/benchmark/benchmarks/nearest/trunc.bench.cpp new file mode 100644 index 00000000..51acf340 --- /dev/null +++ b/benchmark/benchmarks/nearest/trunc.bench.cpp @@ -0,0 +1,22 @@ +BENCHMARK(BM_power_trunc_ccm)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); +BENCHMARK(BM_power_trunc_rand_int_std)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); +BENCHMARK(BM_power_trunc_rand_int_ccm)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); +BENCHMARK(BM_power_trunc_rand_double_std)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); +BENCHMARK(BM_power_trunc_rand_double_ccm)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); + +#endif + +#ifndef CCM_BM_CONFIG_NO_RT + +BENCHMARK(BM_power_trunc_std_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); +BENCHMARK(BM_power_trunc_ccm_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); +BENCHMARK(BM_power_trunc_rand_int_std_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); +BENCHMARK(BM_power_trunc_rand_int_ccm_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); +BENCHMARK(BM_power_trunc_rand_double_std_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); +BENCHMARK(BM_power_trunc_rand_double_ccm_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); + +#endif + +BENCHMARK_MAIN(); + +// NOLINTEND diff --git a/benchmark/benchmarks/nearest/trunc.bench.hpp b/benchmark/benchmarks/nearest/trunc.bench.hpp new file mode 100644 index 00000000..facf563e --- /dev/null +++ b/benchmark/benchmarks/nearest/trunc.bench.hpp @@ -0,0 +1,149 @@ +// trunc.bench.hpp +/* + * Copyright (c) 2024-Present Ian Pike + * Copyright (c) 2024-Present ccmath contributors + * + * This library is provided under the MIT License. + * See LICENSE for more information. + */ + +#include "../../helpers/randomizers.hpp" + +#include +#include +#include +#include // For SSE2 intrinsics + +namespace bm = benchmark; + +// NOLINTBEGIN + +#ifndef CCM_BM_CONFIG_NO_CT + +static void BM_power_trunc_std(bm::State& state) { + for ([[maybe_unused]] auto _ : state) { + bm::DoNotOptimize(std::trunc(static_cast(state.range(0)))); + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_ccm(bm::State& state) { + for ([[maybe_unused]] auto _ : state) { + bm::DoNotOptimize(ccm::trunc(static_cast(state.range(0)))); + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_rand_int_std(bm::State& state) { + ccm::bench::Randomizer ran; + auto randomIntegers = ran.generateRandomIntegers(state.range(0)); + while (state.KeepRunning()) { + for (auto x : randomIntegers) { + bm::DoNotOptimize(std::trunc(static_cast(x))); + } + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_rand_int_ccm(bm::State& state) { + ccm::bench::Randomizer ran; + auto randomIntegers = ran.generateRandomIntegers(state.range(0)); + while (state.KeepRunning()) { + for (auto x : randomIntegers) { + bm::DoNotOptimize(ccm::trunc(static_cast(x))); + } + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_rand_double_std(bm::State& state) { + ccm::bench::Randomizer ran; + auto randomDoubles = ran.generateRandomDoubles(state.range(0)); + while (state.KeepRunning()) { + for (auto x : randomDoubles) { + bm::DoNotOptimize(std::trunc(x)); + } + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_rand_double_ccm(bm::State& state) { + ccm::bench::Randomizer ran; + auto randomDoubles = ran.generateRandomDoubles(state.range(0)); + while (state.KeepRunning()) { + for (auto x : randomDoubles) { + bm::DoNotOptimize(ccm::trunc(x)); + } + } + state.SetComplexityN(state.range(0)); +} + +#endif + +#ifndef CCM_BM_CONFIG_NO_RT + +inline double trunc_rt_bm(double v) { + return ccm::trunc(v); +} + +static void BM_power_trunc_std_rt(bm::State& state) { + for ([[maybe_unused]] auto _ : state) { + bm::DoNotOptimize(std::trunc(static_cast(state.range(0)))); + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_ccm_rt(bm::State& state) { + for ([[maybe_unused]] auto _ : state) { + bm::DoNotOptimize(trunc_rt_bm(static_cast(state.range(0)))); + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_rand_int_std_rt(bm::State& state) { + ccm::bench::Randomizer ran; + auto randomIntegers = ran.generateRandomIntegers(state.range(0)); + while (state.KeepRunning()) { + for (auto x : randomIntegers) { + bm::DoNotOptimize(std::trunc(static_cast(x))); + } + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_rand_int_ccm_rt(bm::State& state) { + ccm::bench::Randomizer ran; + auto randomIntegers = ran.generateRandomIntegers(state.range(0)); + while (state.KeepRunning()) { + for (auto x : randomIntegers) { + bm::DoNotOptimize(trunc_rt_bm(static_cast(x))); + } + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_rand_double_std_rt(bm::State& state) { + ccm::bench::Randomizer ran; + auto randomDoubles = ran.generateRandomDoubles(state.range(0)); + while (state.KeepRunning()) { + for (auto x : randomDoubles) { + bm::DoNotOptimize(std::trunc(x)); + } + } + state.SetComplexityN(state.range(0)); +} + +static void BM_power_trunc_rand_double_ccm_rt(bm::State& state) { + ccm::bench::Randomizer ran; + auto randomDoubles = ran.generateRandomDoubles(state.range(0)); + while (state.KeepRunning()) { + for (auto x : randomDoubles) { + bm::DoNotOptimize(trunc_rt_bm(x)); + } + } + state.SetComplexityN(state.range(0)); +} + +#endif + +// NOLINTEND From 0d40a8da083da4f3606063baebec5ff6b0af4e5c Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 21:46:09 -0500 Subject: [PATCH 048/102] Apply significantly more aggressive warnings --- benchmark/CMakeLists.txt | 2 +- benchmark/benchmarks/nearest/trunc.bench.cpp | 22 --- benchmark/benchmarks/nearest/trunc.bench.hpp | 149 ------------------ .../math/generic/func/expo/log_gen.hpp | 8 +- .../math/generic/func/power/pow_impl.hpp | 2 +- .../math/generic/func/power/powf_impl.hpp | 2 +- .../predef/expects_bool_condition.hpp | 2 +- include/ccmath/internal/support/bits.hpp | 8 +- .../internal/support/fenv/fenv_support.hpp | 9 ++ .../internal/support/integer_literals.hpp | 8 +- .../ccmath/internal/support/math_support.hpp | 2 +- include/ccmath/internal/types/big_int.hpp | 13 +- .../math/basic/impl/nan_double_impl.hpp | 6 + .../ccmath/math/basic/impl/nan_float_impl.hpp | 2 +- include/ccmath/math/expo/exp.hpp | 9 ++ include/ccmath/math/expo/exp2.hpp | 9 ++ include/ccmath/math/expo/expm1.hpp | 6 +- .../ccmath/math/expo/impl/exp2_float_impl.hpp | 6 + .../ccmath/math/expo/impl/exp_float_impl.hpp | 9 ++ .../math/expo/impl/log2_double_impl.hpp | 5 + include/ccmath/math/expo/log.hpp | 9 ++ include/ccmath/math/expo/log10.hpp | 4 +- include/ccmath/math/expo/log1p.hpp | 4 +- include/ccmath/math/expo/log2.hpp | 9 ++ include/ccmath/math/fmanip/copysign.hpp | 2 +- .../math/fmanip/impl/scalbn_ldouble_impl.hpp | 2 +- include/ccmath/math/fmanip/scalbn.hpp | 9 ++ 27 files changed, 121 insertions(+), 197 deletions(-) diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index ad4f43be..3fab4770 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -38,5 +38,5 @@ if(CCM_BENCH_POWER) endif () if(CCM_BENCH_NEAREST) - add_benchmark(trunc benchmarks/nearest/trunc.bench.cpp benchmarks/nearest/trunc.bench.hpp) + #add_benchmark(trunc benchmarks/nearest/trunc.bench.cpp benchmarks/nearest/trunc.bench.hpp) endif () diff --git a/benchmark/benchmarks/nearest/trunc.bench.cpp b/benchmark/benchmarks/nearest/trunc.bench.cpp index 51acf340..e69de29b 100644 --- a/benchmark/benchmarks/nearest/trunc.bench.cpp +++ b/benchmark/benchmarks/nearest/trunc.bench.cpp @@ -1,22 +0,0 @@ -BENCHMARK(BM_power_trunc_ccm)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); -BENCHMARK(BM_power_trunc_rand_int_std)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); -BENCHMARK(BM_power_trunc_rand_int_ccm)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); -BENCHMARK(BM_power_trunc_rand_double_std)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); -BENCHMARK(BM_power_trunc_rand_double_ccm)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); - -#endif - -#ifndef CCM_BM_CONFIG_NO_RT - -BENCHMARK(BM_power_trunc_std_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); -BENCHMARK(BM_power_trunc_ccm_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); -BENCHMARK(BM_power_trunc_rand_int_std_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); -BENCHMARK(BM_power_trunc_rand_int_ccm_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); -BENCHMARK(BM_power_trunc_rand_double_std_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); -BENCHMARK(BM_power_trunc_rand_double_ccm_rt)->RangeMultiplier(2)->Range(8, 8 << 10)->Complexity(); - -#endif - -BENCHMARK_MAIN(); - -// NOLINTEND diff --git a/benchmark/benchmarks/nearest/trunc.bench.hpp b/benchmark/benchmarks/nearest/trunc.bench.hpp index facf563e..e69de29b 100644 --- a/benchmark/benchmarks/nearest/trunc.bench.hpp +++ b/benchmark/benchmarks/nearest/trunc.bench.hpp @@ -1,149 +0,0 @@ -// trunc.bench.hpp -/* - * Copyright (c) 2024-Present Ian Pike - * Copyright (c) 2024-Present ccmath contributors - * - * This library is provided under the MIT License. - * See LICENSE for more information. - */ - -#include "../../helpers/randomizers.hpp" - -#include -#include -#include -#include // For SSE2 intrinsics - -namespace bm = benchmark; - -// NOLINTBEGIN - -#ifndef CCM_BM_CONFIG_NO_CT - -static void BM_power_trunc_std(bm::State& state) { - for ([[maybe_unused]] auto _ : state) { - bm::DoNotOptimize(std::trunc(static_cast(state.range(0)))); - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_ccm(bm::State& state) { - for ([[maybe_unused]] auto _ : state) { - bm::DoNotOptimize(ccm::trunc(static_cast(state.range(0)))); - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_rand_int_std(bm::State& state) { - ccm::bench::Randomizer ran; - auto randomIntegers = ran.generateRandomIntegers(state.range(0)); - while (state.KeepRunning()) { - for (auto x : randomIntegers) { - bm::DoNotOptimize(std::trunc(static_cast(x))); - } - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_rand_int_ccm(bm::State& state) { - ccm::bench::Randomizer ran; - auto randomIntegers = ran.generateRandomIntegers(state.range(0)); - while (state.KeepRunning()) { - for (auto x : randomIntegers) { - bm::DoNotOptimize(ccm::trunc(static_cast(x))); - } - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_rand_double_std(bm::State& state) { - ccm::bench::Randomizer ran; - auto randomDoubles = ran.generateRandomDoubles(state.range(0)); - while (state.KeepRunning()) { - for (auto x : randomDoubles) { - bm::DoNotOptimize(std::trunc(x)); - } - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_rand_double_ccm(bm::State& state) { - ccm::bench::Randomizer ran; - auto randomDoubles = ran.generateRandomDoubles(state.range(0)); - while (state.KeepRunning()) { - for (auto x : randomDoubles) { - bm::DoNotOptimize(ccm::trunc(x)); - } - } - state.SetComplexityN(state.range(0)); -} - -#endif - -#ifndef CCM_BM_CONFIG_NO_RT - -inline double trunc_rt_bm(double v) { - return ccm::trunc(v); -} - -static void BM_power_trunc_std_rt(bm::State& state) { - for ([[maybe_unused]] auto _ : state) { - bm::DoNotOptimize(std::trunc(static_cast(state.range(0)))); - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_ccm_rt(bm::State& state) { - for ([[maybe_unused]] auto _ : state) { - bm::DoNotOptimize(trunc_rt_bm(static_cast(state.range(0)))); - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_rand_int_std_rt(bm::State& state) { - ccm::bench::Randomizer ran; - auto randomIntegers = ran.generateRandomIntegers(state.range(0)); - while (state.KeepRunning()) { - for (auto x : randomIntegers) { - bm::DoNotOptimize(std::trunc(static_cast(x))); - } - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_rand_int_ccm_rt(bm::State& state) { - ccm::bench::Randomizer ran; - auto randomIntegers = ran.generateRandomIntegers(state.range(0)); - while (state.KeepRunning()) { - for (auto x : randomIntegers) { - bm::DoNotOptimize(trunc_rt_bm(static_cast(x))); - } - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_rand_double_std_rt(bm::State& state) { - ccm::bench::Randomizer ran; - auto randomDoubles = ran.generateRandomDoubles(state.range(0)); - while (state.KeepRunning()) { - for (auto x : randomDoubles) { - bm::DoNotOptimize(std::trunc(x)); - } - } - state.SetComplexityN(state.range(0)); -} - -static void BM_power_trunc_rand_double_ccm_rt(bm::State& state) { - ccm::bench::Randomizer ran; - auto randomDoubles = ran.generateRandomDoubles(state.range(0)); - while (state.KeepRunning()) { - for (auto x : randomDoubles) { - bm::DoNotOptimize(trunc_rt_bm(x)); - } - } - state.SetComplexityN(state.range(0)); -} - -#endif - -// NOLINTEND diff --git a/include/ccmath/internal/math/generic/func/expo/log_gen.hpp b/include/ccmath/internal/math/generic/func/expo/log_gen.hpp index 944cc2eb..b4f2f449 100644 --- a/include/ccmath/internal/math/generic/func/expo/log_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/log_gen.hpp @@ -22,11 +22,13 @@ #include +// TODO: Do something with this. + namespace ccm::gen { namespace internal::impl { - constexpr float log_impl(float num) noexcept + constexpr float log_impl([[maybe_unused]] float num) noexcept { //constexpr double ln2 = 0x1.62e42fefa39efp-1; //using FPBits_t = typename support::fp::FPBits; @@ -42,12 +44,12 @@ namespace ccm::gen return 0; } - constexpr double log_impl(double num) noexcept + constexpr double log_impl([[maybe_unused]] double num) noexcept { return 0; } - constexpr long double log_impl(long double num) noexcept + constexpr long double log_impl([[maybe_unused]] long double num) noexcept { return 0; } diff --git a/include/ccmath/internal/math/generic/func/power/pow_impl.hpp b/include/ccmath/internal/math/generic/func/power/pow_impl.hpp index 7777a9b1..8200c9ac 100644 --- a/include/ccmath/internal/math/generic/func/power/pow_impl.hpp +++ b/include/ccmath/internal/math/generic/func/power/pow_impl.hpp @@ -16,7 +16,7 @@ namespace ccm::gen::impl { namespace internal::impl { - constexpr double pow_impl(double base, double exp) noexcept + constexpr double pow_impl([[maybe_unused]] double base, [[maybe_unused]] double exp) noexcept { // TODO: Implement this. return 0; diff --git a/include/ccmath/internal/math/generic/func/power/powf_impl.hpp b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp index bb3166ad..fd089ca9 100644 --- a/include/ccmath/internal/math/generic/func/power/powf_impl.hpp +++ b/include/ccmath/internal/math/generic/func/power/powf_impl.hpp @@ -16,7 +16,7 @@ namespace ccm::gen::impl { namespace internal::impl { - constexpr float powf_impl(float base, float exp) noexcept + constexpr float powf_impl([[maybe_unused]] float base, [[maybe_unused]] float exp) noexcept { // TODO: Implement this. return 0; diff --git a/include/ccmath/internal/predef/expects_bool_condition.hpp b/include/ccmath/internal/predef/expects_bool_condition.hpp index 44e69d7a..a7faec69 100644 --- a/include/ccmath/internal/predef/expects_bool_condition.hpp +++ b/include/ccmath/internal/predef/expects_bool_condition.hpp @@ -18,7 +18,7 @@ namespace ccm::predef::internal * @brief Helper function to prevent the user from accidentally passing an integer to an expect function. */ template , bool> = true> - constexpr bool expects_bool_condition(T value, bool expected) + constexpr bool expects_bool_condition(T value, [[maybe_unused]] bool expected) { #if defined(__GNUC__) || defined(__clang__) return __builtin_expect(value, expected); diff --git a/include/ccmath/internal/support/bits.hpp b/include/ccmath/internal/support/bits.hpp index 9777f6ba..7dde8bf0 100644 --- a/include/ccmath/internal/support/bits.hpp +++ b/include/ccmath/internal/support/bits.hpp @@ -374,7 +374,7 @@ namespace ccm::support { n = n - (n >> 1) & 0x5555; n = (n & 0x3333) + (n >> 2) & 0x3333; - n = (n + n >> 4) & 0x0F0F; + n = (n + (n >> 4)) & 0x0F0F; return (n * 0x0101) >> 16; } @@ -385,14 +385,14 @@ namespace ccm::support { n = n - (n >> 1) & 0x55555555; n = (n & 0x33333333) + (n >> 2) & 0x33333333; - n = (n + n >> 4) & 0x0F0F0F0F; + n = (n + (n >> 4)) & 0x0F0F0F0F; return (n * 0x01010101) >> 24; } else // 16 bit int { n = n - (n >> 1) & 0x5555; n = (n & 0x3333) + (n >> 2) & 0x3333; - n = (n + n >> 4) & 0x0F0F; + n = (n + (n >> 4)) & 0x0F0F; return (n * 0x0101) >> 16; } } @@ -408,7 +408,7 @@ namespace ccm::support { n = n - (n >> 1) & 0x55555555; n = (n & 0x33333333) + (n >> 2) & 0x33333333; - n = (n + n >> 4) & 0x0F0F0F0F; + n = (n + (n >> 4)) & 0x0F0F0F0F; return (n * 0x01010101) >> 24; } else // 64-bit long diff --git a/include/ccmath/internal/support/fenv/fenv_support.hpp b/include/ccmath/internal/support/fenv/fenv_support.hpp index f6e2262b..87fc6ac0 100644 --- a/include/ccmath/internal/support/fenv/fenv_support.hpp +++ b/include/ccmath/internal/support/fenv/fenv_support.hpp @@ -20,6 +20,11 @@ #include #include +#if defined(_MSC_VER) && !defined(__clang__) +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" +CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code +#endif + namespace ccm::support::fenv::internal { inline int clear_except(const int err_code) @@ -168,3 +173,7 @@ namespace ccm::support::fenv } } } // namespace ccm::support::fenv + +#if defined(_MSC_VER) && !defined(__clang__) +CCM_RESTORE_MSVC_WARNING() +#endif diff --git a/include/ccmath/internal/support/integer_literals.hpp b/include/ccmath/internal/support/integer_literals.hpp index 5a019fc2..d9fa14b2 100644 --- a/include/ccmath/internal/support/integer_literals.hpp +++ b/include/ccmath/internal/support/integer_literals.hpp @@ -72,9 +72,9 @@ namespace ccm::support // for buffer allocation. static constexpr std::size_t calculate_bits_per_digit() { - if (base == 2) { return 1; } - if (base == 10) { return 3; } - if (base == 16) { return 4; } + if constexpr (base == 2) { return 1; } + if constexpr (base == 10) { return 3; } + if constexpr (base == 16) { return 4; } return 0; } @@ -98,7 +98,9 @@ namespace ccm::support const auto is_digit = [](char ch) { return ch >= '0' && ch <= '9'; }; const auto is_alpha = [](char ch) { return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'); }; if (is_digit(c)) { return static_cast(c - '0'); } + CCM_DISABLE_MSVC_WARNING(4127) // MSVC thinks the following is a constant expression. It is not. if (base > 10 && is_alpha(c)) { return static_cast(to_lower(c) - 'a' + 10); } + CCM_RESTORE_MSVC_WARNING() return INVALID_DIGIT; } diff --git a/include/ccmath/internal/support/math_support.hpp b/include/ccmath/internal/support/math_support.hpp index 3a7423b6..d2e9e211 100644 --- a/include/ccmath/internal/support/math_support.hpp +++ b/include/ccmath/internal/support/math_support.hpp @@ -49,7 +49,7 @@ namespace ccm::support } else { - if (lres < 0 || lres > std::numeric_limits::max()) { overflow = true; } + if (static_cast(lres) < 0 || static_cast(lres) > std::numeric_limits::max()) { overflow = true; } } // Store the result if no overflow diff --git a/include/ccmath/internal/types/big_int.hpp b/include/ccmath/internal/types/big_int.hpp index 27671078..6104124d 100644 --- a/include/ccmath/internal/types/big_int.hpp +++ b/include/ccmath/internal/types/big_int.hpp @@ -32,6 +32,11 @@ #include #include +#if defined(_MSC_VER) && !defined(__clang__) +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" +CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code +#endif + namespace ccm::types { namespace multiword @@ -611,7 +616,7 @@ namespace ccm::types template constexpr BigInt(const BigInt & other) // NOLINT(google-explicit-constructor) { - if (OtherBits >= Bits) + if constexpr (OtherBits >= Bits) { // Truncate the extra bits for (size_t i = 0; i < WORD_COUNT; ++i) { val[i] = other[i]; } @@ -1562,7 +1567,7 @@ namespace ccm::support constexpr std::enable_if_t, T> mask_trailing_ones() { static_assert(!T::SIGNED && count <= T::BITS); - if (count == T::BITS) { return T::all_ones(); } + if constexpr (count == T::BITS) { return T::all_ones(); } constexpr std::size_t QUOTIENT = count / T::WORD_SIZE; constexpr std::size_t REMAINDER = count % T::WORD_SIZE; T out; // zero initialized @@ -1624,3 +1629,7 @@ namespace ccm::support return value == std::numeric_limits::max() ? 0 : support::countr_zero(value) + 1; } } // namespace ccm::support + +#if defined(_MSC_VER) && !defined(__clang__) +CCM_RESTORE_MSVC_WARNING() +#endif diff --git a/include/ccmath/math/basic/impl/nan_double_impl.hpp b/include/ccmath/math/basic/impl/nan_double_impl.hpp index 6dbbe934..d08f769d 100644 --- a/include/ccmath/math/basic/impl/nan_double_impl.hpp +++ b/include/ccmath/math/basic/impl/nan_double_impl.hpp @@ -13,9 +13,13 @@ #include "ccmath/internal/support/helpers/digit_to_int.hpp" #include "ccmath/internal/support/bits.hpp" +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" + #include #include +CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code + namespace ccm::internal::impl { @@ -104,3 +108,5 @@ namespace ccm::internal::impl return ccm::support::bit_cast(dbl_bits); } } // namespace ccm::internal::impl + +CCM_RESTORE_MSVC_WARNING() diff --git a/include/ccmath/math/basic/impl/nan_float_impl.hpp b/include/ccmath/math/basic/impl/nan_float_impl.hpp index 40406111..4879a0eb 100644 --- a/include/ccmath/math/basic/impl/nan_float_impl.hpp +++ b/include/ccmath/math/basic/impl/nan_float_impl.hpp @@ -31,7 +31,7 @@ namespace ccm::internal::impl // So if we detect we are using MSVC without Clang-CL then // we can just return NaN and not bother doing any extra work. // To properly mimic the behavior of MSVC. - return std::numeric_limits::quiet_NaN(); // Default NaN + return std::numeric_limits::quiet_NaN(); // Default NaN #endif std::uint32_t flt_bits{0}; diff --git a/include/ccmath/math/expo/exp.hpp b/include/ccmath/math/expo/exp.hpp index db56b205..f9a690f7 100644 --- a/include/ccmath/math/expo/exp.hpp +++ b/include/ccmath/math/expo/exp.hpp @@ -13,6 +13,11 @@ #include "ccmath/math/expo/impl/exp_double_impl.hpp" #include "ccmath/math/expo/impl/exp_float_impl.hpp" +#if defined(_MSC_VER) && !defined(__clang__) +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" +CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code +#endif + namespace ccm { /** @@ -70,3 +75,7 @@ namespace ccm } } // namespace ccm + +#if defined(_MSC_VER) && !defined(__clang__) +CCM_RESTORE_MSVC_WARNING() +#endif diff --git a/include/ccmath/math/expo/exp2.hpp b/include/ccmath/math/expo/exp2.hpp index 04d4d1b7..8e22e06e 100644 --- a/include/ccmath/math/expo/exp2.hpp +++ b/include/ccmath/math/expo/exp2.hpp @@ -17,6 +17,11 @@ #include +#if defined(_MSC_VER) && !defined(__clang__) +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" +CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code +#endif + namespace ccm { /** @@ -74,3 +79,7 @@ namespace ccm } } // namespace ccm +#if defined(_MSC_VER) && !defined(__clang__) +CCM_RESTORE_MSVC_WARNING() +#endif + diff --git a/include/ccmath/math/expo/expm1.hpp b/include/ccmath/math/expo/expm1.hpp index b72a78e0..8bcfb6e3 100644 --- a/include/ccmath/math/expo/expm1.hpp +++ b/include/ccmath/math/expo/expm1.hpp @@ -12,16 +12,18 @@ #include +// TODO: Implement this. + namespace ccm { template , bool> = true> - constexpr T expm1(T num) + constexpr T expm1([[maybe_unused]] T num) { #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) if constexpr (std::is_same_v) { return __builtin_expm1f(num); } if constexpr (std::is_same_v) { return __builtin_expm1(num); } if constexpr (std::is_same_v) { return __builtin_expm1l(num); } - return static_cast(__builtin_expm1l(num)); + return static_cast(__builtin_expm1l(static_cast(num))); #else if constexpr (std::is_same_v) { return 0; } if constexpr (std::is_same_v) { return 0; } diff --git a/include/ccmath/math/expo/impl/exp2_float_impl.hpp b/include/ccmath/math/expo/impl/exp2_float_impl.hpp index f8eee093..6c9f1ecc 100644 --- a/include/ccmath/math/expo/impl/exp2_float_impl.hpp +++ b/include/ccmath/math/expo/impl/exp2_float_impl.hpp @@ -15,9 +15,14 @@ #include "ccmath/internal/types/fp_types.hpp" #include "ccmath/math/expo/impl/exp2_data.hpp" +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" + #include #include +// TODO: Replace with more modern implementation. +CCM_DISABLE_MSVC_WARNING(4056) + namespace ccm::internal { namespace impl @@ -81,3 +86,4 @@ namespace ccm::internal return impl::exp2_float_impl(x); } } // namespace ccm::internal +CCM_RESTORE_MSVC_WARNING() diff --git a/include/ccmath/math/expo/impl/exp_float_impl.hpp b/include/ccmath/math/expo/impl/exp_float_impl.hpp index 8a7f0e7b..4cf76a8b 100644 --- a/include/ccmath/math/expo/impl/exp_float_impl.hpp +++ b/include/ccmath/math/expo/impl/exp_float_impl.hpp @@ -14,8 +14,15 @@ #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/types/fp_types.hpp" #include "ccmath/math/expo/impl/exp_data.hpp" + +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" + #include +// TODO: Replace with more modern implementation. + +CCM_DISABLE_MSVC_WARNING(4056) + namespace ccm::internal::impl { constexpr auto internal_exp_data_flt = ccm::internal::exp_data(); @@ -86,3 +93,5 @@ namespace ccm::internal::impl return static_cast(result); } } // namespace ccm::internal::impl + +CCM_RESTORE_MSVC_WARNING() diff --git a/include/ccmath/math/expo/impl/log2_double_impl.hpp b/include/ccmath/math/expo/impl/log2_double_impl.hpp index 9df5e220..39584e8c 100644 --- a/include/ccmath/math/expo/impl/log2_double_impl.hpp +++ b/include/ccmath/math/expo/impl/log2_double_impl.hpp @@ -18,6 +18,9 @@ #include #include +// TODO: Replace with more modern implementation. +CCM_DISABLE_MSVC_WARNING(4146) + namespace ccm::internal { namespace impl @@ -128,3 +131,5 @@ namespace ccm::internal return impl::log2_double_impl(num); } } // namespace ccm::internal + +CCM_RESTORE_MSVC_WARNING() diff --git a/include/ccmath/math/expo/log.hpp b/include/ccmath/math/expo/log.hpp index 261ee56e..dc9f4ea9 100644 --- a/include/ccmath/math/expo/log.hpp +++ b/include/ccmath/math/expo/log.hpp @@ -14,6 +14,11 @@ #include "ccmath/internal/math/generic/func/expo/log_gen.hpp" #include "ccmath/math/expo/impl/log_float_impl.hpp" +#if defined(_MSC_VER) && !defined(__clang__) +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" +CCM_DISABLE_MSVC_WARNING(4702) +#endif + namespace ccm { /** @@ -86,3 +91,7 @@ namespace ccm return ccm::log(num); } } // namespace ccm + +#if defined(_MSC_VER) && !defined(__clang__) +CCM_RESTORE_MSVC_WARNING() +#endif diff --git a/include/ccmath/math/expo/log10.hpp b/include/ccmath/math/expo/log10.hpp index 7fff8aee..098cdcc0 100644 --- a/include/ccmath/math/expo/log10.hpp +++ b/include/ccmath/math/expo/log10.hpp @@ -15,13 +15,13 @@ namespace ccm { template , bool> = true> - constexpr T log10(T num) + constexpr T log10([[maybe_unused]] T num) { #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) if constexpr (std::is_same_v) { return __builtin_log10f(num); } if constexpr (std::is_same_v) { return __builtin_log10(num); } if constexpr (std::is_same_v) { return __builtin_log10l(num); } - return static_cast(__builtin_expm1l(num)); + return static_cast(__builtin_expm1l(static_cast(num))); #else if constexpr (std::is_same_v) { return 0; } if constexpr (std::is_same_v) { return 0; } diff --git a/include/ccmath/math/expo/log1p.hpp b/include/ccmath/math/expo/log1p.hpp index 9d568427..13944212 100644 --- a/include/ccmath/math/expo/log1p.hpp +++ b/include/ccmath/math/expo/log1p.hpp @@ -15,13 +15,13 @@ namespace ccm { template , bool> = true> - constexpr T log1p(T num) + constexpr T log1p([[maybe_unused]] T num) { #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) if constexpr (std::is_same_v) { return __builtin_log1pf(num); } if constexpr (std::is_same_v) { return __builtin_log1p(num); } if constexpr (std::is_same_v) { return __builtin_log1pl(num); } - return static_cast(__builtin_log1p(num)); + return static_cast(__builtin_log1p(static_cast(num))); #else if constexpr (std::is_same_v) { return 0; } if constexpr (std::is_same_v) { return 0; } diff --git a/include/ccmath/math/expo/log2.hpp b/include/ccmath/math/expo/log2.hpp index 3ce85d37..7c72ddad 100644 --- a/include/ccmath/math/expo/log2.hpp +++ b/include/ccmath/math/expo/log2.hpp @@ -19,6 +19,11 @@ #include #include +#if defined(_MSC_VER) && !defined(__clang__) +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" +CCM_DISABLE_MSVC_WARNING(4702) +#endif + namespace ccm { /** @@ -96,3 +101,7 @@ namespace ccm return ccm::log2(num); } } // namespace ccm + +#if defined(_MSC_VER) && !defined(__clang__) +CCM_RESTORE_MSVC_WARNING() +#endif diff --git a/include/ccmath/math/fmanip/copysign.hpp b/include/ccmath/math/fmanip/copysign.hpp index efbc1c28..e969535e 100644 --- a/include/ccmath/math/fmanip/copysign.hpp +++ b/include/ccmath/math/fmanip/copysign.hpp @@ -32,7 +32,7 @@ namespace ccm return std::numeric_limits::quiet_NaN(); } - T sign_bit = ccm::signbit(sgn) ? -1 : 1; + T sign_bit = ccm::signbit(sgn) ? T(-1) : T(1); return ccm::abs(mag) * sign_bit; } diff --git a/include/ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp b/include/ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp index 8bd87753..4daebe28 100644 --- a/include/ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp +++ b/include/ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp @@ -25,7 +25,7 @@ namespace ccm::internal constexpr long double scalbn_ldouble_impl(long double arg, int exp) noexcept { #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 // If long double is the same as double - return static_cast(ccm::internal::impl::scalbn_double_impl(arg, exp)); + return static_cast(ccm::internal::impl::scalbn_double_impl(static_cast(arg), exp)); #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 // If long double is 80-bit or 128-bit large // This is a generic implementation for long double scalbn that does not use bit manipulation. // May be much slower than the double and float version. diff --git a/include/ccmath/math/fmanip/scalbn.hpp b/include/ccmath/math/fmanip/scalbn.hpp index 66817f57..3a874687 100644 --- a/include/ccmath/math/fmanip/scalbn.hpp +++ b/include/ccmath/math/fmanip/scalbn.hpp @@ -14,6 +14,11 @@ #include "ccmath/math/fmanip/impl/scalbn_float_impl.hpp" #include "ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp" +#if defined(_MSC_VER) && !defined(__clang__) +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" +CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code +#endif + namespace ccm { /** @@ -132,3 +137,7 @@ namespace ccm return ccm::scalbn(num, exp); } } // namespace ccm + +#if defined(_MSC_VER) && !defined(__clang__) +CCM_RESTORE_MSVC_WARNING() +#endif From 7e208e4db272c9b6e54a09d2114d08595892e74e Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 22:10:13 -0500 Subject: [PATCH 049/102] Minor cleanup --- CMakePresets.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index adb249eb..a599642e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -260,7 +260,7 @@ { "name": "build-ninja-gcc-release", "configurePreset": "ninja-gcc-release", - "configuration": "RelWithDebInfo", + "configuration": "Release", "targets": [ "all" ] @@ -284,7 +284,7 @@ { "name": "build-ninja-clang-release", "configurePreset": "ninja-clang-release", - "configuration": "RelWithDebInfo", + "configuration": "Release", "targets": [ "all" ] @@ -324,7 +324,7 @@ { "name": "build-vs19-release", "configurePreset": "vs19-release", - "configuration": "RelWithDebInfo", + "configuration": "Release", "targets": [ "ALL_BUILD" ] @@ -340,7 +340,7 @@ { "name": "build-vs22-release", "configurePreset": "vs22-release", - "configuration": "RelWithDebInfo", + "configuration": "Release", "targets": [ "ALL_BUILD" ] @@ -364,7 +364,7 @@ { "name": "test-ninja-gcc-release", "configurePreset": "ninja-gcc-release", - "configuration": "RelWithDebInfo", + "configuration": "Release", "inheritConfigureEnvironment": true }, { @@ -382,7 +382,7 @@ { "name": "test-ninja-clang-release", "configurePreset": "ninja-clang-release", - "configuration": "RelWithDebInfo", + "configuration": "Release", "inheritConfigureEnvironment": true }, { @@ -412,7 +412,7 @@ { "name": "test-vs19-release", "configurePreset": "vs19-release", - "configuration": "RelWithDebInfo", + "configuration": "Release", "inheritConfigureEnvironment": true }, { @@ -424,7 +424,7 @@ { "name": "test-vs22-release", "configurePreset": "vs22-release", - "configuration": "RelWithDebInfo", + "configuration": "Release", "inheritConfigureEnvironment": true }, { From d6441f6fd869785bc1795aeb36be04ff86fd809d Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 22:15:46 -0500 Subject: [PATCH 050/102] Fix minor bugs --- CMakePresets.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index a599642e..39f27bef 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,7 +15,7 @@ "cacheVariables": { "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", - "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;MinSizeRel", + "CMAKE_CONFIGURATION_TYPES": "Debug;Release;RelWithDebInfo;MinSizeRel", "CMAKE_CXX_STANDARD": "17" } }, @@ -58,7 +58,7 @@ "name": "Release", "hidden": true, "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo" + "CMAKE_BUILD_TYPE": "Release" } }, { @@ -149,7 +149,7 @@ "gcc", "Release" ], - "description": "Ninja Multi-config + GCC (RelWithDebInfo)" + "description": "Ninja Multi-config + GCC (Release)" }, { "name": "ninja-gcc-ccache-debug", @@ -177,7 +177,7 @@ "clang", "Release" ], - "description": "Ninja Multi-config + Clang (RelWithDebInfo)" + "description": "Ninja Multi-config + Clang (Release)" }, { "name": "ninja-clang-minsizerel", @@ -220,7 +220,7 @@ "base-vs19", "Release" ], - "description": "VS2019 + RelWithDebInfo" + "description": "VS2019 + Release" }, { "name": "vs22-debug", @@ -236,7 +236,7 @@ "base-vs22", "Release" ], - "description": "VS2022 + RelWithDebInfo" + "description": "VS2022 + Release" }, { "name": "vs22-clang-debug", From 0b0e94fb8b325c716f3d2ba4c3901b30c46366b9 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 22:18:04 -0500 Subject: [PATCH 051/102] Disable resharper inspection --- include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp b/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp index 362c4ff0..5d5a0801 100644 --- a/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp +++ b/include/ccmath/internal/math/generic/func/power/sqrt_gen.hpp @@ -73,6 +73,7 @@ namespace ccm::gen namespace bit80 { // This has to be defined for sqrt_impl to work as it still needs to see that this function exists + // ReSharper disable once CppFunctionIsNotImplemented static constexpr long double sqrt_calc_80bits(long double x); #if defined(CCM_TYPES_LONG_DOUBLE_IS_FLOAT80) From 96d23cbab8ff7ac1fff89563b3707893d7c2be67 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 22:21:26 -0500 Subject: [PATCH 052/102] Move location of disabled warning macro --- include/ccmath/internal/support/integer_literals.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/ccmath/internal/support/integer_literals.hpp b/include/ccmath/internal/support/integer_literals.hpp index d9fa14b2..eaafe6e3 100644 --- a/include/ccmath/internal/support/integer_literals.hpp +++ b/include/ccmath/internal/support/integer_literals.hpp @@ -90,6 +90,7 @@ namespace ccm::support for (char const ch : str) { push(ch); } } + CCM_DISABLE_MSVC_WARNING(4127) // MSVC thinks the is_alpha is a constant expression; It is not. // Returns the digit for a particular character. // Returns INVALID_DIGIT if the character is invalid. static constexpr uint8_t get_digit_value(const char c) @@ -98,11 +99,12 @@ namespace ccm::support const auto is_digit = [](char ch) { return ch >= '0' && ch <= '9'; }; const auto is_alpha = [](char ch) { return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'); }; if (is_digit(c)) { return static_cast(c - '0'); } - CCM_DISABLE_MSVC_WARNING(4127) // MSVC thinks the following is a constant expression. It is not. + if (base > 10 && is_alpha(c)) { return static_cast(to_lower(c) - 'a' + 10); } - CCM_RESTORE_MSVC_WARNING() return INVALID_DIGIT; } + CCM_RESTORE_MSVC_WARNING() + // Adds a single character to this buffer. constexpr void push(char c) From 67c9fad7069155f9fdd467cc2a1fd85a50a5a1ea Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 22:31:06 -0500 Subject: [PATCH 053/102] Apply possible workaround to SEH issue on runners --- test/power/sqrt_test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/power/sqrt_test.cpp b/test/power/sqrt_test.cpp index 297b5d23..9b757c2b 100644 --- a/test/power/sqrt_test.cpp +++ b/test/power/sqrt_test.cpp @@ -8,6 +8,11 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +// Workaround for the GitHub Actions causing SEH exceptions +// https://github.com/actions/runner-images/issues/10004# +// NOLINTNEXTLINE +#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR + #include #include "ccmath/ccmath.hpp" From 1ae6773b6ac6cd371d5ebd693330e70a43ce6e36 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 22:45:21 -0500 Subject: [PATCH 054/102] Additional fixing of warnings --- include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp | 4 ++++ test/basic/abs_test.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp b/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp index 5ff5c525..8633a867 100644 --- a/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp +++ b/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp @@ -17,6 +17,8 @@ #include +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" + namespace ccm::internal { namespace impl @@ -31,7 +33,9 @@ namespace ccm::internal exp -= 127; if (exp > 127) { + CCM_DISABLE_MSVC_WARNING(4756) // 4756: overflow in constant arithmetic tmp *= 0x1p127F; + CCM_RESTORE_MSVC_WARNING() exp -= 127; exp = ccm::min(exp, 127); } diff --git a/test/basic/abs_test.cpp b/test/basic/abs_test.cpp index 6284a363..eb24afd9 100644 --- a/test/basic/abs_test.cpp +++ b/test/basic/abs_test.cpp @@ -15,6 +15,12 @@ // NOLINTBEGIN +#if defined(_MSC_VER) && !defined(__clang__) +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" +// TODO: Look into this issue at a later date. +CCM_DISABLE_MSVC_WARNING(4756) // 4756: overflow in constant arithmetic - Not sure why this is happening +#endif + namespace { @@ -253,3 +259,7 @@ TEST(CcmathBasicTests, CcmAbsCanBeEvaluatedAtCompileTime) } // NOLINTEND + +#if defined(_MSC_VER) && !defined(__clang__) +CCM_RESTORE_MSVC_WARNING() +#endif From 27ab97a8130bf5648d9eabfff0e75a281cf0f2e6 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 22:52:04 -0500 Subject: [PATCH 055/102] Additional fixing of warnings --- include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp b/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp index 8633a867..2f729aa7 100644 --- a/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp +++ b/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp @@ -18,6 +18,7 @@ #include #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" +CCM_DISABLE_MSVC_WARNING(4756) // 4756: overflow in constant arithmetic namespace ccm::internal { @@ -33,9 +34,7 @@ namespace ccm::internal exp -= 127; if (exp > 127) { - CCM_DISABLE_MSVC_WARNING(4756) // 4756: overflow in constant arithmetic - tmp *= 0x1p127F; - CCM_RESTORE_MSVC_WARNING() + tmp *= 0x1p127F; // This is what we are disabling the warning for. exp -= 127; exp = ccm::min(exp, 127); } @@ -69,3 +68,5 @@ namespace ccm::internal return impl::scalbn_float_impl(arg, static_cast(exp)); } } // namespace ccm::internal + +CCM_RESTORE_MSVC_WARNING() From cd2a6bb67038c3da8463ca0c651c7227216d98a8 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 23:28:25 -0500 Subject: [PATCH 056/102] Additional debugging of CI SEH exception --- .github/workflows/ci-linux.yml | 2 +- .github/workflows/ci-macos.yml | 2 +- .github/workflows/ci-windows.yml | 2 +- CMakeLists.txt | 1 + cmake/config/features/CheckAllSupportedSimdFeatures.cmake | 1 - test/power/sqrt_test.cpp | 3 +-- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 6551e8c8..b87ac4b4 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -112,4 +112,4 @@ jobs: run: cmake --build --preset="${{ matrix.buildPreset }}" - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --extra-verbose --schedule-random -F diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 180ee2dd..8d8354d5 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -98,4 +98,4 @@ jobs: run: cmake --build --preset="${{ matrix.buildPreset }}" - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --extra-verbose --schedule-random -F diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index c3006528..6fccc0eb 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -68,4 +68,4 @@ jobs: run: cmake --build --preset="${{ matrix.buildPreset }}" - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --extra-verbose --schedule-random -F diff --git a/CMakeLists.txt b/CMakeLists.txt index dd4d9500..cccb89d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ if (MSVC) /permissive- /Zc:__cplusplus /D_ENABLE_EXTENDED_ALIGNED_STORAGE + /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR ) # Only define NOMINMAX on Windows platforms if (WIN32) diff --git a/cmake/config/features/CheckAllSupportedSimdFeatures.cmake b/cmake/config/features/CheckAllSupportedSimdFeatures.cmake index 43d3129f..eec72c82 100644 --- a/cmake/config/features/CheckAllSupportedSimdFeatures.cmake +++ b/cmake/config/features/CheckAllSupportedSimdFeatures.cmake @@ -15,4 +15,3 @@ include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckNEONSupport.cmake) if (NOT CCMATH_DISABLE_SVML_USAGE) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSVMLSupport.cmake) endif () - diff --git a/test/power/sqrt_test.cpp b/test/power/sqrt_test.cpp index 9b757c2b..e007bac3 100644 --- a/test/power/sqrt_test.cpp +++ b/test/power/sqrt_test.cpp @@ -11,7 +11,6 @@ // Workaround for the GitHub Actions causing SEH exceptions // https://github.com/actions/runner-images/issues/10004# // NOLINTNEXTLINE -#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR #include @@ -208,4 +207,4 @@ TEST(CcmathPowerTests, Sqrt_RT_LDouble_EdgeCases) //EXPECT_EQ(ccm::sqrt(std::numeric_limits::lowest()), std::sqrt(std::numeric_limits::lowest())); } -#endif +#endif // defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) From 04ae858c9db9fd1adba2d893dae0195b60444349 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 23:37:38 -0500 Subject: [PATCH 057/102] More additional debugging of CI SEH exception --- .github/workflows/ci-linux.yml | 2 +- .github/workflows/ci-macos.yml | 2 +- .github/workflows/ci-windows.yml | 2 +- include/ccmath/math/power/sqrt.hpp | 4 ++-- thirdparty/CMakeLists.txt | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index b87ac4b4..eaef6af9 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -112,4 +112,4 @@ jobs: run: cmake --build --preset="${{ matrix.buildPreset }}" - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --extra-verbose --schedule-random -F + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --verbose --schedule-random -F diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 8d8354d5..6b20f8a6 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -98,4 +98,4 @@ jobs: run: cmake --build --preset="${{ matrix.buildPreset }}" - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --extra-verbose --schedule-random -F + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --verbose --schedule-random -F diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index 6fccc0eb..3417deef 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -68,4 +68,4 @@ jobs: run: cmake --build --preset="${{ matrix.buildPreset }}" - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --extra-verbose --schedule-random -F + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --verbose --schedule-random -F diff --git a/include/ccmath/math/power/sqrt.hpp b/include/ccmath/math/power/sqrt.hpp index a44fa94d..da30e5eb 100644 --- a/include/ccmath/math/power/sqrt.hpp +++ b/include/ccmath/math/power/sqrt.hpp @@ -37,8 +37,8 @@ namespace ccm else if constexpr (std::is_same_v) { return __builtin_sqrtl(num); } else { return static_cast(__builtin_sqrtl(static_cast(num))); } #else - if (support::is_constant_evaluated()) { return gen::sqrt_gen(num); } - return rt::sqrt_rt(num); + if (ccm::support::is_constant_evaluated()) { return ccm::gen::sqrt_gen(num); } + return ccm::rt::sqrt_rt(num); #endif } diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 51bd8902..21abfd9c 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -3,7 +3,7 @@ project(ccmath-ext) include(FetchContent) set(CCMATH_BENCHMARK_VERSION v1.9.1) -set(CCMATH_GTEST_VERSION v1.14.0) +set(CCMATH_GTEST_VERSION v1.15.2) if (CCMATH_BUILD_BENCHMARKS) if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") @@ -22,7 +22,7 @@ if (CCMATH_BUILD_TESTS) set(HAVE_STD_REGEX ON) endif() if (WIN32) - set(gtest_force_shared_crt ON) + #set(gtest_force_shared_crt ON) set(gtest_disable_pthreads ON) endif() set(BUILD_GMOCK OFF) From 8cbc6c96da3d420bf0a9017ff5d272b029d65eb2 Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 23 Dec 2024 23:57:59 -0500 Subject: [PATCH 058/102] Maintainer is testing things for CI specific SEH exception --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cccb89d7..86b668ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ if (MSVC) /Zc:__cplusplus /D_ENABLE_EXTENDED_ALIGNED_STORAGE /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR + /EHsc ) # Only define NOMINMAX on Windows platforms if (WIN32) From 78520b63da316631272cb7875ba9ad5026f7314a Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 14:27:58 -0500 Subject: [PATCH 059/102] Troubleshooting CI SEH Exception on sqrt tests --- test/power/sqrt_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/power/sqrt_test.cpp b/test/power/sqrt_test.cpp index e007bac3..d96671de 100644 --- a/test/power/sqrt_test.cpp +++ b/test/power/sqrt_test.cpp @@ -19,11 +19,13 @@ #include #include + TEST(CcmathPowerTests, Sqrt_StaticAssert) { //static_assert(ccm::sqrt(2.0) == ccm::sqrt(2.0), "ccm::sqrt is not a compile time constant!"); } +/* TEST(CcmathPowerTests, Sqrt_Double) { // Test values that are 2^x @@ -208,3 +210,4 @@ TEST(CcmathPowerTests, Sqrt_RT_LDouble_EdgeCases) //EXPECT_EQ(ccm::sqrt(std::numeric_limits::lowest()), std::sqrt(std::numeric_limits::lowest())); } #endif // defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) +*/ From 3674a26b1873b14a5997e8a995d7377ecdb18612 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 14:29:46 -0500 Subject: [PATCH 060/102] Troubleshooting CI SEH Exception on sqrt tests --- .github/workflows/ci-windows.yml | 2 +- test/power/sqrt_test.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index 3417deef..e3aed86a 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -68,4 +68,4 @@ jobs: run: cmake --build --preset="${{ matrix.buildPreset }}" - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --verbose --schedule-random -F + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --schedule-random -F diff --git a/test/power/sqrt_test.cpp b/test/power/sqrt_test.cpp index d96671de..3a7ecafc 100644 --- a/test/power/sqrt_test.cpp +++ b/test/power/sqrt_test.cpp @@ -25,7 +25,6 @@ TEST(CcmathPowerTests, Sqrt_StaticAssert) //static_assert(ccm::sqrt(2.0) == ccm::sqrt(2.0), "ccm::sqrt is not a compile time constant!"); } -/* TEST(CcmathPowerTests, Sqrt_Double) { // Test values that are 2^x @@ -37,6 +36,8 @@ TEST(CcmathPowerTests, Sqrt_Double) EXPECT_EQ(ccm::sqrt(0.0), std::sqrt(0.0)); + + /* EXPECT_EQ(ccm::sqrt(1.0), std::sqrt(1.0)); EXPECT_EQ(ccm::sqrt(2.0), std::sqrt(2.0)); EXPECT_EQ(ccm::sqrt(4.0), std::sqrt(4.0)); @@ -53,8 +54,10 @@ TEST(CcmathPowerTests, Sqrt_Double) EXPECT_EQ(ccm::sqrt(0.3), std::sqrt(0.3)); EXPECT_EQ(ccm::sqrt(0.4), std::sqrt(0.4)); EXPECT_EQ(ccm::sqrt(0.5), std::sqrt(0.5)); + */ } +/* TEST(CcmathPowerTests, Sqrt_Double_EdgeCases) { // Test edge cases From 26ea10c0ada5fb32f1707dcca17d9a3b16c0155a Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 14:39:32 -0500 Subject: [PATCH 061/102] Adjust dependabot to only update dev --- .github/dependabot.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4a472a78..f5f608fc 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,3 +6,4 @@ updates: interval: "monthly" # Allow up to 3 opened pull requests for github-actions versions. open-pull-requests-limit: 3 + target-branch: "dev" From 809233efa7a4896d9fe64b59a0e233904d3f9660 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 14:39:39 -0500 Subject: [PATCH 062/102] Troubleshooting CI SEH Exception on sqrt tests --- test/power/sqrt_test.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/power/sqrt_test.cpp b/test/power/sqrt_test.cpp index 3a7ecafc..e3a930c5 100644 --- a/test/power/sqrt_test.cpp +++ b/test/power/sqrt_test.cpp @@ -19,12 +19,24 @@ #include #include - +/* TEST(CcmathPowerTests, Sqrt_StaticAssert) { //static_assert(ccm::sqrt(2.0) == ccm::sqrt(2.0), "ccm::sqrt is not a compile time constant!"); } +*/ +TEST(CcmathPowerTests, Sqrt_Double_CheckCCM) +{ + EXPECT_EQ(ccm::sqrt(0.0), ccm::sqrt(0.0)); +} + +TEST(CcmathPowerTests, Sqrt_Double_CheckSTD) +{ + EXPECT_EQ(std::sqrt(0.0), std::sqrt(0.0)); +} + +/* TEST(CcmathPowerTests, Sqrt_Double) { // Test values that are 2^x @@ -35,9 +47,8 @@ TEST(CcmathPowerTests, Sqrt_Double) - EXPECT_EQ(ccm::sqrt(0.0), std::sqrt(0.0)); + EXPECT_EQ(ccm::sqrt(0.0), ccm::sqrt(0.0)); - /* EXPECT_EQ(ccm::sqrt(1.0), std::sqrt(1.0)); EXPECT_EQ(ccm::sqrt(2.0), std::sqrt(2.0)); EXPECT_EQ(ccm::sqrt(4.0), std::sqrt(4.0)); @@ -54,10 +65,10 @@ TEST(CcmathPowerTests, Sqrt_Double) EXPECT_EQ(ccm::sqrt(0.3), std::sqrt(0.3)); EXPECT_EQ(ccm::sqrt(0.4), std::sqrt(0.4)); EXPECT_EQ(ccm::sqrt(0.5), std::sqrt(0.5)); - */ + } -/* + TEST(CcmathPowerTests, Sqrt_Double_EdgeCases) { // Test edge cases From dbcc5b84d81f3b2e8c9c440e4b96d64bb2ed46b3 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 14:48:48 -0500 Subject: [PATCH 063/102] More Troubleshooting CI SEH Exception on sqrt tests --- test/power/sqrt_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/power/sqrt_test.cpp b/test/power/sqrt_test.cpp index e3a930c5..cbc68c51 100644 --- a/test/power/sqrt_test.cpp +++ b/test/power/sqrt_test.cpp @@ -31,6 +31,12 @@ TEST(CcmathPowerTests, Sqrt_Double_CheckCCM) EXPECT_EQ(ccm::sqrt(0.0), ccm::sqrt(0.0)); } +TEST(CcmathPowerTests, Sqrt_Double_CheckCCM_static) +{ + constexpr double sqrt_0 = ccm::sqrt(0.0); + EXPECT_EQ(sqrt_0, sqrt_0); +} + TEST(CcmathPowerTests, Sqrt_Double_CheckSTD) { EXPECT_EQ(std::sqrt(0.0), std::sqrt(0.0)); From 4ecf0f0992f7ef5bd59284140925db11d9e2807e Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 17:04:26 -0500 Subject: [PATCH 064/102] Allow gtest to debug SEH exceptions with abseil and re2 --- test/CMakeLists.txt | 4 ++++ thirdparty/CMakeLists.txt | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7b87b95f..f6972ad6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,9 +11,13 @@ add_library(${PROJECT_NAME} STATIC) add_library(ccmath::test ALIAS ${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME} PUBLIC ccmath::ccmath + + ${Abseil_LIBRARIES} gtest::gtest + re2::re2 ) target_include_directories(${PROJECT_NAME} PUBLIC .) +target_include_directories(${PROJECT_NAME} PUBLIC ${Abseil_INCLUDE_DIRS}) target_sources(${PROJECT_NAME} PRIVATE ccmath_test_main.cpp ) diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 21abfd9c..8a6b554f 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -2,8 +2,12 @@ project(ccmath-ext) include(FetchContent) +# TODO: Cleanup all of the logic of handling deps + set(CCMATH_BENCHMARK_VERSION v1.9.1) set(CCMATH_GTEST_VERSION v1.15.2) +set(CCMATH_ABSEIL_VERSION 20240722.0) +set(CCMATH_RE2_VERSION 2024-07-02) if (CCMATH_BUILD_BENCHMARKS) if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") @@ -18,11 +22,28 @@ if (CCMATH_BUILD_BENCHMARKS) endif() if (CCMATH_BUILD_TESTS) + set(ABSL_PROPAGATE_CXX_STD ON) + set(ABSL_ENABLE_INSTALL ON) + set(GTEST_HAS_ABSL ON) + FetchContent_Declare( + abseil + GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git + GIT_TAG ${CCMATH_ABSEIL_VERSION} + ) + FetchContent_MakeAvailable(abseil) + + FetchContent_Declare( + re2 + GIT_REPOSITORY https://github.com/google/re2.git + GIT_TAG ${CCMATH_RE2_VERSION} + ) + FetchContent_MakeAvailable(re2) + if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") set(HAVE_STD_REGEX ON) endif() if (WIN32) - #set(gtest_force_shared_crt ON) + set(gtest_force_shared_crt ON) set(gtest_disable_pthreads ON) endif() set(BUILD_GMOCK OFF) @@ -43,6 +64,7 @@ if (CCMATH_BUILD_TESTS) add_library(gtest::gtest ALIAS gtest) endif() endif() + endif() FetchContent_MakeAvailable(benchmark) @@ -54,9 +76,12 @@ add_library(ccmath::ext ALIAS ${PROJECT_NAME}) # Link GTest only if tests are enabled if (CCMATH_BUILD_TESTS) target_link_libraries(${PROJECT_NAME} INTERFACE gtest::gtest) + target_link_libraries(${PROJECT_NAME} INTERFACE absl::base absl::debugging re2::re2) endif() # Link Google Benchmark only if benchmarks are enabled if (CCMATH_BUILD_BENCHMARKS) target_link_libraries(${PROJECT_NAME} INTERFACE benchmark::benchmark) endif() + + From e0cc964472fdc5cf424f29455333309a0a6aac9c Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:05:30 -0500 Subject: [PATCH 065/102] Minor modernization for CI --- .github/workflows/ci-linux.yml | 4 +- .github/workflows/ci-macos-m1.yml | 101 ++++++++++++++++++++++++++++++ .github/workflows/ci-macos.yml | 4 +- .github/workflows/ci-windows.yml | 2 +- 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/ci-macos-m1.yml diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index eaef6af9..0f19cc04 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -15,7 +15,7 @@ permissions: jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -112,4 +112,4 @@ jobs: run: cmake --build --preset="${{ matrix.buildPreset }}" - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --verbose --schedule-random -F + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --schedule-random -F diff --git a/.github/workflows/ci-macos-m1.yml b/.github/workflows/ci-macos-m1.yml new file mode 100644 index 00000000..00e73030 --- /dev/null +++ b/.github/workflows/ci-macos-m1.yml @@ -0,0 +1,101 @@ +name: ci-macos + +on: + push: + tags-ignore: + - v*.* + branches: + - '*' + pull_request: + branches: + - '*' + +permissions: + contents: read + +jobs: + build: + runs-on: macos-latest + strategy: + fail-fast: false + matrix: + include: + - name: clang-debug-cxx17 + configurePreset: ninja-clang-debug + buildPreset: build-ninja-clang-debug + testPreset: test-ninja-clang-debug + cxx_version: 17 + + - name: clang-debug-cxx20 + configurePreset: ninja-clang-debug + buildPreset: build-ninja-clang-debug + testPreset: test-ninja-clang-debug + cxx_version: 20 + + - name: clang-release-cxx17 + configurePreset: ninja-clang-release + buildPreset: build-ninja-clang-release + testPreset: test-ninja-clang-release + cxx_version: 17 + + - name: clang-release-cxx20 + configurePreset: ninja-clang-release + buildPreset: build-ninja-clang-release + testPreset: test-ninja-clang-release + cxx_version: 20 + + - name: gcc-debug-cxx17 + configurePreset: ninja-gcc-debug + buildPreset: build-ninja-gcc-debug + testPreset: test-ninja-gcc-debug + cxx_version: 17 + + - name: gcc-debug-cxx20 + configurePreset: ninja-gcc-debug + buildPreset: build-ninja-gcc-debug + testPreset: test-ninja-gcc-debug + cxx_version: 20 + + - name: gcc-release-cxx17 + configurePreset: ninja-gcc-release + buildPreset: build-ninja-gcc-release + testPreset: test-ninja-gcc-release + cxx_version: 17 + + - name: gcc-release-cxx20 + configurePreset: ninja-gcc-release + buildPreset: build-ninja-gcc-release + testPreset: test-ninja-gcc-release + cxx_version: 20 + + steps: + - name: Harden Runner + uses: step-security/harden-runner@v2.9.1 + with: + egress-policy: audit + + - uses: actions/checkout@v4 + + - name: Cache build + uses: actions/cache@v4 + with: + path: | + ./**/CMakeFiles + ./**/CMakeCache.txt + ./**/out + key: ${{ runner.os }}-${{ matrix.name }} + + - name: Install Homebrew + run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + - name: Install Ninja + run: brew install ninja + + - name: Configure + run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" + + - name: Build + run: cmake --build --preset="${{ matrix.buildPreset }}" + + - name: Test + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --schedule-random -F diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 6b20f8a6..2562b5bc 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -15,7 +15,7 @@ permissions: jobs: build: - runs-on: macos-14 + runs-on: macos-13 strategy: fail-fast: false matrix: @@ -98,4 +98,4 @@ jobs: run: cmake --build --preset="${{ matrix.buildPreset }}" - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --verbose --schedule-random -F + run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --schedule-random -F diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index e3aed86a..a3be627a 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -15,7 +15,7 @@ permissions: jobs: build: - runs-on: windows-2022 + runs-on: windows-latest strategy: fail-fast: false matrix: From 1a9a1343e51d8199867e78d9f797c2f3eade35a6 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:10:29 -0500 Subject: [PATCH 066/102] Disable usage of AVX512 Signed-off-by: Ian --- .../config/arch/check_simd_support.hpp | 68 +------------------ .../internal/math/runtime/simd/simd.hpp | 4 -- 2 files changed, 2 insertions(+), 70 deletions(-) diff --git a/include/ccmath/internal/config/arch/check_simd_support.hpp b/include/ccmath/internal/config/arch/check_simd_support.hpp index 0613ddf6..9b60ee10 100644 --- a/include/ccmath/internal/config/arch/check_simd_support.hpp +++ b/include/ccmath/internal/config/arch/check_simd_support.hpp @@ -19,7 +19,6 @@ * - SSE4.2 * - AVX * - AVX2 - * - AVX512 * * ARM: * - NEON @@ -93,71 +92,7 @@ #define CCMATH_HAS_SIMD_AVX2 1 #endif - // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Byte and Word instructions. - #if defined(__AVX512BW__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512BW) - #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD 1 - #endif - #define CCMATH_HAS_SIMD_AVX512BW 1 - #endif - - // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Conflict Detection instructions. - #if defined(__AVX512CD__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512CD) - #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD 1 - #endif - #define CCMATH_HAS_SIMD_AVX512CD 1 - #endif - - // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Doubleword and Quadword instructions. - #if defined(__AVX512DQ__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512DQ) - #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD 1 - #endif - #define CCMATH_HAS_SIMD_AVX512DQ 1 - #endif - - // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Exponential and Reciprocal instructions. - #if defined(__AVX512ER__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512ER) - #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD 1 - #endif - #define CCMATH_HAS_SIMD_AVX512ER 1 - #endif - - // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Foundation instructions. - #if defined(__AVX512F__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512F) - #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD 1 - #endif - #define CCMATH_HAS_SIMD_AVX512F 1 - #endif - - // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Prefetch instructions. - #if defined(__AVX512PF__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512PF) - #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD 1 - #endif - #define CCMATH_HAS_SIMD_AVX512PF 1 - #endif - - // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Vector Length extensions. - #if defined(__AVX512VL__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512VL) - #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD 1 - #endif - #define CCMATH_HAS_SIMD_AVX512VL 1 - #endif - - // Processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Byte and Word instructions. - #if (defined(__AVX512F__) && defined(__AVX512VL__) && defined(__AVX512BW__) && defined(__AVX512DQ__)) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX512) - #ifndef CCMATH_HAS_SIMD - #define CCMATH_HAS_SIMD 1 - #endif - #define CCMATH_HAS_SIMD_AVX512 1 - #endif - -// Intel Short Vector Math Library (SVML) +// FMA (Fused Multiply-Add) Extensions #if defined(__FMA__) || defined(CCM_CONFIG_RT_SIMD_HAS_FMA) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 @@ -166,6 +101,7 @@ #endif // Intel Short Vector Math Library (SVML) +// As far as I am aware, there is no reliable way to detect SVML support at compile-time. #if defined(CCM_CONFIG_RT_SIMD_HAS_SVML) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 diff --git a/include/ccmath/internal/math/runtime/simd/simd.hpp b/include/ccmath/internal/math/runtime/simd/simd.hpp index 4815c9f0..b6613f5f 100644 --- a/include/ccmath/internal/math/runtime/simd/simd.hpp +++ b/include/ccmath/internal/math/runtime/simd/simd.hpp @@ -42,10 +42,6 @@ #include "instructions/avx2.hpp" #endif - #ifdef CCMATH_HAS_SIMD_AVX512F - #include "instructions/avx512.hpp" - #endif - #ifdef CCMATH_HAS_SIMD_NEON #include "instructions/neon.hpp" #endif From dd5c0a230647cebe44649e8ff26adfab3cf6d489 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:18:18 -0500 Subject: [PATCH 067/102] Rename m1 macos ci to better name Signed-off-by: Ian --- .github/workflows/ci-macos-m1.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-macos-m1.yml b/.github/workflows/ci-macos-m1.yml index 00e73030..d35247f7 100644 --- a/.github/workflows/ci-macos-m1.yml +++ b/.github/workflows/ci-macos-m1.yml @@ -1,4 +1,4 @@ -name: ci-macos +name: ci-macos-m1 on: push: From 0b07d7afaa5261007330153206c89b5a3f26ca0a Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:30:11 -0500 Subject: [PATCH 068/102] Remove homebrew install as macos-latest has it preinstalled Signed-off-by: Ian --- .github/workflows/ci-macos-m1.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci-macos-m1.yml b/.github/workflows/ci-macos-m1.yml index d35247f7..69a1c32c 100644 --- a/.github/workflows/ci-macos-m1.yml +++ b/.github/workflows/ci-macos-m1.yml @@ -85,9 +85,6 @@ jobs: ./**/out key: ${{ runner.os }}-${{ matrix.name }} - - name: Install Homebrew - run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - - name: Install Ninja run: brew install ninja From e668311d6a641428b0d89d2cbfd490a750dc3376 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:30:24 -0500 Subject: [PATCH 069/102] Experimental output Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 2562b5bc..9d6c6a7c 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -85,12 +85,15 @@ jobs: ./**/out key: ${{ runner.os }}-${{ matrix.name }} - - name: Install Homebrew - run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - - name: Install Ninja run: brew install ninja + - name: Where is Ninja + run: | + which ninja + ninja --version + ls -l /opt/homebrew/bin/ + - name: Configure run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" From f5f06ee11e24f4cbd8e8f3f42d27f66038eef9f2 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:34:23 -0500 Subject: [PATCH 070/102] Testing with homebrew Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 9d6c6a7c..51c38a2b 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -85,6 +85,9 @@ jobs: ./**/out key: ${{ runner.os }}-${{ matrix.name }} + - name: Install Homebrew + run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + - name: Install Ninja run: brew install ninja From da592013e79a056e4b799ee1f44b06fa722894ee Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:38:12 -0500 Subject: [PATCH 071/102] Check path of ninja Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 51c38a2b..660d75d0 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -95,7 +95,7 @@ jobs: run: | which ninja ninja --version - ls -l /opt/homebrew/bin/ + cat $PATH - name: Configure run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" From 8ad2b0b3db4087dfb5390adcc422a240891c77ba Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:41:16 -0500 Subject: [PATCH 072/102] Remove path check of ninja Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 660d75d0..83ed158f 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -95,7 +95,6 @@ jobs: run: | which ninja ninja --version - cat $PATH - name: Configure run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" From 2ea2673440bf672885717d97a098e9fa8441c5a1 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:46:05 -0500 Subject: [PATCH 073/102] Install cmake also as workaround to path issue Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 83ed158f..39cf2201 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -89,7 +89,7 @@ jobs: run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - name: Install Ninja - run: brew install ninja + run: brew install cmake ninja # /usr/local/bin/ninja - name: Where is Ninja run: | From 0a2b0fcde03b66a4f2555732f1bf767f33a2e07f Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:54:52 -0500 Subject: [PATCH 074/102] Additional work around for issues with cmake Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 39cf2201..24f42528 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -89,12 +89,11 @@ jobs: run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - name: Install Ninja - run: brew install cmake ninja # /usr/local/bin/ninja - - - name: Where is Ninja - run: | - which ninja - ninja --version + run: brew install ninja + # Actual: /usr/local/bin/ninja + # Searched: /opt/homebrew/bin/ninja + - name: Symbolic link Ninja # Workaround for CMake not checking the right area for Ninja + run: ln -s /opt/homebrew/bin/ninja /usr/local/bin/ninja - name: Configure run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" From ea47cfa087ebab71d1f0dad83a4b4a23dea1f0bf Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:57:09 -0500 Subject: [PATCH 075/102] Additional work around for issues with cmake Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 24f42528..b67a0ed7 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -93,7 +93,7 @@ jobs: # Actual: /usr/local/bin/ninja # Searched: /opt/homebrew/bin/ninja - name: Symbolic link Ninja # Workaround for CMake not checking the right area for Ninja - run: ln -s /opt/homebrew/bin/ninja /usr/local/bin/ninja + run: ln -s /usr/local/bin/ninja /opt/homebrew/bin/ninja - name: Configure run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" From df43f6d4f03d18daf92c7d326c28f0538cd65892 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 22:58:15 -0500 Subject: [PATCH 076/102] Remove step to install homebrew Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index b67a0ed7..0e4d9e20 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -85,9 +85,6 @@ jobs: ./**/out key: ${{ runner.os }}-${{ matrix.name }} - - name: Install Homebrew - run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - - name: Install Ninja run: brew install ninja # Actual: /usr/local/bin/ninja From b83f54bd1aa1e776ce50bb7cc838f6c155ed4945 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 23:01:36 -0500 Subject: [PATCH 077/102] Fix sym link issue Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 0e4d9e20..cd7f7c0e 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -90,7 +90,7 @@ jobs: # Actual: /usr/local/bin/ninja # Searched: /opt/homebrew/bin/ninja - name: Symbolic link Ninja # Workaround for CMake not checking the right area for Ninja - run: ln -s /usr/local/bin/ninja /opt/homebrew/bin/ninja + run: mkdir -p /opt/homebrew/bin && ln -s /usr/local/bin/ninja /opt/homebrew/bin/ninja - name: Configure run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" From ff105b06da87753a57925971d270794f83c3337c Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 23:06:30 -0500 Subject: [PATCH 078/102] Enforce Fix sym link issue Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index cd7f7c0e..f764df7a 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -90,7 +90,8 @@ jobs: # Actual: /usr/local/bin/ninja # Searched: /opt/homebrew/bin/ninja - name: Symbolic link Ninja # Workaround for CMake not checking the right area for Ninja - run: mkdir -p /opt/homebrew/bin && ln -s /usr/local/bin/ninja /opt/homebrew/bin/ninja + run: sudo mkdir -p /opt/homebrew/bin && sudo ln -s /usr/local/bin/ninja /opt/homebrew/bin/ninja + - name: Configure run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" From 13a6c89ec771b7b1db375b7d6a9a62d22c3d0ca9 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 26 Dec 2024 23:12:11 -0500 Subject: [PATCH 079/102] For now remove older macos ci Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 103 --------------------------------- 1 file changed, 103 deletions(-) delete mode 100644 .github/workflows/ci-macos.yml diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml deleted file mode 100644 index f764df7a..00000000 --- a/.github/workflows/ci-macos.yml +++ /dev/null @@ -1,103 +0,0 @@ -name: ci-macos - -on: - push: - tags-ignore: - - v*.* - branches: - - '*' - pull_request: - branches: - - '*' - -permissions: - contents: read - -jobs: - build: - runs-on: macos-13 - strategy: - fail-fast: false - matrix: - include: - - name: clang-debug-cxx17 - configurePreset: ninja-clang-debug - buildPreset: build-ninja-clang-debug - testPreset: test-ninja-clang-debug - cxx_version: 17 - - - name: clang-debug-cxx20 - configurePreset: ninja-clang-debug - buildPreset: build-ninja-clang-debug - testPreset: test-ninja-clang-debug - cxx_version: 20 - - - name: clang-release-cxx17 - configurePreset: ninja-clang-release - buildPreset: build-ninja-clang-release - testPreset: test-ninja-clang-release - cxx_version: 17 - - - name: clang-release-cxx20 - configurePreset: ninja-clang-release - buildPreset: build-ninja-clang-release - testPreset: test-ninja-clang-release - cxx_version: 20 - - - name: gcc-debug-cxx17 - configurePreset: ninja-gcc-debug - buildPreset: build-ninja-gcc-debug - testPreset: test-ninja-gcc-debug - cxx_version: 17 - - - name: gcc-debug-cxx20 - configurePreset: ninja-gcc-debug - buildPreset: build-ninja-gcc-debug - testPreset: test-ninja-gcc-debug - cxx_version: 20 - - - name: gcc-release-cxx17 - configurePreset: ninja-gcc-release - buildPreset: build-ninja-gcc-release - testPreset: test-ninja-gcc-release - cxx_version: 17 - - - name: gcc-release-cxx20 - configurePreset: ninja-gcc-release - buildPreset: build-ninja-gcc-release - testPreset: test-ninja-gcc-release - cxx_version: 20 - - steps: - - name: Harden Runner - uses: step-security/harden-runner@v2.9.1 - with: - egress-policy: audit - - - uses: actions/checkout@v4 - - - name: Cache build - uses: actions/cache@v4 - with: - path: | - ./**/CMakeFiles - ./**/CMakeCache.txt - ./**/out - key: ${{ runner.os }}-${{ matrix.name }} - - - name: Install Ninja - run: brew install ninja - # Actual: /usr/local/bin/ninja - # Searched: /opt/homebrew/bin/ninja - - name: Symbolic link Ninja # Workaround for CMake not checking the right area for Ninja - run: sudo mkdir -p /opt/homebrew/bin && sudo ln -s /usr/local/bin/ninja /opt/homebrew/bin/ninja - - - - name: Configure - run: cmake --preset="${{ matrix.configurePreset }}" -DCMAKE_CXX_STANDARD="${{ matrix.cxx_version }}" - - - name: Build - run: cmake --build --preset="${{ matrix.buildPreset }}" - - - name: Test - run: ctest --preset="${{ matrix.testPreset }}" --output-on-failure --schedule-random -F From d927593dc036116ff5b27a31de4211aa6586c087 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 27 Dec 2024 02:57:29 -0500 Subject: [PATCH 080/102] Begin initial work on simd wrapper rework Signed-off-by: Ian --- cmake/helpers/CcmAddHeaders.cmake | 7 + .../internal/math/runtime/CMakeLists.txt | 1 + .../internal/math/runtime/pp/CMakeLists.txt | 3 + .../ccmath/internal/math/runtime/pp/simd.hpp | 330 ++++++++++++++++++ 4 files changed, 341 insertions(+) create mode 100644 include/ccmath/internal/math/runtime/pp/CMakeLists.txt create mode 100644 include/ccmath/internal/math/runtime/pp/simd.hpp diff --git a/cmake/helpers/CcmAddHeaders.cmake b/cmake/helpers/CcmAddHeaders.cmake index c2d7cf38..3b99b70f 100644 --- a/cmake/helpers/CcmAddHeaders.cmake +++ b/cmake/helpers/CcmAddHeaders.cmake @@ -3,3 +3,10 @@ function(ccm_add_headers) # Append all the passed arguments (headers) to the target's sources target_sources(${PROJECT_NAME} INTERFACE "$") endfunction() + +function(ccm_add_headers_temp) + foreach(header IN LISTS ARGV) + target_sources(${PROJECT_NAME} INTERFACE "$") + endforeach() +endfunction() + diff --git a/include/ccmath/internal/math/runtime/CMakeLists.txt b/include/ccmath/internal/math/runtime/CMakeLists.txt index a0a34d09..e5aef513 100644 --- a/include/ccmath/internal/math/runtime/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(func) +add_subdirectory(pp) add_subdirectory(simd) diff --git a/include/ccmath/internal/math/runtime/pp/CMakeLists.txt b/include/ccmath/internal/math/runtime/pp/CMakeLists.txt new file mode 100644 index 00000000..25a74173 --- /dev/null +++ b/include/ccmath/internal/math/runtime/pp/CMakeLists.txt @@ -0,0 +1,3 @@ +ccm_add_headers_temp( + simd.hpp +) diff --git a/include/ccmath/internal/math/runtime/pp/simd.hpp b/include/ccmath/internal/math/runtime/pp/simd.hpp new file mode 100644 index 00000000..92e2aa43 --- /dev/null +++ b/include/ccmath/internal/math/runtime/pp/simd.hpp @@ -0,0 +1,330 @@ +#pragma once + +#include + + +// ISA extension detection. The following defines all the CCMATH_SIMD_HAVE_XXX macros + +// ARM Neon +#if defined __ARM_NEON +#define CCMATH_SIMD_HAVE_NEON 1 +#else +#define CCMATH_SIMD_HAVE_NEON 0 +#endif +#if defined __ARM_NEON && (__ARM_ARCH >= 8 || defined __aarch64__) +#define CCMATH_SIMD_HAVE_NEON_A32 1 +#else +#define CCMATH_SIMD_HAVE_NEON_A32 0 +#endif +#if defined __ARM_NEON && defined __aarch64__ +#define CCMATH_SIMD_HAVE_NEON_A64 1 +#else +#define CCMATH_SIMD_HAVE_NEON_A64 0 +#endif + +// x86 SIMD Extensions +#if defined __SSE2__ || defined __x86_64__ +#define CCMATH_SIMD_HAVE_SSE2 1 +#else +#define CCMATH_SIMD_HAVE_SSE2 0 +#endif +#ifdef __SSE4_2__ +#define CCMATH_SIMD_HAVE_SSE4_2 1 +#else +#define CCMATH_SIMD_HAVE_SSE4_2 0 +#endif +#ifdef __AVX2__ +#define CCMATH_SIMD_HAVE_AVX2 1 +#else +#define CCMATH_SIMD_HAVE_AVX2 0 +#endif +#ifdef __BMI__ +#define CCMATH_SIMD_HAVE_BMI1 1 +#else +#define CCMATH_SIMD_HAVE_BMI1 0 +#endif +#ifdef __BMI2__ +#define CCMATH_SIMD_HAVE_BMI2 1 +#else +#define CCMATH_SIMD_HAVE_BMI2 0 +#endif +#ifdef __FMA__ +#define CCMATH_SIMD_HAVE_FMA 1 +#else +#define CCMATH_SIMD_HAVE_FMA 0 +#endif +#ifdef __FMA4__ +#define CCMATH_SIMD_HAVE_FMA4 1 +#else +#define CCMATH_SIMD_HAVE_FMA4 0 +#endif +#ifdef __F16C__ +#define CCMATH_SIMD_HAVE_F16C 1 +#else +#define CCMATH_SIMD_HAVE_F16C 0 +#endif +#ifdef __POPCNT__ +#define CCMATH_SIMD_HAVE_POPCNT 1 +#else +#define CCMATH_SIMD_HAVE_POPCNT 0 +#endif + +#if defined(__GNUC__) && !defined(__clang__) // GCC +#define CCM_SIMD_INTRINSIC [[gnu::always_inline, gnu::artificial]] inline +#elif defined(_MSC_VER) && !defined(__clang__) // MSVC +#define CCM_SIMD_INTRINSIC __forceinline +#elif defined(__clang__) // Clang +#define CCM_SIMD_INTRINSIC [[gnu::always_inline, gnu::artificial]] inline +#else // Other compilers +#define CCM_SIMD_INTRINSIC inline +#endif + +#if defined(CCMATH_SIMD_HAVE_AVX2) || defined(CCMATH_SIMD_HAVE_SSE2) || defined(CCMATH_SIMD_HAVE_SSE4_2) +#define CCMATH_SIMD_IS_X86 1 +#else +#define CCMATH_SIMD_IS_X86 0 +#endif + +#if defined(CCMATH_SIMD_HAVE_NEON) || defined(CCMATH_SIMD_HAVE_NEON_A32) || defined(CCMATH_SIMD_HAVE_NEON_A64) +#define CCMATH_SIMD_IS_ARM 1 +#else +#define CCMATH_SIMD_IS_ARM 0 +#endif + +// C++20 explicit - if we don't have C++20 explicit then to be safe, we won't enforce explicit. +#ifndef CCM_CPP20_EXPLICIT +#if __cplusplus >= 202002L +#define CCM_CPP20_EXPLICIT(EXPR) explicit(EXPR) +#else +#define CCM_CPP20_EXPLICIT(EXPR) +#endif +#endif + + +namespace ccm::pp +{ + template + struct is_vectorizable : std::is_arithmetic + { + }; + + template <> + struct is_vectorizable : std::false_type + { + }; + + template + inline constexpr bool is_vectorizable_v = is_vectorizable::value; + + template > > + using Vectorizable = T; + + template > + struct is_bitmask : std::false_type + { + }; + + template + struct is_bitmask() = std::declval() & 1u)> > : std::true_type + { + }; + + template + inline constexpr bool is_bitmask_v = is_bitmask::value; + + + // Feature checks + constexpr inline bool have_neon = CCMATH_SIMD_HAVE_NEON; + constexpr inline bool have_neon_a32 = CCMATH_SIMD_HAVE_NEON_A32; + constexpr inline bool have_neon_a64 = CCMATH_SIMD_HAVE_NEON_A64; + constexpr inline bool have_sse2 = CCMATH_SIMD_HAVE_SSE2; + constexpr inline bool have_sse4_2 = CCMATH_SIMD_HAVE_SSE4_2; + constexpr inline bool have_avx2 = CCMATH_SIMD_HAVE_AVX2; + constexpr inline bool have_bmi1 = CCMATH_SIMD_HAVE_BMI1; + constexpr inline bool have_bmi2 = CCMATH_SIMD_HAVE_BMI2; + constexpr inline bool have_fma = CCMATH_SIMD_HAVE_FMA; + constexpr inline bool have_fma4 = CCMATH_SIMD_HAVE_FMA4; + constexpr inline bool have_f16c = CCMATH_SIMD_HAVE_F16C; + constexpr inline bool have_popcnt = CCMATH_SIMD_HAVE_POPCNT; + // TODO: Add support for checking on msvc + // clang-format off + constexpr inline bool support_neon_float = + #if defined(_MSC_VER) + #if defined(_M_ARM) || defined(_M_ARM64) + #if defined(_M_FP_FAST) + true; + #else + false; + #endif + #else + false; + #endif + #else + #if defined(__GCC_IEC_559) + __GCC_IEC_559 == 0; + #elif defined(__FAST_MATH__) + true; + #else + false; + #endif + #endif + // clang-format on + + + template + constexpr size_t + vectorized_sizeof() + { + if constexpr (!is_vectorizable_v) + return 0; + + if constexpr (sizeof(T) <= 8) + { + // X86: + if constexpr (have_avx2) + return 32; + + if constexpr (have_sse2) + return 16; + + // ARM: + if constexpr (have_neon_a64 + || (have_neon_a32 && !std::is_same_v)) + return 16; + if constexpr (have_neon + && sizeof(T) < 8 + // Only allow fp if the user allows non-ICE559 fp (e.g. + // via -ffast-math). ARMv7 NEON fp is not conforming to + // IEC559. + && (support_neon_float || !std::is_floating_point_v)) + return 16; + } + + return sizeof(T); + } + + + namespace simd_abi + { + template + struct vec_builtin + { + template + static constexpr size_t size = UsedBytes / sizeof(T); + + struct is_valid_abi_tag : std::bool_constant<(UsedBytes > 1)> + { + }; + + template + struct is_valid_size_for : std::bool_constant<( + UsedBytes / sizeof(T) > 1 && + UsedBytes % sizeof(T) == 0 && + UsedBytes <= vectorized_sizeof() && + UsedBytes <= 32)> {}; + + template + struct is_valid : std::conjunction, is_valid_size_for> {}; + + template + static constexpr bool is_valid_v = is_valid::value; + + // https://github.com/VcDevel/std-simd/blob/a0054893e8f0dc89d4f694c63a080e4b2e32850b/experimental/bits/simd_builtin.h#L954 + }; + + + template + struct scalar + { + }; + + template + struct sse2 + { + }; + + template + struct sse4_2 + { + }; + + template + struct avx2 + { + }; + + template + struct neon + { + }; + + #if CCMATH_SIMD_HAVE_NEON + using native = neon; + #elif CCMATH_SIMD_HAVE_AVX2 + using native = avx2; + #elif CCMATH_SIMD_HAVE_SSE4_2 + using native = sse4_2; + #elif CCMATH_SIMD_HAVE_SSE2 + using native = sse2; + #else + using native = scalar; + #endif + + } + + // https://isocpp.org/files/papers/P1928R15.pdf + // page 42 + template + struct basic_simd + { + using value_type = T; + using mask_type = basic_simd_mask; + using abi_type = Abi; + + // static constexpr integral_constant> size { + //static constexpr std::integral_constant<> + + constexpr basic_simd() noexcept = default; + + // ctors + + template + constexpr basic_simd(U&& value) noexcept + { + } + + template + constexpr CCM_CPP20_EXPLICIT(true) basic_simd(basic_simd const& value) noexcept + { + } + + + }; + + template + struct basic_simd_mask + { + using type = T; + }; + + template + using simd = basic_simd; +} + + +// Cleanup global namespace +#undef CCMATH_SIMD_HAVE_NEON +#undef CCMATH_SIMD_HAVE_NEON_A32 +#undef CCMATH_SIMD_HAVE_NEON_A64 +#undef CCMATH_SIMD_HAVE_SSE2 +#undef CCMATH_SIMD_HAVE_SSE4_2 +#undef CCMATH_SIMD_HAVE_AVX2 +#undef CCMATH_SIMD_HAVE_BMI1 +#undef CCMATH_SIMD_HAVE_BMI2 +#undef CCMATH_SIMD_HAVE_FMA +#undef CCMATH_SIMD_HAVE_FMA4 +#undef CCMATH_SIMD_HAVE_F16C +#undef CCMATH_SIMD_HAVE_POPCNT + +#undef CCMATH_SIMD_IS_X86 +#undef CCMATH_SIMD_IS_ARM From b83a1a8c17c9ca6c1aa96c45462c80b1498dfc02 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 28 Dec 2024 13:43:20 -0500 Subject: [PATCH 081/102] Switch over to improved ccm_add_headers Signed-off-by: Ian --- cmake/helpers/CcmAddHeaders.cmake | 10 ++--- include/ccmath/CMakeLists.txt | 2 +- include/ccmath/ext/CMakeLists.txt | 26 ++++++------ include/ccmath/internal/CMakeLists.txt | 2 +- include/ccmath/internal/config/CMakeLists.txt | 6 +-- .../internal/config/arch/CMakeLists.txt | 4 +- .../config/arch/targets/CMakeLists.txt | 4 +- .../internal/config/builtin/CMakeLists.txt | 12 +++--- .../internal/config/platform/CMakeLists.txt | 8 ++-- .../math/generic/func/basic/CMakeLists.txt | 16 +++---- .../math/generic/func/expo/CMakeLists.txt | 14 +++---- .../math/generic/func/fmanip/CMakeLists.txt | 16 +++---- .../math/generic/func/hyper/CMakeLists.txt | 12 +++--- .../math/generic/func/misc/CMakeLists.txt | 2 +- .../math/generic/func/nearest/CMakeLists.txt | 12 +++--- .../math/generic/func/power/CMakeLists.txt | 12 +++--- .../math/generic/func/special/CMakeLists.txt | 42 +++++++++---------- .../math/generic/func/trig/CMakeLists.txt | 14 +++---- .../math/runtime/func/power/CMakeLists.txt | 4 +- .../internal/math/runtime/pp/CMakeLists.txt | 2 +- .../internal/math/runtime/simd/CMakeLists.txt | 10 ++--- .../math/runtime/simd/func/CMakeLists.txt | 4 +- .../runtime/simd/func/impl/avx/CMakeLists.txt | 4 +- .../simd/func/impl/avx2/CMakeLists.txt | 4 +- .../simd/func/impl/avx512/CMakeLists.txt | 4 +- .../simd/func/impl/neon/CMakeLists.txt | 4 +- .../simd/func/impl/scalar/CMakeLists.txt | 4 +- .../simd/func/impl/sse2/CMakeLists.txt | 4 +- .../simd/func/impl/sse3/CMakeLists.txt | 4 +- .../simd/func/impl/sse4/CMakeLists.txt | 4 +- .../simd/func/impl/ssse3/CMakeLists.txt | 4 +- .../simd/func/impl/vector_size/CMakeLists.txt | 2 +- .../runtime/simd/instructions/CMakeLists.txt | 16 +++---- include/ccmath/internal/predef/CMakeLists.txt | 14 +++---- .../internal/predef/attributes/CMakeLists.txt | 14 +++---- .../compiler_suppression/CMakeLists.txt | 6 +-- .../internal/predef/versioning/CMakeLists.txt | 12 +++--- .../ccmath/internal/support/CMakeLists.txt | 28 ++++++------- .../internal/support/fenv/CMakeLists.txt | 4 +- .../ccmath/internal/support/fp/CMakeLists.txt | 6 +-- .../internal/support/helpers/CMakeLists.txt | 10 ++--- include/ccmath/internal/types/CMakeLists.txt | 20 ++++----- include/ccmath/math/CMakeLists.txt | 20 ++++----- include/ccmath/math/basic/CMakeLists.txt | 18 ++++---- include/ccmath/math/basic/impl/CMakeLists.txt | 12 +++--- include/ccmath/math/compare/CMakeLists.txt | 24 +++++------ include/ccmath/math/expo/CMakeLists.txt | 14 +++---- include/ccmath/math/expo/impl/CMakeLists.txt | 24 +++++------ include/ccmath/math/fmanip/CMakeLists.txt | 18 ++++---- .../ccmath/math/fmanip/impl/CMakeLists.txt | 10 ++--- include/ccmath/math/hyper/CMakeLists.txt | 12 +++--- include/ccmath/math/misc/CMakeLists.txt | 6 +-- include/ccmath/math/nearest/CMakeLists.txt | 12 +++--- include/ccmath/math/power/CMakeLists.txt | 8 ++-- include/ccmath/math/special/CMakeLists.txt | 42 +++++++++---------- include/ccmath/math/trig/CMakeLists.txt | 14 +++---- 56 files changed, 318 insertions(+), 318 deletions(-) diff --git a/cmake/helpers/CcmAddHeaders.cmake b/cmake/helpers/CcmAddHeaders.cmake index 3b99b70f..6a8266f4 100644 --- a/cmake/helpers/CcmAddHeaders.cmake +++ b/cmake/helpers/CcmAddHeaders.cmake @@ -1,10 +1,10 @@ # Helper function to add headers to the global source list -function(ccm_add_headers) - # Append all the passed arguments (headers) to the target's sources - target_sources(${PROJECT_NAME} INTERFACE "$") -endfunction() +#function(ccm_add_headers) +# # Append all the passed arguments (headers) to the target's sources +# target_sources(${PROJECT_NAME} INTERFACE "$") +#endfunction() -function(ccm_add_headers_temp) +function(ccm_add_headers) foreach(header IN LISTS ARGV) target_sources(${PROJECT_NAME} INTERFACE "$") endforeach() diff --git a/include/ccmath/CMakeLists.txt b/include/ccmath/CMakeLists.txt index 53cd7465..bf08d303 100644 --- a/include/ccmath/CMakeLists.txt +++ b/include/ccmath/CMakeLists.txt @@ -1,5 +1,5 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/ccmath.hpp + ccmath.hpp ) add_subdirectory(ext) diff --git a/include/ccmath/ext/CMakeLists.txt b/include/ccmath/ext/CMakeLists.txt index 3493955f..ed424883 100644 --- a/include/ccmath/ext/CMakeLists.txt +++ b/include/ccmath/ext/CMakeLists.txt @@ -1,15 +1,15 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/align.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/clamp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cubic.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/degrees.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fract.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/is_power_of_two.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/lerp_smooth.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/mix.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/normalize.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ping_pong.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/radians.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/rcp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/smoothstep.hpp + align.hpp + clamp.hpp + cubic.hpp + degrees.hpp + fract.hpp + is_power_of_two.hpp + lerp_smooth.hpp + mix.hpp + normalize.hpp + ping_pong.hpp + radians.hpp + rcp.hpp + smoothstep.hpp ) diff --git a/include/ccmath/internal/CMakeLists.txt b/include/ccmath/internal/CMakeLists.txt index c056b1c7..515a83ed 100644 --- a/include/ccmath/internal/CMakeLists.txt +++ b/include/ccmath/internal/CMakeLists.txt @@ -1,5 +1,5 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/setup.hpp + setup.hpp ) add_subdirectory(config) diff --git a/include/ccmath/internal/config/CMakeLists.txt b/include/ccmath/internal/config/CMakeLists.txt index 807683d5..104148e3 100644 --- a/include/ccmath/internal/config/CMakeLists.txt +++ b/include/ccmath/internal/config/CMakeLists.txt @@ -1,7 +1,7 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/compiler.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/runtime_detection.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/type_support.hpp + compiler.hpp + runtime_detection.hpp + type_support.hpp ) add_subdirectory(arch) diff --git a/include/ccmath/internal/config/arch/CMakeLists.txt b/include/ccmath/internal/config/arch/CMakeLists.txt index 8a8e9d8c..b442df51 100644 --- a/include/ccmath/internal/config/arch/CMakeLists.txt +++ b/include/ccmath/internal/config/arch/CMakeLists.txt @@ -1,6 +1,6 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/check_arch_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/check_simd_support.hpp + check_arch_support.hpp + check_simd_support.hpp ) add_subdirectory(targets) diff --git a/include/ccmath/internal/config/arch/targets/CMakeLists.txt b/include/ccmath/internal/config/arch/targets/CMakeLists.txt index 4378fa5e..46d209d1 100644 --- a/include/ccmath/internal/config/arch/targets/CMakeLists.txt +++ b/include/ccmath/internal/config/arch/targets/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/aarch64.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/x86_64.hpp + aarch64.hpp + x86_64.hpp ) diff --git a/include/ccmath/internal/config/builtin/CMakeLists.txt b/include/ccmath/internal/config/builtin/CMakeLists.txt index 963b9507..1000135c 100644 --- a/include/ccmath/internal/config/builtin/CMakeLists.txt +++ b/include/ccmath/internal/config/builtin/CMakeLists.txt @@ -1,8 +1,8 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/bit_cast_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/copysign_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp2_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fma_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ldexp_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/signbit_support.hpp + bit_cast_support.hpp + copysign_support.hpp + exp2_support.hpp + fma_support.hpp + ldexp_support.hpp + signbit_support.hpp ) diff --git a/include/ccmath/internal/config/platform/CMakeLists.txt b/include/ccmath/internal/config/platform/CMakeLists.txt index 5877e355..c5928a7b 100644 --- a/include/ccmath/internal/config/platform/CMakeLists.txt +++ b/include/ccmath/internal/config/platform/CMakeLists.txt @@ -1,6 +1,6 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/android.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/darwin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/linux.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/windows.hpp + android.hpp + darwin.hpp + linux.hpp + windows.hpp ) diff --git a/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt b/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt index 627b561b..a69f3f6a 100644 --- a/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/basic/CMakeLists.txt @@ -1,10 +1,10 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/abs_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fdim_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fma_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fmod_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/max_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/min_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/remainder_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/remquo_gen.hpp + abs_gen.hpp + fdim_gen.hpp + fma_gen.hpp + fmod_gen.hpp + max_gen.hpp + min_gen.hpp + remainder_gen.hpp + remquo_gen.hpp ) diff --git a/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt b/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt index 4a367450..60f75184 100644 --- a/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/expo/CMakeLists.txt @@ -1,9 +1,9 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/exp2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/expm1_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log1p_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log10_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log_gen.hpp + exp2_gen.hpp + exp_gen.hpp + expm1_gen.hpp + log1p_gen.hpp + log2_gen.hpp + log10_gen.hpp + log_gen.hpp ) diff --git a/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt b/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt index 9ea79bb6..d49ecf39 100644 --- a/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/fmanip/CMakeLists.txt @@ -1,10 +1,10 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/copysign_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/frexp_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ilogb_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ldexp_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/logb_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/modf_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nextafter_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/scalbn_gen.hpp + copysign_gen.hpp + frexp_gen.hpp + ilogb_gen.hpp + ldexp_gen.hpp + logb_gen.hpp + modf_gen.hpp + nextafter_gen.hpp + scalbn_gen.hpp ) diff --git a/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt b/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt index 7aa035de..8e905cdc 100644 --- a/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/hyper/CMakeLists.txt @@ -1,8 +1,8 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/acosh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/asinh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/atanh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cosh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sinh_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/tanh_gen.hpp + acosh_gen.hpp + asinh_gen.hpp + atanh_gen.hpp + cosh_gen.hpp + sinh_gen.hpp + tanh_gen.hpp ) diff --git a/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt b/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt index 09b38858..ec0d6b0e 100644 --- a/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/misc/CMakeLists.txt @@ -1,3 +1,3 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/lerp_gen.hpp + lerp_gen.hpp ) diff --git a/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt b/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt index 965319b6..2bb3a37d 100644 --- a/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/nearest/CMakeLists.txt @@ -1,8 +1,8 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/ceil_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/floor_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nearbyint_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/rint_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/round_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/trunc_gen.hpp + ceil_gen.hpp + floor_gen.hpp + nearbyint_gen.hpp + rint_gen.hpp + round_gen.hpp + trunc_gen.hpp ) diff --git a/include/ccmath/internal/math/generic/func/power/CMakeLists.txt b/include/ccmath/internal/math/generic/func/power/CMakeLists.txt index cd195b93..53200f7a 100644 --- a/include/ccmath/internal/math/generic/func/power/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/power/CMakeLists.txt @@ -1,12 +1,12 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/cbrt_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/hypot_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/pow_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt_gen.hpp + cbrt_gen.hpp + hypot_gen.hpp + pow_gen.hpp + sqrt_gen.hpp ) # TODO: Move this to its own folder at some point ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/powf_impl.hpp + pow_impl.hpp + powf_impl.hpp ) diff --git a/include/ccmath/internal/math/generic/func/special/CMakeLists.txt b/include/ccmath/internal/math/generic/func/special/CMakeLists.txt index 6f2b8ecf..92b1ca0f 100644 --- a/include/ccmath/internal/math/generic/func/special/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/special/CMakeLists.txt @@ -1,23 +1,23 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/assoc_laguerre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/assoc_legendre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/beta_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_1_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_3_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_i_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_j_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_k_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cyl_neumann_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ellint_1_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ellint_2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ellint_3_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/expint_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/hermite_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/laguerre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/legendre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/riemann_zeta_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sph_bessel_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sph_legendre_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sph_neumann_gen.hpp + assoc_laguerre_gen.hpp + assoc_legendre_gen.hpp + beta_gen.hpp + comp_ellint_1_gen.hpp + comp_ellint_2_gen.hpp + comp_ellint_3_gen.hpp + cyl_bessel_i_gen.hpp + cyl_bessel_j_gen.hpp + cyl_bessel_k_gen.hpp + cyl_neumann_gen.hpp + ellint_1_gen.hpp + ellint_2_gen.hpp + ellint_3_gen.hpp + expint_gen.hpp + hermite_gen.hpp + laguerre_gen.hpp + legendre_gen.hpp + riemann_zeta_gen.hpp + sph_bessel_gen.hpp + sph_legendre_gen.hpp + sph_neumann_gen.hpp ) diff --git a/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt b/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt index 22e1eedf..5b3fb595 100644 --- a/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/func/trig/CMakeLists.txt @@ -1,9 +1,9 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/acos_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/asin_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/atan2_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/atan_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cos_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sin_gen.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/tan_gen.hpp + acos_gen.hpp + asin_gen.hpp + atan2_gen.hpp + atan_gen.hpp + cos_gen.hpp + sin_gen.hpp + tan_gen.hpp ) diff --git a/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt b/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt index 51d38ae6..906fadef 100644 --- a/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/func/power/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow_rt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt_rt.hpp + pow_rt.hpp + sqrt_rt.hpp ) diff --git a/include/ccmath/internal/math/runtime/pp/CMakeLists.txt b/include/ccmath/internal/math/runtime/pp/CMakeLists.txt index 25a74173..05e28766 100644 --- a/include/ccmath/internal/math/runtime/pp/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/pp/CMakeLists.txt @@ -1,3 +1,3 @@ -ccm_add_headers_temp( +ccm_add_headers( simd.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt index 55a401c7..c6b6ef77 100644 --- a/include/ccmath/internal/math/runtime/simd/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/CMakeLists.txt @@ -1,9 +1,9 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/common.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/pack.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/simd.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/simd_vectorize.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/vector_size.hpp + common.hpp + pack.hpp + simd.hpp + simd_vectorize.hpp + vector_size.hpp ) add_subdirectory(func) diff --git a/include/ccmath/internal/math/runtime/simd/func/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/CMakeLists.txt index 0c12929f..c5f8bf82 100644 --- a/include/ccmath/internal/math/runtime/simd/func/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/CMakeLists.txt @@ -1,6 +1,6 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) add_subdirectory(impl) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/avx/CMakeLists.txt index 7ed3a7d1..6514f098 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx2/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/avx2/CMakeLists.txt index 7ed3a7d1..6514f098 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx2/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx2/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt index 7ed3a7d1..6514f098 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/neon/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/neon/CMakeLists.txt index 7ed3a7d1..6514f098 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/neon/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/neon/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/scalar/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/CMakeLists.txt index 7ed3a7d1..6514f098 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/scalar/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/CMakeLists.txt index 7ed3a7d1..6514f098 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse2/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse2/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/CMakeLists.txt index 7ed3a7d1..6514f098 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse3/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse3/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/CMakeLists.txt index 7ed3a7d1..6514f098 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/sse4/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/sse4/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/CMakeLists.txt index 7ed3a7d1..6514f098 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/ssse3/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/CMakeLists.txt index c66b35a8..7eb038ca 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/CMakeLists.txt @@ -1,3 +1,3 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + sqrt.hpp ) diff --git a/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt index ad2041ce..b5ec4993 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt @@ -1,10 +1,10 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/avx.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/avx2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/avx512.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/neon.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sse2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sse3.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sse4.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ssse3.hpp + avx.hpp + avx2.hpp + avx512.hpp + neon.hpp + sse2.hpp + sse3.hpp + sse4.hpp + ssse3.hpp ) diff --git a/include/ccmath/internal/predef/CMakeLists.txt b/include/ccmath/internal/predef/CMakeLists.txt index 0db29860..b921575e 100644 --- a/include/ccmath/internal/predef/CMakeLists.txt +++ b/include/ccmath/internal/predef/CMakeLists.txt @@ -1,11 +1,11 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/assume.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/expects_bool_condition.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/has_attribute.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/has_builtin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/has_const_builtin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/likely.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/unlikely.hpp + assume.hpp + expects_bool_condition.hpp + has_attribute.hpp + has_builtin.hpp + has_const_builtin.hpp + likely.hpp + unlikely.hpp ) add_subdirectory(attributes) diff --git a/include/ccmath/internal/predef/attributes/CMakeLists.txt b/include/ccmath/internal/predef/attributes/CMakeLists.txt index 0e858d29..a162a35f 100644 --- a/include/ccmath/internal/predef/attributes/CMakeLists.txt +++ b/include/ccmath/internal/predef/attributes/CMakeLists.txt @@ -1,9 +1,9 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/always_inline.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/gpu_device.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/gpu_host_device.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/gsl_suppress.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/never_inline.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/no_debug.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/optnone.hpp + always_inline.hpp + gpu_device.hpp + gpu_host_device.hpp + gsl_suppress.hpp + never_inline.hpp + no_debug.hpp + optnone.hpp ) diff --git a/include/ccmath/internal/predef/compiler_suppression/CMakeLists.txt b/include/ccmath/internal/predef/compiler_suppression/CMakeLists.txt index b57712da..52334b3c 100644 --- a/include/ccmath/internal/predef/compiler_suppression/CMakeLists.txt +++ b/include/ccmath/internal/predef/compiler_suppression/CMakeLists.txt @@ -1,5 +1,5 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/clang_compiler_suppression.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/gcc_compiler_suppression.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/msvc_compiler_suppression.hpp + clang_compiler_suppression.hpp + gcc_compiler_suppression.hpp + msvc_compiler_suppression.hpp ) diff --git a/include/ccmath/internal/predef/versioning/CMakeLists.txt b/include/ccmath/internal/predef/versioning/CMakeLists.txt index c72c8021..53b384ba 100644 --- a/include/ccmath/internal/predef/versioning/CMakeLists.txt +++ b/include/ccmath/internal/predef/versioning/CMakeLists.txt @@ -1,9 +1,9 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/arm_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/clang_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/gcc_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/intel_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/msvc_version.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/version_encode.hpp + arm_version.hpp + clang_version.hpp + gcc_version.hpp + intel_version.hpp + msvc_version.hpp + version_encode.hpp ) diff --git a/include/ccmath/internal/support/CMakeLists.txt b/include/ccmath/internal/support/CMakeLists.txt index 216a84bf..6c61cbed 100644 --- a/include/ccmath/internal/support/CMakeLists.txt +++ b/include/ccmath/internal/support/CMakeLists.txt @@ -1,18 +1,18 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/always_false.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/bits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ctz.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/endian.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/floating_point_traits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/integer_literals.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/is_constant_evaluated.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/limits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/math_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/meta_compare.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/multiply_add.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/poly_eval.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/type_traits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/unreachable.hpp + always_false.hpp + bits.hpp + ctz.hpp + endian.hpp + floating_point_traits.hpp + integer_literals.hpp + is_constant_evaluated.hpp + limits.hpp + math_support.hpp + meta_compare.hpp + multiply_add.hpp + poly_eval.hpp + type_traits.hpp + unreachable.hpp ) add_subdirectory(fenv) diff --git a/include/ccmath/internal/support/fenv/CMakeLists.txt b/include/ccmath/internal/support/fenv/CMakeLists.txt index a90ef78f..ce66ef44 100644 --- a/include/ccmath/internal/support/fenv/CMakeLists.txt +++ b/include/ccmath/internal/support/fenv/CMakeLists.txt @@ -1,5 +1,5 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/fenv_support.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/rounding_mode.hpp + fenv_support.hpp + rounding_mode.hpp ) diff --git a/include/ccmath/internal/support/fp/CMakeLists.txt b/include/ccmath/internal/support/fp/CMakeLists.txt index edbace57..b30bba7a 100644 --- a/include/ccmath/internal/support/fp/CMakeLists.txt +++ b/include/ccmath/internal/support/fp/CMakeLists.txt @@ -1,6 +1,6 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/bit_mask_traits.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/directional_rounding_utils.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fp_bits.hpp + bit_mask_traits.hpp + directional_rounding_utils.hpp + fp_bits.hpp ) diff --git a/include/ccmath/internal/support/helpers/CMakeLists.txt b/include/ccmath/internal/support/helpers/CMakeLists.txt index e44bc0ea..bf7cdb01 100644 --- a/include/ccmath/internal/support/helpers/CMakeLists.txt +++ b/include/ccmath/internal/support/helpers/CMakeLists.txt @@ -1,8 +1,8 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/digit_to_int.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp10.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp_helpers.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fpclassify_helper.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/internal_ldexp.hpp + digit_to_int.hpp + exp10.hpp + exp_helpers.hpp + fpclassify_helper.hpp + internal_ldexp.hpp ) diff --git a/include/ccmath/internal/types/CMakeLists.txt b/include/ccmath/internal/types/CMakeLists.txt index 6cad760c..84a45bb6 100644 --- a/include/ccmath/internal/types/CMakeLists.txt +++ b/include/ccmath/internal/types/CMakeLists.txt @@ -1,13 +1,13 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/big_int.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/double_double.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/dyadic_float.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/float128.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fp_types.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/int128_types.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/normalized_float.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/number_pair.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sign.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/triple_double.hpp + big_int.hpp + double_double.hpp + dyadic_float.hpp + float128.hpp + fp_types.hpp + int128_types.hpp + normalized_float.hpp + number_pair.hpp + sign.hpp + triple_double.hpp ) diff --git a/include/ccmath/math/CMakeLists.txt b/include/ccmath/math/CMakeLists.txt index 5bb71c3f..2b8a267d 100644 --- a/include/ccmath/math/CMakeLists.txt +++ b/include/ccmath/math/CMakeLists.txt @@ -1,14 +1,14 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/basic.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/compare.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/expo.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fmanip.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/hyper.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nearest.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/numbers.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/power.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/special.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/trig.hpp + basic.hpp + compare.hpp + expo.hpp + fmanip.hpp + hyper.hpp + nearest.hpp + numbers.hpp + power.hpp + special.hpp + trig.hpp ) add_subdirectory(basic) diff --git a/include/ccmath/math/basic/CMakeLists.txt b/include/ccmath/math/basic/CMakeLists.txt index 4007659a..cb39fdc3 100644 --- a/include/ccmath/math/basic/CMakeLists.txt +++ b/include/ccmath/math/basic/CMakeLists.txt @@ -1,13 +1,13 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/abs.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fdim.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fma.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/fmod.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/max.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/min.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nan.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/remainder.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/remquo.hpp + abs.hpp + fdim.hpp + fma.hpp + fmod.hpp + max.hpp + min.hpp + nan.hpp + remainder.hpp + remquo.hpp ) add_subdirectory(impl) diff --git a/include/ccmath/math/basic/impl/CMakeLists.txt b/include/ccmath/math/basic/impl/CMakeLists.txt index 1d13933b..44fe9fa9 100644 --- a/include/ccmath/math/basic/impl/CMakeLists.txt +++ b/include/ccmath/math/basic/impl/CMakeLists.txt @@ -1,9 +1,9 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/nan_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nan_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nan_ldouble_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/remquo_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/remquo_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/remquo_ldouble_impl.hpp + nan_double_impl.hpp + nan_float_impl.hpp + nan_ldouble_impl.hpp + remquo_double_impl.hpp + remquo_float_impl.hpp + remquo_ldouble_impl.hpp ) diff --git a/include/ccmath/math/compare/CMakeLists.txt b/include/ccmath/math/compare/CMakeLists.txt index 962be1fb..99f89e4c 100644 --- a/include/ccmath/math/compare/CMakeLists.txt +++ b/include/ccmath/math/compare/CMakeLists.txt @@ -1,14 +1,14 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/fpclassify.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/isfinite.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/isgreater.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/isgreaterequal.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/isinf.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/isless.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/islessequal.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/islessgreater.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/isnan.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/isnormal.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/isunordered.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/signbit.hpp + fpclassify.hpp + isfinite.hpp + isgreater.hpp + isgreaterequal.hpp + isinf.hpp + isless.hpp + islessequal.hpp + islessgreater.hpp + isnan.hpp + isnormal.hpp + isunordered.hpp + signbit.hpp ) diff --git a/include/ccmath/math/expo/CMakeLists.txt b/include/ccmath/math/expo/CMakeLists.txt index 57a51a62..1336873b 100644 --- a/include/ccmath/math/expo/CMakeLists.txt +++ b/include/ccmath/math/expo/CMakeLists.txt @@ -1,11 +1,11 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/exp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/expm1.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log1p.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log10.hpp + exp.hpp + exp2.hpp + expm1.hpp + log.hpp + log1p.hpp + log2.hpp + log10.hpp ) add_subdirectory(impl) diff --git a/include/ccmath/math/expo/impl/CMakeLists.txt b/include/ccmath/math/expo/impl/CMakeLists.txt index 674f555e..93e28840 100644 --- a/include/ccmath/math/expo/impl/CMakeLists.txt +++ b/include/ccmath/math/expo/impl/CMakeLists.txt @@ -1,14 +1,14 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/exp2_data.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp2_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp2_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp_data.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/exp_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log2_data.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log2_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log2_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log_data.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/log_float_impl.hpp + exp2_data.hpp + exp2_double_impl.hpp + exp2_float_impl.hpp + exp_data.hpp + exp_double_impl.hpp + exp_float_impl.hpp + log2_data.hpp + log2_double_impl.hpp + log2_float_impl.hpp + log_data.hpp + log_double_impl.hpp + log_float_impl.hpp ) diff --git a/include/ccmath/math/fmanip/CMakeLists.txt b/include/ccmath/math/fmanip/CMakeLists.txt index 76a8fc3f..fc349195 100644 --- a/include/ccmath/math/fmanip/CMakeLists.txt +++ b/include/ccmath/math/fmanip/CMakeLists.txt @@ -1,13 +1,13 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/copysign.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/frexp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ilogb.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ldexp.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/logb.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/modf.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nextafter.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nexttoward.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/scalbn.hpp + copysign.hpp + frexp.hpp + ilogb.hpp + ldexp.hpp + logb.hpp + modf.hpp + nextafter.hpp + nexttoward.hpp + scalbn.hpp ) add_subdirectory(impl) diff --git a/include/ccmath/math/fmanip/impl/CMakeLists.txt b/include/ccmath/math/fmanip/impl/CMakeLists.txt index 87d1c68e..2090fc13 100644 --- a/include/ccmath/math/fmanip/impl/CMakeLists.txt +++ b/include/ccmath/math/fmanip/impl/CMakeLists.txt @@ -1,8 +1,8 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/modf_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/modf_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/scalbn_double_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/scalbn_float_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/scalbn_ldouble_impl.hpp + modf_double_impl.hpp + modf_float_impl.hpp + scalbn_double_impl.hpp + scalbn_float_impl.hpp + scalbn_ldouble_impl.hpp ) diff --git a/include/ccmath/math/hyper/CMakeLists.txt b/include/ccmath/math/hyper/CMakeLists.txt index 7c0290ab..b18cb199 100644 --- a/include/ccmath/math/hyper/CMakeLists.txt +++ b/include/ccmath/math/hyper/CMakeLists.txt @@ -1,8 +1,8 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/acosh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/asinh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/atanh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cosh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sinh.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/tanh.hpp + acosh.hpp + asinh.hpp + atanh.hpp + cosh.hpp + sinh.hpp + tanh.hpp ) diff --git a/include/ccmath/math/misc/CMakeLists.txt b/include/ccmath/math/misc/CMakeLists.txt index 1726e077..85b8dc36 100644 --- a/include/ccmath/math/misc/CMakeLists.txt +++ b/include/ccmath/math/misc/CMakeLists.txt @@ -1,5 +1,5 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/gamma.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/lgamma.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/lerp.hpp + gamma.hpp + lgamma.hpp + lerp.hpp ) diff --git a/include/ccmath/math/nearest/CMakeLists.txt b/include/ccmath/math/nearest/CMakeLists.txt index 46c1f94d..60727f1d 100644 --- a/include/ccmath/math/nearest/CMakeLists.txt +++ b/include/ccmath/math/nearest/CMakeLists.txt @@ -1,8 +1,8 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/ceil.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/floor.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/nearbyint.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/rint.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/round.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/trunc.hpp + ceil.hpp + floor.hpp + nearbyint.hpp + rint.hpp + round.hpp + trunc.hpp ) diff --git a/include/ccmath/math/power/CMakeLists.txt b/include/ccmath/math/power/CMakeLists.txt index 12918e59..1f509c39 100644 --- a/include/ccmath/math/power/CMakeLists.txt +++ b/include/ccmath/math/power/CMakeLists.txt @@ -1,6 +1,6 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/cbrt.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/hypot.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/pow.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sqrt.hpp + cbrt.hpp + hypot.hpp + pow.hpp + sqrt.hpp ) diff --git a/include/ccmath/math/special/CMakeLists.txt b/include/ccmath/math/special/CMakeLists.txt index 18e7c28f..eb463fa9 100644 --- a/include/ccmath/math/special/CMakeLists.txt +++ b/include/ccmath/math/special/CMakeLists.txt @@ -1,23 +1,23 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/assoc_laguerre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/assoc_legendre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/beta.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_1.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/comp_ellint_3.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_i.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_j.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cyl_bessel_k.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cyl_neumann.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ellint_1.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ellint_2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/ellint_3.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/expint.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/hermite.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/laguerre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/legendre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/riemann_zeta.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sph_bessel.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sph_legendre.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sph_neumann.hpp + assoc_laguerre.hpp + assoc_legendre.hpp + beta.hpp + comp_ellint_1.hpp + comp_ellint_2.hpp + comp_ellint_3.hpp + cyl_bessel_i.hpp + cyl_bessel_j.hpp + cyl_bessel_k.hpp + cyl_neumann.hpp + ellint_1.hpp + ellint_2.hpp + ellint_3.hpp + expint.hpp + hermite.hpp + laguerre.hpp + legendre.hpp + riemann_zeta.hpp + sph_bessel.hpp + sph_legendre.hpp + sph_neumann.hpp ) diff --git a/include/ccmath/math/trig/CMakeLists.txt b/include/ccmath/math/trig/CMakeLists.txt index b0be016a..11860937 100644 --- a/include/ccmath/math/trig/CMakeLists.txt +++ b/include/ccmath/math/trig/CMakeLists.txt @@ -1,9 +1,9 @@ ccm_add_headers( - ${CMAKE_CURRENT_SOURCE_DIR}/acos.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/asin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/atan.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/atan2.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/cos.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/sin.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/tan.hpp + acos.hpp + asin.hpp + atan.hpp + atan2.hpp + cos.hpp + sin.hpp + tan.hpp ) From 561ec06e7b6bc4f8e4387bff9bf51d026bfb9446 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 28 Dec 2024 13:44:35 -0500 Subject: [PATCH 082/102] experimental simd Signed-off-by: Ian --- .../ccmath/internal/math/runtime/pp/simd.hpp | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/include/ccmath/internal/math/runtime/pp/simd.hpp b/include/ccmath/internal/math/runtime/pp/simd.hpp index 92e2aa43..4e04c025 100644 --- a/include/ccmath/internal/math/runtime/pp/simd.hpp +++ b/include/ccmath/internal/math/runtime/pp/simd.hpp @@ -176,28 +176,38 @@ namespace ccm::pp vectorized_sizeof() { if constexpr (!is_vectorizable_v) + { return 0; + } if constexpr (sizeof(T) <= 8) { // X86: if constexpr (have_avx2) + { return 32; + } if constexpr (have_sse2) + { return 16; + } // ARM: if constexpr (have_neon_a64 || (have_neon_a32 && !std::is_same_v)) + { return 16; + } if constexpr (have_neon && sizeof(T) < 8 // Only allow fp if the user allows non-ICE559 fp (e.g. // via -ffast-math). ARMv7 NEON fp is not conforming to // IEC559. && (support_neon_float || !std::is_floating_point_v)) + { return 16; + } } return sizeof(T); @@ -221,10 +231,14 @@ namespace ccm::pp UsedBytes / sizeof(T) > 1 && UsedBytes % sizeof(T) == 0 && UsedBytes <= vectorized_sizeof() && - UsedBytes <= 32)> {}; + UsedBytes <= 32)> + { + }; template - struct is_valid : std::conjunction, is_valid_size_for> {}; + struct is_valid : std::conjunction, is_valid_size_for > + { + }; template static constexpr bool is_valid_v = is_valid::value; @@ -289,12 +303,12 @@ namespace ccm::pp // ctors template - constexpr basic_simd(U&& value) noexcept + constexpr basic_simd(U && value) noexcept { } template - constexpr CCM_CPP20_EXPLICIT(true) basic_simd(basic_simd const& value) noexcept + constexpr CCM_CPP20_EXPLICIT(true) basic_simd(basic_simd const & value) noexcept { } From ce5d4b86f53f4768d38df087d541f5155d2fdf60 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 28 Dec 2024 13:45:18 -0500 Subject: [PATCH 083/102] experimental compiler flags Signed-off-by: Ian --- include/ccmath/internal/config/compiler.hpp | 81 +++++++++++++++++---- 1 file changed, 68 insertions(+), 13 deletions(-) diff --git a/include/ccmath/internal/config/compiler.hpp b/include/ccmath/internal/config/compiler.hpp index 66bf732c..36c1fb4d 100644 --- a/include/ccmath/internal/config/compiler.hpp +++ b/include/ccmath/internal/config/compiler.hpp @@ -25,17 +25,17 @@ /// MSVC #if defined(_MSC_VER) && !defined(__clang__) && !defined(CCMATH_COMPILER_MSVC) - #define CCMATH_COMPILER_MSVC - #define CCMATH_COMPILER_MSVC_VER _MSC_VER +#define CCMATH_COMPILER_MSVC +#define CCMATH_COMPILER_MSVC_VER _MSC_VER /// Intel DPC++ Compiler #elif defined(SYCL_LANGUAGE_VERSION) || defined(__INTEL_LLVM_COMPILER) && !defined(CCMATH_COMPILER_INTEL) #define CCMATH_COMPILER_INTEL #define CCMATH_COMPILER_INTEL_VER __INTEL_LLVM_COMPILER - #ifndef CCMATH_COMPILER_CLANG_BASED +#ifndef CCMATH_COMPILER_CLANG_BASED #define CCMATH_COMPILER_CLANG_BASED - #endif +#endif // TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler @@ -47,14 +47,13 @@ #define CCMATH_COMPILER_CLANG_CL_VER_MINOR __clang_minor__ #define CCMATH_COMPILER_CLANG_CL_VER_PATCH __clang_patchlevel__ - #ifndef CCMATH_COMPILER_CLANG_BASED +#ifndef CCMATH_COMPILER_CLANG_BASED #define CCMATH_COMPILER_CLANG_BASED - #endif +#endif // TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler - /// Nvidia HPC SDK #elif defined(__NVCOMPILER) || defined(__NVCOMPILER_LLVM__) && !defined(CCMATH_COMPILER_NVIDIA_HPC) #define CCMATH_COMPILER_NVIDIA_HPC @@ -68,9 +67,9 @@ /// Nvidia CUDA #elif defined(__CUDACC__) && !defined(CCMATH_COMPILER_NVIDIA_CUDA) - #if !defined(CUDA_VERSION) +#if !defined(CUDA_VERSION) #include // We need to make sure the version is defined since nvcc doesn't define it - #endif +#endif #define CCMATH_COMPILER_NVIDIA_CUDA #define CCMATH_COMPILER_NVIDIA_CUDA_VER (CUDA_VERSION / 1000) @@ -93,9 +92,9 @@ #define CCMATH_COMPILER_APPLE_CLANG_VER_MINOR __clang_minor__ #define CCMATH_COMPILER_APPLE_CLANG_VER_PATCH __clang_patchlevel__ - #ifndef CCMATH_COMPILER_CLANG_BASED +#ifndef CCMATH_COMPILER_CLANG_BASED #define CCMATH_COMPILER_CLANG_BASED - #endif +#endif // TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler @@ -107,9 +106,9 @@ #define CCMATH_COMPILER_CLANG_VER_MINOR __clang_minor__ #define CCMATH_COMPILER_CLANG_VER_PATCH __clang_patchlevel__ - #ifndef CCMATH_COMPILER_CLANG_BASED +#ifndef CCMATH_COMPILER_CLANG_BASED #define CCMATH_COMPILER_CLANG_BASED - #endif +#endif // TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler @@ -125,3 +124,59 @@ #else #define CCMATH_COMPILER_UNKNOWN #endif + +// TODO: Explore this idea further + +namespace ccm::internal::platform +{ + // NOLINTNEXTLINE + enum class compiler + { + eUnknown, + eGCC, + eClang, + eMSVC, + eClangCL, + eIntel, + eNvidiaHPC + }; + + template + struct native_compiler : std::false_type{}; + + template <> + struct native_compiler : std::false_type + { + }; + + #ifdef CCMATH_COMPILER_GCC + template <> + struct native_compiler : std::true_type + { + }; + #endif + + #ifdef CCMATH_COMPILER_CLANG + template <> + struct native_compiler : std::true_type + { + }; + #endif + + #ifdef CCMATH_COMPILER_MSVC + template <> + struct native_compiler : std::true_type + { + }; + #endif + + #ifdef CCMATH_COMPILER_CLANG_CL + template <> + struct native_compiler : std::true_type + { + }; + #endif + + + +} // namespace ccm::internal::platform From 88328bc50728848c3c3787a891954eabae8f35e3 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 28 Dec 2024 13:45:33 -0500 Subject: [PATCH 084/102] experimental builtin_fma support Signed-off-by: Ian --- include/ccmath/internal/builtins/fma.hpp | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 include/ccmath/internal/builtins/fma.hpp diff --git a/include/ccmath/internal/builtins/fma.hpp b/include/ccmath/internal/builtins/fma.hpp new file mode 100644 index 00000000..20691c4e --- /dev/null +++ b/include/ccmath/internal/builtins/fma.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +namespace ccm::internal::builtin +{ + template + inline constexpr bool has_constexpr_fma = + #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) + (std::is_same_v || std::is_same_v || std::is_same_v); + #else + false; + #endif + + template + constexpr auto fma(T x, T y, T z) + -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) { + return __builtin_fmaf(x, y, z); + } + if constexpr (std::is_same_v) { + return __builtin_fma(x, y, z); + } + if constexpr (std::is_same_v) { + return __builtin_fmal(x, y, z); + } + } +} // namespace ccm::internal::builtin From a606a4766f9439bc24463cfd0e26e8edece999f4 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 28 Dec 2024 13:48:39 -0500 Subject: [PATCH 085/102] return to old name Signed-off-by: Ian --- .github/workflows/{ci-macos-m1.yml => ci-macos.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{ci-macos-m1.yml => ci-macos.yml} (100%) diff --git a/.github/workflows/ci-macos-m1.yml b/.github/workflows/ci-macos.yml similarity index 100% rename from .github/workflows/ci-macos-m1.yml rename to .github/workflows/ci-macos.yml From bfd496d7f74d0760beb4dc58b54e5f51b101d329 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 28 Dec 2024 13:54:51 -0500 Subject: [PATCH 086/102] return to old name Signed-off-by: Ian --- .github/workflows/ci-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 69a1c32c..623d8e3d 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -1,4 +1,4 @@ -name: ci-macos-m1 +name: ci-macos on: push: From 15283ebca6627dc09036ac9ee57e6f19ac86ae60 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 28 Dec 2024 14:20:27 -0500 Subject: [PATCH 087/102] Completely remove avx512 support Signed-off-by: Ian --- .../runtime/simd/func/impl/CMakeLists.txt | 1 - .../simd/func/impl/avx512/CMakeLists.txt | 4 - .../runtime/simd/func/impl/avx512/pow.hpp | 35 --- .../runtime/simd/func/impl/avx512/sqrt.hpp | 34 --- .../runtime/simd/instructions/CMakeLists.txt | 1 - .../math/runtime/simd/instructions/avx512.hpp | 221 ------------------ 6 files changed, 296 deletions(-) delete mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt delete mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp delete mode 100644 include/ccmath/internal/math/runtime/simd/func/impl/avx512/sqrt.hpp delete mode 100644 include/ccmath/internal/math/runtime/simd/instructions/avx512.hpp diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/CMakeLists.txt index cf1ce420..fe1f8d56 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/func/impl/CMakeLists.txt @@ -1,6 +1,5 @@ add_subdirectory(avx) add_subdirectory(avx2) -add_subdirectory(avx512) add_subdirectory(neon) add_subdirectory(scalar) add_subdirectory(sse2) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt deleted file mode 100644 index 6514f098..00000000 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -ccm_add_headers( - pow.hpp - sqrt.hpp -) diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp deleted file mode 100644 index bc0154b7..00000000 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/pow.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) Ian Pike - * Copyright (c) CCMath contributors - * - * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. - * See LICENSE for more information. - * - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#pragma once - -#include "ccmath/internal/math/runtime/simd/simd.hpp" - -#ifdef CCMATH_HAS_SIMD - #ifdef CCMATH_HAS_SIMD_AVX512F -namespace ccm::intrin -{ - CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) - { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm512_pow_ps(a.get(), b.get())); - } - - CCM_ALWAYS_INLINE simd pow(simd const & a, simd const & b) - { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm512_pow_pd(a.get(), b.get())); - - } - -} // namespace ccm::intrin - - #endif // CCMATH_HAS_SIMD_AVX512F -#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/sqrt.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/avx512/sqrt.hpp deleted file mode 100644 index fc9f2b80..00000000 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx512/sqrt.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) Ian Pike - * Copyright (c) CCMath contributors - * - * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. - * See LICENSE for more information. - * - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#pragma once - -#include "ccmath/internal/math/runtime/simd/simd.hpp" - -#ifdef CCMATH_HAS_SIMD - #ifdef CCMATH_HAS_SIMD_AVX512F -namespace ccm::intrin -{ - CCM_ALWAYS_INLINE simd sqrt(simd const & a) - { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm512_sqrt_ps(a.get())); - } - - CCM_ALWAYS_INLINE simd sqrt(simd const & a) - { - // NOLINTNEXTLINE(modernize-return-braced-init-list) - return simd(_mm512_sqrt_pd(a.get())); - } - -} // namespace ccm::intrin - - #endif // CCMATH_HAS_SIMD_AVX512F -#endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt b/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt index b5ec4993..ee719953 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/simd/instructions/CMakeLists.txt @@ -1,7 +1,6 @@ ccm_add_headers( avx.hpp avx2.hpp - avx512.hpp neon.hpp sse2.hpp sse3.hpp diff --git a/include/ccmath/internal/math/runtime/simd/instructions/avx512.hpp b/include/ccmath/internal/math/runtime/simd/instructions/avx512.hpp deleted file mode 100644 index 3e1ec5c4..00000000 --- a/include/ccmath/internal/math/runtime/simd/instructions/avx512.hpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) Ian Pike - * Copyright (c) CCMath contributors - * - * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. - * See LICENSE for more information. - * - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#pragma once - -#include "ccmath/internal/config/arch/check_simd_support.hpp" -#include "ccmath/internal/math/runtime/simd/common.hpp" - -#ifdef CCMATH_HAS_SIMD - #ifdef CCMATH_HAS_SIMD_AVX512F - - #include - -// NOLINTBEGIN -namespace ccm::intrin -{ - namespace abi - { - struct avx512 - { - }; - } // namespace abi - - template <> - struct simd_mask - { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::avx512; - CCM_ALWAYS_INLINE simd_mask() = default; - CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(-static_cast(value)) {} - CCM_ALWAYS_INLINE static constexpr int size() { return 16; } - CCM_ALWAYS_INLINE constexpr simd_mask(__mmask16 const & value_in) : m_value(value_in) {} - [[nodiscard]] CCM_ALWAYS_INLINE constexpr __mmask16 get() const { return m_value; } - CCM_ALWAYS_INLINE simd_mask operator||(simd_mask const & other) const { return simd_mask(_kor_mask16(m_value, other.m_value)); } - CCM_ALWAYS_INLINE simd_mask operator&&(simd_mask const & other) const { return simd_mask(_kand_mask16(m_value, other.m_value)); } - CCM_ALWAYS_INLINE simd_mask operator!() const { return simd_mask(_knot_mask16(m_value)); } - - private: - __mmask16 m_value; - }; - - CCM_ALWAYS_INLINE bool all_of(simd_mask const & a) - { - static const __mmask16 false_value(-static_cast(false)); - return _kortestc_mask16_u8(a.get(), false_value) != 0U; - } - - CCM_ALWAYS_INLINE bool any_of(simd_mask const & a) - { - static const __mmask16 false_value(-static_cast(false)); - return _kortestc_mask16_u8(~a.get(), false_value) == 0U; - } - - template <> - struct simd - { - CCM_ALWAYS_INLINE simd() = default; - using value_type = float; - using abi_type = abi::avx512; - using mask_type = simd_mask; - using storage_type = simd_storage; - static constexpr int size() { return 16; } - CCM_ALWAYS_INLINE simd(float value) : m_value(_mm512_set1_ps(value)) {} - CCM_ALWAYS_INLINE simd(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, - float n, float o, float p) - : m_value(_mm512_setr_ps(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)) - { - } - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } - CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) - { - copy_from(value.data(), element_aligned_tag()); - return *this; - } - template - CCM_ALWAYS_INLINE simd(float const * ptr, Flags /*flags*/) : m_value(_mm512_loadu_ps(ptr)) - { - } - CCM_ALWAYS_INLINE simd(float const * ptr, int stride) - : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride], ptr[4 * stride], ptr[5 * stride], ptr[6 * stride], ptr[7 * stride], ptr[8 * stride], - ptr[9 * stride], ptr[10 * stride], ptr[11 * stride], ptr[12 * stride], ptr[13 * stride], ptr[14 * stride], ptr[15 * stride]) - { - } - CCM_ALWAYS_INLINE constexpr simd(__m512 const & value_in) : m_value(value_in) {} - CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return simd(_mm512_mul_ps(m_value, other.m_value)); } - CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return simd(_mm512_div_ps(m_value, other.m_value)); } - CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return simd(_mm512_add_ps(m_value, other.m_value)); } - CCM_ALWAYS_INLINE simd operator-(simd const & other) const { return simd(_mm512_sub_ps(m_value, other.m_value)); } - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd operator-() const { return simd(_mm512_sub_ps(_mm512_set1_ps(0.0), m_value)); } - CCM_ALWAYS_INLINE void copy_from(float const * ptr, element_aligned_tag /*unused*/) { m_value = _mm512_loadu_ps(ptr); } - CCM_ALWAYS_INLINE void copy_to(float * ptr, element_aligned_tag /*unused*/) const { _mm512_storeu_ps(ptr, m_value); } - [[nodiscard]] CCM_ALWAYS_INLINE constexpr __m512 get() const { return m_value; } - [[nodiscard]] CCM_ALWAYS_INLINE float convert() const { return _mm512_cvtss_f32(m_value); } - CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const - { - return simd_mask(_mm512_cmplt_ps_mask(m_value, other.m_value)); - } - CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const - { - return simd_mask(_mm512_cmpeq_ps_mask(m_value, other.m_value)); - } - - private: - __m512 m_value; - }; - - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) - { - return simd(_mm512_mask_blend_ps(a.get(), c.get(), b.get())); - } - - template <> - struct simd_mask - { - using value_type = bool; - CCM_ALWAYS_INLINE simd_mask() = default; - CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(-std::int16_t(value)) {} - static constexpr int size() { return 8; } - CCM_ALWAYS_INLINE constexpr simd_mask(__mmask8 const & value_in) : m_value(value_in) {} - [[nodiscard]] CCM_ALWAYS_INLINE constexpr __mmask8 get() const { return m_value; } - CCM_ALWAYS_INLINE simd_mask operator||(simd_mask const & other) const { return simd_mask(static_cast<__mmask8>(_mm512_kor(m_value, other.m_value))); } - CCM_ALWAYS_INLINE simd_mask operator&&(simd_mask const & other) const { return simd_mask(static_cast<__mmask8>(_mm512_kand(m_value, other.m_value))); } - CCM_ALWAYS_INLINE simd_mask operator!() const - { - static const __mmask8 true_value(simd_mask(true).get()); - return simd_mask(static_cast<__mmask8>(_mm512_kxor(true_value, m_value))); - } - - private: - __mmask8 m_value; - }; - - CCM_ALWAYS_INLINE bool all_of(simd_mask const & a) - { - static const __mmask16 false_value(-static_cast(false)); - const __mmask16 a_value(0xFF00 | a.get()); - return _kortestc_mask16_u8(a_value, false_value) != 0U; - } - - CCM_ALWAYS_INLINE bool any_of(simd_mask const & a) - { - static const __mmask16 false_value(-static_cast(false)); - const __mmask16 a_value(0x0000 | a.get()); - return _kortestc_mask16_u8(~a_value, false_value) == 0U; - } - - template <> - struct simd - { - using value_type = double; - using abi_type = abi::avx512; - using mask_type = simd_mask; - using storage_type = simd_storage; - CCM_ALWAYS_INLINE simd() = default; - CCM_ALWAYS_INLINE simd(simd const &) = default; - CCM_ALWAYS_INLINE simd(simd &&) = default; - CCM_ALWAYS_INLINE simd & operator=(simd const &) = default; - CCM_ALWAYS_INLINE simd & operator=(simd &&) = default; - static constexpr int size() { return 8; } - CCM_ALWAYS_INLINE simd(double value) : m_value(_mm512_set1_pd(value)) {} - CCM_ALWAYS_INLINE simd(double a, double b, double c, double d, double e, double f, double g, double h) - : m_value(_mm512_setr_pd(a, b, c, d, e, f, g, h)) - { - } - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } - CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) - { - copy_from(value.data(), element_aligned_tag()); - return *this; - } - template - CCM_ALWAYS_INLINE simd(double const * ptr, Flags /*flags*/) : m_value(_mm512_loadu_pd(ptr)) - { - } - CCM_ALWAYS_INLINE simd(double const * ptr, int stride) - : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride], ptr[4 * stride], ptr[5 * stride], ptr[6 * stride], ptr[7 * stride]) - { - } - CCM_ALWAYS_INLINE constexpr simd(__m512d const & value_in) : m_value(value_in) {} - CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return simd(_mm512_mul_pd(m_value, other.m_value)); } - CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return simd(_mm512_div_pd(m_value, other.m_value)); } - CCM_ALWAYS_INLINE simd operator+(simd const & other) const { return simd(_mm512_add_pd(m_value, other.m_value)); } - CCM_ALWAYS_INLINE simd operator-(simd const & other) const { return simd(_mm512_sub_pd(m_value, other.m_value)); } - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd operator-() const { return simd(_mm512_sub_pd(_mm512_set1_pd(0.0), m_value)); } - CCM_ALWAYS_INLINE void copy_from(double const * ptr, element_aligned_tag) { m_value = _mm512_loadu_pd(ptr); } - CCM_ALWAYS_INLINE void copy_to(double * ptr, element_aligned_tag) const { _mm512_storeu_pd(ptr, m_value); } - [[nodiscard]] CCM_ALWAYS_INLINE constexpr __m512d get() const { return m_value; } - [[nodiscard]] CCM_ALWAYS_INLINE double convert() const { return _mm512_cvtsd_f64(m_value); } - CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const - { - return simd_mask(_mm512_cmplt_pd_mask(m_value, other.m_value)); - } - CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const - { - return simd_mask(_mm512_cmpeq_pd_mask(m_value, other.m_value)); - } - - private: - __m512d m_value; - }; - - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) - { - return simd(_mm512_mask_blend_pd(a.get(), c.get(), b.get())); - } - -} // namespace ccm::intrin -// NOLINTEND - - #endif // CCMATH_HAS_SIMD_AVX512F -#endif // CCMATH_HAS_SIMD From feff8343159ce28799d7fdb4135fff54dedd7c98 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 28 Dec 2024 14:21:16 -0500 Subject: [PATCH 088/102] Completely remove avx512 support Signed-off-by: Ian --- .../CheckAllSupportedSimdFeatures.cmake | 1 - .../features/simd/CheckAVX512Support.cmake | 90 ------------------- 2 files changed, 91 deletions(-) delete mode 100644 cmake/config/features/simd/CheckAVX512Support.cmake diff --git a/cmake/config/features/CheckAllSupportedSimdFeatures.cmake b/cmake/config/features/CheckAllSupportedSimdFeatures.cmake index eec72c82..3b2ac385 100644 --- a/cmake/config/features/CheckAllSupportedSimdFeatures.cmake +++ b/cmake/config/features/CheckAllSupportedSimdFeatures.cmake @@ -5,7 +5,6 @@ endif () include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckFMASupport.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckAVXSupport.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckAVX2Support.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckAVX512Support.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSE2Support.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSE3Support.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/simd/CheckSSSE3Support.cmake) diff --git a/cmake/config/features/simd/CheckAVX512Support.cmake b/cmake/config/features/simd/CheckAVX512Support.cmake deleted file mode 100644 index 7ec03547..00000000 --- a/cmake/config/features/simd/CheckAVX512Support.cmake +++ /dev/null @@ -1,90 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check for AVX-512-F (Foundation) -check_cxx_source_compiles(" - #include - int main() { - __m512d avx512f_test = _mm512_set1_pd(1.0); - return 0; - } - " CCMATH_SIMD_HAS_AVX512F_SUPPORT) - -if (CCMATH_SIMD_HAS_AVX512F_SUPPORT) - add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512F) -endif () - -# Check for AVX-512-DQ (Double and Quadword) -check_cxx_source_compiles(" - #include - int main() { - __m512i avx512dq_test = _mm512_mul_epu32(_mm512_set1_epi64(1), _mm512_set1_epi64(2)); - return 0; - } - " CCMATH_SIMD_HAS_AVX512DQ_SUPPORT) - -if (CCMATH_SIMD_HAS_AVX512DQ_SUPPORT) - add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512DQ) -endif () - -# Check for AVX-512-IFMA (Integer Fused Multiply-Add) -check_cxx_source_compiles(" - #include - int main() { - __m512i avx512ifma_test = _mm512_madd52hi_epu64(_mm512_set1_epi64(1), _mm512_set1_epi64(2), _mm512_set1_epi64(3)); - return 0; - } - " CCMATH_SIMD_HAS_AVX512IFMA_SUPPORT) - -if (CCMATH_SIMD_HAS_AVX512IFMA_SUPPORT) - add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512IFMA) -endif () - -# Check for AVX-512-CD (Conflict Detection) -check_cxx_source_compiles(" - #include - int main() { - __m512i avx512cd_test = _mm512_conflict_epi64(_mm512_set1_epi64(1)); - return 0; - } - " CCMATH_SIMD_HAS_AVX512CD_SUPPORT) - -if (CCMATH_SIMD_HAS_AVX512CD_SUPPORT) - add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512CD) -endif () - -# Check for AVX-512-BW (Byte and Word) -check_cxx_source_compiles(" - #include - int main() { - __m512i avx512bw_test = _mm512_cvtepi16_epi8(_mm512_set1_epi16(1)); - return 0; - } - " CCMATH_SIMD_HAS_AVX512BW_SUPPORT) - -if (CCMATH_SIMD_HAS_AVX512BW_SUPPORT) - add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512BW) -endif () - -# Check for AVX-512-VL (Vector Length Extensions) -check_cxx_source_compiles(" - #include - int main() { - __m256i avx512vl_test = _mm256_abs_epi16(_mm256_set1_epi16(-1)); - return 0; - } - " CCMATH_SIMD_HAS_AVX512VL_SUPPORT) - -if (CCMATH_SIMD_HAS_AVX512VL_SUPPORT) - add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512VL) -endif () - - -# Check if we have full AVX-512 support -if (CCMATH_SIMD_HAS_AVX512F_SUPPORT AND - CCMATH_SIMD_HAS_AVX512DQ_SUPPORT AND - CCMATH_SIMD_HAS_AVX512IFMA_SUPPORT AND - CCMATH_SIMD_HAS_AVX512CD_SUPPORT AND - CCMATH_SIMD_HAS_AVX512BW_SUPPORT AND - CCMATH_SIMD_HAS_AVX512VL_SUPPORT) - add_compile_definitions(CCM_CONFIG_RT_SIMD_HAS_AVX512) -endif () From b4c3a532e8c04e6f35da8655a8096d86ff4d5411 Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 28 Dec 2024 15:14:33 -0500 Subject: [PATCH 089/102] Remove builtin checking for now Signed-off-by: Ian --- cmake/config/features/GetAllSupportedFeatures.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmake/config/features/GetAllSupportedFeatures.cmake b/cmake/config/features/GetAllSupportedFeatures.cmake index 5be2b4eb..a0649974 100644 --- a/cmake/config/features/GetAllSupportedFeatures.cmake +++ b/cmake/config/features/GetAllSupportedFeatures.cmake @@ -1,4 +1,11 @@ -include(${CCMATH_SOURCE_DIR}/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake) +# Common Support Builtins +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/support/CheckBuiltinBitCastSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/support/CheckBuiltinFmaSupport.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake) + + +# TODO: Revisit this in a manner that is better. The current approach takes up too much time in the cmake. +#include(${CCMATH_SOURCE_DIR}/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake) if (CCMATH_ENABLE_RUNTIME_SIMD) include(${CCMATH_SOURCE_DIR}/cmake/config/features/CheckAllSupportedSimdFeatures.cmake) From ddb56daa8c80c32fd76536ac97f334186a947825 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 05:56:44 -0500 Subject: [PATCH 090/102] Bring in starting work of new builtin checking Signed-off-by: Ian --- include/ccmath/internal/builtins/fma.hpp | 29 ------ .../internal/math/generic/CMakeLists.txt | 1 + .../math/generic/builtins/CMakeLists.txt | 12 +++ .../generic/builtins/basic/CMakeLists.txt | 11 +++ .../math/generic/builtins/basic/abs.hpp | 89 +++++++++++++++++++ .../math/generic/builtins/basic/fdim.hpp | 69 ++++++++++++++ .../math/generic/builtins/basic/fma.hpp | 70 +++++++++++++++ .../math/generic/builtins/basic/fmod.hpp | 69 ++++++++++++++ .../math/generic/builtins/basic/nan.hpp | 68 ++++++++++++++ .../math/generic/builtins/basic/remainder.hpp | 68 ++++++++++++++ .../math/generic/builtins/basic/remquo.hpp | 68 ++++++++++++++ .../math/generic/builtins/builtin_helpers.hpp | 10 +++ .../generic/builtins/compare/CMakeLists.txt | 8 ++ .../generic/builtins/compare/isfinite.hpp | 68 ++++++++++++++ .../math/generic/builtins/compare/isinf.hpp | 68 ++++++++++++++ .../math/generic/builtins/compare/isnan.hpp | 68 ++++++++++++++ .../generic/builtins/compare/isnormal.hpp | 68 ++++++++++++++ .../generic/builtins/compare/isunordered.hpp | 68 ++++++++++++++ .../math/generic/builtins/compare/signbit.hpp | 68 ++++++++++++++ .../math/generic/builtins/expo/CMakeLists.txt | 10 +++ .../math/generic/builtins/expo/exp.hpp | 68 ++++++++++++++ .../math/generic/builtins/expo/exp2.hpp | 68 ++++++++++++++ .../math/generic/builtins/expo/expm1.hpp | 68 ++++++++++++++ .../math/generic/builtins/expo/log.hpp | 68 ++++++++++++++ .../math/generic/builtins/expo/log10.hpp | 68 ++++++++++++++ .../math/generic/builtins/expo/log1p.hpp | 68 ++++++++++++++ .../math/generic/builtins/expo/log2.hpp | 68 ++++++++++++++ .../generic/builtins/fmanip/CMakeLists.txt | 12 +++ .../math/generic/builtins/fmanip/copysign.hpp | 68 ++++++++++++++ .../math/generic/builtins/fmanip/frexp.hpp | 68 ++++++++++++++ .../math/generic/builtins/fmanip/ilogb.hpp | 68 ++++++++++++++ .../math/generic/builtins/fmanip/ldexp.hpp | 68 ++++++++++++++ .../math/generic/builtins/fmanip/logb.hpp | 68 ++++++++++++++ .../math/generic/builtins/fmanip/modf.hpp | 68 ++++++++++++++ .../generic/builtins/fmanip/nextafter.hpp | 68 ++++++++++++++ .../generic/builtins/fmanip/nexttoward.hpp | 68 ++++++++++++++ .../math/generic/builtins/fmanip/scalbn.hpp | 68 ++++++++++++++ .../generic/builtins/hyper/CMakeLists.txt | 8 ++ .../math/generic/builtins/hyper/acosh.hpp | 68 ++++++++++++++ .../math/generic/builtins/hyper/asinh.hpp | 68 ++++++++++++++ .../math/generic/builtins/hyper/atanh.hpp | 68 ++++++++++++++ .../math/generic/builtins/hyper/cosh.hpp | 68 ++++++++++++++ .../math/generic/builtins/hyper/sinh.hpp | 68 ++++++++++++++ .../math/generic/builtins/hyper/tanh.hpp | 68 ++++++++++++++ .../math/generic/builtins/misc/CMakeLists.txt | 4 + .../math/generic/builtins/misc/gamma.hpp | 68 ++++++++++++++ .../math/generic/builtins/misc/lgamma.hpp | 68 ++++++++++++++ .../generic/builtins/nearest/CMakeLists.txt | 8 ++ .../math/generic/builtins/nearest/ceil.hpp | 68 ++++++++++++++ .../math/generic/builtins/nearest/floor.hpp | 68 ++++++++++++++ .../generic/builtins/nearest/nearbyint.hpp | 68 ++++++++++++++ .../math/generic/builtins/nearest/rint.hpp | 68 ++++++++++++++ .../math/generic/builtins/nearest/round.hpp | 68 ++++++++++++++ .../math/generic/builtins/nearest/trunc.hpp | 68 ++++++++++++++ .../generic/builtins/power/CMakeLists.txt | 6 ++ .../math/generic/builtins/power/cbrt.hpp | 68 ++++++++++++++ .../math/generic/builtins/power/hypot.hpp | 68 ++++++++++++++ .../math/generic/builtins/power/pow.hpp | 68 ++++++++++++++ .../math/generic/builtins/power/sqrt.hpp | 68 ++++++++++++++ .../math/generic/builtins/trig/CMakeLists.txt | 9 ++ .../math/generic/builtins/trig/acos.hpp | 68 ++++++++++++++ .../math/generic/builtins/trig/asin.hpp | 68 ++++++++++++++ .../math/generic/builtins/trig/atan.hpp | 68 ++++++++++++++ .../math/generic/builtins/trig/atan2.hpp | 68 ++++++++++++++ .../math/generic/builtins/trig/cos.hpp | 68 ++++++++++++++ .../math/generic/builtins/trig/sin.hpp | 68 ++++++++++++++ .../math/generic/builtins/trig/tan.hpp | 68 ++++++++++++++ .../math/generic/func/basic/fma_gen.hpp | 73 +++++++-------- include/ccmath/math/basic/abs.hpp | 31 ++++--- include/ccmath/math/basic/fdim.hpp | 24 +++-- include/ccmath/math/basic/fma.hpp | 1 + include/ccmath/math/compare/signbit.hpp | 50 +++-------- 72 files changed, 3882 insertions(+), 122 deletions(-) delete mode 100644 include/ccmath/internal/builtins/fma.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/basic/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/basic/abs.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/basic/fdim.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/basic/fma.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/basic/fmod.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/basic/nan.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/basic/remainder.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/basic/remquo.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/builtin_helpers.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/isinf.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/isnan.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/signbit.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/expo/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/expo/exp.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/expo/exp2.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/expo/expm1.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/expo/log.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/expo/log10.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/expo/log1p.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/expo/log2.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/hyper/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/misc/gamma.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/misc/lgamma.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/nearest/floor.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/nearest/nearbyint.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/nearest/rint.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/nearest/round.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/power/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/power/cbrt.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/power/hypot.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/power/pow.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/power/sqrt.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/trig/CMakeLists.txt create mode 100644 include/ccmath/internal/math/generic/builtins/trig/acos.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/trig/asin.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/trig/atan.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/trig/atan2.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/trig/cos.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/trig/sin.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/trig/tan.hpp diff --git a/include/ccmath/internal/builtins/fma.hpp b/include/ccmath/internal/builtins/fma.hpp deleted file mode 100644 index 20691c4e..00000000 --- a/include/ccmath/internal/builtins/fma.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -namespace ccm::internal::builtin -{ - template - inline constexpr bool has_constexpr_fma = - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - (std::is_same_v || std::is_same_v || std::is_same_v); - #else - false; - #endif - - template - constexpr auto fma(T x, T y, T z) - -> std::enable_if_t, T> - { - if constexpr (std::is_same_v) { - return __builtin_fmaf(x, y, z); - } - if constexpr (std::is_same_v) { - return __builtin_fma(x, y, z); - } - if constexpr (std::is_same_v) { - return __builtin_fmal(x, y, z); - } - } -} // namespace ccm::internal::builtin diff --git a/include/ccmath/internal/math/generic/CMakeLists.txt b/include/ccmath/internal/math/generic/CMakeLists.txt index 77809222..7dba481d 100644 --- a/include/ccmath/internal/math/generic/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(builtins) add_subdirectory(func) diff --git a/include/ccmath/internal/math/generic/builtins/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/CMakeLists.txt new file mode 100644 index 00000000..688ca191 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/CMakeLists.txt @@ -0,0 +1,12 @@ +ccm_add_headers( + builtin_helpers.hpp +) + +add_subdirectory(basic) +add_subdirectory(expo) +add_subdirectory(fmanip) +add_subdirectory(hyper) +add_subdirectory(misc) +add_subdirectory(nearest) +add_subdirectory(power) +add_subdirectory(trig) diff --git a/include/ccmath/internal/math/generic/builtins/basic/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/basic/CMakeLists.txt new file mode 100644 index 00000000..07caa0c3 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/CMakeLists.txt @@ -0,0 +1,11 @@ +ccm_add_headers( + abs.hpp + fdim.hpp + fma.hpp + fmod.hpp + fmax.hpp + fmin.hpp + nan.hpp + remainder.hpp + remquo.hpp +) diff --git a/include/ccmath/internal/math/generic/builtins/basic/abs.hpp b/include/ccmath/internal/math/generic/builtins/basic/abs.hpp new file mode 100644 index 00000000..7f5f89a2 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/abs.hpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ABS +/// This is a macro that is defined if the compiler has constexpr __builtin functions for abs that allow static_assert +/// +/// Compilers with Support: +/// - GCC 5.1+ +/// - NVC++ 22.7+ (Lowest tested version) +/// - Clang trunk allows it, but it is not yet in a release +/// TODO: Add clang version when it is released + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ABS +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ABS +#endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ABS +#if defined(__NVCOMPILER_MAJOR__) && (__NVCOMPILER_MAJOR__ > 22 || (__NVCOMPILER_MAJOR__ == 22 && __NVCOMPILER_MINOR__ >= 7)) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ABS +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_abs = + #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ABS + std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v || ( + std::is_integral_v && std::is_signed_v) || (std::is_integral_v && std::is_unsigned_v); + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin_abs functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_abs functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto abs(T x) + -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_fabsf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_fabs(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_fabsl(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_llabs(x); + } + else if constexpr (std::is_integral_v && std::is_signed_v) + { + return __builtin_abs(x); + } + else if constexpr (std::is_integral_v && std::is_unsigned_v) + { + return x; // Absolute value of unsigned is the value itself + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ABS diff --git a/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp b/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp new file mode 100644 index 00000000..0c598dd4 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM +/// This is a macro that is defined if the compiler has constexpr __builtin functions for fdim that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_fdim = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin fdim functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin fdim functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto fdim(T x, T y) + -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_fdimf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fdim(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fdiml(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM diff --git a/include/ccmath/internal/math/generic/builtins/basic/fma.hpp b/include/ccmath/internal/math/generic/builtins/basic/fma.hpp new file mode 100644 index 00000000..234d08fc --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/fma.hpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_FMA +/// This is a macro that is defined if the compiler has constexpr __builtin_copysign that allows static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMA +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMA +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_fma = + #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FMA + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin_fma. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_fma without triggering a compiler error + * when the compiler does not support it. + * This is thanks to taking advantage of ADL. + */ + template + constexpr auto fma(T x, T y, T z) + -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_fmaf(x, y, z); + } + if constexpr (std::is_same_v) + { + return __builtin_fma(x, y, z); + } + if constexpr (std::is_same_v) + { + return __builtin_fmal(x, y, z); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_FMA diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp new file mode 100644 index 00000000..5cae35a4 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp @@ -0,0 +1,69 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD +/// This is a macro that is defined if the compiler has constexpr __builtin functions for fmod that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_fmod = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin fmod functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin fmod functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto fmod(T x, T y) + -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_fmodf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fmod(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fmodl(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD diff --git a/include/ccmath/internal/math/generic/builtins/basic/nan.hpp b/include/ccmath/internal/math/generic/builtins/basic/nan.hpp new file mode 100644 index 00000000..a738c267 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/nan.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_NAN +/// This is a macro that is defined if the compiler has constexpr __builtin functions for nan that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NAN +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_NAN +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_nan = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_NAN + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin nan functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin nan functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto nan(const char* tag) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_nanf(tag); + } + else if constexpr (std::is_same_v) + { + return __builtin_nan(tag); + } + else if constexpr (std::is_same_v) + { + return __builtin_nanl(tag); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_NAN diff --git a/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp b/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp new file mode 100644 index 00000000..9324fe5f --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER +/// This is a macro that is defined if the compiler has constexpr __builtin functions for remainder that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_remainder = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin remainder functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin remainder functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto remainder(T x, T y) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_remainderf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_remainder(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_remainderl(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER diff --git a/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp b/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp new file mode 100644 index 00000000..c74632d8 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO +/// This is a macro that is defined if the compiler has constexpr __builtin functions for remquo that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_remquo = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin remquo functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin remquo functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto remquo(T x, T y, int* quo) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_remquof(x, y, quo); + } + else if constexpr (std::is_same_v) + { + return __builtin_remquo(x, y, quo); + } + else if constexpr (std::is_same_v) + { + return __builtin_remquol(x, y, quo); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO diff --git a/include/ccmath/internal/math/generic/builtins/builtin_helpers.hpp b/include/ccmath/internal/math/generic/builtins/builtin_helpers.hpp new file mode 100644 index 00000000..e28625c3 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/builtin_helpers.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace ccm::builtin +{ + // Helper to check that a valid builtin type is used + template + inline constexpr bool is_valid_builtin_type = std::is_same_v || std::is_same_v || std::is_same_v; +} // namespace ccm::builtin diff --git a/include/ccmath/internal/math/generic/builtins/compare/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/compare/CMakeLists.txt new file mode 100644 index 00000000..27dda1e7 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/CMakeLists.txt @@ -0,0 +1,8 @@ +ccm_add_headers( + isfinite.hpp + isinf.hpp + isnan.hpp + isnormal.hpp + isunordered.hpp + signbit.hpp +) diff --git a/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp b/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp new file mode 100644 index 00000000..a69b835b --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE +/// This is a macro that is defined if the compiler has constexpr __builtin functions for isfinite that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_isfinite = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin isfinite functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin isfinite functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto isfinite(T x) -> std::enable_if_t, bool> + { + if constexpr (std::is_same_v) + { + return __builtin_isfinite(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_isfinite(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_isfinite(x); + } + // This should never be reached + return false; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE diff --git a/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp b/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp new file mode 100644 index 00000000..157ab3d8 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF +/// This is a macro that is defined if the compiler has constexpr __builtin functions for isinf that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_isinf = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin isinf functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin isinf functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto isinf(T x) -> std::enable_if_t, bool> + { + if constexpr (std::is_same_v) + { + return __builtin_isinf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_isinf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_isinf(x); + } + // This should never be reached + return false; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF diff --git a/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp b/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp new file mode 100644 index 00000000..86b6e4be --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN +/// This is a macro that is defined if the compiler has constexpr __builtin functions for isnan that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_isnan = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin isnan functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin isnan functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto isnan(T x) -> std::enable_if_t, bool> + { + if constexpr (std::is_same_v) + { + return __builtin_isnan(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_isnan(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_isnan(x); + } + // This should never be reached + return false; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN diff --git a/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp b/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp new file mode 100644 index 00000000..a80378c1 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL +/// This is a macro that is defined if the compiler has constexpr __builtin functions for isnormal that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_isnormal = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin isnormal functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin isnormal functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto isnormal(T x) -> std::enable_if_t, bool> + { + if constexpr (std::is_same_v) + { + return __builtin_isnormal(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_isnormal(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_isnormal(x); + } + // This should never be reached + return false; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL diff --git a/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp b/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp new file mode 100644 index 00000000..00c672af --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED +/// This is a macro that is defined if the compiler has constexpr __builtin functions for isunordered that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_isunordered = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin isunordered functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin isunordered functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto isunordered(T x, T y) -> std::enable_if_t, bool> + { + if constexpr (std::is_same_v) + { + return __builtin_isunordered(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_isunordered(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_isunordered(x, y); + } + // This should never be reached + return false; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED diff --git a/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp b/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp new file mode 100644 index 00000000..94694fdb --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT +/// This is a macro that is defined if the compiler has constexpr __builtin functions for signbit that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_signbit = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin signbit functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin signbit functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto signbit(T x) -> std::enable_if_t, bool> + { + if constexpr (std::is_same_v) + { + return __builtin_signbit(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_signbit(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_signbit(x); + } + // This should never be reached + return false; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT diff --git a/include/ccmath/internal/math/generic/builtins/expo/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/expo/CMakeLists.txt new file mode 100644 index 00000000..b80073b3 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/expo/CMakeLists.txt @@ -0,0 +1,10 @@ +ccm_add_headers( + exp.hpp + exp2.hpp + expm1.hpp + log.hpp + log1p.hpp + log2.hpp + log10.hpp +) + diff --git a/include/ccmath/internal/math/generic/builtins/expo/exp.hpp b/include/ccmath/internal/math/generic/builtins/expo/exp.hpp new file mode 100644 index 00000000..a8df84b9 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/expo/exp.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_EXP +/// This is a macro that is defined if the compiler has constexpr __builtin functions for exp that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_EXP +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_exp = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin exp functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin exp functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto exp(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_expf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_exp(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_expl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP diff --git a/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp b/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp new file mode 100644 index 00000000..3b16e662 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 +/// This is a macro that is defined if the compiler has constexpr __builtin functions for exp2 that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_exp2 = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin exp2 functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin exp2 functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto exp2(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_exp2f(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_exp2(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_exp2l(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 diff --git a/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp b/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp new file mode 100644 index 00000000..aabb520d --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 +/// This is a macro that is defined if the compiler has constexpr __builtin functions for expm1 that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_expm1 = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin expm1 functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin expm1 functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto expm1(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_expm1f(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_expm1(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_expm1l(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 diff --git a/include/ccmath/internal/math/generic/builtins/expo/log.hpp b/include/ccmath/internal/math/generic/builtins/expo/log.hpp new file mode 100644 index 00000000..b5bff3a3 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/expo/log.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_LOG +/// This is a macro that is defined if the compiler has constexpr __builtin functions for log that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_log = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin log functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin log functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto log(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_logf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_log(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_logl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG diff --git a/include/ccmath/internal/math/generic/builtins/expo/log10.hpp b/include/ccmath/internal/math/generic/builtins/expo/log10.hpp new file mode 100644 index 00000000..7b8a4d37 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/expo/log10.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 +/// This is a macro that is defined if the compiler has constexpr __builtin functions for log10 that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_log10 = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin log10 functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin log10 functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto log10(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_log10f(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_log10(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_log10l(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 diff --git a/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp b/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp new file mode 100644 index 00000000..97cecfe4 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P +/// This is a macro that is defined if the compiler has constexpr __builtin functions for log1p that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_log1p = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin log1p functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin log1p functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto log1p(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_log1pf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_log1p(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_log1pl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P diff --git a/include/ccmath/internal/math/generic/builtins/expo/log2.hpp b/include/ccmath/internal/math/generic/builtins/expo/log2.hpp new file mode 100644 index 00000000..c6075af8 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/expo/log2.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 +/// This is a macro that is defined if the compiler has constexpr __builtin functions for log2 that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_log2 = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin log2 functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin log2 functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto log2(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_log2f(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_log2(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_log2l(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/fmanip/CMakeLists.txt new file mode 100644 index 00000000..86c7d029 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/CMakeLists.txt @@ -0,0 +1,12 @@ +ccm_add_headers( + copysign.hpp + frexp.hpp + ilogb.hpp + ldexp.hpp + logb.hpp + modf.hpp + nextafter.hpp + nexttoward.hpp + scalbn.hpp +) + diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp new file mode 100644 index 00000000..f924765e --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN +/// This is a macro that is defined if the compiler has constexpr __builtin functions for copysign that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_copysign = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin copysign functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin copysign functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto copysign(T x, T y) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_copysignf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_copysign(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_copysignl(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp new file mode 100644 index 00000000..dae1818d --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP +/// This is a macro that is defined if the compiler has constexpr __builtin functions for frexp that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_frexp = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin frexp functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin frexp functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto frexp(T x, int* exp) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_frexpf(x, exp); + } + else if constexpr (std::is_same_v) + { + return __builtin_frexp(x, exp); + } + else if constexpr (std::is_same_v) + { + return __builtin_frexpl(x, exp); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp new file mode 100644 index 00000000..8f5c3c9a --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB +/// This is a macro that is defined if the compiler has constexpr __builtin functions for ilogb that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_ilogb = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin ilogb functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin ilogb functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto ilogb(T x) -> std::enable_if_t, int> + { + if constexpr (std::is_same_v) + { + return __builtin_ilogbf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_ilogb(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_ilogbl(x); + } + // This should never be reached + return 0; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp new file mode 100644 index 00000000..8c1c1102 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP +/// This is a macro that is defined if the compiler has constexpr __builtin functions for ldexp that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_ldexp = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin ldexp functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin ldexp functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto ldexp(T x, int exp) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_ldexpf(x, exp); + } + else if constexpr (std::is_same_v) + { + return __builtin_ldexp(x, exp); + } + else if constexpr (std::is_same_v) + { + return __builtin_ldexpl(x, exp); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp new file mode 100644 index 00000000..be2c46a7 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB +/// This is a macro that is defined if the compiler has constexpr __builtin functions for logb that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_logb = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin logb functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin logb functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto logb(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_logbf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_logb(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_logbl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp new file mode 100644 index 00000000..8216c9de --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_MODF +/// This is a macro that is defined if the compiler has constexpr __builtin functions for modf that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_MODF +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_MODF +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_modf = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_MODF + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin modf functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin modf functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto modf(T x, T* intpart) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_modff(x, intpart); + } + else if constexpr (std::is_same_v) + { + return __builtin_modf(x, intpart); + } + else if constexpr (std::is_same_v) + { + return __builtin_modfl(x, intpart); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_MODF diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp new file mode 100644 index 00000000..c0810880 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER +/// This is a macro that is defined if the compiler has constexpr __builtin functions for nextafter that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_nextafter = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin nextafter functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin nextafter functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto nextafter(T x, T y) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_nextafterf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_nextafter(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_nextafterl(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp new file mode 100644 index 00000000..2b7575db --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD +/// This is a macro that is defined if the compiler has constexpr __builtin functions for nexttoward that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_nexttoward = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin nexttoward functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin nexttoward functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto nexttoward(T x, long double y) -> std::enable_if_t || std::is_same_v || std::is_same_v, T> + { + if constexpr (std::is_same_v) + { + return __builtin_nexttowardf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_nexttoward(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_nexttowardl(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp new file mode 100644 index 00000000..a7a53f68 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN +/// This is a macro that is defined if the compiler has constexpr __builtin functions for scalbn that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_scalbn = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin scalbn functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin scalbn functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto scalbn(T x, int exp) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_scalbnf(x, exp); + } + else if constexpr (std::is_same_v) + { + return __builtin_scalbn(x, exp); + } + else if constexpr (std::is_same_v) + { + return __builtin_scalbnl(x, exp); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN diff --git a/include/ccmath/internal/math/generic/builtins/hyper/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/hyper/CMakeLists.txt new file mode 100644 index 00000000..b18cb199 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/hyper/CMakeLists.txt @@ -0,0 +1,8 @@ +ccm_add_headers( + acosh.hpp + asinh.hpp + atanh.hpp + cosh.hpp + sinh.hpp + tanh.hpp +) diff --git a/include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp new file mode 100644 index 00000000..fac5ca2d --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH +/// This is a macro that is defined if the compiler has constexpr __builtin functions for acosh that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_acosh = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin acosh functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin acosh functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto acosh(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_acoshf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_acosh(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_acoshl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH diff --git a/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp new file mode 100644 index 00000000..fb438bdd --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH +/// This is a macro that is defined if the compiler has constexpr __builtin functions for asinh that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_asinh = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin asinh functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin asinh functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto asinh(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_asinhf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_asinh(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_asinhl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH diff --git a/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp new file mode 100644 index 00000000..802d104e --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH +/// This is a macro that is defined if the compiler has constexpr __builtin functions for atanh that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_atanh = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin atanh functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin atanh functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto atanh(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_atanhf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_atanh(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_atanhl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH diff --git a/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp new file mode 100644 index 00000000..186e406a --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_COSH +/// This is a macro that is defined if the compiler has constexpr __builtin functions for cosh that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COSH +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_COSH +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_cosh = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_COSH + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin cosh functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin cosh functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto cosh(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_coshf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_cosh(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_coshl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_COSH diff --git a/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp new file mode 100644 index 00000000..86c76479 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_SINH +/// This is a macro that is defined if the compiler has constexpr __builtin functions for sinh that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SINH +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_SINH +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_sinh = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_SINH + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin sinh functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin sinh functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto sinh(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_sinhf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_sinh(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_sinhl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_SINH diff --git a/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp new file mode 100644 index 00000000..bb6c69ba --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_TANH +/// This is a macro that is defined if the compiler has constexpr __builtin functions for tanh that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_TANH +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_TANH +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_tanh = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_TANH + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin tanh functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin tanh functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto tanh(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_tanhf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_tanh(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_tanhl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_TANH diff --git a/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt new file mode 100644 index 00000000..a702e582 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt @@ -0,0 +1,4 @@ +ccm_add_headers( + gamma.hpp + lgamma.hpp +) diff --git a/include/ccmath/internal/math/generic/builtins/misc/gamma.hpp b/include/ccmath/internal/math/generic/builtins/misc/gamma.hpp new file mode 100644 index 00000000..f98c5fa9 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/misc/gamma.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA +/// This is a macro that is defined if the compiler has constexpr __builtin functions for gamma that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_gamma = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin gamma functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin gamma functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto gamma(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_gammaf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_gamma(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_gammal(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA diff --git a/include/ccmath/internal/math/generic/builtins/misc/lgamma.hpp b/include/ccmath/internal/math/generic/builtins/misc/lgamma.hpp new file mode 100644 index 00000000..5b4a908f --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/misc/lgamma.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA +/// This is a macro that is defined if the compiler has constexpr __builtin functions for lgamma that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_lgamma = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin lgamma functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin lgamma functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto lgamma(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_lgammaf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_lgamma(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_lgammal(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA diff --git a/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt new file mode 100644 index 00000000..60727f1d --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt @@ -0,0 +1,8 @@ +ccm_add_headers( + ceil.hpp + floor.hpp + nearbyint.hpp + rint.hpp + round.hpp + trunc.hpp +) diff --git a/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp b/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp new file mode 100644 index 00000000..8bfa4bb6 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL +/// This is a macro that is defined if the compiler has constexpr __builtin functions for ceil that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_ceil = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin ceil functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin ceil functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto ceil(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_ceilf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_ceil(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_ceill(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL diff --git a/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp b/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp new file mode 100644 index 00000000..6bfb0214 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR +/// This is a macro that is defined if the compiler has constexpr __builtin functions for floor that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_floor = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin floor functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin floor functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto floor(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_floorf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_floor(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_floorl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR diff --git a/include/ccmath/internal/math/generic/builtins/nearest/nearbyint.hpp b/include/ccmath/internal/math/generic/builtins/nearest/nearbyint.hpp new file mode 100644 index 00000000..2e6436a3 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/nearest/nearbyint.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT +/// This is a macro that is defined if the compiler has constexpr __builtin functions for nearbyint that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_nearbyint = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin nearbyint functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin nearbyint functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto nearbyint(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_nearbyintf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_nearbyint(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_nearbyintl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT diff --git a/include/ccmath/internal/math/generic/builtins/nearest/rint.hpp b/include/ccmath/internal/math/generic/builtins/nearest/rint.hpp new file mode 100644 index 00000000..36c92063 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/nearest/rint.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_RINT +/// This is a macro that is defined if the compiler has constexpr __builtin functions for rint that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_RINT +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_RINT +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_rint = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_RINT + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin rint functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin rint functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto rint(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_rintf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_rint(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_rintl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_RINT diff --git a/include/ccmath/internal/math/generic/builtins/nearest/round.hpp b/include/ccmath/internal/math/generic/builtins/nearest/round.hpp new file mode 100644 index 00000000..c8ca4e88 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/nearest/round.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND +/// This is a macro that is defined if the compiler has constexpr __builtin functions for round that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_round = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin round functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin round functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto round(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_roundf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_round(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_roundl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND diff --git a/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp b/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp new file mode 100644 index 00000000..2062c250 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC +/// This is a macro that is defined if the compiler has constexpr __builtin functions for trunc that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_trunc = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin trunc functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin trunc functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto trunc(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_truncf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_trunc(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_truncl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC diff --git a/include/ccmath/internal/math/generic/builtins/power/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/power/CMakeLists.txt new file mode 100644 index 00000000..1f509c39 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/power/CMakeLists.txt @@ -0,0 +1,6 @@ +ccm_add_headers( + cbrt.hpp + hypot.hpp + pow.hpp + sqrt.hpp +) diff --git a/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp b/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp new file mode 100644 index 00000000..a9a2485b --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT +/// This is a macro that is defined if the compiler has constexpr __builtin functions for cbrt that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_cbrt = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin cbrt functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin cbrt functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto cbrt(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_cbrtf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_cbrt(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_cbrtl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT diff --git a/include/ccmath/internal/math/generic/builtins/power/hypot.hpp b/include/ccmath/internal/math/generic/builtins/power/hypot.hpp new file mode 100644 index 00000000..8560bf68 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/power/hypot.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT +/// This is a macro that is defined if the compiler has constexpr __builtin functions for hypot that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_hypot = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin hypot functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin hypot functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto hypot(T x, T y) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_hypotf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_hypot(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_hypotl(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT diff --git a/include/ccmath/internal/math/generic/builtins/power/pow.hpp b/include/ccmath/internal/math/generic/builtins/power/pow.hpp new file mode 100644 index 00000000..121a7b13 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/power/pow.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_POW +/// This is a macro that is defined if the compiler has constexpr __builtin functions for pow that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_POW +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_POW +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_pow = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_POW + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin pow functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin pow functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto pow(T x, T y) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_powf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_pow(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_powl(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_POW diff --git a/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp b/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp new file mode 100644 index 00000000..c8ee8c0f --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT +/// This is a macro that is defined if the compiler has constexpr __builtin functions for sqrt that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_sqrt = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin sqrt functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin sqrt functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto sqrt(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_sqrtf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_sqrt(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_sqrtl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT diff --git a/include/ccmath/internal/math/generic/builtins/trig/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/trig/CMakeLists.txt new file mode 100644 index 00000000..11860937 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/trig/CMakeLists.txt @@ -0,0 +1,9 @@ +ccm_add_headers( + acos.hpp + asin.hpp + atan.hpp + atan2.hpp + cos.hpp + sin.hpp + tan.hpp +) diff --git a/include/ccmath/internal/math/generic/builtins/trig/acos.hpp b/include/ccmath/internal/math/generic/builtins/trig/acos.hpp new file mode 100644 index 00000000..3fdeda7f --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/trig/acos.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS +/// This is a macro that is defined if the compiler has constexpr __builtin functions for acos that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_acos = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin acos functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin acos functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto acos(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_acosf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_acos(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_acosl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS diff --git a/include/ccmath/internal/math/generic/builtins/trig/asin.hpp b/include/ccmath/internal/math/generic/builtins/trig/asin.hpp new file mode 100644 index 00000000..0e2ca719 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/trig/asin.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN +/// This is a macro that is defined if the compiler has constexpr __builtin functions for asin that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_asin = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin asin functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin asin functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto asin(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_asinf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_asin(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_asinl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN diff --git a/include/ccmath/internal/math/generic/builtins/trig/atan.hpp b/include/ccmath/internal/math/generic/builtins/trig/atan.hpp new file mode 100644 index 00000000..62ee9275 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/trig/atan.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN +/// This is a macro that is defined if the compiler has constexpr __builtin functions for atan that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_atan = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin atan functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin atan functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto atan(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_atanf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_atan(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_atanl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN diff --git a/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp b/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp new file mode 100644 index 00000000..64288faf --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 +/// This is a macro that is defined if the compiler has constexpr __builtin functions for atan2 that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_atan2 = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin atan2 functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin atan2 functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto atan2(T y, T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_atan2f(y, x); + } + else if constexpr (std::is_same_v) + { + return __builtin_atan2(y, x); + } + else if constexpr (std::is_same_v) + { + return __builtin_atan2l(y, x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 diff --git a/include/ccmath/internal/math/generic/builtins/trig/cos.hpp b/include/ccmath/internal/math/generic/builtins/trig/cos.hpp new file mode 100644 index 00000000..d1beaa32 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/trig/cos.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_COS +/// This is a macro that is defined if the compiler has constexpr __builtin functions for cos that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COS +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_COS +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_cos = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_COS + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin cos functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin cos functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto cos(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_cosf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_cos(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_cosl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_COS diff --git a/include/ccmath/internal/math/generic/builtins/trig/sin.hpp b/include/ccmath/internal/math/generic/builtins/trig/sin.hpp new file mode 100644 index 00000000..34049c9d --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/trig/sin.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_SIN +/// This is a macro that is defined if the compiler has constexpr __builtin functions for sin that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SIN +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_SIN +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_sin = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_SIN + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin sin functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin sin functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto sin(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_sinf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_sin(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_sinl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_SIN diff --git a/include/ccmath/internal/math/generic/builtins/trig/tan.hpp b/include/ccmath/internal/math/generic/builtins/trig/tan.hpp new file mode 100644 index 00000000..2709fab4 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/trig/tan.hpp @@ -0,0 +1,68 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_TAN +/// This is a macro that is defined if the compiler has constexpr __builtin functions for tan that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_TAN +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_TAN +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_tan = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_TAN + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin tan functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin tan functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto tan(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_tanf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_tan(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_tanl(x); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_TAN diff --git a/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp b/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp index b4eda434..f398fe8c 100644 --- a/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp +++ b/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp @@ -15,6 +15,8 @@ #include "ccmath/math/compare/isnan.hpp" #include "ccmath/math/compare/signbit.hpp" +#include "ccmath/internal/math/generic/builtins/basic/fma.hpp" + #include #include @@ -29,52 +31,51 @@ namespace ccm * @return If successful, returns the value of x * y + z as if calculated to infinite precision and rounded once to fit the result type (or, alternatively, * calculated as a single ternary floating-point operation). */ - template , bool> = true> + template , bool> = true> constexpr T fma(T x, T y, T z) noexcept { - // Check for GCC 6.1 or later - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - if constexpr (std::is_same_v) { return __builtin_fmaf(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fma(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fmal(x, y, z); } - return static_cast(__builtin_fmal(x, y, z)); - #else - if (CCM_UNLIKELY(x == 0 || y == 0 || z == 0)) { return x * y + z; } - - // If x is zero, and y is infinity, or if y is zero and x is infinity and... - if ((x == static_cast(0) && ccm::isinf(y)) || (y == T{0} && ccm::isinf(x))) + if constexpr (ccm::builtin::has_constexpr_fma) + { + return ccm::builtin::fma(x, y, z); + } + else { - // ...z is NaN, return +NaN... - if (ccm::isnan(z)) + if (CCM_UNLIKELY(x == 0 || y == 0 || z == 0)) { return x * y + z; } + + // If x is zero, and y is infinity, or if y is zero and x is infinity and... + if ((x == static_cast(0) && ccm::isinf(y)) || (y == T{0} && ccm::isinf(x))) { - return std::numeric_limits::quiet_NaN(); + // ...z is NaN, return +NaN... + if (ccm::isnan(z)) + { + return std::numeric_limits::quiet_NaN(); + } + + // ...else return -NaN if Z is not NaN. + return -std::numeric_limits::quiet_NaN(); } - // ...else return -NaN if Z is not NaN. - return -std::numeric_limits::quiet_NaN(); - } + // If x is a zero and y is an infinity, or if y is zero and x is an infinity and Z is NaN, then the result is -NaN. + if (ccm::isinf(x * y) && ccm::isinf(z) && ccm::signbit(x * y) != ccm::signbit(z)) + { + return -std::numeric_limits::quiet_NaN(); + } - // If x is a zero and y is an infinity, or if y is zero and x is an infinity and Z is NaN, then the result is -NaN. - if (ccm::isinf(x * y) && ccm::isinf(z) && ccm::signbit(x * y) != ccm::signbit(z)) - { - return -std::numeric_limits::quiet_NaN(); - } + // If x or y are NaN, NaN is returned. + if (ccm::isnan(x) || ccm::isnan(y)) { return std::numeric_limits::quiet_NaN(); } - // If x or y are NaN, NaN is returned. - if (ccm::isnan(x) || ccm::isnan(y)) { return std::numeric_limits::quiet_NaN(); } + // If z is NaN, and x * y is not 0 * Inf or Inf * 0, then +NaN is returned + if (ccm::isnan(z) && (x * y != 0 * std::numeric_limits::infinity() || x * y != std::numeric_limits::infinity() * 0)) + { + return std::numeric_limits::quiet_NaN(); + } - // If z is NaN, and x * y is not 0 * Inf or Inf * 0, then +NaN is returned - if (ccm::isnan(z) && (x * y != 0 * std::numeric_limits::infinity() || x * y != std::numeric_limits::infinity() * 0)) - { - return std::numeric_limits::quiet_NaN(); + // Hope the compiler optimizes this. + return (x * y) + z; } - - // Hope the compiler optimizes this. - return (x * y) + z; -#endif } - template , bool> = true> + template , bool> = true> constexpr Integer fma(Integer x, Integer y, Integer z) noexcept { return (x * y) + z; @@ -105,7 +106,7 @@ namespace ccm using shared_type = std::conditional_t< TCommon <= std::numeric_limits::epsilon() && TCommon <= UCommon, T, std::conditional_t::epsilon() && UCommon <= TCommon, U, - std::conditional_t::epsilon() && VCommon <= UCommon, V, epsilon_type>>>; + std::conditional_t::epsilon() && VCommon <= UCommon, V, epsilon_type> > >; return ccm::fma(static_cast(x), static_cast(y), static_cast(z)); } @@ -121,7 +122,7 @@ namespace ccm * @return If successful, returns the value of x * y + z as if calculated to infinite precision and rounded once to fit the result type (or, alternatively, * calculated as a single ternary floating-point operation). */ - template && std::is_integral_v && std::is_integral_v, bool> = true> + template && std::is_integral_v && std::is_integral_v, bool> = true> constexpr auto fma(T x, U y, V z) noexcept // Special case for if all types are integers. { using shared_type = std::common_type_t; diff --git a/include/ccmath/math/basic/abs.hpp b/include/ccmath/math/basic/abs.hpp index 2d624a61..ad9d892e 100644 --- a/include/ccmath/math/basic/abs.hpp +++ b/include/ccmath/math/basic/abs.hpp @@ -11,6 +11,7 @@ #pragma once #include "ccmath/internal/predef/unlikely.hpp" +#include "ccmath/internal/math/generic/builtins/basic/abs.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" #include @@ -23,20 +24,24 @@ namespace ccm * @param num Floating-point or integer value. * @return If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes. */ - template && std::is_signed_v, bool> = true> + template && std::is_signed_v, bool> = true> constexpr T abs(T num) noexcept { - using FPBits_t = typename ccm::support::fp::FPBits; - const FPBits_t num_bits(num); + if constexpr (ccm::builtin::has_constexpr_abs) { return ccm::builtin::abs(num); } + else + { + using FPBits_t = typename ccm::support::fp::FPBits; + const FPBits_t num_bits(num); - // If num is NaN, return a quiet NaN. - if (CCM_UNLIKELY(num_bits.is_nan())) { return std::numeric_limits::quiet_NaN(); } + // If num is NaN, return a quiet NaN. + if (CCM_UNLIKELY(num_bits.is_nan())) { return std::numeric_limits::quiet_NaN(); } - // If num is equal to ±zero, return +zero. - if (num_bits.is_zero()) { return static_cast(0); } + // If num is equal to ±zero, return +zero. + if (num_bits.is_zero()) { return static_cast(0); } - // If num is less than zero, return -num, otherwise return num. - return num < 0 ? -num : num; + // If num is less than zero, return -num, otherwise return num. + return num < 0 ? -num : num; + } } /** @@ -45,7 +50,7 @@ namespace ccm * @param num Floating-point or integer value. * @return If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes. */ - template && std::is_signed_v, bool> = true> + template && std::is_signed_v, bool> = true> constexpr T abs(T num) noexcept { // If num is less than zero, return -num, otherwise return num. @@ -58,7 +63,7 @@ namespace ccm * @param num Floating-point or integer value. * @return If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes. */ - template , bool> = true> + template , bool> = true> constexpr T abs(T num) noexcept { // If abs is called with an argument of type X for which is_unsigned_v is true, and @@ -79,7 +84,7 @@ namespace ccm * @param num Floating-point value. * @return If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes. */ - template , bool> = true> + template , bool> = true> constexpr T fabs(T num) noexcept { return ccm::abs(num); @@ -91,7 +96,7 @@ namespace ccm * @param num Integer value. * @return If successful, returns the absolute value of arg (|arg|). The value returned is exact and does not depend on any rounding modes. */ - template , bool> = true> + template , bool> = true> constexpr double fabs(Integer num) noexcept { return ccm::abs(static_cast(num)); diff --git a/include/ccmath/math/basic/fdim.hpp b/include/ccmath/math/basic/fdim.hpp index a00ba240..a3d4181e 100644 --- a/include/ccmath/math/basic/fdim.hpp +++ b/include/ccmath/math/basic/fdim.hpp @@ -11,6 +11,7 @@ #pragma once #include "ccmath/internal/predef/unlikely.hpp" +#include "ccmath/internal/math/generic/builtins/basic/fdim.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" #include @@ -28,15 +29,22 @@ namespace ccm template , bool> = true> constexpr T fdim(T x, T y) { - using FPBits_t = typename ccm::support::fp::FPBits; - const FPBits_t x_bits(x); - const FPBits_t y_bits(y); + if constexpr (builtin::has_constexpr_fdim) + { + return builtin::fdim(x, y); + } + else + { + using FPBits_t = typename ccm::support::fp::FPBits; + const FPBits_t x_bits(x); + const FPBits_t y_bits(y); - if (CCM_UNLIKELY(x_bits.is_nan())) { return x; } - if (CCM_UNLIKELY(y_bits.is_nan())) { return y; } - if (x <= y) { return static_cast(+0.0); } - if (y < static_cast(0.0) && x > std::numeric_limits::max() + y) { return std::numeric_limits::infinity(); } - return x - y; + if (CCM_UNLIKELY(x_bits.is_nan())) { return x; } + if (CCM_UNLIKELY(y_bits.is_nan())) { return y; } + if (x <= y) { return static_cast(+0.0); } + if (y < static_cast(0.0) && x > std::numeric_limits::max() + y) { return std::numeric_limits::infinity(); } + return x - y; + } } /** diff --git a/include/ccmath/math/basic/fma.hpp b/include/ccmath/math/basic/fma.hpp index edbcafdd..7e9cf8a2 100644 --- a/include/ccmath/math/basic/fma.hpp +++ b/include/ccmath/math/basic/fma.hpp @@ -14,6 +14,7 @@ #include "ccmath/math/compare/isinf.hpp" #include "ccmath/math/compare/isnan.hpp" #include "ccmath/math/compare/signbit.hpp" +#include "ccmath/internal/math/generic/builtins/basic/fma.hpp" #include #include diff --git a/include/ccmath/math/compare/signbit.hpp b/include/ccmath/math/compare/signbit.hpp index 15f4959c..3c3b77dc 100644 --- a/include/ccmath/math/compare/signbit.hpp +++ b/include/ccmath/math/compare/signbit.hpp @@ -9,22 +9,10 @@ */ #pragma once -#if defined(CCM_CONFIG_HAS_BUILTIN_BIT_CAST) || defined(CCM_CONFIG_HAS_BUILTIN_SIGNBIT_CONSTEXPR) -#include "ccmath/internal/config/builtin/bit_cast_support.hpp" -#include "ccmath/internal/config/builtin/copysign_support.hpp" -#include "ccmath/internal/config/builtin/signbit_support.hpp" -#endif - -// Include the necessary headers for each different fallback -#if defined(CCM_CONFIG_HAS_BUILTIN_SIGNBIT_CONSTEXPR) || defined(CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN) - #include "ccmath/math/compare/isnan.hpp" -#elif defined(CCM_CONFIG_HAS_BUILTIN_BIT_CAST) || defined(CCMATH_HAS_BUILTIN_BIT_CAST) - #include "ccmath/internal/support/bits.hpp" - #include "ccmath/internal/support/floating_point_traits.hpp" -#else - #include "ccmath/internal/support/always_false.hpp" -#endif +#include "ccmath/internal/math/generic/builtins/compare/signbit.hpp" +#include "ccmath/internal/support/bits.hpp" +#include "ccmath/internal/support/floating_point_traits.hpp" namespace ccm { @@ -44,31 +32,21 @@ namespace ccm template , bool> = true> [[nodiscard]] constexpr bool signbit(T num) noexcept { -#if defined(CCM_CONFIG_HAS_BUILTIN_SIGNBIT_CONSTEXPR) - return __builtin_signbit(num); -#elif defined(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) - // use __builtin_copysign to check for the sign of zero - if (num == static_cast(0) || ccm::isnan(num)) + if constexpr (builtin::has_constexpr_signbit) { - // If constexpr only works with gcc 7.1+. Without if constexpr we work till GCC 5.1+ - // This works with clang 5.0.0 no problem even with if constexpr - if constexpr (std::is_same_v) { return __builtin_copysignf(1.0F, num) < 0; } - if constexpr (std::is_same_v) { return __builtin_copysign(1.0, num) < 0; } - if constexpr (std::is_same_v) { return __builtin_copysignl(1.0L, num) < 0; } - return false; + return builtin::signbit(num); } - - return num < static_cast(0); -#else - // Check for the sign of +0.0 and -0.0 with bit_cast - if (num == static_cast(0) || ccm::isnan(num)) + else { - const auto bits = support::bit_cast>(num); - return (bits & support::sign_mask_v) != 0; - } + // Check for the sign of +0.0 and -0.0 with bit_cast + if (num == static_cast(0) || ccm::isnan(num)) + { + const auto bits = support::bit_cast>(num); + return (bits & support::sign_mask_v) != 0; + } - return num < static_cast(0); -#endif + return num < static_cast(0); + } } /** From e110ab51112fb8d4f60262e8f2392de38f0303fd Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 05:57:03 -0500 Subject: [PATCH 091/102] Bring in starting work of new builtin checking Signed-off-by: Ian --- .../math/generic/builtins/basic/fmax.hpp | 69 +++++++++++++++++++ .../math/generic/builtins/basic/fmin.hpp | 69 +++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 include/ccmath/internal/math/generic/builtins/basic/fmax.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/basic/fmin.hpp diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp new file mode 100644 index 00000000..8d0fadcc --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX +/// This is a macro that is defined if the compiler has constexpr __builtin functions for fmax that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_fmax = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX + is_valid_builtin_type; +#else + false; +#endif + // clang-format on + + /** + * Wrapper for constexpr __builtin fmax functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin fmax functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto fmax(T x, T y) + -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_fmaxf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fmax(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fmaxl(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp new file mode 100644 index 00000000..f8f01510 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp @@ -0,0 +1,69 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN +/// This is a macro that is defined if the compiler has constexpr __builtin functions for fmin that allow static_assert +/// +/// Compilers with Support: +/// - GCC 6.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_fmin = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin fmin functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin fmin functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto fmin(T x, T y) + -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_fminf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fmin(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fminl(x, y); + } + // This should never be reached + return T{}; + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN From c7c95c97eaa997f9ec418e569018c2cac5b52035 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 05:58:09 -0500 Subject: [PATCH 092/102] Fix missing added sub dir Signed-off-by: Ian --- include/ccmath/internal/math/generic/builtins/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/include/ccmath/internal/math/generic/builtins/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/CMakeLists.txt index 688ca191..2e5a0071 100644 --- a/include/ccmath/internal/math/generic/builtins/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/builtins/CMakeLists.txt @@ -3,6 +3,7 @@ ccm_add_headers( ) add_subdirectory(basic) +add_subdirectory(compare) add_subdirectory(expo) add_subdirectory(fmanip) add_subdirectory(hyper) From 3fc2bc213746265ecd8242c933eef0d17ab205d4 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 06:08:02 -0500 Subject: [PATCH 093/102] Formatting Signed-off-by: Ian --- include/ccmath/ext/README.md | 8 ++- include/ccmath/internal/README.md | 6 +- .../math/generic/builtins/basic/fmax.hpp | 66 +++++++++---------- .../math/generic/builtins/basic/fmod.hpp | 2 +- .../math/generic/builtins/basic/nan.hpp | 4 +- .../math/generic/builtins/basic/remquo.hpp | 64 +++++++++--------- .../math/generic/builtins/compare/signbit.hpp | 23 +++---- .../internal/math/runtime/pp/CMakeLists.txt | 2 +- .../ccmath/internal/math/runtime/pp/simd.hpp | 8 +-- 9 files changed, 91 insertions(+), 92 deletions(-) diff --git a/include/ccmath/ext/README.md b/include/ccmath/ext/README.md index 52b341a0..7f21e138 100644 --- a/include/ccmath/ext/README.md +++ b/include/ccmath/ext/README.md @@ -1,8 +1,10 @@ # CCMath Extension Headers Info > [!CAUTION] -> The extension headers are generally experimental and could have a change to their overall API. This is generally avoided, but not guaranteed. +> The extension headers are generally experimental and could have a change to their overall API. This is generally +> avoided, but not guaranteed. -The extension headers in this directory are intended to provide additional functionality to the CCMath library. -Functions here are not a part of the `` API but provide additional functionality people may find useful in general mathematics. \ No newline at end of file +The extension headers in this directory are intended to provide additional functionality to the CCMath library. +Functions here are not a part of the `` API but provide additional functionality people may find useful in +general mathematics. diff --git a/include/ccmath/internal/README.md b/include/ccmath/internal/README.md index 3e3ba444..3b3e0aa4 100644 --- a/include/ccmath/internal/README.md +++ b/include/ccmath/internal/README.md @@ -1,8 +1,12 @@ # CCMath Internal Headers Info + > [!CAUTION] -> This directory contains internal headers for the CCMath library. These headers are not intended for public use and are subject to change at any time. They are used for internal implementation details and are not guaranteed to be stable or to have a stable API. Assume anything included here directly could change its signature at any moment. +> This directory contains internal headers for the CCMath library. These headers are not intended for public use and are +> subject to change at any time. They are used for internal implementation details and are not guaranteed to be stable or +> to have a stable API. Assume anything included here directly could change its signature at any moment. ## Folders + - `config`: Predefined macros and configuration settings for the library. - `helpers`: Helper functions that are generally specific to a particular function. - `predef`: Predefined macro wrappers for compiler and platform-specific features. diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp index 8d0fadcc..5a7bf44d 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp @@ -28,41 +28,41 @@ namespace ccm::builtin { - // clang-format off - template - inline constexpr bool has_constexpr_fmax = -#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX - is_valid_builtin_type; -#else + // clang-format off + template + inline constexpr bool has_constexpr_fmax = + #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX + is_valid_builtin_type; + #else false; -#endif - // clang-format on + #endif + // clang-format on - /** - * Wrapper for constexpr __builtin fmax functions. - * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin fmax functions without triggering a compiler error - * when the compiler does not support them. - */ - template - constexpr auto fmax(T x, T y) - -> std::enable_if_t, T> - { - if constexpr (std::is_same_v) - { - return __builtin_fmaxf(x, y); - } - else if constexpr (std::is_same_v) - { - return __builtin_fmax(x, y); - } - else if constexpr (std::is_same_v) - { - return __builtin_fmaxl(x, y); - } - // This should never be reached - return T{}; - } + /** + * Wrapper for constexpr __builtin fmax functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin fmax functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto fmax(T x, T y) + -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_fmaxf(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fmax(x, y); + } + else if constexpr (std::is_same_v) + { + return __builtin_fmaxl(x, y); + } + // This should never be reached + return T{}; + } } // namespace ccm::builtin // Cleanup the global namespace diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp index 5cae35a4..646c9d22 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp @@ -31,7 +31,7 @@ namespace ccm::builtin // clang-format off template inline constexpr bool has_constexpr_fmod = -#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD + #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD is_valid_builtin_type; #else false; diff --git a/include/ccmath/internal/math/generic/builtins/basic/nan.hpp b/include/ccmath/internal/math/generic/builtins/basic/nan.hpp index a738c267..0c884950 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/nan.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/nan.hpp @@ -31,7 +31,7 @@ namespace ccm::builtin // clang-format off template inline constexpr bool has_constexpr_nan = -#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_NAN + #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_NAN is_valid_builtin_type; #else false; @@ -45,7 +45,7 @@ namespace ccm::builtin * when the compiler does not support them. */ template - constexpr auto nan(const char* tag) -> std::enable_if_t, T> + constexpr auto nan(const char * tag) -> std::enable_if_t, T> { if constexpr (std::is_same_v) { diff --git a/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp b/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp index c74632d8..73046d2b 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp @@ -28,40 +28,40 @@ namespace ccm::builtin { - // clang-format off - template - inline constexpr bool has_constexpr_remquo = -#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO - is_valid_builtin_type; -#else + // clang-format off + template + inline constexpr bool has_constexpr_remquo = + #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO + is_valid_builtin_type; + #else false; -#endif - // clang-format on + #endif + // clang-format on - /** - * Wrapper for constexpr __builtin remquo functions. - * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin remquo functions without triggering a compiler error - * when the compiler does not support them. - */ - template - constexpr auto remquo(T x, T y, int* quo) -> std::enable_if_t, T> - { - if constexpr (std::is_same_v) - { - return __builtin_remquof(x, y, quo); - } - else if constexpr (std::is_same_v) - { - return __builtin_remquo(x, y, quo); - } - else if constexpr (std::is_same_v) - { - return __builtin_remquol(x, y, quo); - } - // This should never be reached - return T{}; - } + /** + * Wrapper for constexpr __builtin remquo functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin remquo functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto remquo(T x, T y, int * quo) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_remquof(x, y, quo); + } + else if constexpr (std::is_same_v) + { + return __builtin_remquo(x, y, quo); + } + else if constexpr (std::is_same_v) + { + return __builtin_remquol(x, y, quo); + } + // This should never be reached + return T{}; + } } // namespace ccm::builtin // Cleanup the global namespace diff --git a/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp b/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp index 94694fdb..0ca8cf2d 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp @@ -26,13 +26,12 @@ #endif #endif -namespace ccm::builtin -{ +namespace ccm::builtin { // clang-format off - template + template inline constexpr bool has_constexpr_signbit = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT - is_valid_builtin_type; + is_valid_builtin_type; #else false; #endif @@ -44,19 +43,13 @@ namespace ccm::builtin * It exists only to allow for usage of __builtin signbit functions without triggering a compiler error * when the compiler does not support them. */ - template - constexpr auto signbit(T x) -> std::enable_if_t, bool> - { - if constexpr (std::is_same_v) - { + template + constexpr auto signbit(T x) -> std::enable_if_t, bool> { + if constexpr (std::is_same_v) { return __builtin_signbit(x); - } - else if constexpr (std::is_same_v) - { + } else if constexpr (std::is_same_v) { return __builtin_signbit(x); - } - else if constexpr (std::is_same_v) - { + } else if constexpr (std::is_same_v) { return __builtin_signbit(x); } // This should never be reached diff --git a/include/ccmath/internal/math/runtime/pp/CMakeLists.txt b/include/ccmath/internal/math/runtime/pp/CMakeLists.txt index 05e28766..69fdb447 100644 --- a/include/ccmath/internal/math/runtime/pp/CMakeLists.txt +++ b/include/ccmath/internal/math/runtime/pp/CMakeLists.txt @@ -1,3 +1,3 @@ ccm_add_headers( - simd.hpp + simd.hpp ) diff --git a/include/ccmath/internal/math/runtime/pp/simd.hpp b/include/ccmath/internal/math/runtime/pp/simd.hpp index 4e04c025..f07e9e1b 100644 --- a/include/ccmath/internal/math/runtime/pp/simd.hpp +++ b/include/ccmath/internal/math/runtime/pp/simd.hpp @@ -158,10 +158,10 @@ namespace ccm::pp #endif #else false; - #endif - #else - #if defined(__GCC_IEC_559) - __GCC_IEC_559 == 0; + #endif + #else + #if defined(__GCC_IEC_559) + __GCC_IEC_559 == 0; #elif defined(__FAST_MATH__) true; #else From dca6633cfcd9af295226b384b3df7ce27e811770 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 16:02:34 -0500 Subject: [PATCH 094/102] Bring in builtin detection for all builtins in gcc Signed-off-by: Ian --- include/ccmath/ext/ping_pong.hpp | 2 +- .../generic/builtins/basic/CMakeLists.txt | 2 +- .../builtins/basic/{abs.hpp => fabs.hpp} | 0 .../math/generic/builtins/basic/fdim.hpp | 4 +- .../math/generic/builtins/basic/fma.hpp | 4 +- .../math/generic/builtins/basic/fmax.hpp | 4 +- .../math/generic/builtins/basic/fmin.hpp | 4 +- .../math/generic/builtins/basic/fmod.hpp | 4 +- .../math/generic/builtins/basic/nan.hpp | 4 +- .../math/generic/builtins/basic/remainder.hpp | 4 +- .../math/generic/builtins/basic/remquo.hpp | 4 +- .../generic/builtins/compare/isfinite.hpp | 4 +- .../generic/builtins/compare/isgreater.hpp | 55 +++++++++++++++ .../builtins/compare/isgreaterequal.hpp | 55 +++++++++++++++ .../math/generic/builtins/compare/isinf.hpp | 4 +- .../math/generic/builtins/compare/isless.hpp | 55 +++++++++++++++ .../generic/builtins/compare/islessequal.hpp | 55 +++++++++++++++ .../builtins/compare/islessgreater.hpp | 55 +++++++++++++++ .../math/generic/builtins/compare/isnan.hpp | 4 +- .../generic/builtins/compare/isnormal.hpp | 4 +- .../generic/builtins/compare/isunordered.hpp | 4 +- .../math/generic/builtins/compare/signbit.hpp | 4 +- .../math/generic/builtins/expo/exp.hpp | 4 +- .../math/generic/builtins/expo/exp2.hpp | 4 +- .../math/generic/builtins/expo/expm1.hpp | 4 +- .../math/generic/builtins/expo/log.hpp | 4 +- .../math/generic/builtins/expo/log10.hpp | 4 +- .../math/generic/builtins/expo/log1p.hpp | 4 +- .../math/generic/builtins/expo/log2.hpp | 4 +- .../math/generic/builtins/fmanip/copysign.hpp | 4 +- .../math/generic/builtins/fmanip/frexp.hpp | 4 +- .../math/generic/builtins/fmanip/ilogb.hpp | 4 +- .../math/generic/builtins/fmanip/ldexp.hpp | 4 +- .../math/generic/builtins/fmanip/logb.hpp | 4 +- .../math/generic/builtins/fmanip/modf.hpp | 4 +- .../generic/builtins/fmanip/nextafter.hpp | 4 +- .../generic/builtins/fmanip/nexttoward.hpp | 4 +- .../math/generic/builtins/fmanip/scalbn.hpp | 4 +- .../math/generic/builtins/hyper/acosh.hpp | 4 +- .../math/generic/builtins/hyper/asinh.hpp | 4 +- .../math/generic/builtins/hyper/atanh.hpp | 4 +- .../math/generic/builtins/hyper/cosh.hpp | 4 +- .../math/generic/builtins/hyper/sinh.hpp | 4 +- .../math/generic/builtins/hyper/tanh.hpp | 4 +- .../math/generic/builtins/misc/CMakeLists.txt | 2 +- .../{nearest/rint.hpp => misc/erf.hpp} | 32 ++++----- .../builtins/misc/{lgamma.hpp => erfc.hpp} | 34 +++++----- .../builtins/misc/{gamma.hpp => tgamma.hpp} | 4 +- .../generic/builtins/nearest/CMakeLists.txt | 1 - .../math/generic/builtins/nearest/ceil.hpp | 4 +- .../math/generic/builtins/nearest/floor.hpp | 4 +- .../generic/builtins/nearest/nearbyint.hpp | 68 ------------------- .../math/generic/builtins/nearest/round.hpp | 64 ++++++++++++++--- .../math/generic/builtins/nearest/trunc.hpp | 4 +- .../math/generic/builtins/power/cbrt.hpp | 4 +- .../math/generic/builtins/power/hypot.hpp | 4 +- .../math/generic/builtins/power/pow.hpp | 4 +- .../math/generic/builtins/power/sqrt.hpp | 4 +- .../math/generic/builtins/trig/acos.hpp | 4 +- .../math/generic/builtins/trig/asin.hpp | 4 +- .../math/generic/builtins/trig/atan.hpp | 4 +- .../math/generic/builtins/trig/atan2.hpp | 4 +- .../math/generic/builtins/trig/cos.hpp | 4 +- .../math/generic/builtins/trig/sin.hpp | 4 +- .../math/generic/builtins/trig/tan.hpp | 2 +- .../math/generic/func/expo/exp2_gen.hpp | 2 +- .../math/generic/func/expo/exp_gen.hpp | 2 +- .../math/generic/func/expo/log2_gen.hpp | 2 +- .../math/generic/func/expo/log_gen.hpp | 2 +- .../math/generic/func/fmanip/copysign_gen.hpp | 2 +- include/ccmath/math/basic.hpp | 2 +- include/ccmath/math/basic/CMakeLists.txt | 2 +- .../ccmath/math/basic/{abs.hpp => fabs.hpp} | 2 +- .../math/basic/impl/remquo_double_impl.hpp | 2 +- .../math/basic/impl/remquo_float_impl.hpp | 2 +- .../math/basic/impl/remquo_ldouble_impl.hpp | 2 +- include/ccmath/math/compare/fpclassify.hpp | 2 +- include/ccmath/math/compare/isnormal.hpp | 2 +- include/ccmath/math/fmanip/copysign.hpp | 2 +- test/basic/abs_test.cpp | 2 +- 80 files changed, 482 insertions(+), 230 deletions(-) rename include/ccmath/internal/math/generic/builtins/basic/{abs.hpp => fabs.hpp} (100%) create mode 100644 include/ccmath/internal/math/generic/builtins/compare/isgreater.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/isgreaterequal.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/isless.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/islessequal.hpp create mode 100644 include/ccmath/internal/math/generic/builtins/compare/islessgreater.hpp rename include/ccmath/internal/math/generic/builtins/{nearest/rint.hpp => misc/erf.hpp} (59%) rename include/ccmath/internal/math/generic/builtins/misc/{lgamma.hpp => erfc.hpp} (57%) rename include/ccmath/internal/math/generic/builtins/misc/{gamma.hpp => tgamma.hpp} (95%) delete mode 100644 include/ccmath/internal/math/generic/builtins/nearest/nearbyint.hpp rename include/ccmath/math/basic/{abs.hpp => fabs.hpp} (98%) diff --git a/include/ccmath/ext/ping_pong.hpp b/include/ccmath/ext/ping_pong.hpp index 065e75bc..d765e314 100644 --- a/include/ccmath/ext/ping_pong.hpp +++ b/include/ccmath/ext/ping_pong.hpp @@ -11,7 +11,7 @@ #pragma once #include "ccmath/ext/fract.hpp" -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include diff --git a/include/ccmath/internal/math/generic/builtins/basic/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/basic/CMakeLists.txt index 07caa0c3..4bb96d59 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/builtins/basic/CMakeLists.txt @@ -1,5 +1,5 @@ ccm_add_headers( - abs.hpp + fabs.hpp fdim.hpp fma.hpp fmod.hpp diff --git a/include/ccmath/internal/math/generic/builtins/basic/abs.hpp b/include/ccmath/internal/math/generic/builtins/basic/fabs.hpp similarity index 100% rename from include/ccmath/internal/math/generic/builtins/basic/abs.hpp rename to include/ccmath/internal/math/generic/builtins/basic/fabs.hpp diff --git a/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp b/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp index 0c598dd4..4a909044 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for fdim that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/basic/fma.hpp b/include/ccmath/internal/math/generic/builtins/basic/fma.hpp index 234d08fc..5f57916f 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fma.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fma.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin_copysign that allows static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMA -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMA #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp index 5a7bf44d..ce3eb408 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for fmax that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp index f8f01510..e5dda18c 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for fmin that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp index 646c9d22..cc0e5637 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for fmod that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 12.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 12 || (__GNUC__ == 12 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/basic/nan.hpp b/include/ccmath/internal/math/generic/builtins/basic/nan.hpp index 0c884950..6ecb749a 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/nan.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/nan.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for nan that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NAN -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_NAN #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp b/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp index 9324fe5f..d98d4e99 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for remainder that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp b/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp index 73046d2b..36038c5d 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for remquo that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 7.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp b/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp index a69b835b..03e14c6f 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for isfinite that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/compare/isgreater.hpp b/include/ccmath/internal/math/generic/builtins/compare/isgreater.hpp new file mode 100644 index 00000000..37688eae --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/isgreater.hpp @@ -0,0 +1,55 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATER +/// This is a macro that is defined if the compiler has constexpr __builtin_isgreater that allows static_assert +/// +/// Compilers with Support: +/// - GCC 5.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATER +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATER +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_isgreater = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATER + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin_isgreater. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_isgreater without triggering a compiler error + * when the compiler does not support it. + */ + template + constexpr auto isgreater(T x, T y) -> std::enable_if_t, bool> + { + return __builtin_isgreater(x, y); + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATER diff --git a/include/ccmath/internal/math/generic/builtins/compare/isgreaterequal.hpp b/include/ccmath/internal/math/generic/builtins/compare/isgreaterequal.hpp new file mode 100644 index 00000000..4c6df87e --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/isgreaterequal.hpp @@ -0,0 +1,55 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATEREQUAL +/// This is a macro that is defined if the compiler has constexpr __builtin_isgreaterequal that allows static_assert +/// +/// Compilers with Support: +/// - GCC 5.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATEREQUAL +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATEREQUAL +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_isgreaterequal = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATEREQUAL + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin_isgreaterequal. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_isgreaterequal without triggering a compiler error + * when the compiler does not support it. + */ + template + constexpr auto isgreaterequal(T x, T y) -> std::enable_if_t, bool> + { + return __builtin_isgreaterequal(x, y); + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISGREATEREQUAL diff --git a/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp b/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp index 157ab3d8..b08eb72c 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for isinf that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/compare/isless.hpp b/include/ccmath/internal/math/generic/builtins/compare/isless.hpp new file mode 100644 index 00000000..7e4352a6 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/isless.hpp @@ -0,0 +1,55 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESS +/// This is a macro that is defined if the compiler has constexpr __builtin_isless that allows static_assert +/// +/// Compilers with Support: +/// - GCC 5.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESS +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESS +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_isless = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESS + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin_isless. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_isless without triggering a compiler error + * when the compiler does not support it. + */ + template + constexpr auto isless(T x, T y) -> std::enable_if_t, bool> + { + return __builtin_isless(x, y); + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESS diff --git a/include/ccmath/internal/math/generic/builtins/compare/islessequal.hpp b/include/ccmath/internal/math/generic/builtins/compare/islessequal.hpp new file mode 100644 index 00000000..24a0ab7f --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/islessequal.hpp @@ -0,0 +1,55 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSEQUAL +/// This is a macro that is defined if the compiler has constexpr __builtin_islessequal that allows static_assert +/// +/// Compilers with Support: +/// - GCC 5.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSEQUAL +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSEQUAL +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_islessequal = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSEQUAL + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin_islessequal. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_islessequal without triggering a compiler error + * when the compiler does not support it. + */ + template + constexpr auto islessequal(T x, T y) -> std::enable_if_t, bool> + { + return __builtin_islessequal(x, y); + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSEQUAL diff --git a/include/ccmath/internal/math/generic/builtins/compare/islessgreater.hpp b/include/ccmath/internal/math/generic/builtins/compare/islessgreater.hpp new file mode 100644 index 00000000..7ed01298 --- /dev/null +++ b/include/ccmath/internal/math/generic/builtins/compare/islessgreater.hpp @@ -0,0 +1,55 @@ +/* +* Copyright (c) Ian Pike + * Copyright (c) CCMath contributors + * + * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. + * See LICENSE for more information. + * + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#pragma once + +#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" + +#include + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSGREATER +/// This is a macro that is defined if the compiler has constexpr __builtin_islessgreater that allows static_assert +/// +/// Compilers with Support: +/// - GCC 5.1+ + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSGREATER +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSGREATER +#endif +#endif + +namespace ccm::builtin +{ + // clang-format off + template + inline constexpr bool has_constexpr_islessgreater = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSGREATER + is_valid_builtin_type; + #else + false; + #endif + // clang-format on + + /** + * Wrapper for constexpr __builtin_islessgreater. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_islessgreater without triggering a compiler error + * when the compiler does not support it. + */ + template + constexpr auto islessgreater(T x, T y) -> std::enable_if_t, bool> + { + return __builtin_islessgreater(x, y); + } +} // namespace ccm::builtin + +// Cleanup the global namespace +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ISLESSGREATER diff --git a/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp b/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp index 86b6e4be..ab1222d4 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for isnan that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp b/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp index a80378c1..b7c40dda 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for isnormal that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp b/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp index 00c672af..6585390f 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for isunordered that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp b/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp index 0ca8cf2d..9f990142 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for signbit that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/expo/exp.hpp b/include/ccmath/internal/math/generic/builtins/expo/exp.hpp index a8df84b9..c12493f4 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/exp.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/exp.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for exp that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_EXP #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp b/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp index 3b16e662..1aa7b97b 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for exp2 that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp b/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp index aabb520d..72e08e70 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for expm1 that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/expo/log.hpp b/include/ccmath/internal/math/generic/builtins/expo/log.hpp index b5bff3a3..eb29acd8 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/log.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/log.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for log that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/expo/log10.hpp b/include/ccmath/internal/math/generic/builtins/expo/log10.hpp index 7b8a4d37..efd03077 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/log10.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/log10.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for log10 that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp b/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp index 97cecfe4..ae7b9814 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for log1p that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/expo/log2.hpp b/include/ccmath/internal/math/generic/builtins/expo/log2.hpp index c6075af8..84d43566 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/log2.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/log2.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for log2 that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp index f924765e..753f8d7c 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for copysign that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp index dae1818d..823778ec 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for frexp that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 7.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp index 8f5c3c9a..2dc81bbf 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for ilogb that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp index 8c1c1102..fffc4bbb 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for ldexp that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp index be2c46a7..6edea011 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for logb that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp index 8216c9de..79ffad38 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for modf that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 7.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_MODF -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_MODF #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp index c0810880..bae8e9c0 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for nextafter that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 9.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 9 || (__GNUC__ == 9 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp index 2b7575db..93c3419a 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for nexttoward that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 9.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 9 || (__GNUC__ == 9 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp index a7a53f68..fdb2ee46 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for scalbn that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp index fac5ca2d..83242d57 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for acosh that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp index fb438bdd..bdf24250 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for asinh that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp index 802d104e..b710d6c7 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for atanh that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp index 186e406a..6d45e048 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for cosh that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COSH -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_COSH #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp index 86c76479..17a9c292 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for sinh that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SINH -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_SINH #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp index bb6c69ba..863b2e6e 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for tanh that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_TANH -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_TANH #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt index a702e582..c1e9d82e 100644 --- a/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt @@ -1,4 +1,4 @@ ccm_add_headers( - gamma.hpp + tgamma.hpp lgamma.hpp ) diff --git a/include/ccmath/internal/math/generic/builtins/nearest/rint.hpp b/include/ccmath/internal/math/generic/builtins/misc/erf.hpp similarity index 59% rename from include/ccmath/internal/math/generic/builtins/nearest/rint.hpp rename to include/ccmath/internal/math/generic/builtins/misc/erf.hpp index 36c92063..a9e6366b 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/rint.hpp +++ b/include/ccmath/internal/math/generic/builtins/misc/erf.hpp @@ -14,15 +14,15 @@ #include -/// CCMATH_HAS_CONSTEXPR_BUILTIN_RINT -/// This is a macro that is defined if the compiler has constexpr __builtin functions for rint that allow static_assert +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ERF +/// This is a macro that is defined if the compiler has constexpr __builtin_erf that allows static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ -#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_RINT -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_RINT +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ERF +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ERF #endif #endif @@ -30,8 +30,8 @@ namespace ccm::builtin { // clang-format off template - inline constexpr bool has_constexpr_rint = -#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_RINT + inline constexpr bool has_constexpr_erf = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ERF is_valid_builtin_type; #else false; @@ -39,25 +39,25 @@ namespace ccm::builtin // clang-format on /** - * Wrapper for constexpr __builtin rint functions. + * Wrapper for constexpr __builtin_erf functions. * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin rint functions without triggering a compiler error - * when the compiler does not support them. + * It exists only to allow for usage of __builtin_erf without triggering a compiler error + * when the compiler does not support it. */ template - constexpr auto rint(T x) -> std::enable_if_t, T> + constexpr auto erf(T x) -> std::enable_if_t, T> { if constexpr (std::is_same_v) { - return __builtin_rintf(x); + return __builtin_erff(x); } else if constexpr (std::is_same_v) { - return __builtin_rint(x); + return __builtin_erf(x); } else if constexpr (std::is_same_v) { - return __builtin_rintl(x); + return __builtin_erfl(x); } // This should never be reached return T{}; @@ -65,4 +65,4 @@ namespace ccm::builtin } // namespace ccm::builtin // Cleanup the global namespace -#undef CCMATH_HAS_CONSTEXPR_BUILTIN_RINT +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ERF diff --git a/include/ccmath/internal/math/generic/builtins/misc/lgamma.hpp b/include/ccmath/internal/math/generic/builtins/misc/erfc.hpp similarity index 57% rename from include/ccmath/internal/math/generic/builtins/misc/lgamma.hpp rename to include/ccmath/internal/math/generic/builtins/misc/erfc.hpp index 5b4a908f..df191d8c 100644 --- a/include/ccmath/internal/math/generic/builtins/misc/lgamma.hpp +++ b/include/ccmath/internal/math/generic/builtins/misc/erfc.hpp @@ -1,5 +1,5 @@ /* -* Copyright (c) Ian Pike + * Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -14,15 +14,15 @@ #include -/// CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA -/// This is a macro that is defined if the compiler has constexpr __builtin functions for lgamma that allow static_assert +/// CCMATH_HAS_CONSTEXPR_BUILTIN_ERFC +/// This is a macro that is defined if the compiler has constexpr __builtin_erfc that allows static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ -#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ERFC +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_ERFC #endif #endif @@ -30,8 +30,8 @@ namespace ccm::builtin { // clang-format off template - inline constexpr bool has_constexpr_lgamma = -#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA + inline constexpr bool has_constexpr_erfc = +#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ERFC is_valid_builtin_type; #else false; @@ -39,25 +39,25 @@ namespace ccm::builtin // clang-format on /** - * Wrapper for constexpr __builtin lgamma functions. + * Wrapper for constexpr __builtin_erfc functions. * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin lgamma functions without triggering a compiler error - * when the compiler does not support them. + * It exists only to allow for usage of __builtin_erfc without triggering a compiler error + * when the compiler does not support it. */ template - constexpr auto lgamma(T x) -> std::enable_if_t, T> + constexpr auto erfc(T x) -> std::enable_if_t, T> { if constexpr (std::is_same_v) { - return __builtin_lgammaf(x); + return __builtin_erfcf(x); } else if constexpr (std::is_same_v) { - return __builtin_lgamma(x); + return __builtin_erfc(x); } else if constexpr (std::is_same_v) { - return __builtin_lgammal(x); + return __builtin_erfcl(x); } // This should never be reached return T{}; @@ -65,4 +65,4 @@ namespace ccm::builtin } // namespace ccm::builtin // Cleanup the global namespace -#undef CCMATH_HAS_CONSTEXPR_BUILTIN_LGAMMA +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_ERFC diff --git a/include/ccmath/internal/math/generic/builtins/misc/gamma.hpp b/include/ccmath/internal/math/generic/builtins/misc/tgamma.hpp similarity index 95% rename from include/ccmath/internal/math/generic/builtins/misc/gamma.hpp rename to include/ccmath/internal/math/generic/builtins/misc/tgamma.hpp index f98c5fa9..8e3631c0 100644 --- a/include/ccmath/internal/math/generic/builtins/misc/gamma.hpp +++ b/include/ccmath/internal/math/generic/builtins/misc/tgamma.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for gamma that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt index 60727f1d..f025a720 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt @@ -2,7 +2,6 @@ ccm_add_headers( ceil.hpp floor.hpp nearbyint.hpp - rint.hpp round.hpp trunc.hpp ) diff --git a/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp b/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp index 8bfa4bb6..b6342750 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp +++ b/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for ceil that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp b/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp index 6bfb0214..b928a4a4 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp +++ b/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for floor that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/nearest/nearbyint.hpp b/include/ccmath/internal/math/generic/builtins/nearest/nearbyint.hpp deleted file mode 100644 index 2e6436a3..00000000 --- a/include/ccmath/internal/math/generic/builtins/nearest/nearbyint.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) Ian Pike - * Copyright (c) CCMath contributors - * - * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. - * See LICENSE for more information. - * - * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - */ - -#pragma once - -#include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" - -#include - -/// CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT -/// This is a macro that is defined if the compiler has constexpr __builtin functions for nearbyint that allow static_assert -/// -/// Compilers with Support: -/// - GCC 6.1+ - -#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT -#endif -#endif - -namespace ccm::builtin -{ - // clang-format off - template - inline constexpr bool has_constexpr_nearbyint = -#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT - is_valid_builtin_type; -#else - false; -#endif - // clang-format on - - /** - * Wrapper for constexpr __builtin nearbyint functions. - * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin nearbyint functions without triggering a compiler error - * when the compiler does not support them. - */ - template - constexpr auto nearbyint(T x) -> std::enable_if_t, T> - { - if constexpr (std::is_same_v) - { - return __builtin_nearbyintf(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_nearbyint(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_nearbyintl(x); - } - // This should never be reached - return T{}; - } -} // namespace ccm::builtin - -// Cleanup the global namespace -#undef CCMATH_HAS_CONSTEXPR_BUILTIN_NEARBYINT diff --git a/include/ccmath/internal/math/generic/builtins/nearest/round.hpp b/include/ccmath/internal/math/generic/builtins/nearest/round.hpp index c8ca4e88..035fe007 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/round.hpp +++ b/include/ccmath/internal/math/generic/builtins/nearest/round.hpp @@ -1,5 +1,5 @@ /* -* Copyright (c) Ian Pike + * Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -18,30 +18,50 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for round that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ + +/// CCMATH_HAS_CONSTEXPR_BUILTIN_LROUND +/// This is a macro that is defined if the compiler has constexpr __builtin functions for lround that allow static_assert +/// +/// Compilers with Support: +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND #endif #endif +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LROUND +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#define CCMATH_HAS_CONSTEXPR_BUILTIN_LROUND +#endif +#endif + namespace ccm::builtin { // clang-format off template inline constexpr bool has_constexpr_round = -#ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND - is_valid_builtin_type; - #else + #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND + is_valid_builtin_type; + #else + false; + #endif + + template + inline constexpr bool has_constexpr_lround = + #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LROUND + is_valid_builtin_type; + #else false; - #endif + #endif // clang-format on /** - * Wrapper for constexpr __builtin round functions. + * Wrapper for constexpr __builtin_round functions. * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin round functions without triggering a compiler error + * It exists only to allow for usage of __builtin_round functions without triggering a compiler error * when the compiler does not support them. */ template @@ -62,7 +82,33 @@ namespace ccm::builtin // This should never be reached return T{}; } + + /** + * Wrapper for constexpr __builtin_lround functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_lround functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto lround(T x) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_lroundf(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_lround(x); + } + else if constexpr (std::is_same_v) + { + return __builtin_lroundl(x); + } + // This should never be reached + return T{}; + } } // namespace ccm::builtin // Cleanup the global namespace #undef CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND +#undef CCMATH_HAS_CONSTEXPR_BUILTIN_LROUND diff --git a/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp b/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp index 2062c250..6136577b 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp +++ b/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for trunc that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp b/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp index a9a2485b..d18e760b 100644 --- a/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp +++ b/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for cbrt that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/power/hypot.hpp b/include/ccmath/internal/math/generic/builtins/power/hypot.hpp index 8560bf68..57e424a9 100644 --- a/include/ccmath/internal/math/generic/builtins/power/hypot.hpp +++ b/include/ccmath/internal/math/generic/builtins/power/hypot.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for hypot that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/power/pow.hpp b/include/ccmath/internal/math/generic/builtins/power/pow.hpp index 121a7b13..c1ad4c6e 100644 --- a/include/ccmath/internal/math/generic/builtins/power/pow.hpp +++ b/include/ccmath/internal/math/generic/builtins/power/pow.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for pow that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_POW -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_POW #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp b/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp index c8ee8c0f..41bf704a 100644 --- a/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp +++ b/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for sqrt that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/trig/acos.hpp b/include/ccmath/internal/math/generic/builtins/trig/acos.hpp index 3fdeda7f..6a8ad9ce 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/acos.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/acos.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for acos that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/trig/asin.hpp b/include/ccmath/internal/math/generic/builtins/trig/asin.hpp index 0e2ca719..1f336d47 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/asin.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/asin.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for asin that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/trig/atan.hpp b/include/ccmath/internal/math/generic/builtins/trig/atan.hpp index 62ee9275..c8cf0066 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/atan.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/atan.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for atan that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp b/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp index 64288faf..e97fa418 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for atan2 that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/trig/cos.hpp b/include/ccmath/internal/math/generic/builtins/trig/cos.hpp index d1beaa32..5d1bfe26 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/cos.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/cos.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for cos that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COS -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_COS #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/trig/sin.hpp b/include/ccmath/internal/math/generic/builtins/trig/sin.hpp index 34049c9d..ccf12bc4 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/sin.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/sin.hpp @@ -18,10 +18,10 @@ /// This is a macro that is defined if the compiler has constexpr __builtin functions for sin that allow static_assert /// /// Compilers with Support: -/// - GCC 6.1+ +/// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SIN -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_SIN #endif #endif diff --git a/include/ccmath/internal/math/generic/builtins/trig/tan.hpp b/include/ccmath/internal/math/generic/builtins/trig/tan.hpp index 2709fab4..8dfe4a2a 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/tan.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/tan.hpp @@ -21,7 +21,7 @@ /// - GCC 6.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_TAN -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) +#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_TAN #endif #endif diff --git a/include/ccmath/internal/math/generic/func/expo/exp2_gen.hpp b/include/ccmath/internal/math/generic/func/expo/exp2_gen.hpp index f418931a..ed9c1b9a 100644 --- a/include/ccmath/internal/math/generic/func/expo/exp2_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/exp2_gen.hpp @@ -16,7 +16,7 @@ #include "ccmath/internal/support/fp/fp_bits.hpp" #include "ccmath/internal/support/unreachable.hpp" #include "ccmath/internal/types/big_int.hpp" -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isnan.hpp" #include "ccmath/math/power/sqrt.hpp" diff --git a/include/ccmath/internal/math/generic/func/expo/exp_gen.hpp b/include/ccmath/internal/math/generic/func/expo/exp_gen.hpp index aca46c60..dfa8edc0 100644 --- a/include/ccmath/internal/math/generic/func/expo/exp_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/exp_gen.hpp @@ -16,7 +16,7 @@ #include "ccmath/internal/support/fp/fp_bits.hpp" #include "ccmath/internal/support/unreachable.hpp" #include "ccmath/internal/types/big_int.hpp" -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isnan.hpp" #include "ccmath/math/power/sqrt.hpp" diff --git a/include/ccmath/internal/math/generic/func/expo/log2_gen.hpp b/include/ccmath/internal/math/generic/func/expo/log2_gen.hpp index fa788cb1..a13b0f1a 100644 --- a/include/ccmath/internal/math/generic/func/expo/log2_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/log2_gen.hpp @@ -16,7 +16,7 @@ #include "ccmath/internal/support/fp/fp_bits.hpp" #include "ccmath/internal/support/unreachable.hpp" #include "ccmath/internal/types/big_int.hpp" -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isnan.hpp" #include "ccmath/math/power/sqrt.hpp" diff --git a/include/ccmath/internal/math/generic/func/expo/log_gen.hpp b/include/ccmath/internal/math/generic/func/expo/log_gen.hpp index b4f2f449..e3c47699 100644 --- a/include/ccmath/internal/math/generic/func/expo/log_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/log_gen.hpp @@ -16,7 +16,7 @@ #include "ccmath/internal/support/fp/fp_bits.hpp" #include "ccmath/internal/support/unreachable.hpp" #include "ccmath/internal/types/big_int.hpp" -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isnan.hpp" #include "ccmath/math/power/sqrt.hpp" diff --git a/include/ccmath/internal/math/generic/func/fmanip/copysign_gen.hpp b/include/ccmath/internal/math/generic/func/fmanip/copysign_gen.hpp index 34cb02d7..fc936514 100644 --- a/include/ccmath/internal/math/generic/func/fmanip/copysign_gen.hpp +++ b/include/ccmath/internal/math/generic/func/fmanip/copysign_gen.hpp @@ -10,7 +10,7 @@ #pragma once -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isnan.hpp" #include "ccmath/math/compare/signbit.hpp" diff --git a/include/ccmath/math/basic.hpp b/include/ccmath/math/basic.hpp index 59f8c7d4..2bf10466 100644 --- a/include/ccmath/math/basic.hpp +++ b/include/ccmath/math/basic.hpp @@ -10,7 +10,7 @@ #pragma once -#include "basic/abs.hpp" +#include "basic/fabs.hpp" #include "basic/fdim.hpp" #include "basic/fma.hpp" #include "basic/fmod.hpp" diff --git a/include/ccmath/math/basic/CMakeLists.txt b/include/ccmath/math/basic/CMakeLists.txt index cb39fdc3..decb5f52 100644 --- a/include/ccmath/math/basic/CMakeLists.txt +++ b/include/ccmath/math/basic/CMakeLists.txt @@ -1,5 +1,5 @@ ccm_add_headers( - abs.hpp + fabs.hpp fdim.hpp fma.hpp fmod.hpp diff --git a/include/ccmath/math/basic/abs.hpp b/include/ccmath/math/basic/fabs.hpp similarity index 98% rename from include/ccmath/math/basic/abs.hpp rename to include/ccmath/math/basic/fabs.hpp index ad9d892e..61b02924 100644 --- a/include/ccmath/math/basic/abs.hpp +++ b/include/ccmath/math/basic/fabs.hpp @@ -11,7 +11,7 @@ #pragma once #include "ccmath/internal/predef/unlikely.hpp" -#include "ccmath/internal/math/generic/builtins/basic/abs.hpp" +#include "ccmath/internal/math/generic/builtins/basic/fabs.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" #include diff --git a/include/ccmath/math/basic/impl/remquo_double_impl.hpp b/include/ccmath/math/basic/impl/remquo_double_impl.hpp index 37c8397c..9d0bbf4f 100644 --- a/include/ccmath/math/basic/impl/remquo_double_impl.hpp +++ b/include/ccmath/math/basic/impl/remquo_double_impl.hpp @@ -14,7 +14,7 @@ #include "ccmath/internal/predef/compiler_suppression/gcc_compiler_suppression.hpp" #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/basic/fmod.hpp" #include diff --git a/include/ccmath/math/basic/impl/remquo_float_impl.hpp b/include/ccmath/math/basic/impl/remquo_float_impl.hpp index f30034e7..352ce521 100644 --- a/include/ccmath/math/basic/impl/remquo_float_impl.hpp +++ b/include/ccmath/math/basic/impl/remquo_float_impl.hpp @@ -15,7 +15,7 @@ #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/basic/fmod.hpp" namespace ccm::internal diff --git a/include/ccmath/math/basic/impl/remquo_ldouble_impl.hpp b/include/ccmath/math/basic/impl/remquo_ldouble_impl.hpp index 930bd90a..56818b8a 100644 --- a/include/ccmath/math/basic/impl/remquo_ldouble_impl.hpp +++ b/include/ccmath/math/basic/impl/remquo_ldouble_impl.hpp @@ -15,7 +15,7 @@ #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/basic/fmod.hpp" namespace ccm::internal diff --git a/include/ccmath/math/compare/fpclassify.hpp b/include/ccmath/math/compare/fpclassify.hpp index 85f8f4f3..0303c657 100644 --- a/include/ccmath/math/compare/fpclassify.hpp +++ b/include/ccmath/math/compare/fpclassify.hpp @@ -11,7 +11,7 @@ #pragma once #include "ccmath/internal/support/helpers/fpclassify_helper.hpp" -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isinf.hpp" #include "ccmath/math/compare/isnan.hpp" diff --git a/include/ccmath/math/compare/isnormal.hpp b/include/ccmath/math/compare/isnormal.hpp index 1c8f66bf..b69b0516 100644 --- a/include/ccmath/math/compare/isnormal.hpp +++ b/include/ccmath/math/compare/isnormal.hpp @@ -10,7 +10,7 @@ #pragma once -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isinf.hpp" #include "ccmath/math/compare/isnan.hpp" diff --git a/include/ccmath/math/fmanip/copysign.hpp b/include/ccmath/math/fmanip/copysign.hpp index e969535e..eab72e91 100644 --- a/include/ccmath/math/fmanip/copysign.hpp +++ b/include/ccmath/math/fmanip/copysign.hpp @@ -10,7 +10,7 @@ #pragma once -#include "ccmath/math/basic/abs.hpp" +#include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isnan.hpp" #include "ccmath/math/compare/signbit.hpp" diff --git a/test/basic/abs_test.cpp b/test/basic/abs_test.cpp index eb24afd9..119e2bc7 100644 --- a/test/basic/abs_test.cpp +++ b/test/basic/abs_test.cpp @@ -9,7 +9,7 @@ */ #include -#include +#include #include #include From 9f1943bfdb1cc21863e708d294c2d2c15611ba51 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 16:11:21 -0500 Subject: [PATCH 095/102] Clean up missing headers in cmake Signed-off-by: Ian --- .../internal/math/generic/builtins/compare/CMakeLists.txt | 5 +++++ .../internal/math/generic/builtins/misc/CMakeLists.txt | 3 ++- .../internal/math/generic/builtins/nearest/CMakeLists.txt | 1 - 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/ccmath/internal/math/generic/builtins/compare/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/compare/CMakeLists.txt index 27dda1e7..feb43803 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/builtins/compare/CMakeLists.txt @@ -1,6 +1,11 @@ ccm_add_headers( isfinite.hpp + isgreater.hpp + isgreaterequal.hpp isinf.hpp + isless.hpp + islessequal.hpp + islessgreater.hpp isnan.hpp isnormal.hpp isunordered.hpp diff --git a/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt index c1e9d82e..1ce6b5ac 100644 --- a/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/builtins/misc/CMakeLists.txt @@ -1,4 +1,5 @@ ccm_add_headers( + erf.hpp + erfc.hpp tgamma.hpp - lgamma.hpp ) diff --git a/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt b/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt index f025a720..8c30a0f7 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt +++ b/include/ccmath/internal/math/generic/builtins/nearest/CMakeLists.txt @@ -1,7 +1,6 @@ ccm_add_headers( ceil.hpp floor.hpp - nearbyint.hpp round.hpp trunc.hpp ) From 2983062953988c8b43b2878e280e9fbb5ffc0567 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 16:44:45 -0500 Subject: [PATCH 096/102] Bring in new builtin detection system into front face code base Signed-off-by: Ian --- .../math/generic/builtins/fmanip/scalbn.hpp | 29 ++++++- include/ccmath/math/compare/isfinite.hpp | 12 ++- include/ccmath/math/compare/isgreater.hpp | 9 ++- .../ccmath/math/compare/isgreaterequal.hpp | 8 +- include/ccmath/math/compare/isinf.hpp | 16 ++-- include/ccmath/math/compare/isless.hpp | 8 +- include/ccmath/math/compare/islessequal.hpp | 8 +- include/ccmath/math/compare/islessgreater.hpp | 8 +- include/ccmath/math/compare/isnan.hpp | 18 +++-- include/ccmath/math/compare/isnormal.hpp | 8 +- include/ccmath/math/compare/isunordered.hpp | 9 ++- include/ccmath/math/expo/exp.hpp | 21 +++-- include/ccmath/math/expo/exp2.hpp | 21 +++-- include/ccmath/math/expo/expm1.hpp | 21 +++-- include/ccmath/math/expo/log.hpp | 43 +++++------ include/ccmath/math/expo/log10.hpp | 21 +++-- include/ccmath/math/expo/log1p.hpp | 21 +++-- include/ccmath/math/expo/log2.hpp | 58 +++++++------- include/ccmath/math/fmanip/copysign.hpp | 19 +++-- include/ccmath/math/fmanip/frexp.hpp | 30 +++++--- include/ccmath/math/fmanip/ldexp.hpp | 77 +------------------ include/ccmath/math/fmanip/modf.hpp | 11 ++- include/ccmath/math/fmanip/nextafter.hpp | 10 ++- include/ccmath/math/fmanip/nexttoward.hpp | 6 +- include/ccmath/math/fmanip/scalbn.hpp | 40 +++++----- include/ccmath/math/nearest/floor.hpp | 21 +++-- include/ccmath/math/nearest/trunc.hpp | 42 +++++----- include/ccmath/math/power/pow.hpp | 12 ++- include/ccmath/math/power/sqrt.hpp | 25 +++--- 29 files changed, 341 insertions(+), 291 deletions(-) diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp index fdb2ee46..652f4507 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp @@ -39,9 +39,9 @@ namespace ccm::builtin // clang-format on /** - * Wrapper for constexpr __builtin scalbn functions. + * Wrapper for constexpr __builtin_scalbn functions. * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin scalbn functions without triggering a compiler error + * It exists only to allow for usage of __builtin_scalbn functions without triggering a compiler error * when the compiler does not support them. */ template @@ -62,6 +62,31 @@ namespace ccm::builtin // This should never be reached return T{}; } + + /** + * Wrapper for constexpr __builtin_scalbn functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_scalbn functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto scalbn(T x, long exp) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) + { + return __builtin_scalblnf(x, exp); + } + else if constexpr (std::is_same_v) + { + return __builtin_scalbln(x, exp); + } + else if constexpr (std::is_same_v) + { + return __builtin_scalblnl(x, exp); + } + // This should never be reached + return T{}; + } } // namespace ccm::builtin // Cleanup the global namespace diff --git a/include/ccmath/math/compare/isfinite.hpp b/include/ccmath/math/compare/isfinite.hpp index 960e8215..0c18055b 100644 --- a/include/ccmath/math/compare/isfinite.hpp +++ b/include/ccmath/math/compare/isfinite.hpp @@ -11,6 +11,8 @@ #pragma once #include "ccmath/internal/support/fp/fp_bits.hpp" +#include "ccmath/internal/math/generic/builtins/compare/isfinite.hpp" + namespace ccm { @@ -23,9 +25,13 @@ namespace ccm template , bool> = true> constexpr bool isfinite(T num) { - using FPBits_t = typename ccm::support::fp::FPBits; - const FPBits_t num_bits(num); - return num_bits.is_finite(); + if constexpr (ccm::builtin::has_constexpr_isfinite) { return ccm::builtin::isfinite(num); } + else + { + using FPBits_t = typename ccm::support::fp::FPBits; + const FPBits_t num_bits(num); + return num_bits.is_finite(); + } } /** diff --git a/include/ccmath/math/compare/isgreater.hpp b/include/ccmath/math/compare/isgreater.hpp index 4d24af7e..103fd278 100644 --- a/include/ccmath/math/compare/isgreater.hpp +++ b/include/ccmath/math/compare/isgreater.hpp @@ -12,6 +12,9 @@ #include +#include "ccmath/internal/math/generic/builtins/compare/isgreater.hpp" + + namespace ccm { /** @@ -24,7 +27,11 @@ namespace ccm template constexpr bool isgreater(T x, T y) noexcept { - return x > y; + if constexpr (ccm::builtin::has_constexpr_isgreater) { return ccm::builtin::isgreater(x, y); } + else + { + return x > y; + } } /** diff --git a/include/ccmath/math/compare/isgreaterequal.hpp b/include/ccmath/math/compare/isgreaterequal.hpp index 2187a13b..3c2aa2ab 100644 --- a/include/ccmath/math/compare/isgreaterequal.hpp +++ b/include/ccmath/math/compare/isgreaterequal.hpp @@ -10,6 +10,8 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/compare/isgreaterequal.hpp" + #include namespace ccm @@ -24,7 +26,11 @@ namespace ccm template constexpr bool isgreaterequal(T x, T y) noexcept { - return x >= y; + if constexpr (ccm::builtin::has_constexpr_isgreaterequal) { return ccm::builtin::isgreaterequal(x, y); } + else + { + return x >= y; + } } /** diff --git a/include/ccmath/math/compare/isinf.hpp b/include/ccmath/math/compare/isinf.hpp index 3744fa91..0230865f 100644 --- a/include/ccmath/math/compare/isinf.hpp +++ b/include/ccmath/math/compare/isinf.hpp @@ -11,6 +11,7 @@ #pragma once #include "ccmath/internal/support/fp/fp_bits.hpp" +#include "ccmath/internal/math/generic/builtins/compare/isinf.hpp" #include #include @@ -26,13 +27,14 @@ namespace ccm template , bool> = true> constexpr bool isinf(T num) noexcept { -#if defined(__GNUC__) || defined(__clang__) || defined(CCM_CONFIG_HAS_BUILTIN_ISINF_CONSTEXPR) - return __builtin_isinf(num); // GCC and Clang implement this as constexpr -#else // If we can't use the builtin, fallback to this comparison and hope for the best. - using FPBits_t = typename ccm::support::fp::FPBits; - const FPBits_t num_bits(num); - return num_bits.is_inf(); -#endif + if constexpr (ccm::builtin::has_constexpr_isinf) { return ccm::builtin::isinf(num); } + else + { + // If we can't use the builtin, fallback to this comparison and hope for the best. + using FPBits_t = typename ccm::support::fp::FPBits; + const FPBits_t num_bits(num); + return num_bits.is_inf(); + } } /** diff --git a/include/ccmath/math/compare/isless.hpp b/include/ccmath/math/compare/isless.hpp index 4a21d559..c4de9816 100644 --- a/include/ccmath/math/compare/isless.hpp +++ b/include/ccmath/math/compare/isless.hpp @@ -10,6 +10,8 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/compare/isless.hpp" + #include namespace ccm @@ -24,7 +26,11 @@ namespace ccm template constexpr bool isless(T x, T y) noexcept { - return x < y; + if constexpr (ccm::builtin::has_constexpr_isless) { return ccm::builtin::isless(x, y); } + else + { + return x < y; + } } /** diff --git a/include/ccmath/math/compare/islessequal.hpp b/include/ccmath/math/compare/islessequal.hpp index f510ac9f..75829ac0 100644 --- a/include/ccmath/math/compare/islessequal.hpp +++ b/include/ccmath/math/compare/islessequal.hpp @@ -10,6 +10,8 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/compare/islessequal.hpp" + #include namespace ccm @@ -24,7 +26,11 @@ namespace ccm template constexpr bool islessequal(T x, T y) noexcept { - return x <= y; + if constexpr (ccm::builtin::has_constexpr_islessequal) { return ccm::builtin::islessequal(x, y); } + else + { + return x <= y; + } } /** diff --git a/include/ccmath/math/compare/islessgreater.hpp b/include/ccmath/math/compare/islessgreater.hpp index 52d5c9f6..860b2a64 100644 --- a/include/ccmath/math/compare/islessgreater.hpp +++ b/include/ccmath/math/compare/islessgreater.hpp @@ -10,6 +10,8 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/compare/islessgreater.hpp" + #include namespace ccm @@ -24,7 +26,11 @@ namespace ccm template constexpr bool islessgreater(T x, T y) noexcept { - return x < y || x > y; + if constexpr (ccm::builtin::has_constexpr_islessgreater) { return ccm::builtin::islessgreater(x, y); } + else + { + return x < y || x > y; + } } /** diff --git a/include/ccmath/math/compare/isnan.hpp b/include/ccmath/math/compare/isnan.hpp index 75237797..a71107c2 100644 --- a/include/ccmath/math/compare/isnan.hpp +++ b/include/ccmath/math/compare/isnan.hpp @@ -10,6 +10,9 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/compare/isnan.hpp" + + #include namespace ccm @@ -23,13 +26,14 @@ namespace ccm template , bool> = true> [[nodiscard]] constexpr bool isnan(T num) noexcept { -#if defined(__GNUC__) || defined(__clang__) || defined(CCM_CONFIG_HAS_BUILTIN_ISNAN_CONSTEXPR) - return __builtin_isnan(num); // GCC and Clang implement this as constexpr -#else // If we can't use the builtin, fallback to this comparison and hope for the best. - using FPBits_t = typename ccm::support::fp::FPBits; - const FPBits_t num_bits(num); - return num_bits.is_nan(); -#endif + if constexpr (ccm::builtin::has_constexpr_isnan) { return ccm::builtin::isnan(num); } + else + { + // If we can't use the builtin, fallback to this comparison and hope for the best. + using FPBits_t = typename ccm::support::fp::FPBits; + const FPBits_t num_bits(num); + return num_bits.is_nan(); + } } /** diff --git a/include/ccmath/math/compare/isnormal.hpp b/include/ccmath/math/compare/isnormal.hpp index b69b0516..6a671e4d 100644 --- a/include/ccmath/math/compare/isnormal.hpp +++ b/include/ccmath/math/compare/isnormal.hpp @@ -13,6 +13,8 @@ #include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isinf.hpp" #include "ccmath/math/compare/isnan.hpp" +#include "ccmath/internal/math/generic/builtins/compare/isnormal.hpp" + namespace ccm { @@ -25,7 +27,11 @@ namespace ccm template , bool> = true> constexpr bool isnormal(T num) noexcept { - return num != static_cast(0) && !ccm::isnan(num) && !ccm::isinf(num) && ccm::abs(num) >= std::numeric_limits::min(); + if constexpr (ccm::builtin::has_constexpr_isnormal) { return ccm::builtin::isnormal(num); } + else + { + return num != static_cast(0) && !ccm::isnan(num) && !ccm::isinf(num) && ccm::abs(num) >= std::numeric_limits::min(); + } } /** diff --git a/include/ccmath/math/compare/isunordered.hpp b/include/ccmath/math/compare/isunordered.hpp index 3df75c5c..1a0dd1c1 100644 --- a/include/ccmath/math/compare/isunordered.hpp +++ b/include/ccmath/math/compare/isunordered.hpp @@ -11,6 +11,9 @@ #pragma once #include "ccmath/math/compare/isnan.hpp" +#include "ccmath/internal/math/generic/builtins/compare/isunordered.hpp" + + #include namespace ccm @@ -25,7 +28,11 @@ namespace ccm template , bool> = true> constexpr bool isunordered(T x, T y) noexcept { - return ccm::isnan(x) || ccm::isnan(y); + if constexpr (ccm::builtin::has_constexpr_isunordered) { return ccm::builtin::isunordered(x, y); } + else + { + return ccm::isnan(x) || ccm::isnan(y); + } } /** diff --git a/include/ccmath/math/expo/exp.hpp b/include/ccmath/math/expo/exp.hpp index f9a690f7..236c8596 100644 --- a/include/ccmath/math/expo/exp.hpp +++ b/include/ccmath/math/expo/exp.hpp @@ -12,6 +12,8 @@ #include "ccmath/math/expo/impl/exp_double_impl.hpp" #include "ccmath/math/expo/impl/exp_float_impl.hpp" +#include "ccmath/internal/math/generic/builtins/expo/exp.hpp" + #if defined(_MSC_VER) && !defined(__clang__) #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" @@ -29,17 +31,14 @@ namespace ccm template , bool> = true> constexpr T exp(T num) { -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - if constexpr (std::is_same_v) { return __builtin_expf(num); } - if constexpr (std::is_same_v) { return __builtin_exp(num); } - if constexpr (std::is_same_v) { return __builtin_expl(num); } - return static_cast(__builtin_expl(num)); -#else - if constexpr (std::is_same_v) { return internal::impl::exp_float_impl(num); } - if constexpr (std::is_same_v) { return internal::impl::exp_double_impl(num); } - if constexpr (std::is_same_v) { return static_cast(internal::impl::exp_double_impl(static_cast(num))); } - return static_cast(internal::impl::exp_double_impl(static_cast(num))); -#endif + if constexpr (ccm::builtin::has_constexpr_exp) { return ccm::builtin::exp(num); } + else + { + if constexpr (std::is_same_v) { return internal::impl::exp_float_impl(num); } + if constexpr (std::is_same_v) { return internal::impl::exp_double_impl(num); } + if constexpr (std::is_same_v) { return static_cast(internal::impl::exp_double_impl(static_cast(num))); } + return static_cast(internal::impl::exp_double_impl(static_cast(num))); + } } /** diff --git a/include/ccmath/math/expo/exp2.hpp b/include/ccmath/math/expo/exp2.hpp index 8e22e06e..1c58c12d 100644 --- a/include/ccmath/math/expo/exp2.hpp +++ b/include/ccmath/math/expo/exp2.hpp @@ -14,6 +14,8 @@ #include "ccmath/internal/predef/has_const_builtin.hpp" #include "ccmath/math/expo/impl/exp2_double_impl.hpp" #include "ccmath/math/expo/impl/exp2_float_impl.hpp" +#include "ccmath/internal/math/generic/builtins/expo/exp2.hpp" + #include @@ -33,17 +35,14 @@ namespace ccm template , bool> = true> constexpr T exp2(T num) { -#if defined(CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2) || CCM_HAS_CONST_BUILTIN(__builtin_exp2) - if constexpr (std::is_same_v) { return __builtin_exp2f(num); } - if constexpr (std::is_same_v) { return __builtin_exp2(num); } - if constexpr (std::is_same_v) { return __builtin_exp2l(num); } - return static_cast(__builtin_exp2l(num)); -#else - if constexpr (std::is_same_v) { return internal::exp2_float(num); } - if constexpr (std::is_same_v) { return internal::exp2_double(num); } - if constexpr (std::is_same_v) { return static_cast(internal::exp2_double(static_cast(num))); } - return static_cast(internal::exp2_double(static_cast(num))); -#endif + if constexpr (ccm::builtin::has_constexpr_exp2) { return ccm::builtin::exp2(num); } + else + { + if constexpr (std::is_same_v) { return internal::exp2_float(num); } + if constexpr (std::is_same_v) { return internal::exp2_double(num); } + if constexpr (std::is_same_v) { return static_cast(internal::exp2_double(static_cast(num))); } + return static_cast(internal::exp2_double(static_cast(num))); + } } /** diff --git a/include/ccmath/math/expo/expm1.hpp b/include/ccmath/math/expo/expm1.hpp index 8bcfb6e3..187192ac 100644 --- a/include/ccmath/math/expo/expm1.hpp +++ b/include/ccmath/math/expo/expm1.hpp @@ -10,6 +10,8 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/expo/expm1.hpp" + #include // TODO: Implement this. @@ -19,17 +21,14 @@ namespace ccm template , bool> = true> constexpr T expm1([[maybe_unused]] T num) { - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - if constexpr (std::is_same_v) { return __builtin_expm1f(num); } - if constexpr (std::is_same_v) { return __builtin_expm1(num); } - if constexpr (std::is_same_v) { return __builtin_expm1l(num); } - return static_cast(__builtin_expm1l(static_cast(num))); - #else - if constexpr (std::is_same_v) { return 0; } - if constexpr (std::is_same_v) { return 0; } - if constexpr (std::is_same_v) { return 0; } - return 0; - #endif + if constexpr (ccm::builtin::has_constexpr_expm1) { return ccm::builtin::expm1(num); } + else + { + if constexpr (std::is_same_v) { return 0; } + if constexpr (std::is_same_v) { return 0; } + if constexpr (std::is_same_v) { return 0; } + return 0; + } } template , bool> = true> diff --git a/include/ccmath/math/expo/log.hpp b/include/ccmath/math/expo/log.hpp index dc9f4ea9..c66d38d9 100644 --- a/include/ccmath/math/expo/log.hpp +++ b/include/ccmath/math/expo/log.hpp @@ -13,6 +13,8 @@ #include "ccmath/math/expo/impl/log_double_impl.hpp" #include "ccmath/internal/math/generic/func/expo/log_gen.hpp" #include "ccmath/math/expo/impl/log_float_impl.hpp" +#include "ccmath/internal/math/generic/builtins/expo/log.hpp" + #if defined(_MSC_VER) && !defined(__clang__) #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" @@ -30,33 +32,30 @@ namespace ccm template , bool> = true> constexpr T log(const T num) noexcept { -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - if constexpr (std::is_same_v) { return __builtin_logf(num); } - if constexpr (std::is_same_v) { return __builtin_log(num); } - if constexpr (std::is_same_v) { return __builtin_logl(num); } - return static_cast(__builtin_logl(num)); -#else - // If the number is 1, return +0. - if (num == static_cast(1)) { return static_cast(0); } + if constexpr (ccm::builtin::has_constexpr_log) { return ccm::builtin::log(num); } + else + { + // If the number is 1, return +0. + if (num == static_cast(1)) { return static_cast(0); } - // If the argument is ±0, -∞ is returned. - if (num == static_cast(0)) { return -std::numeric_limits::infinity(); } + // If the argument is ±0, -∞ is returned. + if (num == static_cast(0)) { return -std::numeric_limits::infinity(); } - // If the argument is negative, -NaN is returned. - if (num < static_cast(0)) { return -std::numeric_limits::quiet_NaN(); } + // If the argument is negative, -NaN is returned. + if (num < static_cast(0)) { return -std::numeric_limits::quiet_NaN(); } - // If the argument is +∞, +∞ is returned. - if (CCM_UNLIKELY(num == std::numeric_limits::infinity())) { return std::numeric_limits::infinity(); } + // If the argument is +∞, +∞ is returned. + if (CCM_UNLIKELY(num == std::numeric_limits::infinity())) { return std::numeric_limits::infinity(); } - // If the argument is NaN, NaN is returned. - if (CCM_UNLIKELY(ccm::isnan(num))) { return std::numeric_limits::quiet_NaN(); } + // If the argument is NaN, NaN is returned. + if (CCM_UNLIKELY(ccm::isnan(num))) { return std::numeric_limits::quiet_NaN(); } - // Select the correct implementation based on the type. - if constexpr (std::is_same_v) { return internal::log_float(num); } - if constexpr (std::is_same_v) { return internal::log_double(num); } - if constexpr (std::is_same_v) { return static_cast(internal::log_double(static_cast(num))); } - return static_cast(internal::log_double(num)); -#endif + // Select the correct implementation based on the type. + if constexpr (std::is_same_v) { return internal::log_float(num); } + if constexpr (std::is_same_v) { return internal::log_double(num); } + if constexpr (std::is_same_v) { return static_cast(internal::log_double(static_cast(num))); } + return static_cast(internal::log_double(num)); + } } /** diff --git a/include/ccmath/math/expo/log10.hpp b/include/ccmath/math/expo/log10.hpp index 098cdcc0..6175ee1e 100644 --- a/include/ccmath/math/expo/log10.hpp +++ b/include/ccmath/math/expo/log10.hpp @@ -10,6 +10,8 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/expo/log10.hpp" + #include namespace ccm @@ -17,17 +19,14 @@ namespace ccm template , bool> = true> constexpr T log10([[maybe_unused]] T num) { - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - if constexpr (std::is_same_v) { return __builtin_log10f(num); } - if constexpr (std::is_same_v) { return __builtin_log10(num); } - if constexpr (std::is_same_v) { return __builtin_log10l(num); } - return static_cast(__builtin_expm1l(static_cast(num))); - #else - if constexpr (std::is_same_v) { return 0; } - if constexpr (std::is_same_v) { return 0; } - if constexpr (std::is_same_v) { return 0; } - return 0; - #endif + if constexpr (ccm::builtin::has_constexpr_log10) { return ccm::builtin::log10(num); } + else + { + if constexpr (std::is_same_v) { return 0; } + if constexpr (std::is_same_v) { return 0; } + if constexpr (std::is_same_v) { return 0; } + return 0; + } } template , bool> = true> diff --git a/include/ccmath/math/expo/log1p.hpp b/include/ccmath/math/expo/log1p.hpp index 13944212..88294a1f 100644 --- a/include/ccmath/math/expo/log1p.hpp +++ b/include/ccmath/math/expo/log1p.hpp @@ -12,22 +12,21 @@ #include +#include "ccmath/internal/math/generic/builtins/expo/log1p.hpp" + namespace ccm { template , bool> = true> constexpr T log1p([[maybe_unused]] T num) { - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - if constexpr (std::is_same_v) { return __builtin_log1pf(num); } - if constexpr (std::is_same_v) { return __builtin_log1p(num); } - if constexpr (std::is_same_v) { return __builtin_log1pl(num); } - return static_cast(__builtin_log1p(static_cast(num))); - #else - if constexpr (std::is_same_v) { return 0; } - if constexpr (std::is_same_v) { return 0; } - if constexpr (std::is_same_v) { return 0; } - return 0; - #endif + if constexpr (ccm::builtin::has_constexpr_log1p) { return ccm::builtin::log1p(num); } + else + { + if constexpr (std::is_same_v) { return 0; } + if constexpr (std::is_same_v) { return 0; } + if constexpr (std::is_same_v) { return 0; } + return 0; + } } template , bool> = true> diff --git a/include/ccmath/math/expo/log2.hpp b/include/ccmath/math/expo/log2.hpp index 7c72ddad..033657ee 100644 --- a/include/ccmath/math/expo/log2.hpp +++ b/include/ccmath/math/expo/log2.hpp @@ -12,10 +12,12 @@ #include "ccmath/math/compare/isnan.hpp" #include "ccmath/internal/config/compiler.hpp" +#include "ccmath/internal/math/generic/builtins/expo/log2.hpp" #include "ccmath/math/compare/signbit.hpp" #include "ccmath/math/expo/impl/log2_double_impl.hpp" #include "ccmath/math/expo/impl/log2_float_impl.hpp" + #include #include @@ -35,38 +37,38 @@ namespace ccm template , bool> = true> constexpr T log2(T num) noexcept { -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - if constexpr (std::is_same_v) { return __builtin_log2f(num); } - if constexpr (std::is_same_v) { return __builtin_log2(num); } - if constexpr (std::is_same_v) { return __builtin_log2l(num); } - return static_cast(__builtin_log2l(num)); -#else - // If the argument is ±0, -∞ is returned - if (num == static_cast(0)) { return -std::numeric_limits::infinity(); } - - // If the argument is 1, +0 is returned. - if (num == static_cast(1)) { return 0; } - - // If the argument is NaN, NaN is returned. - if (ccm::isnan(num) || num == std::numeric_limits::infinity()) + if constexpr (ccm::builtin::has_constexpr_log2) { - return num; + return ccm::builtin::log2(num); } + else + { + // If the argument is ±0, -∞ is returned + if (num == static_cast(0)) { return -std::numeric_limits::infinity(); } - // If the argument is negative, -NaN is returned - #ifdef CCMATH_COMPILER_APPLE_CLANG // Apple clang returns +qNaN - if (ccm::signbit(num)) { return std::numeric_limits::quiet_NaN(); } - #else // All other major compilers return -qNaN - if (ccm::signbit(num)) { return -std::numeric_limits::quiet_NaN(); } - #endif + // If the argument is 1, +0 is returned. + if (num == static_cast(1)) { return 0; } - // We cannot handle long double at this time due to problems - // with long double being platform-dependent with its bit size. - if constexpr (std::is_same_v) { return internal::log2_float(num); } - if constexpr (std::is_same_v) { return internal::log2_double(num); } - if constexpr (std::is_same_v) { return static_cast(internal::log2_double(static_cast(num))); } - return static_cast(internal::log2_double(static_cast(num))); -#endif + // If the argument is NaN, NaN is returned. + if (ccm::isnan(num) || num == std::numeric_limits::infinity()) + { + return num; + } + + // If the argument is negative, -NaN is returned + #ifdef CCMATH_COMPILER_APPLE_CLANG // Apple clang returns +qNaN + if (ccm::signbit(num)) { return std::numeric_limits::quiet_NaN(); } + #else // All other major compilers return -qNaN + if (ccm::signbit(num)) { return -std::numeric_limits::quiet_NaN(); } + #endif + + // We cannot handle long double at this time due to problems + // with long double being platform-dependent with its bit size. + if constexpr (std::is_same_v) { return internal::log2_float(num); } + if constexpr (std::is_same_v) { return internal::log2_double(num); } + if constexpr (std::is_same_v) { return static_cast(internal::log2_double(static_cast(num))); } + return static_cast(internal::log2_double(static_cast(num))); + } } /** diff --git a/include/ccmath/math/fmanip/copysign.hpp b/include/ccmath/math/fmanip/copysign.hpp index eab72e91..578f5b56 100644 --- a/include/ccmath/math/fmanip/copysign.hpp +++ b/include/ccmath/math/fmanip/copysign.hpp @@ -13,6 +13,8 @@ #include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/compare/isnan.hpp" #include "ccmath/math/compare/signbit.hpp" +#include "ccmath/internal/math/generic/builtins/fmanip/copysign.hpp" + namespace ccm { @@ -26,14 +28,21 @@ namespace ccm template , bool> = true> constexpr T copysign(T mag, T sgn) { - if (ccm::isnan(mag) || ccm::isnan(sgn)) + if constexpr (ccm::builtin::has_constexpr_copysign) { - if (ccm::signbit(sgn)) { return -std::numeric_limits::quiet_NaN(); } - return std::numeric_limits::quiet_NaN(); + return ccm::builtin::copysign(mag, sgn); } + else + { + if (ccm::isnan(mag) || ccm::isnan(sgn)) + { + if (ccm::signbit(sgn)) { return -std::numeric_limits::quiet_NaN(); } + return std::numeric_limits::quiet_NaN(); + } - T sign_bit = ccm::signbit(sgn) ? T(-1) : T(1); - return ccm::abs(mag) * sign_bit; + T sign_bit = ccm::signbit(sgn) ? T(-1) : T(1); + return ccm::abs(mag) * sign_bit; + } } /** diff --git a/include/ccmath/math/fmanip/frexp.hpp b/include/ccmath/math/fmanip/frexp.hpp index 95bb0123..bf36d3a5 100644 --- a/include/ccmath/math/fmanip/frexp.hpp +++ b/include/ccmath/math/fmanip/frexp.hpp @@ -10,23 +10,33 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/fmanip/frexp.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" // TODO: Finish implementing. namespace ccm { - template , int> = 0> -constexpr T frexp(T x, int &exp) { - support::fp::FPBits bits(x); - if (bits.is_inf_or_nan()) { - return x; -} - if (bits.is_zero()) { - exp = 0; - return x; + template , int> = 0> + constexpr T frexp(T x, int & exp) + { + if constexpr (ccm::builtin::has_constexpr_frexp) + { + return ccm::builtin::frexp(x, &exp); + } + else + { + support::fp::FPBits bits(x); + if (bits.is_inf_or_nan()) + { + return x; + } + if (bits.is_zero()) + { + exp = 0; + return x; + } } - } } // namespace ccm diff --git a/include/ccmath/math/fmanip/ldexp.hpp b/include/ccmath/math/fmanip/ldexp.hpp index 1cd43517..aab6dd2d 100644 --- a/include/ccmath/math/fmanip/ldexp.hpp +++ b/include/ccmath/math/fmanip/ldexp.hpp @@ -12,17 +12,10 @@ #include "ccmath/internal/config/builtin/bit_cast_support.hpp" #include "ccmath/internal/config/builtin/ldexp_support.hpp" +#include "ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp" #include "ccmath/internal/predef/has_const_builtin.hpp" #include "ccmath/internal/support/helpers/internal_ldexp.hpp" -/* TODO: Move, remove, or change this to not use bit_cast. - #include "ccmath/internal/support/bits.hpp" - #include "ccmath/internal/support/fenv/fenv_support.hpp" - #include "ccmath/internal/support/floating_point_traits.hpp" - #include "ccmath/math/compare/isfinite.hpp" - - #include -*/ namespace ccm { @@ -38,72 +31,8 @@ namespace ccm template , bool> = true> constexpr T ldexp(T num, int exp) noexcept { -#if defined(CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP) || CCM_HAS_CONST_BUILTIN(__builtin_ldexp) - if constexpr (std::is_same_v) { return __builtin_ldexpf(num, exp); } - if constexpr (std::is_same_v) { return __builtin_ldexp(num, exp); } - if constexpr (std::is_same_v) { return __builtin_ldexpl(num, exp); } - return static_cast(__builtin_ldexpl(num, exp)); -#else - return support::helpers::internal_ldexp(num, exp); - /* TODO: Move, remove, or change this to not use bit_cast. - // Fallback option. Does not give perfect results, but generally good enough. - int old_exp = static_cast(support::get_exponent_of_floating_point(num)); - - // if the mantissa is 0 and the original exponent is 0, or infinite, return num - - if (const auto bits = support::bit_cast>(num); - CCM_UNLIKELY(!ccm::isfinite(num)) || old_exp < support::floating_point_traits::minimum_binary_exponent || - ((old_exp == 0) && ((bits & support::floating_point_traits::normal_mantissa_mask) == 0))) - { - return num; - } - - // An overflow will occur if the exponent is larger than the maximum exponent - if (exp > support::floating_point_traits::maximum_binary_exponent) - { - // These func do nothing at compile time, but at runtime will set errno and raise exceptions if required. - support::fenv::set_errno_if_required(ERANGE); - support::fenv::raise_except_if_required(FE_OVERFLOW); - - return std::numeric_limits::infinity(); - } - // the reference source says -2 * exp_max - // An underflow has occurred if the exponent is less than the minimum exponent - if (exp < support::floating_point_traits::minimum_binary_exponent) - { - // These func do nothing at compile time, but at runtime will set errno and raise exceptions if required. - support::fenv::set_errno_if_required(ERANGE); - support::fenv::raise_except_if_required(FE_UNDERFLOW); - - return 0; - } - // normalizes an abnormal floating point - if (old_exp == 0) - { - num *= support::floating_point_traits::normalize_factor; - exp = -static_cast(sizeof(T)) * std::numeric_limits::digits; // bits in a byte - old_exp = static_cast(support::get_exponent_of_floating_point(num)); - } - - exp += old_exp; - // If we left maximum exponent, we need to return infinity and report overflow - if (exp >= support::floating_point_traits::maximum_binary_exponent) - { - // These func do nothing at compile time, but at runtime will set errno and raise exceptions if required. - support::fenv::set_errno_if_required(ERANGE); - support::fenv::raise_except_if_required(FE_OVERFLOW); - - return std::numeric_limits::infinity(); - } - if (exp > 0) { return static_cast(support::set_exponent_of_floating_point(num, exp)); } - // denormal, or underflow - exp += static_cast(sizeof(T)) * std::numeric_limits::digits; // bits in a byte - num = support::set_exponent_of_floating_point(num, exp); - num /= support::floating_point_traits::normalize_factor; - - return num; - */ -#endif + if constexpr (ccm::builtin::has_constexpr_ldexp) { return ccm::builtin::ldexp(num, exp); } + else { return support::helpers::internal_ldexp(num, exp); } } /** diff --git a/include/ccmath/math/fmanip/modf.hpp b/include/ccmath/math/fmanip/modf.hpp index 1e5cb713..aead3b61 100644 --- a/include/ccmath/math/fmanip/modf.hpp +++ b/include/ccmath/math/fmanip/modf.hpp @@ -10,11 +10,20 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/fmanip/modf.hpp" + namespace ccm { template constexpr T modf(T x, T* iptr) noexcept { - return 0; + if constexpr (ccm::builtin::has_constexpr_modf) + { + return ccm::builtin::modf(x, iptr); + } + else + { + return 0; + } } } // namespace ccm diff --git a/include/ccmath/math/fmanip/nextafter.hpp b/include/ccmath/math/fmanip/nextafter.hpp index bc61e0d3..dd28df3f 100644 --- a/include/ccmath/math/fmanip/nextafter.hpp +++ b/include/ccmath/math/fmanip/nextafter.hpp @@ -11,6 +11,8 @@ #pragma once #include "ccmath/internal/math/generic/func/fmanip/nextafter_gen.hpp" +#include "ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp" + #include @@ -19,7 +21,9 @@ namespace ccm template , bool> = true> constexpr T nextafter(T from, T to) noexcept { - return gen::nextafter_gen(from, to); + // TODO: Better define how this interacts with the builtin. + if constexpr (ccm::builtin::has_constexpr_nextafter) { return ccm::builtin::nextafter(from, to); } + else { return gen::nextafter_gen(from, to); } } template && std::is_arithmetic_v, bool> = true> @@ -30,11 +34,11 @@ namespace ccm constexpr float nextafterf(float from, float to) noexcept { - return gen::nextafter_gen(from, to); + return ccm::nextafter(from, to); } constexpr long double nextafterl(long double from, long double to) noexcept { - return gen::nextafter_gen(from, to); + return ccm::nextafter(from, to); } } // namespace ccm diff --git a/include/ccmath/math/fmanip/nexttoward.hpp b/include/ccmath/math/fmanip/nexttoward.hpp index b7b66fde..6b5160f8 100644 --- a/include/ccmath/math/fmanip/nexttoward.hpp +++ b/include/ccmath/math/fmanip/nexttoward.hpp @@ -10,8 +10,10 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp" #include "ccmath/internal/math/generic/func/fmanip/nextafter_gen.hpp" + #include namespace ccm @@ -19,7 +21,9 @@ namespace ccm template , bool> = true> constexpr T nexttoward(T from, long double to) noexcept { - return gen::nextafter_gen(from, to); + // TODO: Better define how this interacts with the builtin. + if constexpr (ccm::builtin::has_constexpr_nexttoward) { return ccm::builtin::nexttoward(from, to); } + else { return gen::nextafter_gen(from, to); } } template , bool> = true> diff --git a/include/ccmath/math/fmanip/scalbn.hpp b/include/ccmath/math/fmanip/scalbn.hpp index 3a874687..4f439fb9 100644 --- a/include/ccmath/math/fmanip/scalbn.hpp +++ b/include/ccmath/math/fmanip/scalbn.hpp @@ -10,10 +10,12 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp" #include "ccmath/math/fmanip/impl/scalbn_double_impl.hpp" #include "ccmath/math/fmanip/impl/scalbn_float_impl.hpp" #include "ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp" + #if defined(_MSC_VER) && !defined(__clang__) #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code @@ -31,17 +33,14 @@ namespace ccm template , bool> = true> constexpr T scalbn(T num, int exp) noexcept { -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - if constexpr (std::is_same_v) { return __builtin_scalbnf(num, exp); } - if constexpr (std::is_same_v) { return __builtin_scalbn(num, exp); } - if constexpr (std::is_same_v) { return __builtin_scalbnl(num, exp); } - return static_cast(__builtin_scalbnl(num, exp)); -#else - if constexpr (std::is_same_v) { return internal::scalbn_float(num, exp); } - if constexpr (std::is_same_v) { return internal::scalbn_double(num, exp); } - if constexpr (std::is_same_v) { return internal::scalbn_ldouble(num, exp); } - return static_cast(internal::scalbn_ldouble(num, exp)); -#endif + if constexpr (ccm::builtin::has_constexpr_scalbn) { return ccm::builtin::scalbn(num, exp); } + else + { + if constexpr (std::is_same_v) { return internal::scalbn_float(num, exp); } + if constexpr (std::is_same_v) { return internal::scalbn_double(num, exp); } + if constexpr (std::is_same_v) { return internal::scalbn_ldouble(num, exp); } + return static_cast(internal::scalbn_ldouble(num, exp)); + } } /** @@ -54,17 +53,14 @@ namespace ccm template , bool> = true> constexpr T scalbn(T num, long exp) noexcept { - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) - if constexpr (std::is_same_v) { return __builtin_scalbnf(num, static_cast(exp)); } - if constexpr (std::is_same_v) { return __builtin_scalbn(num, static_cast(exp)); } - if constexpr (std::is_same_v) { return __builtin_scalbnl(num, static_cast(exp)); } - return static_cast(__builtin_scalbnl(num, static_cast(exp))); - #else - if constexpr (std::is_same_v) { return internal::scalbn_float(num, exp); } - if constexpr (std::is_same_v) { return internal::scalbn_double(num, exp); } - if constexpr (std::is_same_v) { return internal::scalbn_ldouble(num, exp); } - return static_cast(internal::scalbn_ldouble(num, exp)); - #endif + if constexpr (ccm::builtin::has_constexpr_scalbn) { return ccm::builtin::scalbn(num, exp); } + else + { + if constexpr (std::is_same_v) { return internal::scalbn_float(num, exp); } + if constexpr (std::is_same_v) { return internal::scalbn_double(num, exp); } + if constexpr (std::is_same_v) { return internal::scalbn_ldouble(num, exp); } + return static_cast(internal::scalbn_ldouble(num, exp)); + } } /** diff --git a/include/ccmath/math/nearest/floor.hpp b/include/ccmath/math/nearest/floor.hpp index 19a92c37..792b0ca8 100644 --- a/include/ccmath/math/nearest/floor.hpp +++ b/include/ccmath/math/nearest/floor.hpp @@ -12,6 +12,7 @@ #include "ccmath/math/compare/isinf.hpp" #include "ccmath/math/compare/isnan.hpp" +#include "ccmath/internal/math/generic/builtins/nearest/floor.hpp" #include #include @@ -82,14 +83,18 @@ namespace ccm template , bool> = true> constexpr T floor(T num) noexcept { - // If num is NaN, NaN is returned. - // If num is ±∞ or ±0, num is returned, unmodified. - if (ccm::isinf(num) || num == static_cast(0) || ccm::isnan(num)) { return num; } - - // TODO: This approach should work with long double perfectly, but is slow. - // at some consider adding a faster approach that is just as consistent. - if (num > 0) { return internal::impl::floor_pos_impl(num); } - return internal::impl::floor_neg_impl(num); + if constexpr (ccm::builtin::has_constexpr_floor) { return ccm::builtin::floor(num); } + else + { + // If num is NaN, NaN is returned. + // If num is ±∞ or ±0, num is returned, unmodified. + if (ccm::isinf(num) || num == static_cast(0) || ccm::isnan(num)) { return num; } + + // TODO: This approach should work with long double perfectly, but is slow. + // at some consider adding a faster approach that is just as consistent. + if (num > 0) { return internal::impl::floor_pos_impl(num); } + return internal::impl::floor_neg_impl(num); + } } /** diff --git a/include/ccmath/math/nearest/trunc.hpp b/include/ccmath/math/nearest/trunc.hpp index 15550e5e..fb13f193 100644 --- a/include/ccmath/math/nearest/trunc.hpp +++ b/include/ccmath/math/nearest/trunc.hpp @@ -12,6 +12,8 @@ #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" +#include "ccmath/internal/math/generic/builtins/nearest/trunc.hpp" + namespace ccm { @@ -24,31 +26,35 @@ namespace ccm template , bool> = true> constexpr T trunc(T num) noexcept { - using FPBits_t = ccm::support::fp::FPBits; - using Storage_t = typename FPBits_t::storage_type; + if constexpr (ccm::builtin::has_constexpr_trunc) { return ccm::builtin::trunc(num); } + else + { + using FPBits_t = ccm::support::fp::FPBits; + using Storage_t = typename FPBits_t::storage_type; - FPBits_t bits(num); + FPBits_t bits(num); - // If x == ±∞ then return num - // If x == ±NaN then return num - if (CCM_UNLIKELY(bits.is_inf_or_nan())) { return num; } + // If x == ±∞ then return num + // If x == ±NaN then return num + if (CCM_UNLIKELY(bits.is_inf_or_nan())) { return num; } - // If x == ±0 then return num - if (CCM_UNLIKELY(num == 0.0)) { return num; } + // If x == ±0 then return num + if (CCM_UNLIKELY(num == 0.0)) { return num; } - const int exponent = bits.get_exponent(); + const int exponent = bits.get_exponent(); - // If the exponent is greater than or equal to the fraction length, then we will return the number as is since it is already an integer. - if (exponent >= FPBits_t::fraction_length) { return num; } + // If the exponent is greater than or equal to the fraction length, then we will return the number as is since it is already an integer. + if (exponent >= FPBits_t::fraction_length) { return num; } - // If our exponent is set up such that the abs(x) is less than 1 we will instead return 0. - if (exponent <= -1) { return FPBits_t::zero(bits.sign()).get_val(); } + // If our exponent is set up such that the abs(x) is less than 1 we will instead return 0. + if (exponent <= -1) { return FPBits_t::zero(bits.sign()).get_val(); } - // Perform the truncation - const int trimming_size = FPBits_t::fraction_length - exponent; - const auto truncated_mantissa = static_cast((bits.get_mantissa() >> trimming_size) << trimming_size); - bits.set_mantissa(truncated_mantissa); - return bits.get_val(); + // Perform the truncation + const int trimming_size = FPBits_t::fraction_length - exponent; + const auto truncated_mantissa = static_cast((bits.get_mantissa() >> trimming_size) << trimming_size); + bits.set_mantissa(truncated_mantissa); + return bits.get_val(); + } } /** diff --git a/include/ccmath/math/power/pow.hpp b/include/ccmath/math/power/pow.hpp index fe777de6..91ea37a3 100644 --- a/include/ccmath/math/power/pow.hpp +++ b/include/ccmath/math/power/pow.hpp @@ -13,6 +13,8 @@ #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" #include "ccmath/internal/math/runtime/func/power/pow_rt.hpp" #include "ccmath/internal/support/is_constant_evaluated.hpp" +#include "ccmath/internal/math/generic/builtins/power/pow.hpp" + #include @@ -21,10 +23,14 @@ namespace ccm template , bool> = true> constexpr T pow(T base, T exp) { - // TODO: Add in usage of builtins that meet ccmath standards. + if constexpr (ccm::builtin::has_constexpr_pow) { return ccm::builtin::pow(base, exp); } + else + { + // TODO: Add in usage of builtins that meet ccmath standards. - if (support::is_constant_evaluated()) { return gen::pow_gen(base, exp); } - return rt::pow_rt(base, exp); + if (support::is_constant_evaluated()) { return gen::pow_gen(base, exp); } + return rt::pow_rt(base, exp); + } } template , bool> = true> diff --git a/include/ccmath/math/power/sqrt.hpp b/include/ccmath/math/power/sqrt.hpp index da30e5eb..83d5d7bc 100644 --- a/include/ccmath/math/power/sqrt.hpp +++ b/include/ccmath/math/power/sqrt.hpp @@ -10,12 +10,10 @@ #pragma once -// If we don't have constexpr sqrt builtins, include the generic and runtime implementations. -#if !(defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__)) - #include "ccmath/internal/math/generic/func/power/sqrt_gen.hpp" - #include "ccmath/internal/math/runtime/func/power/sqrt_rt.hpp" - #include "ccmath/internal/support/is_constant_evaluated.hpp" -#endif +#include "ccmath/internal/math/generic/builtins/power/sqrt.hpp" +#include "ccmath/internal/math/generic/func/power/sqrt_gen.hpp" +#include "ccmath/internal/math/runtime/func/power/sqrt_rt.hpp" +#include "ccmath/internal/support/is_constant_evaluated.hpp" #include @@ -31,15 +29,12 @@ namespace ccm template , bool> = true> constexpr T sqrt(T num) { -#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) // GCC 6.1+ has constexpr sqrt builtins. - if constexpr (std::is_same_v) { return __builtin_sqrtf(num); } - else if constexpr (std::is_same_v) { return __builtin_sqrt(num); } - else if constexpr (std::is_same_v) { return __builtin_sqrtl(num); } - else { return static_cast(__builtin_sqrtl(static_cast(num))); } -#else - if (ccm::support::is_constant_evaluated()) { return ccm::gen::sqrt_gen(num); } - return ccm::rt::sqrt_rt(num); -#endif + if constexpr (ccm::builtin::has_constexpr_sqrt) { return ccm::builtin::sqrt(num); } + else + { + if (ccm::support::is_constant_evaluated()) { return ccm::gen::sqrt_gen(num); } + return ccm::rt::sqrt_rt(num); + } } /** From 16825a45204fab9488533c73369004353be6aedf Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 17:05:52 -0500 Subject: [PATCH 097/102] Make it so gtests internal implementation details can never trigger our compiler on clang Signed-off-by: Ian --- thirdparty/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 8a6b554f..8dbd7aac 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -77,6 +77,10 @@ add_library(ccmath::ext ALIAS ${PROJECT_NAME}) if (CCMATH_BUILD_TESTS) target_link_libraries(${PROJECT_NAME} INTERFACE gtest::gtest) target_link_libraries(${PROJECT_NAME} INTERFACE absl::base absl::debugging re2::re2) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(gtest INTERFACE -Wno-everything) + endif() + endif() # Link Google Benchmark only if benchmarks are enabled From 112b7105567b771333704816480fbc79e5ebabf4 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 17:06:40 -0500 Subject: [PATCH 098/102] disable static assert on long double nanl due to issues with how clang handles bit_cast Signed-off-by: Ian --- test/basic/nan_test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/basic/nan_test.cpp b/test/basic/nan_test.cpp index a28ae8c4..3227c5b4 100644 --- a/test/basic/nan_test.cpp +++ b/test/basic/nan_test.cpp @@ -27,7 +27,9 @@ TEST(CcmathBasicTests, NanStaticAssert) // Assume we have access to ccm::isnan static_assert(ccm::isnan(ccm::nanf("")), "ccm::nanf() is NOT static assertable!"); static_assert(ccm::isnan(ccm::nan("")), "ccm::nan() is NOT static assertable!"); - static_assert(ccm::isnan(ccm::nanl("")), "ccm::nanl() is NOT static assertable!"); + // Currently nanl is not possible to static assert on clang due to issues with bit_cast. + // TODO: Look into alternative approach to handling nanl. + //static_assert(ccm::isnan(ccm::nanl("")), "ccm::nanl() is NOT static assertable!"); } TEST(CcmathBasicTests, Nan_Double) From bc83e99a9d21ea8e9639f8b26048e82ffdb43cf1 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 18:42:42 -0500 Subject: [PATCH 099/102] Add support for Clang, NVC++, and Intel DPC++ for builtin detection Signed-off-by: Ian --- .../math/generic/builtins/basic/fabs.hpp | 52 +++++++------- .../math/generic/builtins/basic/fmax.hpp | 37 +++++----- .../math/generic/builtins/basic/fmin.hpp | 39 ++++++----- .../generic/builtins/compare/isfinite.hpp | 61 +++++++++-------- .../math/generic/builtins/compare/isinf.hpp | 42 ++++++++---- .../math/generic/builtins/compare/isnan.hpp | 42 ++++++++---- .../generic/builtins/compare/isnormal.hpp | 68 +++++++++++-------- .../math/generic/builtins/compare/signbit.hpp | 53 ++++++++------- .../math/generic/builtins/fmanip/copysign.hpp | 68 +++++++++++-------- .../math/generic/builtins/nearest/ceil.hpp | 28 ++++---- 10 files changed, 276 insertions(+), 214 deletions(-) diff --git a/include/ccmath/internal/math/generic/builtins/basic/fabs.hpp b/include/ccmath/internal/math/generic/builtins/basic/fabs.hpp index 7f5f89a2..592184b6 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fabs.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fabs.hpp @@ -18,19 +18,31 @@ /// Compilers with Support: /// - GCC 5.1+ /// - NVC++ 22.7+ (Lowest tested version) -/// - Clang trunk allows it, but it is not yet in a release -/// TODO: Add clang version when it is released +/// - Clang 5.0.0+ +/// - Intel DPC++ 2021.1.2+ (Lowest tested version) #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ABS -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ABS + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ABS + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ABS + #if defined(__NVCOMPILER_MAJOR__) && (__NVCOMPILER_MAJOR__ > 22 || (__NVCOMPILER_MAJOR__ == 22 && __NVCOMPILER_MINOR__ >= 7)) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ABS + #endif #endif #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ABS -#if defined(__NVCOMPILER_MAJOR__) && (__NVCOMPILER_MAJOR__ > 22 || (__NVCOMPILER_MAJOR__ == 22 && __NVCOMPILER_MINOR__ >= 7)) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ABS + #if defined(__clang__) && (__clang_major__ > 5 || (__clang_major__ == 5 && __clang_minor__ >= 0)) && !defined(__MSC_VER) && !defined(__INTEL_LLVM_COMPILER) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ABS + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ABS + #if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER >= 202110) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ABS + #endif #endif namespace ccm::builtin @@ -53,29 +65,13 @@ namespace ccm::builtin * when the compiler does not support them. */ template - constexpr auto abs(T x) - -> std::enable_if_t, T> + constexpr auto abs(T x) -> std::enable_if_t, T> { - if constexpr (std::is_same_v) - { - return __builtin_fabsf(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_fabs(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_fabsl(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_llabs(x); - } - else if constexpr (std::is_integral_v && std::is_signed_v) - { - return __builtin_abs(x); - } + if constexpr (std::is_same_v) { return __builtin_fabsf(x); } + else if constexpr (std::is_same_v) { return __builtin_fabs(x); } + else if constexpr (std::is_same_v) { return __builtin_fabsl(x); } + else if constexpr (std::is_same_v) { return __builtin_llabs(x); } + else if constexpr (std::is_integral_v && std::is_signed_v) { return __builtin_abs(x); } else if constexpr (std::is_integral_v && std::is_unsigned_v) { return x; // Absolute value of unsigned is the value itself diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp index ce3eb408..f26fd696 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fmax.hpp @@ -19,11 +19,26 @@ /// /// Compilers with Support: /// - GCC 5.1+ +/// - Clang 16.0.0+ +/// - Intel DPC++ 2023.1.0+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX + #if defined(__clang__) && (__clang_major__ > 16 || (__clang_major__ == 16 && __clang_minor__ >= 0)) && !defined(__MSC_VER) && \ + !defined(__INTEL_LLVM_COMPILER) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX + #if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER >= 20230100) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMAX + #endif #endif namespace ccm::builtin @@ -45,21 +60,11 @@ namespace ccm::builtin * when the compiler does not support them. */ template - constexpr auto fmax(T x, T y) - -> std::enable_if_t, T> + constexpr auto fmax(T x, T y) -> std::enable_if_t, T> { - if constexpr (std::is_same_v) - { - return __builtin_fmaxf(x, y); - } - else if constexpr (std::is_same_v) - { - return __builtin_fmax(x, y); - } - else if constexpr (std::is_same_v) - { - return __builtin_fmaxl(x, y); - } + if constexpr (std::is_same_v) { return __builtin_fmaxf(x, y); } + else if constexpr (std::is_same_v) { return __builtin_fmax(x, y); } + else if constexpr (std::is_same_v) { return __builtin_fmaxl(x, y); } // This should never be reached return T{}; } diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp index e5dda18c..46b2e94a 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fmin.hpp @@ -1,5 +1,5 @@ /* -* Copyright (c) Ian Pike + * Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -19,11 +19,26 @@ /// /// Compilers with Support: /// - GCC 5.1+ +/// - Clang 16.0.0+ +/// - Intel DPC++ 2023.1.0+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN + #if defined(__clang__) && (__clang_major__ > 16 || (__clang_major__ == 16 && __clang_minor__ >= 0)) && !defined(__MSC_VER) && \ + !defined(__INTEL_LLVM_COMPILER) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN + #if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER >= 20230100) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMIN + #endif #endif namespace ccm::builtin @@ -45,21 +60,11 @@ namespace ccm::builtin * when the compiler does not support them. */ template - constexpr auto fmin(T x, T y) - -> std::enable_if_t, T> + constexpr auto fmin(T x, T y) -> std::enable_if_t, T> { - if constexpr (std::is_same_v) - { - return __builtin_fminf(x, y); - } - else if constexpr (std::is_same_v) - { - return __builtin_fmin(x, y); - } - else if constexpr (std::is_same_v) - { - return __builtin_fminl(x, y); - } + if constexpr (std::is_same_v) { return __builtin_fminf(x, y); } + else if constexpr (std::is_same_v) { return __builtin_fmin(x, y); } + else if constexpr (std::is_same_v) { return __builtin_fminl(x, y); } // This should never be reached return T{}; } diff --git a/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp b/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp index 03e14c6f..9a0b8110 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isfinite.hpp @@ -19,16 +19,30 @@ /// /// Compilers with Support: /// - GCC 5.1+ +/// - Clang 5.0.0+ +/// - Intel DPC++ 2021.1.2+ (Lowest tested version) #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE + #if defined(__clang__) && (__clang_major__ > 5 || (__clang_major__ == 5 && __clang_minor__ >= 0)) && !defined(__MSC_VER) && !defined(__INTEL_LLVM_COMPILER) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE + #if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER >= 202110) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_isfinite = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISFINITE @@ -36,32 +50,23 @@ namespace ccm::builtin #else false; #endif - // clang-format on + // clang-format on - /** - * Wrapper for constexpr __builtin isfinite functions. - * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin isfinite functions without triggering a compiler error - * when the compiler does not support them. - */ - template - constexpr auto isfinite(T x) -> std::enable_if_t, bool> - { - if constexpr (std::is_same_v) - { - return __builtin_isfinite(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_isfinite(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_isfinite(x); - } - // This should never be reached - return false; - } + /** + * Wrapper for constexpr __builtin isfinite functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin isfinite functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto isfinite(T x) -> std::enable_if_t, bool> + { + if constexpr (std::is_same_v) { return __builtin_isfinite(x); } + else if constexpr (std::is_same_v) { return __builtin_isfinite(x); } + else if constexpr (std::is_same_v) { return __builtin_isfinite(x); } + // This should never be reached + return false; + } } // namespace ccm::builtin // Cleanup the global namespace diff --git a/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp b/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp index b08eb72c..b12d491d 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isinf.hpp @@ -1,5 +1,5 @@ /* -* Copyright (c) Ian Pike + * Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -19,11 +19,32 @@ /// /// Compilers with Support: /// - GCC 5.1+ +/// - Clang 5.0.0+ +/// - NVC++ 22.7+ (Lowest tested version) +/// - Intel DPC++ 2021.1.2+ (Lowest tested version) #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF + #if defined(__clang__) && (__clang_major__ > 5 || (__clang_major__ == 5 && __clang_minor__ >= 0)) && !defined(__MSC_VER) && !defined(__INTEL_LLVM_COMPILER) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF + #if defined(__NVCOMPILER_MAJOR__) && (__NVCOMPILER_MAJOR__ > 22 || (__NVCOMPILER_MAJOR__ == 22 && __NVCOMPILER_MINOR__ >= 7)) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF + #if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER >= 202110) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISINF + #endif #endif namespace ccm::builtin @@ -47,18 +68,9 @@ namespace ccm::builtin template constexpr auto isinf(T x) -> std::enable_if_t, bool> { - if constexpr (std::is_same_v) - { - return __builtin_isinf(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_isinf(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_isinf(x); - } + if constexpr (std::is_same_v) { return __builtin_isinf(x); } + else if constexpr (std::is_same_v) { return __builtin_isinf(x); } + else if constexpr (std::is_same_v) { return __builtin_isinf(x); } // This should never be reached return false; } diff --git a/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp b/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp index ab1222d4..30006ece 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isnan.hpp @@ -1,5 +1,5 @@ /* -* Copyright (c) Ian Pike + * Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -19,11 +19,32 @@ /// /// Compilers with Support: /// - GCC 5.1+ +/// - Clang 5.0.0+ +/// NVC++ 22.7+ (Lowest tested version) +/// Intel DPC++ 2021.1.2+ (Lowest tested version) #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN + #if defined(__clang__) && (__clang_major__ > 5 || (__clang_major__ == 5 && __clang_minor__ >= 0)) && !defined(__MSC_VER) && !defined(__INTEL_LLVM_COMPILER) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN + #if defined(__NVCOMPILER_MAJOR__) && (__NVCOMPILER_MAJOR__ > 22 || (__NVCOMPILER_MAJOR__ == 22 && __NVCOMPILER_MINOR__ >= 7)) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN + #if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER >= 202110) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNAN + #endif #endif namespace ccm::builtin @@ -47,18 +68,9 @@ namespace ccm::builtin template constexpr auto isnan(T x) -> std::enable_if_t, bool> { - if constexpr (std::is_same_v) - { - return __builtin_isnan(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_isnan(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_isnan(x); - } + if constexpr (std::is_same_v) { return __builtin_isnan(x); } + else if constexpr (std::is_same_v) { return __builtin_isnan(x); } + else if constexpr (std::is_same_v) { return __builtin_isnan(x); } // This should never be reached return false; } diff --git a/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp b/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp index b7c40dda..392ecbc7 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isnormal.hpp @@ -19,16 +19,37 @@ /// /// Compilers with Support: /// - GCC 5.1+ +/// - Clang 5.0.0+ +/// - NVC++ 22.7+ (Lowest tested version) +/// - Intel DPC++ 2021.1.2+ (Lowest tested version) #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL + #if defined(__clang__) && (__clang_major__ > 5 || (__clang_major__ == 5 && __clang_minor__ >= 0)) && !defined(__MSC_VER) && !defined(__INTEL_LLVM_COMPILER) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL + #if defined(__NVCOMPILER_MAJOR__) && (__NVCOMPILER_MAJOR__ > 22 || (__NVCOMPILER_MAJOR__ == 22 && __NVCOMPILER_MINOR__ >= 7)) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL + #if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER >= 202110) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_isnormal = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISNORMAL @@ -36,32 +57,23 @@ namespace ccm::builtin #else false; #endif - // clang-format on + // clang-format on - /** - * Wrapper for constexpr __builtin isnormal functions. - * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin isnormal functions without triggering a compiler error - * when the compiler does not support them. - */ - template - constexpr auto isnormal(T x) -> std::enable_if_t, bool> - { - if constexpr (std::is_same_v) - { - return __builtin_isnormal(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_isnormal(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_isnormal(x); - } - // This should never be reached - return false; - } + /** + * Wrapper for constexpr __builtin isnormal functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin isnormal functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto isnormal(T x) -> std::enable_if_t, bool> + { + if constexpr (std::is_same_v) { return __builtin_isnormal(x); } + else if constexpr (std::is_same_v) { return __builtin_isnormal(x); } + else if constexpr (std::is_same_v) { return __builtin_isnormal(x); } + // This should never be reached + return false; + } } // namespace ccm::builtin // Cleanup the global namespace diff --git a/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp b/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp index 9f990142..3aa5bcf8 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/signbit.hpp @@ -19,15 +19,23 @@ /// /// Compilers with Support: /// - GCC 5.1+ +/// - NVC++ 22.7+ (Lowest tested version) #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT + #if defined(__NVCOMPILER_MAJOR__) && (__NVCOMPILER_MAJOR__ > 22 || (__NVCOMPILER_MAJOR__ == 22 && __NVCOMPILER_MINOR__ >= 7)) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT + #endif #endif -namespace ccm::builtin { - // clang-format off +namespace ccm::builtin +{ + // clang-format off template inline constexpr bool has_constexpr_signbit = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_SIGNBIT @@ -35,26 +43,23 @@ namespace ccm::builtin { #else false; #endif - // clang-format on - - /** - * Wrapper for constexpr __builtin signbit functions. - * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin signbit functions without triggering a compiler error - * when the compiler does not support them. - */ - template - constexpr auto signbit(T x) -> std::enable_if_t, bool> { - if constexpr (std::is_same_v) { - return __builtin_signbit(x); - } else if constexpr (std::is_same_v) { - return __builtin_signbit(x); - } else if constexpr (std::is_same_v) { - return __builtin_signbit(x); - } - // This should never be reached - return false; - } + // clang-format on + + /** + * Wrapper for constexpr __builtin signbit functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin signbit functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto signbit(T x) -> std::enable_if_t, bool> + { + if constexpr (std::is_same_v) { return __builtin_signbit(x); } + else if constexpr (std::is_same_v) { return __builtin_signbit(x); } + else if constexpr (std::is_same_v) { return __builtin_signbit(x); } + // This should never be reached + return false; + } } // namespace ccm::builtin // Cleanup the global namespace diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp index 753f8d7c..7a7fed63 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/copysign.hpp @@ -19,16 +19,37 @@ /// /// Compilers with Support: /// - GCC 5.1+ +/// - Clang 5.0.0+ +/// - NVC++ 23.9+ +/// - Intel DPC++ 2021.1.2+ (Lowest tested version) #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #if defined(__clang__) && (__clang_major__ > 5 || (__clang_major__ == 5 && __clang_minor__ >= 0)) && !defined(__MSC_VER) && !defined(__INTEL_LLVM_COMPILER) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #if defined(__NVCOMPILER_MAJOR__) && (__NVCOMPILER_MAJOR__ > 23 || (__NVCOMPILER_MAJOR__ == 23 && __NVCOMPILER_MINOR__ >= 9)) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #endif +#endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #if defined(__INTEL_LLVM_COMPILER) && (__INTEL_LLVM_COMPILER >= 202110) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_copysign = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN @@ -36,32 +57,23 @@ namespace ccm::builtin #else false; #endif - // clang-format on + // clang-format on - /** - * Wrapper for constexpr __builtin copysign functions. - * This should be used internally and always be wrapped in an if constexpr statement. - * It exists only to allow for usage of __builtin copysign functions without triggering a compiler error - * when the compiler does not support them. - */ - template - constexpr auto copysign(T x, T y) -> std::enable_if_t, T> - { - if constexpr (std::is_same_v) - { - return __builtin_copysignf(x, y); - } - else if constexpr (std::is_same_v) - { - return __builtin_copysign(x, y); - } - else if constexpr (std::is_same_v) - { - return __builtin_copysignl(x, y); - } - // This should never be reached - return T{}; - } + /** + * Wrapper for constexpr __builtin copysign functions. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin copysign functions without triggering a compiler error + * when the compiler does not support them. + */ + template + constexpr auto copysign(T x, T y) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) { return __builtin_copysignf(x, y); } + else if constexpr (std::is_same_v) { return __builtin_copysign(x, y); } + else if constexpr (std::is_same_v) { return __builtin_copysignl(x, y); } + // This should never be reached + return T{}; + } } // namespace ccm::builtin // Cleanup the global namespace diff --git a/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp b/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp index b6342750..a1bb4ba2 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp +++ b/include/ccmath/internal/math/generic/builtins/nearest/ceil.hpp @@ -1,5 +1,5 @@ /* -* Copyright (c) Ian Pike + * Copyright (c) Ian Pike * Copyright (c) CCMath contributors * * CCMath is provided under the Apache-2.0 License WITH LLVM-exception. @@ -19,11 +19,18 @@ /// /// Compilers with Support: /// - GCC 5.1+ +/// - NVC++ 23.9+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL + #endif #endif + +#ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL + #if defined(__NVCOMPILER_MAJOR__) && (__NVCOMPILER_MAJOR__ > 23 || (__NVCOMPILER_MAJOR__ == 23 && __NVCOMPILER_MINOR__ >= 9)) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_CEIL + #endif #endif namespace ccm::builtin @@ -47,18 +54,9 @@ namespace ccm::builtin template constexpr auto ceil(T x) -> std::enable_if_t, T> { - if constexpr (std::is_same_v) - { - return __builtin_ceilf(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_ceil(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_ceill(x); - } + if constexpr (std::is_same_v) { return __builtin_ceilf(x); } + else if constexpr (std::is_same_v) { return __builtin_ceil(x); } + else if constexpr (std::is_same_v) { return __builtin_ceill(x); } // This should never be reached return T{}; } From d460366ee07fc1bcc5c5fd185cd5006464a3c588 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 20:31:59 -0500 Subject: [PATCH 100/102] Remove builtin detection with cmake Signed-off-by: Ian --- .../CheckAllSupportedBuiltinFeatures.cmake | 56 ------------------- .../features/GetAllSupportedFeatures.cmake | 11 +--- .../math/basic/CheckBuiltinNanSupport.cmake | 32 ----------- .../compare/CheckBuiltinIsInfSupport.cmake | 13 ----- .../compare/CheckBuiltinIsNanSupport.cmake | 13 ----- .../compare/CheckBuiltinSignbitSupport.cmake | 26 --------- .../math/expo/CheckBuiltinExp2Support.cmake | 31 ---------- .../math/expo/CheckBuiltinExpSupport.cmake | 31 ---------- .../math/expo/CheckBuiltinExpm1Support.cmake | 31 ---------- .../math/expo/CheckBuiltinLog10Support.cmake | 31 ---------- .../math/expo/CheckBuiltinLog1pSupport.cmake | 31 ---------- .../math/expo/CheckBuiltinLog2Support.cmake | 31 ---------- .../math/expo/CheckBuiltinLogSupport.cmake | 31 ---------- .../fmanip/CheckBuiltinCopysignSupport.cmake | 26 --------- .../fmanip/CheckBuiltinFrexpSupport.cmake | 26 --------- .../fmanip/CheckBuiltinIlogbSupport.cmake | 26 --------- .../fmanip/CheckBuiltinLdexpSupport.cmake | 26 --------- .../math/fmanip/CheckBuiltinLogbSupport.cmake | 26 --------- .../math/fmanip/CheckBuiltinModfSupport.cmake | 26 --------- .../fmanip/CheckBuiltinScalbnSupport.cmake | 3 - .../math/hyper/CheckBuiltinAcoshSupport.cmake | 31 ---------- .../math/hyper/CheckBuiltinAsinhSupport.cmake | 31 ---------- .../math/hyper/CheckBuiltinAtanhSupport.cmake | 31 ---------- .../math/hyper/CheckBuiltinCoshSupport.cmake | 31 ---------- .../math/hyper/CheckBuiltinSinhSupport.cmake | 31 ---------- .../math/hyper/CheckBuiltinTanhSupport.cmake | 31 ---------- .../math/power/CheckBuiltinCbrtSupport.cmake | 31 ---------- .../math/power/CheckBuiltinHypotSupport.cmake | 31 ---------- .../math/power/CheckBuiltinPowSupport.cmake | 31 ---------- .../math/power/CheckBuiltinSqrtSupport.cmake | 31 ---------- .../math/trig/CheckBuiltinAcosSupport.cmake | 31 ---------- .../math/trig/CheckBuiltinAsinSupport.cmake | 31 ---------- .../math/trig/CheckBuiltinAtan2Support.cmake | 31 ---------- .../math/trig/CheckBuiltinAtanSupport.cmake | 31 ---------- .../math/trig/CheckBuiltinCosSupport.cmake | 31 ---------- .../math/trig/CheckBuiltinSinSupport.cmake | 31 ---------- .../math/trig/CheckBuiltinTanSupport.cmake | 31 ---------- 37 files changed, 2 insertions(+), 1052 deletions(-) delete mode 100644 cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake delete mode 100644 cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake delete mode 100644 cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake delete mode 100644 cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake delete mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake delete mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake delete mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake delete mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake delete mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake delete mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake delete mode 100644 cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake delete mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake delete mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake delete mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake delete mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake delete mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake delete mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake delete mode 100644 cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake delete mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake delete mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake delete mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake delete mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake delete mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake delete mode 100644 cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake delete mode 100644 cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake delete mode 100644 cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake delete mode 100644 cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake delete mode 100644 cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake delete mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake delete mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake delete mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake delete mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake delete mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake delete mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake delete mode 100644 cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake diff --git a/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake b/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake index fee276c5..5927c342 100644 --- a/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake +++ b/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake @@ -12,59 +12,3 @@ # Common Support Builtins include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/support/CheckBuiltinBitCastSupport.cmake) include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/support/CheckBuiltinFmaSupport.cmake) - - -# Basic -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake) - - -# Compare -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake) - - -# Exponential -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake) - - -# Fmanip -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake) - - -# Hyperbolic -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake) - - -# Power -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake) - - -# Trigonometric -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake) diff --git a/cmake/config/features/GetAllSupportedFeatures.cmake b/cmake/config/features/GetAllSupportedFeatures.cmake index a0649974..80ee92d6 100644 --- a/cmake/config/features/GetAllSupportedFeatures.cmake +++ b/cmake/config/features/GetAllSupportedFeatures.cmake @@ -1,12 +1,5 @@ -# Common Support Builtins -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/support/CheckBuiltinBitCastSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/support/CheckBuiltinFmaSupport.cmake) -include(${CCMATH_SOURCE_DIR}/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake) - - -# TODO: Revisit this in a manner that is better. The current approach takes up too much time in the cmake. -#include(${CCMATH_SOURCE_DIR}/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake) +include(${CCMATH_SOURCE_DIR}/cmake/config/features/CheckAllSupportedBuiltinFeatures.cmake) if (CCMATH_ENABLE_RUNTIME_SIMD) - include(${CCMATH_SOURCE_DIR}/cmake/config/features/CheckAllSupportedSimdFeatures.cmake) + include(${CCMATH_SOURCE_DIR}/cmake/config/features/CheckAllSupportedSimdFeatures.cmake) endif () diff --git a/cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake b/cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake deleted file mode 100644 index 5696d64b..00000000 --- a/cmake/config/features/builtin/math/basic/CheckBuiltinNanSupport.cmake +++ /dev/null @@ -1,32 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_nan is supported -check_cxx_source_compiles(" - int main() { - float fr = __builtin_nanf(); - double dr = __builtin_nan(); - long double lr = __builtin_nanl(); - return 0; - } -" CCMATH_BUILTIN_NAN_SUPPORT) - -if (CCMATH_BUILTIN_NAN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_NAN) -endif () - -# Check if __builtin_nan can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr float fr = __builtin_nanf(); - constexpr double dr = __builtin_nan(); - constexpr long double lr = __builtin_nanl(); - static_assert(fr != fr); - static_assert(dr != dr); - static_assert(lr != lr); - return 0; - } -" CCMATH_BUILTIN_NAN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_NAN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_NAN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake b/cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake deleted file mode 100644 index 71215d27..00000000 --- a/cmake/config/features/builtin/math/compare/CheckBuiltinIsInfSupport.cmake +++ /dev/null @@ -1,13 +0,0 @@ -include(CheckCXXSourceCompiles) - -# We only care about the constexpr support for isinf -check_cxx_source_compiles(" - int main() { - static_assert(__builtin_isinf(1.0 / 0.0)); - return 0; - } -" CCMATH_BUILTIN_ISINF_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_ISINF_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ISINF_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake b/cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake deleted file mode 100644 index d393146f..00000000 --- a/cmake/config/features/builtin/math/compare/CheckBuiltinIsNanSupport.cmake +++ /dev/null @@ -1,13 +0,0 @@ -include(CheckCXXSourceCompiles) - -# We only care about the constexpr support for isnan -check_cxx_source_compiles(" - int main() { - static_assert(__builtin_isnan(0.0 / 0.0)); - return 0; - } -" CCMATH_BUILTIN_ISNAN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_ISNAN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ISNAN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake b/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake deleted file mode 100644 index f177015f..00000000 --- a/cmake/config/features/builtin/math/compare/CheckBuiltinSignbitSupport.cmake +++ /dev/null @@ -1,26 +0,0 @@ -include(CheckCXXSourceCompiles) - -check_cxx_source_compiles(" - int main() { - return __builtin_signbit(1.0) + - __builtin_signbitf(1.0f) + - __builtin_signbitl(1.0l); - } -" CCMATH_BUILTIN_SIGNBIT_SUPPORT) - -if (CCMATH_BUILTIN_SIGNBIT_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SIGNBIT) -endif () - -check_cxx_source_compiles(" - int main() { - static_assert(__builtin_signbit(-1.0)); - static_assert(__builtin_signbitf(-1.0f)); - static_assert(__builtin_signbitl(-1.0l)); - return 0; - } -" CCMATH_BUILTIN_SIGNBIT_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_SIGNBIT_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SIGNBIT_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake deleted file mode 100644 index ea1cf0e4..00000000 --- a/cmake/config/features/builtin/math/expo/CheckBuiltinExp2Support.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_exp2 is supported -check_cxx_source_compiles(" - int main() { - double x = 2.0; - float fr = __builtin_exp2f(x); - double dr = __builtin_exp2(x); - long double lr = __builtin_exp2l(x); - return 0; - } -" CCMATH_BUILTIN_EXP2_SUPPORT) - -if (CCMATH_BUILTIN_EXP2_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXP2) -endif () - -# Check if __builtin_exp2 can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 2.0; - static_assert(__builtin_exp2f(x) == __builtin_exp2f(x)); - static_assert(__builtin_exp2(x) == __builtin_exp2(x)); - static_assert(__builtin_exp2l(x) == __builtin_exp2l(x)); - return 0; - } -" CCMATH_BUILTIN_EXP2_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_EXP2_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXP2_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake deleted file mode 100644 index f46fd9e2..00000000 --- a/cmake/config/features/builtin/math/expo/CheckBuiltinExpSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_exp is supported -check_cxx_source_compiles(" - int main() { - double x = 2.0; - float fr = __builtin_expf(x); - double dr = __builtin_exp(x); - long double lr = __builtin_expl(x); - return 0; - } -" CCMATH_BUILTIN_EXP_SUPPORT) - -if (CCMATH_BUILTIN_EXP_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXP) -endif () - -# Check if __builtin_exp can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 2.0; - static_assert(__builtin_expf(x) == __builtin_expf(x)); - static_assert(__builtin_exp(x) == __builtin_exp(x)); - static_assert(__builtin_expl(x) == __builtin_expl(x)); - return 0; - } -" CCMATH_BUILTIN_EXP_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_EXP_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXP_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake deleted file mode 100644 index 7c476660..00000000 --- a/cmake/config/features/builtin/math/expo/CheckBuiltinExpm1Support.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_expm1 is supported -check_cxx_source_compiles(" - int main() { - double x = 2.0; - float fr = __builtin_expm1f(x); - double dr = __builtin_expm1(x); - long double lr = __builtin_expm1l(x); - return 0; - } -" CCMATH_BUILTIN_EXPM1_SUPPORT) - -if (CCMATH_BUILTIN_EXPM1_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXPM1) -endif () - -# Check if __builtin_expm1 can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 2.0; - static_assert(__builtin_expm1f(x) == __builtin_expm1f(x)); - static_assert(__builtin_expm1(x) == __builtin_expm1(x)); - static_assert(__builtin_expm1l(x) == __builtin_expm1l(x)); - return 0; - } -" CCMATH_BUILTIN_EXPM1_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_EXPM1_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_EXPM1_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake deleted file mode 100644 index 443f5bc9..00000000 --- a/cmake/config/features/builtin/math/expo/CheckBuiltinLog10Support.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_log10 is supported -check_cxx_source_compiles(" - int main() { - double x = 2.0; - float fr = __builtin_log10f(x); - double dr = __builtin_log10(x); - long double lr = __builtin_log10l(x); - return 0; - } -" CCMATH_BUILTIN_LOG10_SUPPORT) - -if (CCMATH_BUILTIN_LOG10_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG10) -endif () - -# Check if __builtin_log10 can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 2.0; - static_assert(__builtin_log10f(x) == __builtin_log10f(x)); - static_assert(__builtin_log10(x) == __builtin_log10(x)); - static_assert(__builtin_log10l(x) == __builtin_log10l(x)); - return 0; - } -" CCMATH_BUILTIN_LOG10_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_LOG10_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG10_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake deleted file mode 100644 index c946b720..00000000 --- a/cmake/config/features/builtin/math/expo/CheckBuiltinLog1pSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_log1p is supported -check_cxx_source_compiles(" - int main() { - double x = 2.0; - float fr = __builtin_log1pf(x); - double dr = __builtin_log1p(x); - long double lr = __builtin_log1pl(x); - return 0; - } -" CCMATH_BUILTIN_LOG1P_SUPPORT) - -if (CCMATH_BUILTIN_LOG1P_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG1P) -endif () - -# Check if __builtin_log1p can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 2.0; - static_assert(__builtin_log1pf(x) == __builtin_log1pf(x)); - static_assert(__builtin_log1p(x) == __builtin_log1p(x)); - static_assert(__builtin_log1pl(x) == __builtin_log1pl(x)); - return 0; - } -" CCMATH_BUILTIN_LOG1P_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_LOG1P_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG1P_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake deleted file mode 100644 index 8ce1ab09..00000000 --- a/cmake/config/features/builtin/math/expo/CheckBuiltinLog2Support.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_log2 is supported -check_cxx_source_compiles(" - int main() { - double x = 2.0; - float fr = __builtin_log2f(x); - double dr = __builtin_log2(x); - long double lr = __builtin_log2l(x); - return 0; - } -" CCMATH_BUILTIN_LOG2_SUPPORT) - -if (CCMATH_BUILTIN_LOG2_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG2) -endif () - -# Check if __builtin_log2 can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 2.0; - static_assert(__builtin_log2f(x) == __builtin_log2f(x)); - static_assert(__builtin_log2(x) == __builtin_log2(x)); - static_assert(__builtin_log2l(x) == __builtin_log2l(x)); - return 0; - } -" CCMATH_BUILTIN_LOG2_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_LOG2_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG2_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake b/cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake deleted file mode 100644 index 1cd9781a..00000000 --- a/cmake/config/features/builtin/math/expo/CheckBuiltinLogSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_log is supported -check_cxx_source_compiles(" - int main() { - double x = 2.0; - float fr = __builtin_logf(x); - double dr = __builtin_log(x); - long double lr = __builtin_logl(x); - return 0; - } -" CCMATH_BUILTIN_LOG_SUPPORT) - -if (CCMATH_BUILTIN_LOG_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG) -endif () - -# Check if __builtin_log can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 2.0; - static_assert(__builtin_logf(x) == __builtin_logf(x)); - static_assert(__builtin_log(x) == __builtin_log(x)); - static_assert(__builtin_logl(x) == __builtin_logl(x)); - return 0; - } -" CCMATH_BUILTIN_LOG_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_LOG_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_LOG_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake deleted file mode 100644 index e3932c69..00000000 --- a/cmake/config/features/builtin/math/fmanip/CheckBuiltinCopysignSupport.cmake +++ /dev/null @@ -1,26 +0,0 @@ -include(CheckCXXSourceCompiles) - -check_cxx_source_compiles(" - int main() { - return __builtin_copysign(1.0, -1.0) + - __builtin_copysignf(1.0f, -1.0f) + - __builtin_copysignl(1.0l, -1.0l); - } -" CCMATH_BUILTIN_COPYSIGN_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) -endif () - -check_cxx_source_compiles(" - int main() { - static_assert(__builtin_copysign(1.0, -1.0) == -1.0); - static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); - static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); - return 0; - } -" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake deleted file mode 100644 index e3932c69..00000000 --- a/cmake/config/features/builtin/math/fmanip/CheckBuiltinFrexpSupport.cmake +++ /dev/null @@ -1,26 +0,0 @@ -include(CheckCXXSourceCompiles) - -check_cxx_source_compiles(" - int main() { - return __builtin_copysign(1.0, -1.0) + - __builtin_copysignf(1.0f, -1.0f) + - __builtin_copysignl(1.0l, -1.0l); - } -" CCMATH_BUILTIN_COPYSIGN_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) -endif () - -check_cxx_source_compiles(" - int main() { - static_assert(__builtin_copysign(1.0, -1.0) == -1.0); - static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); - static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); - return 0; - } -" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake deleted file mode 100644 index e3932c69..00000000 --- a/cmake/config/features/builtin/math/fmanip/CheckBuiltinIlogbSupport.cmake +++ /dev/null @@ -1,26 +0,0 @@ -include(CheckCXXSourceCompiles) - -check_cxx_source_compiles(" - int main() { - return __builtin_copysign(1.0, -1.0) + - __builtin_copysignf(1.0f, -1.0f) + - __builtin_copysignl(1.0l, -1.0l); - } -" CCMATH_BUILTIN_COPYSIGN_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) -endif () - -check_cxx_source_compiles(" - int main() { - static_assert(__builtin_copysign(1.0, -1.0) == -1.0); - static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); - static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); - return 0; - } -" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake deleted file mode 100644 index e3932c69..00000000 --- a/cmake/config/features/builtin/math/fmanip/CheckBuiltinLdexpSupport.cmake +++ /dev/null @@ -1,26 +0,0 @@ -include(CheckCXXSourceCompiles) - -check_cxx_source_compiles(" - int main() { - return __builtin_copysign(1.0, -1.0) + - __builtin_copysignf(1.0f, -1.0f) + - __builtin_copysignl(1.0l, -1.0l); - } -" CCMATH_BUILTIN_COPYSIGN_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) -endif () - -check_cxx_source_compiles(" - int main() { - static_assert(__builtin_copysign(1.0, -1.0) == -1.0); - static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); - static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); - return 0; - } -" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake deleted file mode 100644 index e3932c69..00000000 --- a/cmake/config/features/builtin/math/fmanip/CheckBuiltinLogbSupport.cmake +++ /dev/null @@ -1,26 +0,0 @@ -include(CheckCXXSourceCompiles) - -check_cxx_source_compiles(" - int main() { - return __builtin_copysign(1.0, -1.0) + - __builtin_copysignf(1.0f, -1.0f) + - __builtin_copysignl(1.0l, -1.0l); - } -" CCMATH_BUILTIN_COPYSIGN_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) -endif () - -check_cxx_source_compiles(" - int main() { - static_assert(__builtin_copysign(1.0, -1.0) == -1.0); - static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); - static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); - return 0; - } -" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake deleted file mode 100644 index e3932c69..00000000 --- a/cmake/config/features/builtin/math/fmanip/CheckBuiltinModfSupport.cmake +++ /dev/null @@ -1,26 +0,0 @@ -include(CheckCXXSourceCompiles) - -check_cxx_source_compiles(" - int main() { - return __builtin_copysign(1.0, -1.0) + - __builtin_copysignf(1.0f, -1.0f) + - __builtin_copysignl(1.0l, -1.0l); - } -" CCMATH_BUILTIN_COPYSIGN_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN) -endif () - -check_cxx_source_compiles(" - int main() { - static_assert(__builtin_copysign(1.0, -1.0) == -1.0); - static_assert(__builtin_copysignf(1.0f, -1.0f) == -1.0f); - static_assert(__builtin_copysignl(1.0l, -1.0l) == -1.0l); - return 0; - } -" CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_COPYSIGN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COPYSIGN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake b/cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake deleted file mode 100644 index d727c3eb..00000000 --- a/cmake/config/features/builtin/math/fmanip/CheckBuiltinScalbnSupport.cmake +++ /dev/null @@ -1,3 +0,0 @@ -include(CheckCXXSourceCompiles) - -# TODO: For now I'm not implementing checks for scalbn as checking it for constexpr is a little trickier. diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake deleted file mode 100644 index 16dde682..00000000 --- a/cmake/config/features/builtin/math/hyper/CheckBuiltinAcoshSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_acosh is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_acoshf(x); - double dr = __builtin_acosh(x); - long double lr = __builtin_acoshl(x); - return 0; - } -" CCMATH_BUILTIN_ACOSH_SUPPORT) - -if (CCMATH_BUILTIN_ACOSH_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ACOSH) -endif () - -# Check if __builtin_acosh can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_acoshf(x) == __builtin_acoshf(x)); - static_assert(__builtin_acosh(x) == __builtin_acosh(x)); - static_assert(__builtin_acoshl(x) == __builtin_acoshl(x)); - return 0; - } -" CCMATH_BUILTIN_ACOSH_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_ACOSH_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ACOSH_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake deleted file mode 100644 index 89280eb7..00000000 --- a/cmake/config/features/builtin/math/hyper/CheckBuiltinAsinhSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_asinh is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_asinhf(x); - double dr = __builtin_asinh(x); - long double lr = __builtin_asinhl(x); - return 0; - } -" CCMATH_BUILTIN_ASINH_SUPPORT) - -if (CCMATH_BUILTIN_ASINH_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ASINH) -endif () - -# Check if __builtin_asinh can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_asinhf(x) == __builtin_asinhf(x)); - static_assert(__builtin_asinh(x) == __builtin_asinh(x)); - static_assert(__builtin_asinhl(x) == __builtin_asinhl(x)); - return 0; - } -" CCMATH_BUILTIN_ASINH_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_ASINH_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ASINH_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake deleted file mode 100644 index 6b6b4151..00000000 --- a/cmake/config/features/builtin/math/hyper/CheckBuiltinAtanhSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_atanh is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_atanhf(x); - double dr = __builtin_atanh(x); - long double lr = __builtin_atanhl(x); - return 0; - } -" CCMATH_BUILTIN_ATANH_SUPPORT) - -if (CCMATH_BUILTIN_ATANH_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATANH) -endif () - -# Check if __builtin_atanh can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_atanhf(x) == __builtin_atanhf(x)); - static_assert(__builtin_atanh(x) == __builtin_atanh(x)); - static_assert(__builtin_atanhl(x) == __builtin_atanhl(x)); - return 0; - } -" CCMATH_BUILTIN_ATANH_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_ATANH_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATANH_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake deleted file mode 100644 index e063a2ab..00000000 --- a/cmake/config/features/builtin/math/hyper/CheckBuiltinCoshSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_cosh is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_coshf(x); - double dr = __builtin_cosh(x); - long double lr = __builtin_coshl(x); - return 0; - } -" CCMATH_BUILTIN_COSH_SUPPORT) - -if (CCMATH_BUILTIN_COSH_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COSH) -endif () - -# Check if __builtin_cosh can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_coshf(x) == __builtin_coshf(x)); - static_assert(__builtin_cosh(x) == __builtin_cosh(x)); - static_assert(__builtin_coshl(x) == __builtin_coshl(x)); - return 0; - } -" CCMATH_BUILTIN_COSH_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_COSH_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COSH_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake deleted file mode 100644 index 3f8faf4f..00000000 --- a/cmake/config/features/builtin/math/hyper/CheckBuiltinSinhSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_sinh is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_sinhf(x); - double dr = __builtin_sinh(x); - long double lr = __builtin_sinhl(x); - return 0; - } -" CCMATH_BUILTIN_SINH_SUPPORT) - -if (CCMATH_BUILTIN_SINH_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SINH) -endif () - -# Check if __builtin_sinh can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_sinhf(x) == __builtin_sinhf(x)); - static_assert(__builtin_sinh(x) == __builtin_sinh(x)); - static_assert(__builtin_sinhl(x) == __builtin_sinhl(x)); - return 0; - } -" CCMATH_BUILTIN_SINH_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_SINH_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SINH_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake b/cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake deleted file mode 100644 index 36abaac5..00000000 --- a/cmake/config/features/builtin/math/hyper/CheckBuiltinTanhSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_tanh is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_tanhf(x); - double dr = __builtin_tanh(x); - long double lr = __builtin_tanhl(x); - return 0; - } -" CCMATH_BUILTIN_TANH_SUPPORT) - -if (CCMATH_BUILTIN_TANH_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_TANH) -endif () - -# Check if __builtin_tanh can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_tanhf(x) == __builtin_tanhf(x)); - static_assert(__builtin_tanh(x) == __builtin_tanh(x)); - static_assert(__builtin_tanhl(x) == __builtin_tanhl(x)); - return 0; - } -" CCMATH_BUILTIN_TANH_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_TANH_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_TANH_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake b/cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake deleted file mode 100644 index 239f1a55..00000000 --- a/cmake/config/features/builtin/math/power/CheckBuiltinCbrtSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_cbrt is supported -check_cxx_source_compiles(" - int main() { - double x = 2.0; - float fr = __builtin_cbrtf(x); - double dr = __builtin_cbrt(x); - long double lr = __builtin_cbrtl(x); - return 0; - } -" CCMATH_BUILTIN_CBRT_SUPPORT) - -if (CCMATH_BUILTIN_CBRT_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_CBRT) -endif () - -# Check if __builtin_cbrt can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 2.0; - static_assert(__builtin_cbrtf(x) == __builtin_cbrtf(x)); - static_assert(__builtin_cbrt(x) == __builtin_cbrt(x)); - static_assert(__builtin_cbrtl(x) == __builtin_cbrtl(x)); - return 0; - } -" CCMATH_BUILTIN_CBRT_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_CBRT_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_CBRT_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake b/cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake deleted file mode 100644 index f1e260f8..00000000 --- a/cmake/config/features/builtin/math/power/CheckBuiltinHypotSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_hypot is supported -check_cxx_source_compiles(" - int main() { - double x = 3.0, y = 4.0; - float fr = __builtin_hypotf(x, y); - double dr = __builtin_hypot(x, y); - long double lr = __builtin_hypotl(x, y); - return 0; - } -" CCMATH_BUILTIN_HYPOT_SUPPORT) - -if (CCMATH_BUILTIN_HYPOT_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_HYPOT) -endif () - -# Check if __builtin_hypot can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 3.0, y = 4.0; - static_assert(__builtin_hypotf(x, y) == __builtin_hypotf(x, y)); - static_assert(__builtin_hypot(x, y) == __builtin_hypot(x, y)); - static_assert(__builtin_hypotl(x, y) == __builtin_hypotl(x, y)); - return 0; - } -" CCMATH_BUILTIN_HYPOT_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_HYPOT_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_HYPOT_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake b/cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake deleted file mode 100644 index 1ed9178a..00000000 --- a/cmake/config/features/builtin/math/power/CheckBuiltinPowSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_pow is supported -check_cxx_source_compiles(" - int main() { - double x = 3.0, y = 2.0; - float fr = __builtin_powf(x, y); - double dr = __builtin_pow(x, y); - long double lr = __builtin_powl(x, y); - return 0; - } -" CCMATH_BUILTIN_POW_SUPPORT) - -if (CCMATH_BUILTIN_POW_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_POW) -endif () - -# Check if __builtin_pow can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 3.0, y = 2.0; - static_assert(__builtin_powf(x, y) == __builtin_powf(x, y)); - static_assert(__builtin_pow(x, y) == __builtin_pow(x, y)); - static_assert(__builtin_powl(x, y) == __builtin_powl(x, y)); - return 0; - } -" CCMATH_BUILTIN_POW_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_POW_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_POW_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake b/cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake deleted file mode 100644 index 4f24e011..00000000 --- a/cmake/config/features/builtin/math/power/CheckBuiltinSqrtSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_sqrt is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_sqrtf(x); - double dr = __builtin_sqrt(x); - long double lr = __builtin_sqrtl(x); - return 0; - } -" CCMATH_BUILTIN_SQRT_SUPPORT) - -if (CCMATH_BUILTIN_SQRT_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SQRT) -endif () - -# Check if __builtin_sqrt can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_sqrtf(x) == __builtin_sqrtf(x)); - static_assert(__builtin_sqrt(x) == __builtin_sqrt(x)); - static_assert(__builtin_sqrtl(x) == __builtin_sqrtl(x)); - return 0; - } -" CCMATH_BUILTIN_SQRT_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_SQRT_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SQRT_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake deleted file mode 100644 index ee1a7d48..00000000 --- a/cmake/config/features/builtin/math/trig/CheckBuiltinAcosSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_acos is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_acosf(x); - double dr = __builtin_acos(x); - long double lr = __builtin_acosl(x); - return 0; - } -" CCMATH_BUILTIN_ACOS_SUPPORT) - -if (CCMATH_BUILTIN_ACOS_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ACOS) -endif () - -# Check if __builtin_acos can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_acosf(x) == __builtin_acosf(x)); - static_assert(__builtin_acos(x) == __builtin_acos(x)); - static_assert(__builtin_acosl(x) == __builtin_acosl(x)); - return 0; - } -" CCMATH_BUILTIN_ACOS_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_ACOS_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ACOS_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake deleted file mode 100644 index 1391625c..00000000 --- a/cmake/config/features/builtin/math/trig/CheckBuiltinAsinSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_asin is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_asinf(x); - double dr = __builtin_asin(x); - long double lr = __builtin_asinl(x); - return 0; - } -" CCMATH_BUILTIN_ASIN_SUPPORT) - -if (CCMATH_BUILTIN_ASIN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ASIN) -endif () - -# Check if __builtin_asin can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_asinf(x) == __builtin_asinf(x)); - static_assert(__builtin_asin(x) == __builtin_asin(x)); - static_assert(__builtin_asinl(x) == __builtin_asinl(x)); - return 0; - } -" CCMATH_BUILTIN_ASIN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_ASIN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ASIN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake deleted file mode 100644 index 635ce981..00000000 --- a/cmake/config/features/builtin/math/trig/CheckBuiltinAtan2Support.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_atan2 is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0, y = 2.0; - float fr = __builtin_atan2f(x, y); - double dr = __builtin_atan2(x, y); - long double lr = __builtin_atan2l(x, y); - return 0; - } -" CCMATH_BUILTIN_ATAN2_SUPPORT) - -if (CCMATH_BUILTIN_ATAN2_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATAN2) -endif () - -# Check if __builtin_atan2 can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0, y = 2.0; - static_assert(__builtin_atan2f(x, y) == __builtin_atan2f(x, y)); - static_assert(__builtin_atan2(x, y) == __builtin_atan2(x, y)); - static_assert(__builtin_atan2l(x, y) == __builtin_atan2l(x, y)); - return 0; - } -" CCMATH_BUILTIN_ATAN2_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_ATAN2_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATAN2_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake deleted file mode 100644 index 1a4140de..00000000 --- a/cmake/config/features/builtin/math/trig/CheckBuiltinAtanSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_atan is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_atanf(x); - double dr = __builtin_atan(x); - long double lr = __builtin_atanl(x); - return 0; - } -" CCMATH_BUILTIN_ATAN_SUPPORT) - -if (CCMATH_BUILTIN_ATAN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATAN) -endif () - -# Check if __builtin_atan can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_atanf(x) == __builtin_atanf(x)); - static_assert(__builtin_atan(x) == __builtin_atan(x)); - static_assert(__builtin_atanl(x) == __builtin_atanl(x)); - return 0; - } -" CCMATH_BUILTIN_ATAN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_ATAN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_ATAN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake deleted file mode 100644 index b926d21f..00000000 --- a/cmake/config/features/builtin/math/trig/CheckBuiltinCosSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_cos is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_cosf(x); - double dr = __builtin_cos(x); - long double lr = __builtin_cosl(x); - return 0; - } -" CCMATH_BUILTIN_COS_SUPPORT) - -if (CCMATH_BUILTIN_COS_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COS) -endif () - -# Check if __builtin_cos can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_cosf(x) == __builtin_cosf(x)); - static_assert(__builtin_cos(x) == __builtin_cos(x)); - static_assert(__builtin_cosl(x) == __builtin_cosl(x)); - return 0; - } -" CCMATH_BUILTIN_COS_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_COS_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_COS_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake deleted file mode 100644 index 459ebb26..00000000 --- a/cmake/config/features/builtin/math/trig/CheckBuiltinSinSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_sin is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_sinf(x); - double dr = __builtin_sin(x); - long double lr = __builtin_sinl(x); - return 0; - } -" CCMATH_BUILTIN_SIN_SUPPORT) - -if (CCMATH_BUILTIN_SIN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SIN) -endif () - -# Check if __builtin_sin can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_sinf(x) == __builtin_sinf(x)); - static_assert(__builtin_sin(x) == __builtin_sin(x)); - static_assert(__builtin_sinl(x) == __builtin_sinl(x)); - return 0; - } -" CCMATH_BUILTIN_SIN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_SIN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_SIN_CONSTEXPR) -endif () diff --git a/cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake b/cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake deleted file mode 100644 index 3f6b77b6..00000000 --- a/cmake/config/features/builtin/math/trig/CheckBuiltinTanSupport.cmake +++ /dev/null @@ -1,31 +0,0 @@ -include(CheckCXXSourceCompiles) - -# Check if __builtin_tan is supported -check_cxx_source_compiles(" - int main() { - double x = 4.0; - float fr = __builtin_tanf(x); - double dr = __builtin_tan(x); - long double lr = __builtin_tanl(x); - return 0; - } -" CCMATH_BUILTIN_TAN_SUPPORT) - -if (CCMATH_BUILTIN_TAN_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_TAN) -endif () - -# Check if __builtin_tan can be used as a constexpr in C++17 -check_cxx_source_compiles(" - int main() { - constexpr double x = 4.0; - static_assert(__builtin_tanf(x) == __builtin_tanf(x)); - static_assert(__builtin_tan(x) == __builtin_tan(x)); - static_assert(__builtin_tanl(x) == __builtin_tanl(x)); - return 0; - } -" CCMATH_BUILTIN_TAN_CONSTEXPR_SUPPORT) - -if (CCMATH_BUILTIN_TAN_CONSTEXPR_SUPPORT) - add_compile_definitions(CCM_CONFIG_HAS_BUILTIN_TAN_CONSTEXPR) -endif () From 388e6807c5a2f0b2cd00068e7e33b80f1a7523a5 Mon Sep 17 00:00:00 2001 From: Ian Date: Sun, 29 Dec 2024 21:00:46 -0500 Subject: [PATCH 101/102] Finalize fma Signed-off-by: Ian --- .../math/generic/builtins/basic/fma.hpp | 47 ++++++++++------ .../ccmath/internal/support/multiply_add.hpp | 55 +++++++------------ 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/include/ccmath/internal/math/generic/builtins/basic/fma.hpp b/include/ccmath/internal/math/generic/builtins/basic/fma.hpp index 5f57916f..a4f27ca1 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fma.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fma.hpp @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMA -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMA -#endif + #endif #endif namespace ccm::builtin @@ -36,6 +36,14 @@ namespace ccm::builtin #else false; #endif + + template + inline constexpr bool has_fma = + #if defined(__builtin_fma) || defined(__builtin_fmaf) || defined(__builtin_fmal) + is_valid_builtin_type; + #else + false; + #endif // clang-format on /** @@ -46,21 +54,28 @@ namespace ccm::builtin * This is thanks to taking advantage of ADL. */ template - constexpr auto fma(T x, T y, T z) - -> std::enable_if_t, T> + constexpr auto fma(T x, T y, T z) -> std::enable_if_t, T> + { + if constexpr (std::is_same_v) { return __builtin_fmaf(x, y, z); } + if constexpr (std::is_same_v) { return __builtin_fma(x, y, z); } + if constexpr (std::is_same_v) { return __builtin_fmal(x, y, z); } + // This should never be reached + return T{}; + } + + /** + * Wrapper for constexpr __builtin_fma. + * This should be used internally and always be wrapped in an if constexpr statement. + * It exists only to allow for usage of __builtin_fma without triggering a compiler error + * when the compiler does not support it. + * This is thanks to taking advantage of ADL. + */ + template + auto fma(T x, T y, T z) -> std::enable_if_t, T> { - if constexpr (std::is_same_v) - { - return __builtin_fmaf(x, y, z); - } - if constexpr (std::is_same_v) - { - return __builtin_fma(x, y, z); - } - if constexpr (std::is_same_v) - { - return __builtin_fmal(x, y, z); - } + if constexpr (std::is_same_v) { return __builtin_fmaf(x, y, z); } + if constexpr (std::is_same_v) { return __builtin_fma(x, y, z); } + if constexpr (std::is_same_v) { return __builtin_fmal(x, y, z); } // This should never be reached return T{}; } diff --git a/include/ccmath/internal/support/multiply_add.hpp b/include/ccmath/internal/support/multiply_add.hpp index c819bcfb..307f3732 100644 --- a/include/ccmath/internal/support/multiply_add.hpp +++ b/include/ccmath/internal/support/multiply_add.hpp @@ -10,8 +10,7 @@ #pragma once -#include "ccmath/internal/config/builtin/fma_support.hpp" -#include "ccmath/internal/predef/has_builtin.hpp" +#include "ccmath/internal/math/generic/builtins/basic/fma.hpp" #include "ccmath/internal/support/is_constant_evaluated.hpp" #include @@ -23,48 +22,32 @@ namespace ccm::support template constexpr std::enable_if_t<(sizeof(T) > sizeof(void *)), T> multiply_add(const T & x, const T & y, const T & z) { -#if defined(CCMATH_HAS_CONSTEXPR_BUILTIN_FMA) - if constexpr (std::is_same_v) { return __builtin_fmaf(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fma(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fmal(x, y, z); } - - return static_cast(__builtin_fmal(x, y, z)); -#elif CCM_HAS_BUILTIN(__builtin_fma) // If we don't have constexpr FMA, but we have a non-constexpr FMA, use that when not in constexpr context. - if (is_constant_evaluated()) + if constexpr (ccm::builtin::has_constexpr_fma) { return ccm::builtin::fma(x, y, z); } + else if constexpr (ccm::builtin::has_fma) { - return x * y + z; // We can only hope the compiler optimizes this. - } + if (is_constant_evaluated()) + { + return (x * y) + z; // We can only hope the compiler optimizes this. + } - if constexpr (std::is_same_v) { return __builtin_fmaf(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fma(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fmal(x, y, z); } - -#else - return x * y + z; // If we don't have FMA, just do the multiply and add and hope the compiler optimizes it. -#endif + return ccm::builtin::fma(x, y, z); + } + else { return (x * y) + z; } } template constexpr std::enable_if_t<(sizeof(T) <= sizeof(void *)), T> multiply_add(T x, T y, T z) { -#if defined(CCMATH_HAS_CONSTEXPR_BUILTIN_FMA) - if constexpr (std::is_same_v) { return __builtin_fmaf(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fma(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fmal(x, y, z); } - - return static_cast(__builtin_fmal(x, y, z)); -#elif CCM_HAS_BUILTIN(__builtin_fma) // If we don't have constexpr FMA, but we have a non-constexpr FMA, use that when not in constexpr context. - if (is_constant_evaluated()) + if constexpr (ccm::builtin::has_constexpr_fma) { return ccm::builtin::fma(x, y, z); } + else if constexpr (ccm::builtin::has_fma) { - return x * y + z; // We can only hope the compiler optimizes this. - } + if (is_constant_evaluated()) + { + return (x * y) + z; // We can only hope the compiler optimizes this. + } - if constexpr (std::is_same_v) { return __builtin_fmaf(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fma(x, y, z); } - if constexpr (std::is_same_v) { return __builtin_fmal(x, y, z); } - -#else - return x * y + z; -#endif + return ccm::builtin::fma(x, y, z); + } + else { return (x * y) + z; } } } // namespace ccm::support From 60b433d751fb592289f8b0bb3f5741bc8d9cd05b Mon Sep 17 00:00:00 2001 From: Ian Date: Mon, 30 Dec 2024 16:09:50 -0500 Subject: [PATCH 102/102] Update comparison functions to be more standard conforming Signed-off-by: Ian --- include/ccmath/math/compare/isgreater.hpp | 19 ++++++++----------- .../ccmath/math/compare/isgreaterequal.hpp | 15 ++++++++------- include/ccmath/math/compare/isless.hpp | 18 ++++++++---------- include/ccmath/math/compare/islessequal.hpp | 18 ++++++++---------- include/ccmath/math/compare/islessgreater.hpp | 18 ++++++++---------- include/ccmath/math/compare/isunordered.hpp | 8 ++------ 6 files changed, 42 insertions(+), 54 deletions(-) diff --git a/include/ccmath/math/compare/isgreater.hpp b/include/ccmath/math/compare/isgreater.hpp index 103fd278..54ea8bc0 100644 --- a/include/ccmath/math/compare/isgreater.hpp +++ b/include/ccmath/math/compare/isgreater.hpp @@ -13,7 +13,7 @@ #include #include "ccmath/internal/math/generic/builtins/compare/isgreater.hpp" - +#include "ccmath/math/compare/isunordered.hpp" namespace ccm { @@ -24,29 +24,26 @@ namespace ccm * @param y A floating-point or integer value. * @return true if the first argument is greater than the second, false otherwise. */ - template + template , bool> = true> constexpr bool isgreater(T x, T y) noexcept { if constexpr (ccm::builtin::has_constexpr_isgreater) { return ccm::builtin::isgreater(x, y); } - else - { - return x > y; - } + else { return !ccm::isunordered(x, y) && (x > y); } } /** * @brief Checks if the first argument is greater than the second. - * @tparam T Type of the left-hand side. - * @tparam U Type of the right-hand side. + * @tparam Arithmetic1 Arithmetic type of the left-hand side. + * @tparam Arithmetic2 Arithmetic type of the right-hand side. * @param x Value of the left-hand side of the comparison. * @param y Value of the right-hand side of the comparison. * @return true if the first argument is greater than the second, false otherwise. */ - template - constexpr bool isgreater(T x, U y) noexcept + template && std::is_arithmetic_v, bool> = true> + constexpr bool isgreater(Arithmetic1 x, Arithmetic2 y) noexcept { // Find the common type of the two arguments - using shared_type = std::common_type_t; + using shared_type = std::common_type_t; // Then cast the arguments to the common type and call the single argument version return static_cast(isgreater(static_cast(x), static_cast(y))); diff --git a/include/ccmath/math/compare/isgreaterequal.hpp b/include/ccmath/math/compare/isgreaterequal.hpp index 3c2aa2ab..5cbbe920 100644 --- a/include/ccmath/math/compare/isgreaterequal.hpp +++ b/include/ccmath/math/compare/isgreaterequal.hpp @@ -11,6 +11,7 @@ #pragma once #include "ccmath/internal/math/generic/builtins/compare/isgreaterequal.hpp" +#include "ccmath/math/compare/isunordered.hpp" #include @@ -23,29 +24,29 @@ namespace ccm * @param y A floating-point or integer value. * @return true if the first argument is greater than or equal to the second, false otherwise. */ - template + template , bool> = true> constexpr bool isgreaterequal(T x, T y) noexcept { if constexpr (ccm::builtin::has_constexpr_isgreaterequal) { return ccm::builtin::isgreaterequal(x, y); } else { - return x >= y; + return !ccm::isunordered(x,y) && (x >= y); } } /** * @brief Checks if the first argument is greater than or equal to the second. - * @tparam T Type of the left-hand side. - * @tparam U Type of the right-hand side. + * @tparam Arithmetic1 Arithmetic type of the left-hand side. + * @tparam Arithmetic2 Arithmetic type of the right-hand side. * @param x Value of the left-hand side of the comparison. * @param y Value of the right-hand side of the comparison. * @return true if the first argument is greater than or equal to the second, false otherwise. */ - template - constexpr bool isgreaterequal(T x, U y) noexcept + template && std::is_arithmetic_v, bool> = true> + constexpr bool isgreaterequal(Arithmetic1 x, Arithmetic2 y) noexcept { // Find the common type of the two arguments - using shared_type = std::common_type_t; + using shared_type = std::common_type_t; // Then cast the arguments to the common type and call the single argument version return static_cast(isgreaterequal(static_cast(x), static_cast(y))); diff --git a/include/ccmath/math/compare/isless.hpp b/include/ccmath/math/compare/isless.hpp index c4de9816..4d4832b1 100644 --- a/include/ccmath/math/compare/isless.hpp +++ b/include/ccmath/math/compare/isless.hpp @@ -11,6 +11,7 @@ #pragma once #include "ccmath/internal/math/generic/builtins/compare/isless.hpp" +#include "ccmath/math/compare/isunordered.hpp" #include @@ -23,29 +24,26 @@ namespace ccm * @param y A floating-point or integer value. * @return true if the first argument is less than the second, false otherwise. */ - template + template , bool> = true> constexpr bool isless(T x, T y) noexcept { if constexpr (ccm::builtin::has_constexpr_isless) { return ccm::builtin::isless(x, y); } - else - { - return x < y; - } + else { return !ccm::isunordered(x, y) && (x < y); } } /** * @brief Checks if the first argument is less than the second. - * @tparam T Type of the left-hand side. - * @tparam U Type of the right-hand side. + * @tparam Arithmetic1 Arithmetic type of the left-hand side. + * @tparam Arithmetic2 Arithmetic type of the right-hand side. * @param x Value of the left-hand side of the comparison. * @param y Value of the right-hand side of the comparison. * @return true if the first argument is less than the second, false otherwise. */ - template - constexpr bool isless(T x, U y) noexcept + template && std::is_arithmetic_v, bool> = true> + constexpr bool isless(Arithmetic1 x, Arithmetic2 y) noexcept { // Find the common type of the two arguments - using shared_type = std::common_type_t; + using shared_type = std::common_type_t; // Then cast the arguments to the common type and call the single argument version return static_cast(isless(static_cast(x), static_cast(y))); diff --git a/include/ccmath/math/compare/islessequal.hpp b/include/ccmath/math/compare/islessequal.hpp index 75829ac0..03504a1c 100644 --- a/include/ccmath/math/compare/islessequal.hpp +++ b/include/ccmath/math/compare/islessequal.hpp @@ -11,6 +11,7 @@ #pragma once #include "ccmath/internal/math/generic/builtins/compare/islessequal.hpp" +#include "ccmath/math/compare/isunordered.hpp" #include @@ -23,29 +24,26 @@ namespace ccm * @param y A floating-point or integer value. * @return true if the first argument is less than or equal to the second, false otherwise. */ - template + template , bool> = true> constexpr bool islessequal(T x, T y) noexcept { if constexpr (ccm::builtin::has_constexpr_islessequal) { return ccm::builtin::islessequal(x, y); } - else - { - return x <= y; - } + else { return !ccm::isunordered(x, y) && (x <= y); } } /** * @brief Checks if the first argument is less than or equal to the second. - * @tparam T Type of the left-hand side. - * @tparam U Type of the right-hand side. + * @tparam Arithmetic1 Arithmetic type of the left-hand side. + * @tparam Arithmetic2 Arithmetic type of the right-hand side. * @param x Value of the left-hand side of the comparison. * @param y Value of the right-hand side of the comparison. * @return true if the first argument is less than or equal to the second, false otherwise. */ - template - constexpr bool islessequal(T x, U y) noexcept + template && std::is_arithmetic_v, bool> = true> + constexpr bool islessequal(Arithmetic1 x, Arithmetic2 y) noexcept { // Find the common type of the two arguments - using shared_type = std::common_type_t; + using shared_type = std::common_type_t; // Then cast the arguments to the common type and call the single argument version return static_cast(islessequal(static_cast(x), static_cast(y))); diff --git a/include/ccmath/math/compare/islessgreater.hpp b/include/ccmath/math/compare/islessgreater.hpp index 860b2a64..55971d63 100644 --- a/include/ccmath/math/compare/islessgreater.hpp +++ b/include/ccmath/math/compare/islessgreater.hpp @@ -11,6 +11,7 @@ #pragma once #include "ccmath/internal/math/generic/builtins/compare/islessgreater.hpp" +#include "ccmath/math/compare/isunordered.hpp" #include @@ -23,28 +24,25 @@ namespace ccm * @param y A floating-point or integer value. * @return true if the first argument is less than the second or greater than the second, false otherwise. */ - template + template , bool> = true> constexpr bool islessgreater(T x, T y) noexcept { if constexpr (ccm::builtin::has_constexpr_islessgreater) { return ccm::builtin::islessgreater(x, y); } - else - { - return x < y || x > y; - } + else { return !ccm::isunordered(x, y) && (x < y || x > y); } } /** * @brief Checks if the first argument is less than the second or greater than the second. - * @tparam T Type of the left-hand side. - * @tparam U Type of the right-hand side. + * @tparam Arithmetic1 Arithmetic type of the left-hand side. + * @tparam Arithmetic2 Arithmetic type of the right-hand side. * @param x Value of the left-hand side of the comparison. * @param y Value of the right-hand side of the comparison. * @return true if the first argument is less than the second or greater than the second, false otherwise. */ - template - constexpr bool islessgreater(T x, U y) noexcept + template && std::is_arithmetic_v, bool> = true> + constexpr bool islessgreater(Arithmetic1 x, Arithmetic2 y) noexcept { - using shared_type = std::common_type_t; + using shared_type = std::common_type_t; return static_cast(islessgreater(static_cast(x), static_cast(y))); } } // namespace ccm diff --git a/include/ccmath/math/compare/isunordered.hpp b/include/ccmath/math/compare/isunordered.hpp index 1a0dd1c1..439f598c 100644 --- a/include/ccmath/math/compare/isunordered.hpp +++ b/include/ccmath/math/compare/isunordered.hpp @@ -10,9 +10,8 @@ #pragma once -#include "ccmath/math/compare/isnan.hpp" #include "ccmath/internal/math/generic/builtins/compare/isunordered.hpp" - +#include "ccmath/math/compare/isnan.hpp" #include @@ -29,10 +28,7 @@ namespace ccm constexpr bool isunordered(T x, T y) noexcept { if constexpr (ccm::builtin::has_constexpr_isunordered) { return ccm::builtin::isunordered(x, y); } - else - { - return ccm::isnan(x) || ccm::isnan(y); - } + else { return ccm::isnan(x) || ccm::isnan(y); } } /**