From ec4d1266372eed522edc083aacd050b17dcc4301 Mon Sep 17 00:00:00 2001 From: sal Date: Tue, 31 Dec 2024 21:14:59 -0500 Subject: [PATCH 1/2] cmake updates 1. replaced the guts of the previous deps script with the vcpkg submodule and configs. the deps should now just download, unpack, and build during configuration 2. made some adjustments to cmakepresets.json - not sure if the old structure was favored for others or if the simpler inheritance and overall hierarchy is easier the way it is now (all use ninja so more can be shared) 3.. added NINJA_STATUS env variable (in cmakepresets) to output compilation times and a more detailed progress message 4. reformatted all cmake files so the indentation / whitespace / styling in general is consistent. tried to keep things as close to original style as possible 5. added cmake script that will automatically invoke vcpkg (and update/init the submodule if it hasn't been yet) for everything involving deps management to be automatic. vcpkg.json was also added so it can be used in maniest mode (locallized install in the submodule rather than using a global install) 6. added a clang-format scrtipt that will iterator over every source file and reformat it during configuration. this project has some big files so this should be improved by using `ninja -d explain` to detect which files have updated timestamps since previous configuration and only reformat those. a filter is included now, but mostly just as an example. 7. updated clang-format to try and avoid as many formatting changes as possible in the codebase. (those will come in the next commit) 8. added general cmake utils script to output all library variables worth showing as well as compiler / linker paths, version numbers, etc to make it easy to verify the state of configuration matches what is expected. 9. moved the c++ standard version and compile commands output option out of cmakepresets since those won't change and should probably stay consistent for all when building the library. 10. added a command to copy compile_commands.json from the binary dir into the source dir so IDEs have a better time using it for intellisense. on windows this requires symlink permissions (enable developer mode in windows 10/11 oe can also update your machine's group policy to give yourself permissions necessary for it. it only needs to be updated once, but even still, that probably means this is better off just being copied instead of symlinked. --- .clang-format | 23 +- .gitmodules | 3 + CMakeLists.txt | 296 ++++++----- CMakePresets.json | 860 ++++++++++++++++---------------- benchmark/CMakeLists.txt | 41 +- cmake/config/UserOptions.cmake | 73 ++- cmake/helpers/CMakeUtils.cmake | 141 ++++++ cmake/helpers/ClangFormat.cmake | 42 ++ cmake/helpers/VCPkgInit.cmake | 62 +++ extern/vcpkg | 1 + test/CMakeLists.txt | 183 +++---- thirdparty/CMakeLists.txt | 100 ++-- vcpkg.json | 13 + 13 files changed, 1076 insertions(+), 762 deletions(-) create mode 100644 .gitmodules create mode 100644 cmake/helpers/CMakeUtils.cmake create mode 100644 cmake/helpers/ClangFormat.cmake create mode 100644 cmake/helpers/VCPkgInit.cmake create mode 160000 extern/vcpkg create mode 100644 vcpkg.json diff --git a/.clang-format b/.clang-format index 0de2cb50..3baa5ecf 100644 --- a/.clang-format +++ b/.clang-format @@ -14,7 +14,7 @@ AllowShortLambdasOnASingleLine: All AllowShortBlocksOnASingleLine: Always AllowShortIfStatementsOnASingleLine: WithoutElse AllowShortLoopsOnASingleLine: true -AlwaysBreakTemplateDeclarations: Yes +AlwaysBreakTemplateDeclarations: true BraceWrapping: AfterCaseLabel: true AfterClass: true @@ -34,28 +34,39 @@ BraceWrapping: SplitEmptyRecord: true SplitEmptyNamespace: true BreakAfterAttributes: Never +BreakAfterReturnType: Automatic BreakBeforeBraces: Allman ColumnLimit: 160 CompactNamespaces: false FixNamespaceComments: true IndentPPDirectives: BeforeHash IndentWidth: 4 +IncludeBlocks: Regroup IncludeCategories: # Headers in <> with .h extension. - Regex: '<([A-Za-z0-9\/-_])+\.h>' Priority: 10 + SortPriority: 3 # Headers in <> with .hpp extension. - Regex: '<([A-Za-z0-9\/-_])+\.hpp>' - Priority: 20 + Priority: 10 + SortPriority: 2 # Headers in <> without an extension. - Regex: '<([A-Za-z0-9\/-_])+>' - Priority: 30 + Priority: 10 + # all library includes wrapped in "" + # main header should be the topmost + - Regex: '".*"' + SortPriority: 1 +IncludeIsMainRegex: '""' +IncludeIsMainSourceRegex: '""' NamespaceIndentation: All PointerAlignment: Middle +ReflowComments: true +PPIndentWidth: 4 SpaceAfterTemplateKeyword: true +PenaltyReturnTypeOnItsOwnLine: 1 +PenaltyBreakOpenParenthesis: 250 Standard: c++20 TabWidth: 4 UseTab: Always - - - diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..de4fa46c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "extern/vcpkg"] + path = extern/vcpkg + url = https://github.com/microsoft/vcpkg diff --git a/CMakeLists.txt b/CMakeLists.txt index 86b668ab..4a4273f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,83 +1,102 @@ cmake_minimum_required(VERSION 3.18.0) - set(CCMATH_BUILD_VERSION 0.2.0) -project( - ccmath - VERSION ${CCMATH_BUILD_VERSION} - DESCRIPTION "A C++17 Compile Time Library" - HOMEPAGE_URL "https://github.com/Rinzii/ccmath" - LANGUAGES CXX +list(APPEND CMAKE_MODULE_PATH + "${CMAKE_MODULE_PATH}" + "${CMAKE_SOURCE_DIR}/cmake" + "${CMAKE_SOURCE_DIR}/cmake/helpers" + "${CMAKE_SOURCE_DIR}/cmake/config" + "${CMAKE_SOURCE_DIR}/cmake/config/features" ) -# Determine if this is the root project or a subproject. +include(VCPkgInit) + +project(ccmath + VERSION ${CCMATH_BUILD_VERSION} + DESCRIPTION "A C++17 Compile Time Library" + HOMEPAGE_URL "https://github.com/Rinzii/ccmath" + LANGUAGES CXX +) + +# 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 () + set(is_root_project ON) +endif() + if (NOT CCMATH_SOURCE_DIR) - set(CCMATH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -endif () + set(CCMATH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +endif() # 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) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_COLOR_DIAGNOSTICS ON) +set(CMAKE_DIRECTORY_LABELS ON) message(STATUS "CCMath: Version: ${PROJECT_VERSION}") -# -# User-facing options -# -include(cmake/config/UserOptions.cmake) # To see the options, look at this file +# |==========================================| +# | User-facing options | +# |==========================================| + +# To see the options, look at this +# file in: cmake/config/ +include(UserOptions) add_library(${PROJECT_NAME}-compile-options INTERFACE) -add_library(${PROJECT_NAME}::${PROJECT_NAME}-compile-options ALIAS ${PROJECT_NAME}-compile-options) +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 - /W4 - /permissive- - /Zc:__cplusplus - /D_ENABLE_EXTENDED_ALIGNED_STORAGE - /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR - /EHsc - ) - # Only define NOMINMAX on Windows platforms - if (WIN32) - target_compile_definitions(${PROJECT_NAME}-compile-options INTERFACE NOMINMAX) - endif() +# |==========================================| +# | Compiler Flags and Conditions | +# |==========================================| - if (CCMATH_STRICT_WARNINGS) - target_compile_options(${PROJECT_NAME}-compile-options INTERFACE /WX) - endif() +if (MSVC) + # MSVC-specific options + target_compile_options(${PROJECT_NAME}-compile-options INTERFACE + /W4 + /permissive- + /Zc:__cplusplus + /D_ENABLE_EXTENDED_ALIGNED_STORAGE + /D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR + /EHsc + ) + # 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() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "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 - -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 + # 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 + -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 ) if (CCMATH_STRICT_WARNINGS) - target_compile_options(${PROJECT_NAME}-compile-options INTERFACE -Werror=return-type) - endif () + 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 @@ -86,118 +105,141 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" # endif() else() - message(WARNING "CCMath: Unknown compiler. No specific flags applied.") + 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/helpers/CcmAddHeaders.cmake) +include(CcmAddHeaders) -# Add public headers through a directory-level CMakeLists that sets variables, etc. +# Add public headers through a directory- +# level CMakeLists that sets variables, etc. add_subdirectory(include/ccmath) +# |==========================================| +# | CCMath configuration and detection files | +# |==========================================| -# CCMath configuration and detection files -include(cmake/config/features/GetAllSupportedFeatures.cmake) - +include(GetAllSupportedFeatures) # Ensure proper include directories for consumers target_include_directories(${PROJECT_NAME} INTERFACE - $ - $ + $ + $ ) target_link_libraries(${PROJECT_NAME} INTERFACE - ${PROJECT_NAME}::${PROJECT_NAME}-compile-options + ${PROJECT_NAME}::${PROJECT_NAME}-compile-options ) if (CCMATH_ENABLE_RUNTIME_SIMD) - target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_USE_RT_SIMD) -endif () + target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_USE_RT_SIMD) +endif() if (NOT CCMATH_ENABLE_USER_DEFINED_OPTIMIZATION_MACROS) - target_compile_definitions(${PROJECT_NAME} INTERFACE - $<$:CCM_CONFIG_DEBUG> - $<$:CCM_CONFIG_OPTIMIZE> - $<$:CCM_CONFIG_AGGRESSIVELY_OPTIMIZE> - $<$:CCM_CONFIG_MINSIZE> - ) -endif () + target_compile_definitions(${PROJECT_NAME} INTERFACE + $<$:CCM_CONFIG_DEBUG> + $<$:CCM_CONFIG_OPTIMIZE> + $<$:CCM_CONFIG_AGGRESSIVELY_OPTIMIZE> + $<$:CCM_CONFIG_MINSIZE> + ) +endif() if (CCMATH_DISABLE_ERRNO) - target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_DISABLE_ERRNO) -endif () + target_compile_definitions(${PROJECT_NAME} INTERFACE CCM_CONFIG_DISABLE_ERRNO) +endif() + +# |==========================================| +# | Generate version header | +# |==========================================| -# 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) - # 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 () + # 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) - add_subdirectory(example) -endif () + message("Configuring ccmath examples...") + add_subdirectory(example) +endif() if (CCMATH_BUILD_BENCHMARKS) - add_subdirectory(benchmark) -endif () + message("Configuring ccmath benchmarks...") + add_subdirectory(benchmark) +endif() if (CCMATH_BUILD_TESTS) - enable_testing() - add_subdirectory(test) -endif () + message("Configuring ccmath test...") + enable_testing() + add_subdirectory(test) +endif() # Installation and Packaging if (CCMATH_INSTALL) - include(GNUInstallDirs) - include(CMakePackageConfigHelpers) - - install(TARGETS - ${PROJECT_NAME} - ${PROJECT_NAME}-compile-options - EXPORT ${PROJECT_NAME}-targets - ) - - 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}" - ) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + + install(TARGETS + ${PROJECT_NAME} + ${PROJECT_NAME}-compile-options + EXPORT ${PROJECT_NAME}-targets + ) + + 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}" + ) + + # 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" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + ) +endif() - 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}" - ) +execute_process( + COMMAND + ${CMAKE_COMMAND} -E create_symlink + ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_SOURCE_DIR}/compile_commands.json +) - # Write a version file for strict version checking - write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" - COMPATIBILITY SameMajorVersion - ) +if (CCMATH_ENABLE_AUTOFORMAT_SRC) + include(ClangFormat) +endif() - install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" - ) -endif () +include(CMakeUtils) +print_project_variables() diff --git a/CMakePresets.json b/CMakePresets.json index 39f27bef..cf79d781 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,437 +1,427 @@ { - "version": 2, - "cmakeMinimumRequired": { - "major": 3, - "minor": 18, - "patch": 0 - }, - "configurePresets": [ - { - "name": "base", - "description": "Base configuration using Ninja Multi-config", - "generator": "Ninja Multi-Config", - "hidden": true, - "binaryDir": "${sourceDir}/out/build/ninja/${presetName}", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", - "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}", - "CMAKE_CONFIGURATION_TYPES": "Debug;Release;RelWithDebInfo;MinSizeRel", - "CMAKE_CXX_STANDARD": "17" - } - }, - { - "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_CXX_STANDARD": "17" - } - }, - { - "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_CXX_STANDARD": "17" - } - }, - { - "name": "Debug", - "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "Release", - "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - }, - { - "name": "MinSizeRel", - "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "MinSizeRel" - } - }, - { - "name": "RelWithDebInfo", - "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - } - }, - { - "name": "ccache", - "hidden": true, - "cacheVariables": { - "CMAKE_C_COMPILER_LAUNCHER": "ccache", - "CMAKE_CXX_COMPILER_LAUNCHER": "ccache" - } - }, - { - "name": "gcc", - "hidden": true, - "cacheVariables": { - "CMAKE_C_COMPILER": "gcc", - "CMAKE_CXX_COMPILER": "g++" - } - }, - { - "name": "clang", - "hidden": true, - "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++" - } - }, - { - "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": "msvc", - "hidden": true, - "cacheVariables": { - "CMAKE_C_COMPILER": "cl", - "CMAKE_CXX_COMPILER": "cl" - } - }, - { - "name": "msvc-clang", - "hidden": true, - "cacheVariables": { - "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 (Release)" - }, - { - "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 (Release)" - }, - { - "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 + Release" - }, - { - "name": "vs22-debug", - "inherits": [ - "base-vs22", - "Debug" - ], - "description": "VS2022 + Debug" - }, - { - "name": "vs22-release", - "inherits": [ - "base-vs22", - "Release" - ], - "description": "VS2022 + Release" - }, - { - "name": "vs22-clang-debug", - "inherits": [ - "base-vs22", - "msvc-clang", - "Debug" - ], - "description": "VS2022 + clang-cl (Debug)" - } - ], - "buildPresets": [ - { - "name": "build-ninja-gcc-debug", - "configurePreset": "ninja-gcc-debug", - "configuration": "Debug", - "targets": [ - "all" - ] - }, - { - "name": "build-ninja-gcc-release", - "configurePreset": "ninja-gcc-release", - "configuration": "Release", - "targets": [ - "all" - ] - }, - { - "name": "build-ninja-gcc-ccache-debug", - "configurePreset": "ninja-gcc-ccache-debug", - "configuration": "Debug", - "targets": [ - "all" - ] - }, - { - "name": "build-ninja-clang-debug", - "configurePreset": "ninja-clang-debug", - "configuration": "Debug", - "targets": [ - "all" - ] - }, - { - "name": "build-ninja-clang-release", - "configurePreset": "ninja-clang-release", - "configuration": "Release", - "targets": [ - "all" - ] - }, - { - "name": "build-ninja-clang-minsizerel", - "configurePreset": "ninja-clang-minsizerel", - "configuration": "MinSizeRel", - "targets": [ - "all" - ] - }, - { - "name": "build-ninja-clang-libcpp-relwithdebinfo", - "configurePreset": "ninja-clang-libcpp-relwithdebinfo", - "configuration": "RelWithDebInfo", - "targets": [ - "all" - ] - }, - { - "name": "build-ninja-intel-relwithdebinfo", - "configurePreset": "ninja-intel-relwithdebinfo", - "configuration": "RelWithDebInfo", - "targets": [ - "all" - ] - }, - { - "name": "build-vs19-debug", - "configurePreset": "vs19-debug", - "configuration": "Debug", - "targets": [ - "ALL_BUILD" - ] - }, - { - "name": "build-vs19-release", - "configurePreset": "vs19-release", - "configuration": "Release", - "targets": [ - "ALL_BUILD" - ] - }, - { - "name": "build-vs22-debug", - "configurePreset": "vs22-debug", - "configuration": "Debug", - "targets": [ - "ALL_BUILD" - ] - }, - { - "name": "build-vs22-release", - "configurePreset": "vs22-release", - "configuration": "Release", - "targets": [ - "ALL_BUILD" - ] - }, - { - "name": "build-vs22-clang-debug", - "configurePreset": "vs22-clang-debug", - "configuration": "Debug", - "targets": [ - "ALL_BUILD" - ] - } - ], - "testPresets": [ - { - "name": "test-ninja-gcc-debug", - "configurePreset": "ninja-gcc-debug", - "configuration": "Debug", - "inheritConfigureEnvironment": true - }, - { - "name": "test-ninja-gcc-release", - "configurePreset": "ninja-gcc-release", - "configuration": "Release", - "inheritConfigureEnvironment": true - }, - { - "name": "test-ninja-gcc-ccache-debug", - "configurePreset": "ninja-gcc-ccache-debug", - "configuration": "Debug", - "inheritConfigureEnvironment": true - }, - { - "name": "test-ninja-clang-debug", - "configurePreset": "ninja-clang-debug", - "configuration": "Debug", - "inheritConfigureEnvironment": true - }, - { - "name": "test-ninja-clang-release", - "configurePreset": "ninja-clang-release", - "configuration": "Release", - "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": "Release", - "inheritConfigureEnvironment": true - }, - { - "name": "test-vs22-debug", - "configurePreset": "vs22-debug", - "configuration": "Debug", - "inheritConfigureEnvironment": true - }, - { - "name": "test-vs22-release", - "configurePreset": "vs22-release", - "configuration": "Release", - "inheritConfigureEnvironment": true - }, - { - "name": "test-vs22-clang-debug", - "configurePreset": "vs22-clang-debug", - "configuration": "Debug", - "inheritConfigureEnvironment": true - } - ] + "version": 4, + "cmakeMinimumRequired": { + "major": 3, + "minor": 18, + "patch": 0 + }, + "configurePresets": [ + { + "name": "base", + "hidden": true, + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "toolchainFile": "${sourceDir}/extern/vcpkg/scripts/buildsystems/vcpkg.cmake", + "description": "Base configuration using Ninja Multi-Config", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + }, + "environment": { + "NINJA_STATUS": "%p [%es] (%f/%t) -" + } + }, + { + "name": "debug", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "release", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "minsizerel", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "MinSizeRel" + } + }, + { + "name": "relwithdebinfo", + "hidden": true, + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "ccache", + "hidden": true, + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_C_COMPILER_LAUNCHER": "ccache", + "CMAKE_CXX_COMPILER_LAUNCHER": "ccache" + } + }, + { + "name": "gcc", + "hidden": true, + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + } + }, + { + "name": "clang", + "hidden": true, + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } + }, + { + "name": "clang-libcpp", + "hidden": true, + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_CXX_FLAGS": "-stdlib=libc++", + "CMAKE_EXE_LINKER_FLAGS": "-lc++abi" + } + }, + { + "name": "msvc", + "hidden": true, + "inherits": [ + "base" + ], + "generator": "Ninja", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl", + "CCMATH_BUILD_TESTS": true, + "CCMATH_BUILD_EXAMPLES": true, + "CCMATH_BUILD_BENCHMARKS": true, + "CCM_BENCH_BASIC": true, + "CCM_BENCH_COMPARE": true, + "CCM_BENCH_POWER": true, + "CCM_BENCH_NEAREST": true, + "CCM_BENCH_ALL": true + } + }, + { + "name": "msvc-clang", + "hidden": true, + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" + } + }, + { + "name": "intel", + "hidden": true, + "inherits": [ + "base" + ], + "cacheVariables": { + "CMAKE_C_COMPILER": "icx", + "CMAKE_CXX_COMPILER": "icpx" + } + }, + { + "name": "ninja-gcc-debug", + "displayName": "Ninja Multi-config | GCC (Debug)", + "inherits": [ + "gcc", + "debug" + ] + }, + { + "name": "ninja-gcc-release", + "displayName": "Ninja Multi-config | GCC (Release)", + "inherits": [ + "gcc", + "release" + ] + }, + { + "name": "ninja-gcc-ccache-debug", + "displayName": "Ninja Multi-config | GCC | ccache (Debug)", + "inherits": [ + "ccache", + "gcc", + "debug" + ] + }, + { + "name": "ninja-clang-debug", + "displayName": "Ninja Multi-config | Clang (Debug)", + "inherits": [ + "clang", + "debug" + ] + }, + { + "name": "ninja-clang-release", + "displayName": "Ninja Multi-config | Clang (Release)", + "inherits": [ + "clang", + "release" + ] + }, + { + "name": "ninja-clang-minsizerel", + "displayName": "Ninja Multi-config | Clang (MinSizeRel)", + "inherits": [ + "clang", + "minsizerel" + ] + }, + { + "name": "ninja-clang-libcpp-relwithdebinfo", + "displayName": "Ninja | Clang | libc++ (RelWithDebInfo)", + "inherits": [ + "clang-libcpp", + "relwithdebinfo" + ] + }, + { + "name": "ninja-intel-relwithdebinfo", + "displayName": "Ninja | Intel (RelWithDebInfo)", + "inherits": [ + "intel", + "relwithdebinfo" + ] + }, + { + "name": "vs19-debug", + "displayName": "VS2019 | Debug", + "inherits": [ + "msvc", + "debug" + ] + }, + { + "name": "vs19-release", + "displayName": "VS2019 | Release", + "inherits": [ + "msvc", + "release" + ] + }, + { + "name": "vs22-debug", + "displayName": "VS2022 | Debug", + "inherits": [ + "msvc", + "debug" + ] + }, + { + "name": "vs22-release", + "displayName": "VS2022 | Release", + "inherits": [ + "msvc", + "release" + ] + }, + { + "name": "vs22-clang-debug", + "displayName": "VS2022 | ClangCL (Debug)", + "inherits": [ + "msvc-clang", + "debug" + ] + } + ], + "buildPresets": [ + { + "name": "build-ninja-gcc-debug", + "configurePreset": "ninja-gcc-debug", + "configuration": "Debug", + "targets": [ + "all" + ] + }, + { + "name": "build-ninja-gcc-release", + "configurePreset": "ninja-gcc-release", + "configuration": "Release", + "targets": [ + "all" + ] + }, + { + "name": "build-ninja-gcc-ccache-debug", + "configurePreset": "ninja-gcc-ccache-debug", + "configuration": "Debug", + "targets": [ + "all" + ] + }, + { + "name": "build-ninja-clang-debug", + "configurePreset": "ninja-clang-debug", + "configuration": "Debug", + "targets": [ + "all" + ] + }, + { + "name": "build-ninja-clang-release", + "configurePreset": "ninja-clang-release", + "configuration": "Release", + "targets": [ + "all" + ] + }, + { + "name": "build-ninja-clang-minsizerel", + "configurePreset": "ninja-clang-minsizerel", + "configuration": "MinSizeRel", + "targets": [ + "all" + ] + }, + { + "name": "build-ninja-clang-libcpp-relwithdebinfo", + "configurePreset": "ninja-clang-libcpp-relwithdebinfo", + "configuration": "RelWithDebInfo", + "targets": [ + "all" + ] + }, + { + "name": "build-ninja-intel-relwithdebinfo", + "configurePreset": "ninja-intel-relwithdebinfo", + "configuration": "RelWithDebInfo", + "targets": [ + "all" + ] + }, + { + "name": "build-vs19-debug", + "configurePreset": "vs19-debug", + "configuration": "Debug", + "targets": [ + "all" + ] + }, + { + "name": "build-vs19-release", + "configurePreset": "vs19-release", + "configuration": "Release", + "targets": [ + "all" + ] + }, + { + "name": "build-vs22-debug", + "configurePreset": "vs22-debug", + "configuration": "Debug", + "targets": [ + "all" + ] + }, + { + "name": "build-vs22-release", + "configurePreset": "vs22-release", + "configuration": "Release", + "targets": [ + "all" + ] + }, + { + "name": "build-vs22-clang-debug", + "configurePreset": "vs22-clang-debug", + "configuration": "Debug", + "targets": [ + "all" + ] + } + ], + "testPresets": [ + { + "name": "test-ninja-gcc-debug", + "configurePreset": "ninja-gcc-debug", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-gcc-release", + "configurePreset": "ninja-gcc-release", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-gcc-ccache-debug", + "configurePreset": "ninja-gcc-ccache-debug", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-clang-debug", + "configurePreset": "ninja-clang-debug", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-clang-release", + "configurePreset": "ninja-clang-release", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-clang-minsizerel", + "configurePreset": "ninja-clang-minsizerel", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-clang-libcpp-relwithdebinfo", + "configurePreset": "ninja-clang-libcpp-relwithdebinfo", + "inheritConfigureEnvironment": true + }, + { + "name": "test-ninja-intel-relwithdebinfo", + "configurePreset": "ninja-intel-relwithdebinfo", + "inheritConfigureEnvironment": true + }, + { + "name": "test-vs19-debug", + "configurePreset": "vs19-debug", + "inheritConfigureEnvironment": true + }, + { + "name": "test-vs19-release", + "configurePreset": "vs19-release", + "inheritConfigureEnvironment": true + }, + { + "name": "test-vs22-debug", + "configurePreset": "vs22-debug", + "inheritConfigureEnvironment": true + }, + { + "name": "test-vs22-release", + "configurePreset": "vs22-release", + "inheritConfigureEnvironment": true + }, + { + "name": "test-vs22-clang-debug", + "configurePreset": "vs22-clang-debug", + "inheritConfigureEnvironment": true + } + ] } diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 3fab4770..bfd0f81e 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -4,39 +4,48 @@ cmake_minimum_required(VERSION 3.18 FATAL_ERROR) project(ccmath-benchmark) -option(CCM_BENCH_BASIC "Enable basic benchmarks" OFF) +option(CCM_BENCH_BASIC "Enable basic benchmarks" OFF) option(CCM_BENCH_COMPARE "Enable comparison benchmarks" OFF) -option(CCM_BENCH_POWER "Enable power benchmarks" OFF) -option(CCM_BENCH_NEAREST "Enable nearest benchmarks" ON) - -option(CCM_BENCH_ALL "Enable all benchmarks" OFF) +option(CCM_BENCH_POWER "Enable power benchmarks" OFF) +option(CCM_BENCH_NEAREST "Enable nearest benchmarks" ON) +option(CCM_BENCH_ALL "Enable all benchmarks" OFF) # Force cmake to use Release if debug is detected if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_BUILD_TYPE "Release" ON CACHE STRING "Build type" FORCE) + message(status "ccmath : Changing build type from Debug to Release for benchmarks") + set(CMAKE_BUILD_TYPE "Release" ON CACHE STRING "Build type" FORCE) endif() if(NOT TARGET ccmath) - find_package(ccmath CONFIG REQUIRED) + message(info "ccmath : Searching or ccmath package") + find_package(ccmath CONFIG REQUIRED) 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) - target_compile_features(ccm_benchmark_${function_name} PRIVATE cxx_std_17) + find_package(PkgConfig REQUIRED) + find_package(absl CONFIG REQUIRED) + find_package(re2 CONFIG REQUIRED) + find_package(GTest CONFIG REQUIRED) + find_package(benchmark CONFIG REQUIRED) + + add_executable(ccm_benchmark_${function_name} helpers/randomizers.hpp ${source_files}) + target_link_libraries(ccm_benchmark_${function_name} PRIVATE ccmath::ccmath benchmark::benchmark) + target_compile_features(ccm_benchmark_${function_name} PRIVATE cxx_std_17) endfunction() - if(CCM_BENCH_BASIC) - add_benchmark(abs benchmarks/basic/abs.bench.cpp benchmarks/basic/abs.bench.hpp) - add_benchmark(fdim benchmarks/basic/fdim.bench.cpp benchmarks/basic/fdim.bench.hpp) - add_benchmark(fma benchmarks/basic/fma.bench.cpp benchmarks/basic/fma.bench.hpp) + message(info "ccmath : Adding basic benchmarks") + add_benchmark( abs benchmarks/basic/abs.bench.cpp benchmarks/basic/abs.bench.hpp ) + add_benchmark( fdim benchmarks/basic/fdim.bench.cpp benchmarks/basic/fdim.bench.hpp ) + add_benchmark( fma benchmarks/basic/fma.bench.cpp benchmarks/basic/fma.bench.hpp ) endif () if(CCM_BENCH_POWER) - add_benchmark(sqrt benchmarks/power/sqrt.bench.cpp benchmarks/power/sqrt.bench.hpp) + message(info "ccmath : Adding power benchmarks") + add_benchmark(sqrt benchmarks/power/sqrt.bench.cpp benchmarks/power/sqrt.bench.hpp) endif () if(CCM_BENCH_NEAREST) - #add_benchmark(trunc benchmarks/nearest/trunc.bench.cpp benchmarks/nearest/trunc.bench.hpp) + message(status "ccmath : Adding nearest benchmarks") + #add_benchmark(trunc benchmarks/nearest/trunc.bench.cpp benchmarks/nearest/trunc.bench.hpp) endif () diff --git a/cmake/config/UserOptions.cmake b/cmake/config/UserOptions.cmake index ba91db49..a52c3c3b 100644 --- a/cmake/config/UserOptions.cmake +++ b/cmake/config/UserOptions.cmake @@ -2,79 +2,98 @@ # 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}) +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}) +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_FIND_GTEST_PACKAGE + "Enable finding of gtest package" + ON) # CCMATH_BUILD_BENCHMARKS: # Enable building of ccmath benchmarks. If OFF, benchmarks are skipped. -option(CCMATH_BUILD_BENCHMARKS "Build ccmath benchmarks" ${is_root_project}) +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) +# 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" + ON) # CCMATH_BUILD_EXAMPLES: # Build example code demonstrating usage of ccmath. -option(CCMATH_BUILD_EXAMPLES "Build ccmath examples" ${is_root_project}) +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. +# 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) + "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) + "Enable the extended ccmath library that adds additional methods beyond the standard" + ON) # CCMATH_DISABLE_ERRNO: -# Disable usage of errno during runtime breaking standard compliance, but may lead to faster evaluation and smaller binaries. +# 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) + "Disable the use of errno in ccmath during runtime (may lead to faster evaluations but is non-standard)" + ON) # 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) + "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) + "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) + "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) + "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) + "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}) + "Enable strict warnings and treat certain warnings as errors. May be intrusive downstream." + ${is_root_project}) + +option(CCMATH_ENABLE_AUTOFORMAT_SRC + "Enable automatic source formatting using clang-format during the ccmath configuration" + ON) diff --git a/cmake/helpers/CMakeUtils.cmake b/cmake/helpers/CMakeUtils.cmake new file mode 100644 index 00000000..a4b22683 --- /dev/null +++ b/cmake/helpers/CMakeUtils.cmake @@ -0,0 +1,141 @@ +set(GRAPHVIZ_OUTPUT OFF) +set(DEPENDENCY_DIAGNOSTICS OFF) + +function(run_active_cmake_diagnostics) + if(DEPENDENCY_DIAGNOSTICS MATCHES ON) + # prints a dependency hierarchy for all targets in project + set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE ON) + endif() + + # enabled with -D GRAPHVIZ_OUTPUT=ON + if(GRAPHVIZ_OUTPUT MATCHES ON) + # Outputs graphviz dot files and generates png images showing dependency + # relationships for top level project and all targets it contains. + # All files will be generated in src/build/graphviz_output by default. + set(GRAPHVIZ_GRAPH_NAME "Dependency tree") + add_custom_target(graphviz ALL + COMMAND ${CMAKE_COMMAND} "--graphviz=${CURRENT_CMAKE_BINARY_DIR}/graphviz_output/${PROJECT_NAME}.dot" . + WORKING_DIRECTORY ${CURRENT_CMAKE_BINARY_DIR} + ) + # Generate PNG from graphviz `${PROJECT_NAME}.dot` file... + # Note: png image graph generation requires graphviz (dot executable specifically) to be installed + execute_process( + COMMAND dot -Tpng -o "./graphviz_output/${PROJECT_NAME}.png" "./graphviz_output/${PROJECT_NAME}.dot" + WORKING_DIRECTORY "${CURRENT_CMAKE_BINARY_DIR}" + ) + endif() +endfunction(run_active_cmake_diagnostics) + +# function to output all CMAKE variables along with their +# values using a case insentive regex match +# +# examples: +# 1. print all cmake variables: +# > dump_cmake_variables(".*") +# 2. print all boolt cmake variables: +# > dump_cmake_variables("^boost.*") +function(dump_cmake_variables) + get_cmake_property(_vars VARIABLES) + list(SORT _vars) + + foreach(_var ${_vars}) + if(ARGV0) + unset(MATCHED) + + # case insenstitive match + string(TOLOWER "${ARGV0}" ARGV0_lower) + string(TOLOWER "${_var}" _var_lower) + + string(REGEX MATCH ${ARGV0_lower} MATCHED ${_var_lower}) + + if(NOT MATCHED) + continue() + endif() + endif() + + + set(_value ${${_var}}) + list(LENGTH _value _val_list_len) + if(_val_list_len GREATER 1) + message(DEBUG " [${_var}] =>") + foreach(_val ${_value}) + message(DEBUG " - ${_val}") + endforeach() + else() + message(DEBUG " [${_var}] => ${_value}") + endif() + endforeach() +endfunction() + +# prints a collection of useful C++ project configuration values +function(print_project_variables) + message(DEBUG "") + message(DEBUG "DEBUG CMake Cache Variable Dump") + message(DEBUG "=============================================") + message(DEBUG "") + dump_cmake_variables(".*") + + message(NOTICE "") + message(NOTICE "Project Configuration Settigs: ${PROJECT_NAME} v${CCMATH_BUILD_VERSION}") + message(NOTICE "=============================================") + message(NOTICE "") + message(NOTICE "Build Configuration") + message(NOTICE " CMAKE_SYSTEM_PROCESSOR:..................: " ${CMAKE_SYSTEM_PROCESSOR}) + message(NOTICE " CMAKE_HOST_SYSTEM_NAME:..................: " ${CMAKE_HOST_SYSTEM_NAME}) + message(NOTICE " CMAKE_BUILD_TYPE:........................: " ${CMAKE_BUILD_TYPE}) + message(NOTICE " CMAKE_CXX_COMPILER_ARCHITECTURE_ID:......: " ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}) + message(NOTICE " CMAKE_CXX_STANDARD:......................: " ${CMAKE_CXX_STANDARD}) + message(NOTICE " CMAKE_CXX_COMPILER_VERSION:..............: " ${CMAKE_CXX_COMPILER_VERSION}) + message(NOTICE " CMAKE_GENERATOR:.........................: " ${CMAKE_GENERATOR}) + message(NOTICE " CMAKE_VERSION:...........................: " ${CMAKE_VERSION}) + message(NOTICE " CMAKE_MINIMUM_REQUIRED_VERSION:..........: " ${CMAKE_MINIMUM_REQUIRED_VERSION}) + message(NOTICE " CMAKE_CXX_SIZEOF_DATA_PTR:...............: " ${CMAKE_CXX_SIZEOF_DATA_PTR}) + message(NOTICE " VCPKG_TARGET_TRIPLET.....................: " ${VCPKG_TARGET_TRIPLET}) + message(NOTICE " CMAKE_DEBUG_POSTFIX......................: " ${CMAKE_DEBUG_POSTFIX}) + message(NOTICE "") + message(NOTICE "CMake Paths") + message(NOTICE " CMAKE_CURRENT_SOURCE_DIR.................: " ${CMAKE_CURRENT_SOURCE_DIR}) + message(NOTICE " CMAKE_TOOLCHAIN_FILE:....................: " ${CMAKE_TOOLCHAIN_FILE}) + message(NOTICE " CMAKE_SOURCE_DIR:........................: " ${CMAKE_SOURCE_DIR}) + message(NOTICE " CMAKE_COMMAND:...........................: " ${CMAKE_COMMAND}) + message(NOTICE " CLANG_FORMAT_PROGRAM:....................: " ${CLANG_FORMAT_PROGRAM}) + message(NOTICE " CMAKE_CXX_COMPILER:......................: " ${CMAKE_CXX_COMPILER}) + message(NOTICE " CMAKE_LINKER:............................: " ${CMAKE_LINKER}) + message(NOTICE " CMAKE_BUILD_TOOL:........................: " ${CMAKE_BUILD_TOOL}) + message(NOTICE " VCPKG_PROGRAM:...........................: " ${VCPKG_PROGRAM}) + message(NOTICE " CMAKE_INSTALL_PREFIX:....................: " ${CMAKE_INSTALL_PREFIX}) + message(NOTICE " CMAKE_BINARY_DIR:........................: " ${CMAKE_BINARY_DIR}) + message(NOTICE "") + message(NOTICE "CCMath Project Options") + message(NOTICE " > General") + message(NOTICE " - CCMATH_INSTALL...........................: " ${CCMATH_INSTALL}) + message(NOTICE " - CCMATH_BUILD_TESTS:......................: " ${CCMATH_BUILD_TESTS}) + message(NOTICE " - CCMATH_FIND_GTEST_PACKAGE:...............: " ${CCMATH_FIND_GTEST_PACKAGE}) + message(NOTICE " - CCMATH_BUILD_BENCHMARKS:.................: " ${CCMATH_BUILD_BENCHMARKS}) + message(NOTICE " - CCMATH_FIND_GBENCH_PACKAGE:..............: " ${CCMATH_FIND_GBENCH_PACKAGE}) + message(NOTICE " - CCMATH_BUILD_EXAMPLES:...................: " ${CCMATH_BUILD_EXAMPLES}) + message(NOTICE " - CCMATH_ENABLE_USER_DEFINED_MACROS:.......: " ${CCMATH_ENABLE_USER_DEFINED_MACROS}) + message(NOTICE " - CCMATH_ENABLE_EXTENSIONS:................: " ${CCMATH_ENABLE_EXTENSIONS}) + message(NOTICE " - CCMATH_DISABLE_ERRNO:....................: " ${CCMATH_DISABLE_ERRNO}) + message(NOTICE " - CCMATH_ENABLE_RUNTIME_SIMD:..............: " ${CCMATH_ENABLE_RUNTIME_SIMD}) + message(NOTICE " - CCMATH_DISABLE_SVML_USAGE:...............: " ${CCMATH_DISABLE_SVML_USAGE}) + message(NOTICE " - CCMATH_DISABLE_CMAKE_FEATURE_CHECKS:.....: " ${CCMATH_DISABLE_CMAKE_FEATURE_CHECKS}) + message(NOTICE " - CCMATH_DISABLE_CMAKE_SIMD_CHECKS:........: " ${CCMATH_DISABLE_CMAKE_SIMD_CHECKS}) + message(NOTICE " - CCMATH_DISABLE_CMAKE_BUILTIN_CHECKS:.....: " ${CCMATH_DISABLE_CMAKE_BUILTIN_CHECKS}) + message(NOTICE " - CCMATH_STRICT_WARNINGS:..................: " ${CCMATH_STRICT_WARNINGS}) + message(NOTICE " - CCMATH_ENABLE_AUTOFORMAT_SRC:............: " ${CCMATH_ENABLE_AUTOFORMAT_SRC}) + message(NOTICE "") + + if (CCMATH_BUILD_BENCHMARKS) + message(NOTICE " > Benchmarks") + message(NOTICE " - CCM_BENCH_BASIC:.........................: " ${CCMATH_FIND_GTEST_PACKAGE}) + message(NOTICE " - CCM_BENCH_COMPARE:.......................: " ${CCMATH_FIND_GTEST_PACKAGE}) + message(NOTICE " - CCM_BENCH_POWER:.........................: " ${CCMATH_FIND_GTEST_PACKAGE}) + message(NOTICE " - CCM_BENCH_BASIC:.........................: " ${CCMATH_FIND_GTEST_PACKAGE}) + message(NOTICE " - CCM_BENCH_NEAREST:.......................: " ${CCMATH_FIND_GTEST_PACKAGE}) + message(NOTICE " - CCM_BENCH_ALL:...........................: " ${CCMATH_FIND_GTEST_PACKAGE}) + endif() + +endfunction(print_project_variables) + +print_project_variables() diff --git a/cmake/helpers/ClangFormat.cmake b/cmake/helpers/ClangFormat.cmake new file mode 100644 index 00000000..dfea1e09 --- /dev/null +++ b/cmake/helpers/ClangFormat.cmake @@ -0,0 +1,42 @@ +find_program(CLANG_FORMAT_PROGRAM NAMES clang-format) + +if (CLANG_FORMAT_PROGRAM) + execute_process( + COMMAND "${CLANG_FORMAT_PROGRAM}" --version + OUTPUT_VARIABLE CLANG_FORMAT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + message("Using clang-format: ${CLANG_FORMAT_PROGRAM} (${CLANG_FORMAT_VERSION})") + + file(GLOB_RECURSE + format_src_list RELATIVE + "${CMAKE_SOURCE_DIR}" + "include/*.[hc]" + "include/*.[hc]pp" + "test/*.[hc]" + "test/*.[hc]pp" + "example/*.[hc]" + "example/*.[hc]pp" + ) + + set(skip_pattern "include/ccmath/internal/math/(generic|runtime)/(func|simd)/.*") + + foreach(_src_file ${format_src_list}) + unset(MATCHED_SKIP) + + string(REGEX MATCH ${skip_pattern} MATCHED_SKIP ${_src_file}) + + if (MATCHED_SKIP) + message(" skipping => ${_src_file}") + else() + message(" formatting => ${_src_file}") + execute_process( + COMMAND "${CLANG_FORMAT_PROGRAM}" --style=file -i "${_src_file}" + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + ) + endif() + endforeach() + + unset(CLANG_FORMAT_VERSION) +endif() diff --git a/cmake/helpers/VCPkgInit.cmake b/cmake/helpers/VCPkgInit.cmake new file mode 100644 index 00000000..4ace0752 --- /dev/null +++ b/cmake/helpers/VCPkgInit.cmake @@ -0,0 +1,62 @@ +# |=======================================================================| +# | VCPKG submodule init/update | +# |=======================================================================| + +if(NOT EXISTS "${CMAKE_SOURCE_DIR}/extern/vcpkg/ports") + message(NOTICE "VCPKG package manager sources not found") + message(NOTICE "initializing/updating the vcpkg submodule...") + execute_process( + COMMAND git submodule update --init extern/vcpkg + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND_ERROR_IS_FATAL ANY + ) +endif() + +# VCPKG toolchain file +if(NOT CMAKE_TOOLCHAIN_FILE) + set(toolchain_file_path "${CMAKE_SOURCE_DIR}/extern/vcpkg/scripts/buildsystems/vcpkg.cmake") + if (EXISTS "${toolchain_file_path}") + set(CMAKE_TOOLCHAIN_FILE "${toolchain_file_path}") + else() + message(WARNING "VCPKG toolchain file not found: ${toolchain_file_path}") + endif() +endif() + +# |=======================================================================| +# | VCPKG bootstrap / initialization | +# |=======================================================================| + +if (WIN32) + set(EXECUTABLE_EXTENSION ".exe") +endif() +set(VCPKG_PROGRAM "${CMAKE_SOURCE_DIR}/extern/vcpkg/vcpkg${EXECUTABLE_EXTENSION}") + +if(EXISTS "${VCPKG_PROGRAM}") + message(NOTICE "Found VCPKG Executable: ${VCPKG_PROGRAM}") +else() + message(NOTICE "Could not find VCPKG Executable: ${VCPKG_PROGRAM}") + message(NOTICE "Calling VCPKG bootstrap scripts.") + + if(WIN32) + set(VCPKG_INSTALL_COMMAND + powershell + -c + "${CMAKE_SOURCE_DIR}/extern/vcpkg/bootstrap-vcpkg.bat" + ) + else() + set(VCPKG_INSTALL_COMMAND + bash + "${CMAKE_SOURCE_DIR}/extern/vcpkg/bootstrap-vcpkg.sh" + ) + endif() + + execute_process( + COMMAND ${VCPKG_INSTALL_COMMAND} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMAND_ERROR_IS_FATAL ANY + ) + + if(NOT EXISTS "${VCPKG_PROGRAM}") + message(FATAL_ERROR "ERROR: '${VCPKG_PROGRAM}' not found!") + endif() +endif() diff --git a/extern/vcpkg b/extern/vcpkg new file mode 160000 index 00000000..4b3b6201 --- /dev/null +++ b/extern/vcpkg @@ -0,0 +1 @@ +Subproject commit 4b3b6201414638abfcd8ef4629dfbd958985667e diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f6972ad6..f1b96d96 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,117 +4,130 @@ project(ccmath-test) if (NOT TARGET ccmath) find_package(ccmath CONFIG REQUIRED) -endif () +endif() +# should these go into the `if` above? +find_package(PkgConfig REQUIRED) +find_package(GTest CONFIG REQUIRED) +find_package(re2 CONFIG REQUIRED) 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_link_libraries(${PROJECT_NAME} PUBLIC + ccmath::ccmath + ${Abseil_LIBRARIES} + GTest::gtest + GTest::gtest_main + 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 + ccmath_test_main.cpp ) - add_executable(${PROJECT_NAME}-basic) target_sources(${PROJECT_NAME}-basic PRIVATE - basic/abs_test.cpp - basic/fdim_test.cpp - basic/fma_test.cpp - basic/fmod_test.cpp - basic/max_test.cpp - basic/min_test.cpp - basic/nan_test.cpp - basic/remainder_test.cpp - basic/remquo_test.cpp + basic/abs_test.cpp + basic/fdim_test.cpp + basic/fma_test.cpp + basic/fmod_test.cpp + basic/max_test.cpp + basic/min_test.cpp + basic/nan_test.cpp + basic/remainder_test.cpp + basic/remquo_test.cpp ) + target_link_libraries(${PROJECT_NAME}-basic PRIVATE - ccmath::test - gtest::gtest + ccmath::test + GTest::gtest + GTest::gtest_main ) add_executable(${PROJECT_NAME}-compare) target_sources(${PROJECT_NAME}-compare PRIVATE - compare/fpclassify_test.cpp - compare/isfinite_test.cpp - compare/isgreater_test.cpp - compare/isgreaterequal_test.cpp - compare/isinf_test.cpp - compare/isless_test.cpp - compare/islessequal_test.cpp - compare/islessgreater_test.cpp - compare/isnan_test.cpp - compare/isnormal_test.cpp - compare/isunordered_test.cpp - compare/signbit_test.cpp - + compare/fpclassify_test.cpp + compare/isfinite_test.cpp + compare/isgreater_test.cpp + compare/isgreaterequal_test.cpp + compare/isinf_test.cpp + compare/isless_test.cpp + compare/islessequal_test.cpp + compare/islessgreater_test.cpp + compare/isnan_test.cpp + compare/isnormal_test.cpp + compare/isunordered_test.cpp + compare/signbit_test.cpp ) + target_link_libraries(${PROJECT_NAME}-compare PRIVATE - ccmath::test - gtest::gtest + ccmath::test + GTest::gtest + GTest::gtest_main ) add_executable(${PROJECT_NAME}-exponential) target_sources(${PROJECT_NAME}-exponential PRIVATE - exponential/exp2_test.cpp - exponential/exp_test.cpp - exponential/expm1_test.cpp - exponential/log1p_test.cpp - exponential/log2_test.cpp - exponential/log10_test.cpp - exponential/log_test.cpp - - + exponential/exp2_test.cpp + exponential/exp_test.cpp + exponential/expm1_test.cpp + exponential/log1p_test.cpp + exponential/log2_test.cpp + exponential/log10_test.cpp + exponential/log_test.cpp ) + target_link_libraries(${PROJECT_NAME}-exponential PRIVATE - ccmath::test - gtest::gtest + ccmath::test + GTest::gtest + GTest::gtest_main ) add_executable(${PROJECT_NAME}-fmanip) target_sources(${PROJECT_NAME}-fmanip PRIVATE - fmanip/copysign_test.cpp - fmanip/frexp_test.cpp - fmanip/ilogb_test.cpp - fmanip/ldexp_test.cpp - fmanip/logb_test.cpp - fmanip/modf_test.cpp - fmanip/nextafter_test.cpp - fmanip/nexttoward_test.cpp - fmanip/scalbn_test.cpp + fmanip/copysign_test.cpp + fmanip/frexp_test.cpp + fmanip/ilogb_test.cpp + fmanip/ldexp_test.cpp + fmanip/logb_test.cpp + fmanip/modf_test.cpp + fmanip/nextafter_test.cpp + fmanip/nexttoward_test.cpp + fmanip/scalbn_test.cpp ) + target_link_libraries(${PROJECT_NAME}-fmanip PRIVATE - ccmath::test - gtest::gtest + ccmath::test + GTest::gtest + GTest::gtest_main ) add_executable(${PROJECT_NAME}-nearest) target_sources(${PROJECT_NAME}-nearest PRIVATE - nearest/floor_test.cpp - nearest/nearbyint_test.cpp - nearest/trunc_test.cpp + nearest/floor_test.cpp + nearest/nearbyint_test.cpp + nearest/trunc_test.cpp ) target_link_libraries(${PROJECT_NAME}-nearest PRIVATE - ccmath::test - gtest::gtest + ccmath::test + GTest::gtest + GTest::gtest_main ) add_executable(${PROJECT_NAME}-power) target_sources(${PROJECT_NAME}-power PRIVATE - power/pow_test.cpp - power/sqrt_test.cpp + power/pow_test.cpp + power/sqrt_test.cpp ) + target_link_libraries(${PROJECT_NAME}-power PRIVATE - ccmath::test - gtest::gtest + ccmath::test + GTest::gtest + GTest::gtest_main ) add_executable(${PROJECT_NAME}-misc) @@ -122,48 +135,49 @@ add_executable(${PROJECT_NAME}-misc) # This is required as std::lerp is only available in versions of C++20 or greater. if (CMAKE_CXX_STANDARD GREATER_EQUAL 20) target_sources(${PROJECT_NAME}-misc PRIVATE - misc/lerp_test_std.cpp - + misc/lerp_test_std.cpp ) -else () +else() target_sources(${PROJECT_NAME}-misc PRIVATE - misc/lerp_test_no_std.cpp + misc/lerp_test_no_std.cpp ) -endif () +endif() target_link_libraries(${PROJECT_NAME}-misc PRIVATE - ccmath::test - gtest::gtest + ccmath::test + GTest::gtest + GTest::gtest_main ) - # Tests for internal items add_executable(${PROJECT_NAME}-internal-types) target_sources(${PROJECT_NAME}-internal-types PRIVATE internal/types/big_int_test.cpp - -) -target_link_libraries(${PROJECT_NAME}-internal-types PRIVATE - ccmath::test - gtest::gtest ) +target_link_libraries( + ${PROJECT_NAME}-internal-types + PRIVATE ccmath::test + GTest::gtest + GTest::gtest_main +) if (CCMATH_OS_WINDOWS) - # For Windows: Prevent overriding the parent project's compiler/linker settings - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -endif () + # For Windows: Prevent overriding the + # parent project's compiler/linker settings + set(GTest_force_shared_crt ON CACHE BOOL "" FORCE) +endif() # Only supported compilers currently are MSVC, GNU and Clang if (CMAKE_CXX_COMPILER_ID STREQUAL MSVC) target_compile_options(${PROJECT_NAME} PUBLIC - /W4 /WX + /W4 /WX ) elseif (CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) target_compile_options(${PROJECT_NAME} PUBLIC - -Wall -Wextra -Wno-pedantic -Wno-unused-function + -Wall -Wextra -Wno-pedantic -Wno-unused-function ) -endif () +endif() add_test(NAME ${PROJECT_NAME}-basic COMMAND ${PROJECT_NAME}-basic) @@ -176,4 +190,3 @@ add_test(NAME ${PROJECT_NAME}-misc COMMAND ${PROJECT_NAME}-misc) # Internal tests add_test(NAME ${PROJECT_NAME}-internal-types COMMAND ${PROJECT_NAME}-internal-types) - diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 8dbd7aac..db7f3782 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -1,91 +1,59 @@ 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) +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") - set(HAVE_STD_REGEX ON) - endif() - set(BENCHMARK_ENABLE_TESTING NO) - FetchContent_Declare( - benchmark - GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG ${CCMATH_BENCHMARK_VERSION} - ) + 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) 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) + set(ABSL_PROPAGATE_CXX_STD ON) + set(ABSL_ENABLE_INSTALL ON) + set(GTEST_HAS_ABSL ON) - 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) + if (CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + set(HAVE_STD_REGEX ON) + endif () - if (CCMATH_FIND_GTEST_PACKAGE) - find_package(GTest REQUIRED) - else() - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG ${CCMATH_GTEST_VERSION} - ) - FetchContent_MakeAvailable(googletest) - if (NOT TARGET gtest::gtest) - add_library(gtest::gtest ALIAS gtest) + if (WIN32) + set(gtest_force_shared_crt ON) + set(gtest_disable_pthreads ON) endif() - endif() + set(BUILD_GMOCK OFF) + set(INSTALL_GTEST OFF) + set(gtest_build_samples OFF) + set(gtest_build_tests OFF) endif() -FetchContent_MakeAvailable(benchmark) - # Create the INTERFACE library add_library(${PROJECT_NAME} INTERFACE) 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) - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_options(gtest INTERFACE -Wno-everything) - endif() + find_package(PkgConfig REQUIRED) + find_package(absl CONFIG REQUIRED) + find_package(re2 CONFIG REQUIRED) + find_package(GTest CONFIG REQUIRED) + + 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::gtest INTERFACE -Wno-everything) + endif() endif() # Link Google Benchmark only if benchmarks are enabled if (CCMATH_BUILD_BENCHMARKS) - target_link_libraries(${PROJECT_NAME} INTERFACE benchmark::benchmark) + find_package(benchmark CONFIG REQUIRED) + target_link_libraries(${PROJECT_NAME} INTERFACE benchmark::benchmark) endif() - - diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..155b9df1 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "documentation": "https://github.com/microsoft/vcpkg/blob/master/docs/users/manifests.md", + "name": "roguelike", + "version": "0.1.0", + "dependencies": [ + "pkgconf", + "benchmark", + "abseil", + "gtest", + "re2" + ] +} From 84788c6d094b1cbccc89412435fa3a7ea9a01d0d Mon Sep 17 00:00:00 2001 From: sal Date: Tue, 31 Dec 2024 21:18:34 -0500 Subject: [PATCH 2/2] this entire commit is the resolution of 3 warnings that were causing the build to fail with /W4 and /WX. all other modifications were caused by running clang-format on the codebase (include, tests, examples, benchmark). the formatting changes were mostly header file resorting/regrouping, whitespace, and collapsing shorter for loops onto a single line. tried to also prevent it from doing weird things around the enable_if's (the cossts added to the config) --- example/main.cpp | 43 ++- include/ccmath/ext/clamp.hpp | 54 +-- include/ccmath/ext/cubic.hpp | 2 +- include/ccmath/ext/degrees.hpp | 8 +- include/ccmath/ext/fract.hpp | 6 +- include/ccmath/ext/lerp_smooth.hpp | 12 +- include/ccmath/ext/mix.hpp | 12 +- include/ccmath/ext/normalize.hpp | 2 +- include/ccmath/ext/ping_pong.hpp | 6 +- include/ccmath/ext/smoothstep.hpp | 30 +- .../config/arch/check_simd_support.hpp | 26 +- .../internal/config/arch/targets/aarch64.hpp | 6 +- .../internal/config/arch/targets/x86_64.hpp | 4 +- .../config/builtin/bit_cast_support.hpp | 31 +- .../config/builtin/copysign_support.hpp | 18 +- include/ccmath/internal/config/compiler.hpp | 54 ++- .../internal/config/platform/android.hpp | 6 +- .../internal/config/platform/darwin.hpp | 7 +- .../ccmath/internal/config/platform/linux.hpp | 2 +- .../internal/config/runtime_detection.hpp | 1 - .../ccmath/internal/config/type_support.hpp | 3 +- .../math/generic/builtins/basic/fdim.hpp | 24 +- .../math/generic/builtins/basic/fma.hpp | 4 +- .../math/generic/builtins/basic/fmod.hpp | 26 +- .../math/generic/builtins/basic/nan.hpp | 23 +- .../math/generic/builtins/basic/remainder.hpp | 51 +-- .../math/generic/builtins/basic/remquo.hpp | 21 +- .../generic/builtins/compare/isgreater.hpp | 8 +- .../builtins/compare/isgreaterequal.hpp | 8 +- .../math/generic/builtins/compare/isless.hpp | 8 +- .../generic/builtins/compare/islessequal.hpp | 8 +- .../builtins/compare/islessgreater.hpp | 8 +- .../generic/builtins/compare/isunordered.hpp | 51 +-- .../math/generic/builtins/expo/exp.hpp | 23 +- .../math/generic/builtins/expo/exp2.hpp | 23 +- .../math/generic/builtins/expo/expm1.hpp | 23 +- .../math/generic/builtins/expo/log.hpp | 23 +- .../math/generic/builtins/expo/log10.hpp | 23 +- .../math/generic/builtins/expo/log1p.hpp | 23 +- .../math/generic/builtins/expo/log2.hpp | 23 +- .../math/generic/builtins/fmanip/frexp.hpp | 51 +-- .../math/generic/builtins/fmanip/ilogb.hpp | 23 +- .../math/generic/builtins/fmanip/ldexp.hpp | 51 +-- .../math/generic/builtins/fmanip/logb.hpp | 23 +- .../math/generic/builtins/fmanip/modf.hpp | 51 +-- .../generic/builtins/fmanip/nextafter.hpp | 51 +-- .../generic/builtins/fmanip/nexttoward.hpp | 52 ++- .../math/generic/builtins/fmanip/scalbn.hpp | 82 ++-- .../math/generic/builtins/hyper/acosh.hpp | 23 +- .../math/generic/builtins/hyper/asinh.hpp | 23 +- .../math/generic/builtins/hyper/atanh.hpp | 23 +- .../math/generic/builtins/hyper/cosh.hpp | 23 +- .../math/generic/builtins/hyper/sinh.hpp | 23 +- .../math/generic/builtins/hyper/tanh.hpp | 23 +- .../math/generic/builtins/misc/erf.hpp | 23 +- .../math/generic/builtins/misc/erfc.hpp | 21 +- .../math/generic/builtins/misc/tgamma.hpp | 23 +- .../math/generic/builtins/nearest/floor.hpp | 23 +- .../math/generic/builtins/nearest/round.hpp | 42 +- .../math/generic/builtins/nearest/trunc.hpp | 23 +- .../math/generic/builtins/power/cbrt.hpp | 23 +- .../math/generic/builtins/power/hypot.hpp | 23 +- .../math/generic/builtins/power/pow.hpp | 23 +- .../math/generic/builtins/power/sqrt.hpp | 23 +- .../math/generic/builtins/trig/acos.hpp | 23 +- .../math/generic/builtins/trig/asin.hpp | 23 +- .../math/generic/builtins/trig/atan.hpp | 23 +- .../math/generic/builtins/trig/atan2.hpp | 23 +- .../math/generic/builtins/trig/cos.hpp | 23 +- .../math/generic/builtins/trig/sin.hpp | 23 +- .../math/generic/builtins/trig/tan.hpp | 23 +- .../math/generic/func/basic/fma_gen.hpp | 26 +- .../math/generic/func/basic/remquo_gen.hpp | 1 - .../math/generic/func/expo/exp2_gen.hpp | 26 +- .../math/generic/func/expo/exp_gen.hpp | 26 +- .../math/generic/func/expo/expm1_gen.hpp | 6 +- .../math/generic/func/expo/log10_gen.hpp | 6 +- .../math/generic/func/expo/log1p_gen.hpp | 6 +- .../math/generic/func/expo/log_gen.hpp | 13 +- .../math/generic/func/fmanip/frexp_gen.hpp | 11 +- .../math/generic/func/fmanip/ldexp_gen.hpp | 2 +- .../math/generic/func/fmanip/modf_gen.hpp | 2 +- .../math/generic/func/fmanip/scalbn_gen.hpp | 6 +- .../math/generic/func/nearest/floor_gen.hpp | 1 - .../math/generic/func/nearest/trunc_gen.hpp | 2 +- .../math/generic/func/power/pow_impl.hpp | 2 +- .../math/runtime/func/power/pow_rt.hpp | 7 +- .../ccmath/internal/math/runtime/pp/simd.hpp | 178 ++++----- .../math/runtime/simd/func/impl/avx2/pow.hpp | 1 - .../runtime/simd/func/impl/scalar/pow.hpp | 2 +- .../runtime/simd/func/impl/scalar/sqrt.hpp | 2 +- .../math/runtime/simd/func/impl/sse3/pow.hpp | 4 +- .../math/runtime/simd/func/impl/sse4/pow.hpp | 4 +- .../simd/func/impl/vector_size/sqrt.hpp | 2 +- .../internal/math/runtime/simd/func/pow.hpp | 12 +- .../math/runtime/simd/instructions/avx.hpp | 96 +++-- .../math/runtime/simd/instructions/avx2.hpp | 363 +++++++++--------- .../math/runtime/simd/instructions/neon.hpp | 73 ++-- .../math/runtime/simd/instructions/scalar.hpp | 39 +- .../math/runtime/simd/instructions/sse2.hpp | 72 ++-- .../math/runtime/simd/instructions/sse3.hpp | 69 ++-- .../math/runtime/simd/instructions/sse4.hpp | 71 ++-- .../math/runtime/simd/instructions/ssse3.hpp | 36 +- .../internal/math/runtime/simd/pack.hpp | 24 +- .../internal/math/runtime/simd/simd.hpp | 1 - .../math/runtime/simd/simd_vectorize.hpp | 2 +- .../math/runtime/simd/vector_size.hpp | 26 +- include/ccmath/internal/predef/assume.hpp | 6 +- .../predef/attributes/always_inline.hpp | 2 +- .../predef/attributes/gsl_suppress.hpp | 2 +- .../internal/predef/attributes/optnone.hpp | 1 - .../clang_compiler_suppression.hpp | 6 +- .../internal/predef/has_const_builtin.hpp | 2 +- .../predef/versioning/arm_version.hpp | 1 - include/ccmath/internal/setup.hpp | 2 - include/ccmath/internal/support/bits.hpp | 112 +++--- include/ccmath/internal/support/ctz.hpp | 10 +- include/ccmath/internal/support/endian.hpp | 8 +- .../internal/support/fenv/fenv_support.hpp | 14 +- .../internal/support/fenv/rounding_mode.hpp | 8 +- .../support/fp/directional_rounding_utils.hpp | 10 +- .../ccmath/internal/support/fp/fp_bits.hpp | 62 +-- .../internal/support/helpers/digit_to_int.hpp | 15 +- .../ccmath/internal/support/helpers/exp10.hpp | 3 +- .../internal/support/helpers/exp_helpers.hpp | 1 + .../support/helpers/fpclassify_helper.hpp | 46 +-- .../support/helpers/internal_ldexp.hpp | 4 +- .../internal/support/integer_literals.hpp | 1 - .../support/is_constant_evaluated.hpp | 8 +- .../ccmath/internal/support/math_support.hpp | 1 - include/ccmath/internal/support/poly_eval.hpp | 21 +- .../ccmath/internal/support/type_traits.hpp | 2 - include/ccmath/internal/types/big_int.hpp | 7 +- .../ccmath/internal/types/double_double.hpp | 16 +- .../ccmath/internal/types/dyadic_float.hpp | 28 +- include/ccmath/internal/types/float128.hpp | 1 - include/ccmath/internal/types/fp_types.hpp | 22 +- .../internal/types/normalized_float.hpp | 1 - include/ccmath/math/basic/fabs.hpp | 12 +- include/ccmath/math/basic/fdim.hpp | 7 +- include/ccmath/math/basic/fma.hpp | 18 +- .../math/basic/impl/nan_double_impl.hpp | 10 +- .../ccmath/math/basic/impl/nan_float_impl.hpp | 7 +- .../math/basic/impl/nan_ldouble_impl.hpp | 12 +- .../math/basic/impl/remquo_float_impl.hpp | 6 +- .../math/basic/impl/remquo_ldouble_impl.hpp | 32 +- include/ccmath/math/compare/fpclassify.hpp | 5 +- include/ccmath/math/compare/isfinite.hpp | 3 +- include/ccmath/math/compare/isgreater.hpp | 4 +- .../ccmath/math/compare/isgreaterequal.hpp | 5 +- include/ccmath/math/compare/isinf.hpp | 2 +- include/ccmath/math/compare/isnan.hpp | 1 - include/ccmath/math/compare/isnormal.hpp | 8 +- include/ccmath/math/compare/signbit.hpp | 5 +- include/ccmath/math/expo/exp.hpp | 5 +- include/ccmath/math/expo/exp2.hpp | 6 +- include/ccmath/math/expo/impl/exp2_data.hpp | 9 +- .../math/expo/impl/exp2_double_impl.hpp | 3 +- .../ccmath/math/expo/impl/exp2_float_impl.hpp | 3 +- .../ccmath/math/expo/impl/exp_double_impl.hpp | 3 +- .../ccmath/math/expo/impl/exp_float_impl.hpp | 7 +- include/ccmath/math/expo/impl/log_data.hpp | 2 +- include/ccmath/math/expo/log.hpp | 7 +- include/ccmath/math/expo/log1p.hpp | 4 +- include/ccmath/math/expo/log2.hpp | 23 +- include/ccmath/math/fmanip/copysign.hpp | 8 +- include/ccmath/math/fmanip/frexp.hpp | 12 +- .../math/fmanip/impl/modf_double_impl.hpp | 7 +- .../math/fmanip/impl/modf_float_impl.hpp | 2 +- .../math/fmanip/impl/scalbn_float_impl.hpp | 3 +- .../math/fmanip/impl/scalbn_ldouble_impl.hpp | 9 +- include/ccmath/math/fmanip/ldexp.hpp | 1 - include/ccmath/math/fmanip/modf.hpp | 12 +- include/ccmath/math/fmanip/nextafter.hpp | 3 +- include/ccmath/math/fmanip/nexttoward.hpp | 1 - include/ccmath/math/fmanip/scalbn.hpp | 3 +- include/ccmath/math/nearest/floor.hpp | 3 +- include/ccmath/math/nearest/trunc.hpp | 5 +- include/ccmath/math/power/pow.hpp | 3 +- test/basic/abs_test.cpp | 4 +- test/basic/fdim_test.cpp | 3 +- test/basic/fma_test.cpp | 3 +- test/basic/fmod_test.cpp | 40 +- test/basic/max_test.cpp | 32 +- test/basic/min_test.cpp | 5 +- test/basic/nan_test.cpp | 19 +- test/basic/remainder_test.cpp | 22 +- test/basic/remquo_test.cpp | 39 +- test/ccmath_test_main.cpp | 2 +- test/compare/fpclassify_test.cpp | 35 +- test/compare/isfinite_test.cpp | 4 +- test/compare/isgreater_test.cpp | 5 +- test/compare/isgreaterequal_test.cpp | 6 +- test/compare/isinf_test.cpp | 4 +- test/compare/isless_test.cpp | 6 +- test/compare/islessequal_test.cpp | 6 +- test/compare/islessgreater_test.cpp | 17 +- test/compare/isnan_test.cpp | 6 +- test/compare/isnormal_test.cpp | 18 +- test/compare/isunordered_test.cpp | 21 +- test/compare/signbit_test.cpp | 13 +- test/exponential/exp2_test.cpp | 8 +- test/exponential/exp_test.cpp | 14 +- test/exponential/expm1_test.cpp | 5 +- test/exponential/log10_test.cpp | 5 +- test/exponential/log1p_test.cpp | 5 +- test/exponential/log2_test.cpp | 24 +- test/exponential/log_test.cpp | 8 +- test/fmanip/copysign_test.cpp | 13 +- test/fmanip/frexp_test.cpp | 6 +- test/fmanip/ilogb_test.cpp | 6 +- test/fmanip/ldexp_test.cpp | 33 +- test/fmanip/logb_test.cpp | 6 +- test/fmanip/modf_test.cpp | 6 +- test/fmanip/nextafter_test.cpp | 6 +- test/fmanip/nexttoward_test.cpp | 5 +- test/fmanip/scalbn_test.cpp | 19 +- test/hyperbolic/_test.cpp | 6 +- test/internal/types/big_int_test.cpp | 11 +- test/misc/lerp_test_no_std.cpp | 12 +- test/misc/lerp_test_std.cpp | 8 +- test/nearest/floor_test.cpp | 4 +- test/nearest/nearbyint_test.cpp | 2 - test/nearest/trunc_test.cpp | 11 +- test/power/pow_test.cpp | 11 +- test/power/sqrt_test.cpp | 3 +- 226 files changed, 1743 insertions(+), 2392 deletions(-) diff --git a/example/main.cpp b/example/main.cpp index b32f707e..853ffe26 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -7,6 +7,7 @@ */ #include "ccmath/ccmath.hpp" + #include #include @@ -17,21 +18,21 @@ int main() { try_all_ccm_basic_funcs(); try_all_ccm_compare_funcs(); - return 0; + return 0; } void try_all_ccm_basic_funcs() { - int remquo_ptr = 0; - const auto try_abs = ccm::abs(-1.0); - const auto try_fdim = ccm::fdim(1.0, 0.0); - const auto try_fma = ccm::fma(1.0, 1.0, 1.0); - const auto try_fmax = ccm::fmax(1.0, 1.0); - const auto try_fmin = ccm::fmin(1.0, 1.0); - const auto try_fmod = ccm::fmod(1.0, 1.0); - const auto try_nan = ccm::nan(""); + int remquo_ptr = 0; + const auto try_abs = ccm::abs(-1.0); + const auto try_fdim = ccm::fdim(1.0, 0.0); + const auto try_fma = ccm::fma(1.0, 1.0, 1.0); + const auto try_fmax = ccm::fmax(1.0, 1.0); + const auto try_fmin = ccm::fmin(1.0, 1.0); + const auto try_fmod = ccm::fmod(1.0, 1.0); + const auto try_nan = ccm::nan(""); const auto try_remainder = ccm::remainder(1.0, 1.0); - const auto try_remquo = ccm::remquo(1.0, 1.0, &remquo_ptr); + const auto try_remquo = ccm::remquo(1.0, 1.0, &remquo_ptr); // print all basics output std::cout << "ccm::abs(-1.0): " << try_abs << std::endl; @@ -47,17 +48,17 @@ void try_all_ccm_basic_funcs() void try_all_ccm_compare_funcs() { - const auto try_fpclassify = ccm::fpclassify(1.0); - const auto try_isfinite = ccm::isfinite(1.0); - constexpr auto try_isgreater = ccm::isgreater(1.0, 0.0); + const auto try_fpclassify = ccm::fpclassify(1.0); + const auto try_isfinite = ccm::isfinite(1.0); + constexpr auto try_isgreater = ccm::isgreater(1.0, 0.0); constexpr auto try_isgreaterequal = ccm::isgreaterequal(1.0, 0.0); - constexpr auto try_isless = ccm::isless(1.0, 0.0); - constexpr auto try_islessequal = ccm::islessequal(1.0, 0.0); - constexpr auto try_islessgreater = ccm::islessgreater(1.0, 0.0); - const auto try_isnan = ccm::isnan(1.0); - const auto try_isnormal = ccm::isnormal(1.0); - const auto try_isunordered = ccm::isunordered(1.0, 0.0); - const auto try_signbit = ccm::signbit(1.0); + constexpr auto try_isless = ccm::isless(1.0, 0.0); + constexpr auto try_islessequal = ccm::islessequal(1.0, 0.0); + constexpr auto try_islessgreater = ccm::islessgreater(1.0, 0.0); + const auto try_isnan = ccm::isnan(1.0); + const auto try_isnormal = ccm::isnormal(1.0); + const auto try_isunordered = ccm::isunordered(1.0, 0.0); + const auto try_signbit = ccm::signbit(1.0); // print all compares output std::cout << "ccm::fpclassify(1.0): " << try_fpclassify << std::endl; @@ -71,4 +72,4 @@ void try_all_ccm_compare_funcs() std::cout << "ccm::isnormal(1.0): " << try_isnormal << std::endl; std::cout << "ccm::isunordered(1.0, 0.0): " << try_isunordered << std::endl; std::cout << "ccm::signbit(1.0): " << try_signbit << std::endl; -} \ No newline at end of file +} diff --git a/include/ccmath/ext/clamp.hpp b/include/ccmath/ext/clamp.hpp index 0e870292..a1a012f4 100644 --- a/include/ccmath/ext/clamp.hpp +++ b/include/ccmath/ext/clamp.hpp @@ -10,40 +10,40 @@ #pragma once -#include "ccmath/math/basic/min.hpp" #include "ccmath/math/basic/max.hpp" +#include "ccmath/math/basic/min.hpp" #include namespace ccm::ext { /** - * @brief Clamps a value between a minimum and maximum value. - * @tparam T Type of the input and output. - * @param v Value to clamp. - * @param lo Minimum value. - * @param hi Maximum value. - * @return The clamped value. - */ - template - constexpr T clamp(T v, T lo = T{0}, T hi = T{1}) - { - return ccm::min(ccm::max(v, lo), hi); - } + * @brief Clamps a value between a minimum and maximum value. + * @tparam T Type of the input and output. + * @param v Value to clamp. + * @param lo Minimum value. + * @param hi Maximum value. + * @return The clamped value. + */ + template + constexpr T clamp(T v, T lo = T{0}, T hi = T{1}) + { + return ccm::min(ccm::max(v, lo), hi); + } /** - * @brief Clamps a value between a minimum and maximum value. - * @tparam TVal Type of the input value. - * @tparam TLow Type of the lower bound. - * @tparam THigh Type of the upper bound. - * @param v Value to clamp. - * @param lo Minimum value. - * @param hi Maximum value. - * @return The clamped value. - */ - template - constexpr std::common_type_t clamp(TVal v, TLow lo = TLow{0}, THigh hi = THigh{1}) - { - return ccm::min(ccm::max(v, lo), hi); - } + * @brief Clamps a value between a minimum and maximum value. + * @tparam TVal Type of the input value. + * @tparam TLow Type of the lower bound. + * @tparam THigh Type of the upper bound. + * @param v Value to clamp. + * @param lo Minimum value. + * @param hi Maximum value. + * @return The clamped value. + */ + template + constexpr std::common_type_t clamp(TVal v, TLow lo = TLow{0}, THigh hi = THigh{1}) + { + return ccm::min(ccm::max(v, lo), hi); + } } // namespace ccm::ext diff --git a/include/ccmath/ext/cubic.hpp b/include/ccmath/ext/cubic.hpp index 67b0764d..5f8f3bc4 100644 --- a/include/ccmath/ext/cubic.hpp +++ b/include/ccmath/ext/cubic.hpp @@ -24,7 +24,7 @@ namespace ccm::ext * @param t The interpolation value. * @return The interpolated value. */ - template, bool> = true> + template , bool> = true> constexpr T cubic(T y0, T y1, T y2, T y3, T t) { const T a0 = y3 - y2 - y0 + y1; diff --git a/include/ccmath/ext/degrees.hpp b/include/ccmath/ext/degrees.hpp index 3484211b..877044cf 100644 --- a/include/ccmath/ext/degrees.hpp +++ b/include/ccmath/ext/degrees.hpp @@ -23,8 +23,8 @@ namespace ccm::ext * @return Angle in degrees. */ template , bool> = true> - constexpr T degrees(T radians) noexcept - { - return (static_cast(180) * radians) / ccm::numbers::pi_v; - } + constexpr T degrees(T radians) noexcept + { + return (static_cast(180) * radians) / ccm::numbers::pi_v; + } } // namespace ccm::ext diff --git a/include/ccmath/ext/fract.hpp b/include/ccmath/ext/fract.hpp index fe2c3559..f5b0e428 100644 --- a/include/ccmath/ext/fract.hpp +++ b/include/ccmath/ext/fract.hpp @@ -22,9 +22,9 @@ namespace ccm::ext * @param x Value to get the fractional part of. * @return The fractional part of the input. */ - template , bool> = true> - constexpr T fract(T x) noexcept + template , bool> = true> + constexpr T fract(T x) noexcept { - return x - ccm::floor(x); + return x - ccm::floor(x); } } // namespace ccm::ext diff --git a/include/ccmath/ext/lerp_smooth.hpp b/include/ccmath/ext/lerp_smooth.hpp index bec558a7..32db92ca 100644 --- a/include/ccmath/ext/lerp_smooth.hpp +++ b/include/ccmath/ext/lerp_smooth.hpp @@ -25,10 +25,10 @@ namespace ccm::ext * * @warning Currently waiting on ccm::exp2 to be implemented. Till then this will NOT work. */ - template - constexpr T lerp_smooth(T a, T b, T t, T h) - { - // ReSharper disable once CppRedundantParentheses - return b + ((a - b) * ccm::exp2(-t / h)); - } + template + constexpr T lerp_smooth(T a, T b, T t, 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 f809d201..562af6a8 100644 --- a/include/ccmath/ext/mix.hpp +++ b/include/ccmath/ext/mix.hpp @@ -22,12 +22,12 @@ namespace ccm::ext * @param a The value to use to interpolate between x and y. * @return The interpolated value. */ - template - constexpr T mix(T x, T y, T a) noexcept + template + constexpr T mix(T x, T y, T a) noexcept { // ReSharper disable once CppRedundantParentheses return (x * (1 - a)) + (y * a); - } + } /** * @brief Performs a linear interpolation between x and y using a to weight between them. @@ -41,7 +41,7 @@ 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 bbb73e1c..14b01734 100644 --- a/include/ccmath/ext/normalize.hpp +++ b/include/ccmath/ext/normalize.hpp @@ -24,7 +24,7 @@ namespace ccm::ext * @param max The maximum value of the range. * @return The normalized value. */ - template, bool> = true> + template , bool> = true> constexpr T normalize(T value, T min = T(0), T max = T(1)) { return ext::clamp((value - min) / (max - min), static_cast(0), static_cast(1)); diff --git a/include/ccmath/ext/ping_pong.hpp b/include/ccmath/ext/ping_pong.hpp index d765e314..1d1e61d0 100644 --- a/include/ccmath/ext/ping_pong.hpp +++ b/include/ccmath/ext/ping_pong.hpp @@ -27,12 +27,8 @@ namespace ccm::ext template , bool> = true> constexpr T ping_pong(T a, T b) noexcept { - if (b == 0) - { - return T(0); - } + if (b == 0) { return T(0); } return ccm::abs((ccm::ext::fract((a - b) / (b * 2.0)) * b * 2.0) - b); - } } // namespace ccm::ext diff --git a/include/ccmath/ext/smoothstep.hpp b/include/ccmath/ext/smoothstep.hpp index 78e93e2d..e8c61c8f 100644 --- a/include/ccmath/ext/smoothstep.hpp +++ b/include/ccmath/ext/smoothstep.hpp @@ -16,20 +16,20 @@ namespace ccm::ext { - /** - * @brief Smooth hermite interpolation. - * @tparam T Type of the input and output. - * @param edge0 Lower edge. - * @param edge1 Upper edge. - * @param x Value to interpolate. - * @return The interpolated value. - */ - template, bool> = true> - constexpr T smoothstep(T edge0, T edge1, T x) - { + /** + * @brief Smooth hermite interpolation. + * @tparam T Type of the input and output. + * @param edge0 Lower edge. + * @param edge1 Upper edge. + * @param x Value to interpolate. + * @return The interpolated value. + */ + template , bool> = true> + constexpr T smoothstep(T edge0, T edge1, T x) + { // Scale, bias and saturate x to 0..1 range - x = ccm::ext::clamp((x - edge0) / (edge1 - edge0)); - // Evaluate polynomial - return x * x * (static_cast(3) - static_cast(2) * x); - } + x = ccm::ext::clamp((x - edge0) / (edge1 - edge0)); + // Evaluate polynomial + return x * x * (static_cast(3) - static_cast(2) * x); + } } // namespace ccm::ext diff --git a/include/ccmath/internal/config/arch/check_simd_support.hpp b/include/ccmath/internal/config/arch/check_simd_support.hpp index 9b60ee10..3d1c525e 100644 --- a/include/ccmath/internal/config/arch/check_simd_support.hpp +++ b/include/ccmath/internal/config/arch/check_simd_support.hpp @@ -28,7 +28,7 @@ #ifdef CCM_CONFIG_USE_RT_SIMD -// Streaming SIMD Extensions 2 (SSE2) + // Streaming SIMD Extensions 2 (SSE2) #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 1 @@ -36,7 +36,7 @@ #define CCMATH_HAS_SIMD_SSE2 1 #endif -// Streaming SIMD Extensions 3 (SSE3) + // Streaming SIMD Extensions 3 (SSE3) #if defined(__SSE3__) || defined(CCM_CONFIG_RT_SIMD_HAS_SSE3) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 @@ -44,7 +44,7 @@ #define CCMATH_HAS_SIMD_SSE3 1 #endif -// Supplemental Streaming SIMD Extensions 3 (SSSE3) + // Supplemental Streaming SIMD Extensions 3 (SSSE3) #if defined(__SSSE3__) || defined(CCM_CONFIG_RT_SIMD_HAS_SSSE3) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 @@ -52,7 +52,7 @@ #define CCMATH_HAS_SIMD_SSSE3 1 #endif -// Streaming SIMD Extensions 4.1 (SSE4.1) + // Streaming SIMD Extensions 4.1 (SSE4.1) #if defined(__SSE4_1__) || defined(CCM_CONFIG_RT_SIMD_HAS_SSE4_1) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 @@ -60,7 +60,7 @@ #define CCMATH_HAS_SIMD_SSE4_1 1 #endif -// Streaming SIMD Extensions 4.2 (SSE4.2) + // Streaming SIMD Extensions 4.2 (SSE4.2) #if defined(__SSE4_2__) || defined(CCM_CONFIG_RT_SIMD_HAS_SSE4_2) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 @@ -68,7 +68,7 @@ #define CCMATH_HAS_SIMD_SSE4_2 1 #endif -// Streaming SIMD Extensions 4 (SSE4) + // Streaming SIMD Extensions 4 (SSE4) #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 1 @@ -76,7 +76,7 @@ #define CCMATH_HAS_SIMD_SSE4 1 #endif -// Advanced Vector Extensions (AVX) + // Advanced Vector Extensions (AVX) #if defined(__AVX__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 @@ -84,7 +84,7 @@ #define CCMATH_HAS_SIMD_AVX 1 #endif -// Advanced Vector Extensions 2 (AVX2) + // Advanced Vector Extensions 2 (AVX2) #if defined(__AVX2__) || defined(CCM_CONFIG_RT_SIMD_HAS_AVX2) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 @@ -92,7 +92,7 @@ #define CCMATH_HAS_SIMD_AVX2 1 #endif -// FMA (Fused Multiply-Add) Extensions + // FMA (Fused Multiply-Add) Extensions #if defined(__FMA__) || defined(CCM_CONFIG_RT_SIMD_HAS_FMA) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 @@ -100,8 +100,8 @@ #define CCMATH_HAS_SIMD_FMA 1 #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. + // 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 @@ -109,7 +109,7 @@ #define CCMATH_HAS_SIMD_SVML 1 #endif -// ARM Advanced SIMD (NEON) + // ARM Advanced SIMD (NEON) #if defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(CCM_CONFIG_RT_SIMD_HAS_NEON) #ifndef CCMATH_HAS_SIMD #define CCMATH_HAS_SIMD 1 @@ -117,8 +117,6 @@ #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/config/arch/targets/aarch64.hpp b/include/ccmath/internal/config/arch/targets/aarch64.hpp index 27ead57c..5d87746f 100644 --- a/include/ccmath/internal/config/arch/targets/aarch64.hpp +++ b/include/ccmath/internal/config/arch/targets/aarch64.hpp @@ -16,7 +16,7 @@ // VS defines: _M_ARM // GCC defines: __arm__ #if defined(_M_ARM) || defined(__arm__) - #define CCM_TARGET_ARCH_AARCH32 3 + #define CCM_TARGET_ARCH_AARCH32 3 #define CCM_TARGET_ARCH_IS_ARM_BASED 1 #endif @@ -24,8 +24,6 @@ // VS defines: _M_ARM64 // GCC defines: __aarch64__ #if defined(_M_ARM64) || defined(__aarch64__) - #define CCM_TARGET_ARCH_AARCH64 4 + #define CCM_TARGET_ARCH_AARCH64 4 #define CCM_TARGET_ARCH_IS_ARM_BASED 1 #endif - - diff --git a/include/ccmath/internal/config/arch/targets/x86_64.hpp b/include/ccmath/internal/config/arch/targets/x86_64.hpp index 4956dfac..ee54e6a5 100644 --- a/include/ccmath/internal/config/arch/targets/x86_64.hpp +++ b/include/ccmath/internal/config/arch/targets/x86_64.hpp @@ -16,7 +16,7 @@ // VS defines: _M_IX86 // GCC defines: i386, __i386, __i386__ #if defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(i386) - #define CCMATH_TARGET_ARCH_X86 1 + #define CCMATH_TARGET_ARCH_X86 1 #define CCMATH_TARGET_ARCH_IS_X86_BASED 1 #endif @@ -24,6 +24,6 @@ // VS defines: _M_X64 and _M_AMD64 // GCC defines: __amd64__, __amd64, __x86_64__, and __x86_64 #if defined(_M_X64) || defined(_M_AMD64) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) - #define CCMATH_TARGET_ARCH_X64 1 + #define CCMATH_TARGET_ARCH_X64 1 #define CCMATH_TARGET_ARCH_IS_X86_BASED 1 #endif diff --git a/include/ccmath/internal/config/builtin/bit_cast_support.hpp b/include/ccmath/internal/config/builtin/bit_cast_support.hpp index 8bfd7b33..2891a794 100644 --- a/include/ccmath/internal/config/builtin/bit_cast_support.hpp +++ b/include/ccmath/internal/config/builtin/bit_cast_support.hpp @@ -23,17 +23,18 @@ /// - MSVC 19.27+ // GCC 11.1+ has __builtin_bit_cast -#if defined(__GNUC__) && (__GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER) && !defined(__NVCOMPILER_LLVM__) && !defined(__CUDACC__) - #ifndef CCMATH_HAS_BUILTIN_BIT_CAST - #define CCMATH_HAS_BUILTIN_BIT_CAST - #endif +#if defined(__GNUC__) && (__GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER) && \ + !defined(__NVCOMPILER_LLVM__) && !defined(__CUDACC__) + #ifndef CCMATH_HAS_BUILTIN_BIT_CAST + #define CCMATH_HAS_BUILTIN_BIT_CAST + #endif #endif // Clang 9.0.0+ has __builtin_bit_cast -#if defined(__clang__) && !defined(__apple_build_version__) && __clang_major__ >= 9 - #ifndef CCMATH_HAS_BUILTIN_BIT_CAST - #define CCMATH_HAS_BUILTIN_BIT_CAST - #endif +#if defined(__clang__) && !defined(__apple_build_version__) && __clang_major__ >= 9 + #ifndef CCMATH_HAS_BUILTIN_BIT_CAST + #define CCMATH_HAS_BUILTIN_BIT_CAST + #endif #endif // Apple Clang 9.0.0+ has __builtin_bit_cast @@ -53,10 +54,10 @@ #endif // DPC++ 2021.1.2+ has __builtin_bit_cast -#if (defined(SYCL_LANGUAGE_VERSION) || defined(__INTEL_LLVM_COMPILER)) && (__INTEL_LLVM_COMPILER >= 20210102) - #ifndef CCMATH_HAS_BUILTIN_BIT_CAST - #define CCMATH_HAS_BUILTIN_BIT_CAST - #endif +#if (defined(SYCL_LANGUAGE_VERSION) || defined(__INTEL_LLVM_COMPILER)) && (__INTEL_LLVM_COMPILER >= 20210102) + #ifndef CCMATH_HAS_BUILTIN_BIT_CAST + #define CCMATH_HAS_BUILTIN_BIT_CAST + #endif #endif // NVIDIA HPC 22.7+ has __builtin_bit_cast (Maybe lower? This is as low as I can test currently) @@ -68,7 +69,7 @@ // MSVC 19.27+ has __builtin_bit_cast #if defined(_MSC_VER) && !defined(__clang__) && (_MSC_VER >= 1927) - #ifndef CCMATH_HAS_BUILTIN_BIT_CAST - #define CCMATH_HAS_BUILTIN_BIT_CAST - #endif + #ifndef CCMATH_HAS_BUILTIN_BIT_CAST + #define CCMATH_HAS_BUILTIN_BIT_CAST + #endif #endif diff --git a/include/ccmath/internal/config/builtin/copysign_support.hpp b/include/ccmath/internal/config/builtin/copysign_support.hpp index aef8e3bd..a5142cf1 100644 --- a/include/ccmath/internal/config/builtin/copysign_support.hpp +++ b/include/ccmath/internal/config/builtin/copysign_support.hpp @@ -32,9 +32,9 @@ // Clang 5.0.0+ has constexpr __builtin_copysign that DOES allow static_assert. #if defined(CCMATH_COMPILER_CLANG) && CCMATH_COMPILER_CLANG_VER_MAJOR >= 5 - #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN - #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN - #endif + #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #endif #endif // Clang-CL 5.0.0+ has constexpr __builtin_copysign that DOES allow static_assert. @@ -55,14 +55,14 @@ // DPC++ 2021.1.2+ has constexpr __builtin_copysign that DOES allow static_assert. #if defined(CCMATH_COMPILER_INTEL) && CCMATH_COMPILER_INTEL_VER >= 20210102 - #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN - #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN - #endif + #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #endif #endif // NVIDIA HPC 24.1+ has constexpr __builtin_copysign that DOES allow static_assert. #if defined(CCMATH_COMPILER_NVIDIA) && CCMATH_COMPILER_NVIDIA_VER_MAJOR >= 24 && CCMATH_COMPILER_NVIDIA_VER_MINOR >= 1 - #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN - #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN - #endif + #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #define CCMATH_HAS_CONSTEXPR_BUILTIN_COPYSIGN + #endif #endif diff --git a/include/ccmath/internal/config/compiler.hpp b/include/ccmath/internal/config/compiler.hpp index 36c1fb4d..2465900f 100644 --- a/include/ccmath/internal/config/compiler.hpp +++ b/include/ccmath/internal/config/compiler.hpp @@ -25,21 +25,20 @@ /// 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 - #elif defined(_MSC_VER) && defined(__clang__) && !defined(CCMATH_COMPILER_CLANG_CL) #define CCMATH_COMPILER_CLANG_CL #define CCMATH_COMPILER_CLANG_CL_VER ((__clang_major__ * 10000) + (__clang_minor__ * 100) + __clang_patchlevel__) @@ -47,13 +46,12 @@ #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 @@ -64,26 +62,23 @@ // TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler - /// 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) // TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler - /// AMD HIP #elif defined(__HIP__) && !defined(CCMATH_COMPILER_AMD_HIP) - #define CCMATH_COMPILER_AMD_HIP + #define CCMATH_COMPILER_AMD_HIP // TODO: Add precise detection for specific compiler versions along with a warning if using unsupported compiler - /// Apple Clang #elif defined(__apple_build_version__) && defined(__clang__) && !defined(CCMATH_COMPILER_APPLE_CLANG) #define CCMATH_COMPILER_APPLE_CLANG @@ -92,9 +87,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 @@ -106,9 +101,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 @@ -120,7 +115,6 @@ #define CCMATH_COMPILER_GCC_VER_MINOR __GNUC_MINOR__ #define CCMATH_COMPILER_GCC_VER_PATCH __GNUC_PATCHLEVEL__ - #else #define CCMATH_COMPILER_UNKNOWN #endif @@ -142,41 +136,41 @@ namespace ccm::internal::platform }; template - struct native_compiler : std::false_type{}; + struct native_compiler : std::false_type + { + }; template <> struct native_compiler : std::false_type { }; - #ifdef CCMATH_COMPILER_GCC +#ifdef CCMATH_COMPILER_GCC template <> struct native_compiler : std::true_type { }; - #endif +#endif - #ifdef CCMATH_COMPILER_CLANG +#ifdef CCMATH_COMPILER_CLANG template <> struct native_compiler : std::true_type { }; - #endif +#endif - #ifdef CCMATH_COMPILER_MSVC +#ifdef CCMATH_COMPILER_MSVC template <> struct native_compiler : std::true_type { }; - #endif +#endif - #ifdef CCMATH_COMPILER_CLANG_CL +#ifdef CCMATH_COMPILER_CLANG_CL template <> struct native_compiler : std::true_type { }; - #endif - - +#endif } // namespace ccm::internal::platform diff --git a/include/ccmath/internal/config/platform/android.hpp b/include/ccmath/internal/config/platform/android.hpp index 2a7392b9..5b33f3fd 100644 --- a/include/ccmath/internal/config/platform/android.hpp +++ b/include/ccmath/internal/config/platform/android.hpp @@ -27,9 +27,9 @@ #endif #define CCM_TARGET_PLATFORM_ANDROID 1 - #define CCM_TARGET_PLATFORM_LINUX 1 - #define CCM_TARGET_PLATFORM_UNIX 1 - #define CCM_TARGET_PLATFORM_POSIX 1 + #define CCM_TARGET_PLATFORM_LINUX 1 + #define CCM_TARGET_PLATFORM_UNIX 1 + #define CCM_TARGET_PLATFORM_POSIX 1 #ifdef CCM_TARGET_PLATFORM_MOBILE #undef CCM_TARGET_PLATFORM_MOBILE diff --git a/include/ccmath/internal/config/platform/darwin.hpp b/include/ccmath/internal/config/platform/darwin.hpp index 4cd31249..3cedcf37 100644 --- a/include/ccmath/internal/config/platform/darwin.hpp +++ b/include/ccmath/internal/config/platform/darwin.hpp @@ -10,7 +10,6 @@ #pragma once - #if defined(__APPLE__) || defined(__MACH__) #include @@ -35,7 +34,7 @@ #ifdef CCM_TARGET_PLATFORM_IPHONE #undef CCM_TARGET_PLATFORM_IPHONE #endif - #define CCM_TARGET_PLATFORM_IPHONE 1 + #define CCM_TARGET_PLATFORM_IPHONE 1 #define CCM_TARGET_POSIX_THREADS_AVAILABLE 1 #ifdef CCM_TARGET_PLATFORM_MOBILE @@ -58,8 +57,8 @@ #undef CCM_TARGET_PLATFORM_POSIX #endif - #define CCM_TARGET_PLATFORM_OSX 1 - #define CCM_TARGET_PLATFORM_UNIX 1 + #define CCM_TARGET_PLATFORM_OSX 1 + #define CCM_TARGET_PLATFORM_UNIX 1 #define CCM_TARGET_PLATFORM_POSIX 1 #ifdef CCM_TARGET_PLATFORM_DESKTOP diff --git a/include/ccmath/internal/config/platform/linux.hpp b/include/ccmath/internal/config/platform/linux.hpp index c6ca09d8..b1800a67 100644 --- a/include/ccmath/internal/config/platform/linux.hpp +++ b/include/ccmath/internal/config/platform/linux.hpp @@ -24,7 +24,7 @@ #endif #define CCM_TARGET_PLATFORM_LINUX 1 - #define CCM_TARGET_PLATFORM_UNIX 1 + #define CCM_TARGET_PLATFORM_UNIX 1 #define CCM_TARGET_PLATFORM_POSIX 1 #ifdef CCM_TARGET_PLATFORM_DESKTOP diff --git a/include/ccmath/internal/config/runtime_detection.hpp b/include/ccmath/internal/config/runtime_detection.hpp index ce3db3ac..7a537a40 100644 --- a/include/ccmath/internal/config/runtime_detection.hpp +++ b/include/ccmath/internal/config/runtime_detection.hpp @@ -9,4 +9,3 @@ */ #pragma once - diff --git a/include/ccmath/internal/config/type_support.hpp b/include/ccmath/internal/config/type_support.hpp index 9382d29d..afe2747d 100644 --- a/include/ccmath/internal/config/type_support.hpp +++ b/include/ccmath/internal/config/type_support.hpp @@ -14,7 +14,7 @@ #include // UINT64_MAX, __SIZEOF_INT128__ #if defined(UINT64_MAX) -#define CCM_TYPES_HAS_INT64 + #define CCM_TYPES_HAS_INT64 #endif // UINT64_MAX // Checks whether the __int128 compiler extension for a 128-bit integral type is @@ -51,7 +51,6 @@ // std::_Signed128 // #include __msvc_int128.hpp - // 'long double' properties. #if (LDBL_MANT_DIG == 53) #define CCM_TYPES_LONG_DOUBLE_IS_FLOAT64 diff --git a/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp b/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp index 4a909044..5ade96c6 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fdim.hpp @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FDIM + #endif #endif namespace ccm::builtin @@ -45,21 +45,11 @@ namespace ccm::builtin * when the compiler does not support them. */ template - constexpr auto fdim(T x, T y) - -> std::enable_if_t, T> + 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/basic/fma.hpp b/include/ccmath/internal/math/generic/builtins/basic/fma.hpp index a4f27ca1..495ebe84 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fma.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fma.hpp @@ -10,10 +10,10 @@ #pragma once -#include - #include "ccmath/internal/math/generic/builtins/builtin_helpers.hpp" +#include + /// CCMATH_HAS_CONSTEXPR_BUILTIN_FMA /// This is a macro that is defined if the compiler has constexpr __builtin_copysign that allows static_assert /// diff --git a/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp b/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp index cc0e5637..acad0cb1 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/fmod.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/fmod.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. @@ -21,9 +21,9 @@ /// - GCC 12.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD -#if defined(__GNUC__) && (__GNUC__ > 12 || (__GNUC__ == 12 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD -#endif + #if defined(__GNUC__) && (__GNUC__ > 12 || (__GNUC__ == 12 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FMOD + #endif #endif namespace ccm::builtin @@ -45,21 +45,11 @@ namespace ccm::builtin * when the compiler does not support them. */ template - constexpr auto fmod(T x, T y) - -> std::enable_if_t, T> + 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/basic/nan.hpp b/include/ccmath/internal/math/generic/builtins/basic/nan.hpp index 6ecb749a..ad0095db 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/nan.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/nan.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NAN -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_NAN -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_NAN + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp b/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp index d98d4e99..57781c7e 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/remainder.hpp @@ -21,14 +21,14 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_remainder = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_REMAINDER @@ -36,32 +36,23 @@ namespace ccm::builtin #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{}; - } + // 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 diff --git a/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp b/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp index 36038c5d..237f1d04 100644 --- a/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp +++ b/include/ccmath/internal/math/generic/builtins/basic/remquo.hpp @@ -21,9 +21,9 @@ /// - GCC 7.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO -#if defined(__GNUC__) && (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO -#endif + #if defined(__GNUC__) && (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_REMQUO + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/compare/isgreater.hpp b/include/ccmath/internal/math/generic/builtins/compare/isgreater.hpp index 37688eae..d0c9ec36 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isgreater.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isgreater.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. @@ -21,9 +21,9 @@ /// - 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 + #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 diff --git a/include/ccmath/internal/math/generic/builtins/compare/isgreaterequal.hpp b/include/ccmath/internal/math/generic/builtins/compare/isgreaterequal.hpp index 4c6df87e..0e75928b 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isgreaterequal.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isgreaterequal.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. @@ -21,9 +21,9 @@ /// - 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 + #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 diff --git a/include/ccmath/internal/math/generic/builtins/compare/isless.hpp b/include/ccmath/internal/math/generic/builtins/compare/isless.hpp index 7e4352a6..922aafb8 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isless.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isless.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. @@ -21,9 +21,9 @@ /// - 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 + #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 diff --git a/include/ccmath/internal/math/generic/builtins/compare/islessequal.hpp b/include/ccmath/internal/math/generic/builtins/compare/islessequal.hpp index 24a0ab7f..20ae611d 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/islessequal.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/islessequal.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. @@ -21,9 +21,9 @@ /// - 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 + #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 diff --git a/include/ccmath/internal/math/generic/builtins/compare/islessgreater.hpp b/include/ccmath/internal/math/generic/builtins/compare/islessgreater.hpp index 7ed01298..e91c2770 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/islessgreater.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/islessgreater.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. @@ -21,9 +21,9 @@ /// - 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 + #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 diff --git a/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp b/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp index 6585390f..a5611835 100644 --- a/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp +++ b/include/ccmath/internal/math/generic/builtins/compare/isunordered.hpp @@ -21,14 +21,14 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_isunordered = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_ISUNORDERED @@ -36,32 +36,23 @@ namespace ccm::builtin #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; - } + // 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 diff --git a/include/ccmath/internal/math/generic/builtins/expo/exp.hpp b/include/ccmath/internal/math/generic/builtins/expo/exp.hpp index c12493f4..bc394ae1 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/exp.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/exp.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_EXP -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_EXP + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp b/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp index 1aa7b97b..3818891c 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/exp2.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/exp2.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_EXP2 + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp b/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp index 72e08e70..46ff93b7 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/expm1.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/expm1.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_EXPM1 + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/expo/log.hpp b/include/ccmath/internal/math/generic/builtins/expo/log.hpp index eb29acd8..7704132b 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/log.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/log.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/expo/log10.hpp b/include/ccmath/internal/math/generic/builtins/expo/log10.hpp index efd03077..4cb4bfd2 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/log10.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/log10.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG10 + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp b/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp index ae7b9814..16a5c610 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/log1p.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/log1p.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG1P + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/expo/log2.hpp b/include/ccmath/internal/math/generic/builtins/expo/log2.hpp index 84d43566..b5c6e59a 100644 --- a/include/ccmath/internal/math/generic/builtins/expo/log2.hpp +++ b/include/ccmath/internal/math/generic/builtins/expo/log2.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOG2 + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp index 823778ec..a63a2ed0 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/frexp.hpp @@ -21,14 +21,14 @@ /// - GCC 7.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP -#if defined(__GNUC__) && (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP -#endif + #if defined(__GNUC__) && (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_frexp = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_FREXP @@ -36,32 +36,23 @@ namespace ccm::builtin #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{}; - } + // 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 diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp index 2dc81bbf..7e407f1a 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/ilogb.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ILOGB + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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; } diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp index fffc4bbb..21dd12c1 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/ldexp.hpp @@ -21,14 +21,14 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_ldexp = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_LDEXP @@ -36,32 +36,23 @@ namespace ccm::builtin #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{}; - } + // 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 diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp index 6edea011..5cd7d51a 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/logb.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/logb.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_LOGB + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp index 79ffad38..559e6e45 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/modf.hpp @@ -21,14 +21,14 @@ /// - GCC 7.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_MODF -#if defined(__GNUC__) && (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_MODF -#endif + #if defined(__GNUC__) && (__GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_MODF + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_modf = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_MODF @@ -36,32 +36,23 @@ namespace ccm::builtin #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{}; - } + // 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 diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp index bae8e9c0..1d744645 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp @@ -21,14 +21,14 @@ /// - GCC 9.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER -#if defined(__GNUC__) && (__GNUC__ > 9 || (__GNUC__ == 9 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER -#endif + #if defined(__GNUC__) && (__GNUC__ > 9 || (__GNUC__ == 9 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_nextafter = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTAFTER @@ -36,32 +36,23 @@ namespace ccm::builtin #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{}; - } + // 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 diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp index 93c3419a..7c204738 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp @@ -21,14 +21,14 @@ /// - GCC 9.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD -#if defined(__GNUC__) && (__GNUC__ > 9 || (__GNUC__ == 9 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD -#endif + #if defined(__GNUC__) && (__GNUC__ > 9 || (__GNUC__ == 9 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_nexttoward = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_NEXTTOWARD @@ -36,32 +36,24 @@ namespace ccm::builtin #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{}; - } + // 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 diff --git a/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp b/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp index 652f4507..fffceb8b 100644 --- a/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp +++ b/include/ccmath/internal/math/generic/builtins/fmanip/scalbn.hpp @@ -21,14 +21,14 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN + #endif #endif namespace ccm::builtin { - // clang-format off + // clang-format off template inline constexpr bool has_constexpr_scalbn = #ifdef CCMATH_HAS_CONSTEXPR_BUILTIN_SCALBN @@ -36,57 +36,39 @@ namespace ccm::builtin #else false; #endif - // clang-format on + // 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{}; - } + /** + * 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{}; + } /** - * 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. - */ + * 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{}; - } + { + 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/internal/math/generic/builtins/hyper/acosh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp index 83242d57..40b9ceae 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/acosh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/acosh.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ACOSH + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp index bdf24250..66478a86 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/asinh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/asinh.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ASINH + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp index b710d6c7..c6fd397a 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/atanh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/atanh.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ATANH + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp index 6d45e048..5f792533 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/cosh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/cosh.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COSH -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_COSH -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_COSH + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp index 17a9c292..72e4efa1 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/sinh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/sinh.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SINH -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_SINH -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_SINH + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp b/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp index 863b2e6e..4216f26c 100644 --- a/include/ccmath/internal/math/generic/builtins/hyper/tanh.hpp +++ b/include/ccmath/internal/math/generic/builtins/hyper/tanh.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_TANH -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_TANH -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_TANH + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/misc/erf.hpp b/include/ccmath/internal/math/generic/builtins/misc/erf.hpp index a9e6366b..3fdea405 100644 --- a/include/ccmath/internal/math/generic/builtins/misc/erf.hpp +++ b/include/ccmath/internal/math/generic/builtins/misc/erf.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #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 + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ERF + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin template constexpr auto erf(T x) -> std::enable_if_t, T> { - if constexpr (std::is_same_v) - { - return __builtin_erff(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_erf(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_erfl(x); - } + if constexpr (std::is_same_v) { return __builtin_erff(x); } + else if constexpr (std::is_same_v) { return __builtin_erf(x); } + else if constexpr (std::is_same_v) { return __builtin_erfl(x); } // This should never be reached return T{}; } diff --git a/include/ccmath/internal/math/generic/builtins/misc/erfc.hpp b/include/ccmath/internal/math/generic/builtins/misc/erfc.hpp index df191d8c..a5b44968 100644 --- a/include/ccmath/internal/math/generic/builtins/misc/erfc.hpp +++ b/include/ccmath/internal/math/generic/builtins/misc/erfc.hpp @@ -21,9 +21,9 @@ /// - GCC 5.1+ #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 + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ERFC + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin template constexpr auto erfc(T x) -> std::enable_if_t, T> { - if constexpr (std::is_same_v) - { - return __builtin_erfcf(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_erfc(x); - } - else if constexpr (std::is_same_v) - { - return __builtin_erfcl(x); - } + if constexpr (std::is_same_v) { return __builtin_erfcf(x); } + else if constexpr (std::is_same_v) { return __builtin_erfc(x); } + else if constexpr (std::is_same_v) { return __builtin_erfcl(x); } // This should never be reached return T{}; } diff --git a/include/ccmath/internal/math/generic/builtins/misc/tgamma.hpp b/include/ccmath/internal/math/generic/builtins/misc/tgamma.hpp index 8e3631c0..75b2c442 100644 --- a/include/ccmath/internal/math/generic/builtins/misc/tgamma.hpp +++ b/include/ccmath/internal/math/generic/builtins/misc/tgamma.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_GAMMA + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp b/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp index b928a4a4..abea89e9 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/floor.hpp +++ b/include/ccmath/internal/math/generic/builtins/nearest/floor.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_FLOOR + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/nearest/round.hpp b/include/ccmath/internal/math/generic/builtins/nearest/round.hpp index 035fe007..8175bbff 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/round.hpp +++ b/include/ccmath/internal/math/generic/builtins/nearest/round.hpp @@ -27,15 +27,15 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ROUND -#endif + #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 + #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 @@ -67,18 +67,9 @@ namespace ccm::builtin 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); - } + 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{}; } @@ -92,18 +83,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp b/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp index 6136577b..3d74e750 100644 --- a/include/ccmath/internal/math/generic/builtins/nearest/trunc.hpp +++ b/include/ccmath/internal/math/generic/builtins/nearest/trunc.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_TRUNC + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp b/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp index d18e760b..c0176654 100644 --- a/include/ccmath/internal/math/generic/builtins/power/cbrt.hpp +++ b/include/ccmath/internal/math/generic/builtins/power/cbrt.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_CBRT + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/power/hypot.hpp b/include/ccmath/internal/math/generic/builtins/power/hypot.hpp index 57e424a9..0af3abd7 100644 --- a/include/ccmath/internal/math/generic/builtins/power/hypot.hpp +++ b/include/ccmath/internal/math/generic/builtins/power/hypot.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_HYPOT + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/power/pow.hpp b/include/ccmath/internal/math/generic/builtins/power/pow.hpp index c1ad4c6e..94fc6d14 100644 --- a/include/ccmath/internal/math/generic/builtins/power/pow.hpp +++ b/include/ccmath/internal/math/generic/builtins/power/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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_POW -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_POW -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_POW + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp b/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp index 41bf704a..c6e377ca 100644 --- a/include/ccmath/internal/math/generic/builtins/power/sqrt.hpp +++ b/include/ccmath/internal/math/generic/builtins/power/sqrt.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_SQRT + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/trig/acos.hpp b/include/ccmath/internal/math/generic/builtins/trig/acos.hpp index 6a8ad9ce..4a86ebe9 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/acos.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/acos.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ACOS + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/trig/asin.hpp b/include/ccmath/internal/math/generic/builtins/trig/asin.hpp index 1f336d47..d2671f13 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/asin.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/asin.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ASIN + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/trig/atan.hpp b/include/ccmath/internal/math/generic/builtins/trig/atan.hpp index c8cf0066..901ea3f8 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/atan.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/atan.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp b/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp index e97fa418..71d6c5d7 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/atan2.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/atan2.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_ATAN2 + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/trig/cos.hpp b/include/ccmath/internal/math/generic/builtins/trig/cos.hpp index 5d1bfe26..176a72be 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/cos.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/cos.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_COS -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_COS -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_COS + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/trig/sin.hpp b/include/ccmath/internal/math/generic/builtins/trig/sin.hpp index ccf12bc4..7984e0dc 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/sin.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/sin.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. @@ -21,9 +21,9 @@ /// - GCC 5.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_SIN -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_SIN -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_SIN + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } diff --git a/include/ccmath/internal/math/generic/builtins/trig/tan.hpp b/include/ccmath/internal/math/generic/builtins/trig/tan.hpp index 8dfe4a2a..7c54aa20 100644 --- a/include/ccmath/internal/math/generic/builtins/trig/tan.hpp +++ b/include/ccmath/internal/math/generic/builtins/trig/tan.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. @@ -21,9 +21,9 @@ /// - GCC 6.1+ #ifndef CCMATH_HAS_CONSTEXPR_BUILTIN_TAN -#if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) -#define CCMATH_HAS_CONSTEXPR_BUILTIN_TAN -#endif + #if defined(__GNUC__) && (__GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) && !defined(__NVCOMPILER_MAJOR__) + #define CCMATH_HAS_CONSTEXPR_BUILTIN_TAN + #endif #endif namespace ccm::builtin @@ -47,18 +47,9 @@ namespace ccm::builtin 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); - } + 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{}; } 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 f398fe8c..a20a6eaa 100644 --- a/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp +++ b/include/ccmath/internal/math/generic/func/basic/fma_gen.hpp @@ -10,13 +10,12 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/basic/fma.hpp" #include "ccmath/internal/predef/unlikely.hpp" #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 @@ -31,13 +30,10 @@ 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 { - if constexpr (ccm::builtin::has_constexpr_fma) - { - return ccm::builtin::fma(x, y, z); - } + if constexpr (ccm::builtin::has_constexpr_fma) { return ccm::builtin::fma(x, y, z); } else { if (CCM_UNLIKELY(x == 0 || y == 0 || z == 0)) { return x * y + z; } @@ -46,20 +42,14 @@ namespace ccm if ((x == static_cast(0) && ccm::isinf(y)) || (y == T{0} && ccm::isinf(x))) { // ...z is NaN, return +NaN... - if (ccm::isnan(z)) - { - return std::numeric_limits::quiet_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(); } // 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 (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(); } @@ -75,7 +65,7 @@ namespace ccm } } - template , bool> = true> + template , bool> = true> constexpr Integer fma(Integer x, Integer y, Integer z) noexcept { return (x * y) + z; @@ -106,7 +96,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)); } @@ -122,7 +112,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/internal/math/generic/func/basic/remquo_gen.hpp b/include/ccmath/internal/math/generic/func/basic/remquo_gen.hpp index 3f7ff316..b858fb5a 100644 --- a/include/ccmath/internal/math/generic/func/basic/remquo_gen.hpp +++ b/include/ccmath/internal/math/generic/func/basic/remquo_gen.hpp @@ -7,4 +7,3 @@ * * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ - 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 ed9c1b9a..c59f7455 100644 --- a/include/ccmath/internal/math/generic/func/expo/exp2_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/exp2_gen.hpp @@ -24,20 +24,20 @@ namespace ccm::gen { - namespace internal::impl - { + namespace internal::impl + { - template - constexpr std::enable_if_t, T> exp2_impl(T x, T y) noexcept - { + template + constexpr std::enable_if_t, T> exp2_impl(T x, T y) noexcept + { - return 0; - } - } // namespace internal::impl + return 0; + } + } // namespace internal::impl - template - constexpr std::enable_if_t, T> exp2_gen(T base, T exp) noexcept - { - return internal::impl::exp2_impl(base, exp); - } + template + constexpr std::enable_if_t, T> exp2_gen(T base, T exp) noexcept + { + return internal::impl::exp2_impl(base, exp); + } } // namespace ccm::gen 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 dfa8edc0..76f8b817 100644 --- a/include/ccmath/internal/math/generic/func/expo/exp_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/exp_gen.hpp @@ -24,20 +24,20 @@ namespace ccm::gen { - namespace internal::impl - { + namespace internal::impl + { - template - constexpr std::enable_if_t, T> exp_impl(T x, T y) noexcept - { + template + constexpr std::enable_if_t, T> exp_impl(T x, T y) noexcept + { - return 0; - } - } // namespace internal::impl + return 0; + } + } // namespace internal::impl - template - constexpr std::enable_if_t, T> exp_gen(T base, T exp) noexcept - { - return internal::impl::exp_impl(base, exp); - } + template + constexpr std::enable_if_t, T> exp_gen(T base, T exp) noexcept + { + return internal::impl::exp_impl(base, exp); + } } // namespace ccm::gen diff --git a/include/ccmath/internal/math/generic/func/expo/expm1_gen.hpp b/include/ccmath/internal/math/generic/func/expo/expm1_gen.hpp index b72a78e0..f3aa1e12 100644 --- a/include/ccmath/internal/math/generic/func/expo/expm1_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/expm1_gen.hpp @@ -17,17 +17,17 @@ namespace ccm template , bool> = true> constexpr T expm1(T num) { - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) +#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)); - #else +#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 +#endif } template , bool> = true> diff --git a/include/ccmath/internal/math/generic/func/expo/log10_gen.hpp b/include/ccmath/internal/math/generic/func/expo/log10_gen.hpp index 7fff8aee..414db8fc 100644 --- a/include/ccmath/internal/math/generic/func/expo/log10_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/log10_gen.hpp @@ -17,17 +17,17 @@ namespace ccm template , bool> = true> constexpr T log10(T num) { - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) +#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)); - #else +#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 +#endif } template , bool> = true> diff --git a/include/ccmath/internal/math/generic/func/expo/log1p_gen.hpp b/include/ccmath/internal/math/generic/func/expo/log1p_gen.hpp index 9d568427..e3a9c32d 100644 --- a/include/ccmath/internal/math/generic/func/expo/log1p_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/log1p_gen.hpp @@ -17,17 +17,17 @@ namespace ccm template , bool> = true> constexpr T log1p(T num) { - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) +#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)); - #else +#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 +#endif } template , bool> = true> 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 e3c47699..d6d34f73 100644 --- a/include/ccmath/internal/math/generic/func/expo/log_gen.hpp +++ b/include/ccmath/internal/math/generic/func/expo/log_gen.hpp @@ -30,16 +30,14 @@ namespace ccm::gen { constexpr float log_impl([[maybe_unused]] float num) noexcept { - //constexpr double ln2 = 0x1.62e42fefa39efp-1; - //using FPBits_t = typename support::fp::FPBits; + // constexpr double ln2 = 0x1.62e42fefa39efp-1; + // using FPBits_t = typename support::fp::FPBits; - //FPBits_t num_bits(num); - - //std::uint32_t num_bits_storage = num_bits.uintval(); - - //int m = -FPBits_t::exponent_bias; + // FPBits_t num_bits(num); + // std::uint32_t num_bits_storage = num_bits.uintval(); + // int m = -FPBits_t::exponent_bias; return 0; } @@ -54,7 +52,6 @@ namespace ccm::gen return 0; } - } // namespace internal::impl template diff --git a/include/ccmath/internal/math/generic/func/fmanip/frexp_gen.hpp b/include/ccmath/internal/math/generic/func/fmanip/frexp_gen.hpp index 95bb0123..cfba9636 100644 --- a/include/ccmath/internal/math/generic/func/fmanip/frexp_gen.hpp +++ b/include/ccmath/internal/math/generic/func/fmanip/frexp_gen.hpp @@ -17,16 +17,15 @@ namespace ccm { template , int> = 0> -constexpr T frexp(T x, int &exp) { + constexpr T frexp(T x, int & exp) + { support::fp::FPBits bits(x); - if (bits.is_inf_or_nan()) { - return x; -} - if (bits.is_zero()) { + if (bits.is_inf_or_nan()) { return x; } + if (bits.is_zero()) + { exp = 0; return x; } - } } // namespace ccm 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 8d8e8669..58a5afbb 100644 --- a/include/ccmath/internal/math/generic/func/fmanip/ldexp_gen.hpp +++ b/include/ccmath/internal/math/generic/func/fmanip/ldexp_gen.hpp @@ -38,7 +38,7 @@ namespace ccm template , bool> = true> constexpr T ldexp(T num, int exp) noexcept { - //NOLINTNEXTLINE + // 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); } diff --git a/include/ccmath/internal/math/generic/func/fmanip/modf_gen.hpp b/include/ccmath/internal/math/generic/func/fmanip/modf_gen.hpp index 1e5cb713..9a21f36d 100644 --- a/include/ccmath/internal/math/generic/func/fmanip/modf_gen.hpp +++ b/include/ccmath/internal/math/generic/func/fmanip/modf_gen.hpp @@ -13,7 +13,7 @@ namespace ccm { template - constexpr T modf(T x, T* iptr) noexcept + constexpr T modf(T x, T * iptr) noexcept { return 0; } diff --git a/include/ccmath/internal/math/generic/func/fmanip/scalbn_gen.hpp b/include/ccmath/internal/math/generic/func/fmanip/scalbn_gen.hpp index 66817f57..f5f19946 100644 --- a/include/ccmath/internal/math/generic/func/fmanip/scalbn_gen.hpp +++ b/include/ccmath/internal/math/generic/func/fmanip/scalbn_gen.hpp @@ -49,17 +49,17 @@ 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 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 +#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 +#endif } /** diff --git a/include/ccmath/internal/math/generic/func/nearest/floor_gen.hpp b/include/ccmath/internal/math/generic/func/nearest/floor_gen.hpp index 19a92c37..149eb79c 100644 --- a/include/ccmath/internal/math/generic/func/nearest/floor_gen.hpp +++ b/include/ccmath/internal/math/generic/func/nearest/floor_gen.hpp @@ -72,7 +72,6 @@ namespace ccm } } // namespace internal::impl - /** * @brief Computes the largest integer value not greater than num. * @tparam T The type of the number. diff --git a/include/ccmath/internal/math/generic/func/nearest/trunc_gen.hpp b/include/ccmath/internal/math/generic/func/nearest/trunc_gen.hpp index 15550e5e..575a1afe 100644 --- a/include/ccmath/internal/math/generic/func/nearest/trunc_gen.hpp +++ b/include/ccmath/internal/math/generic/func/nearest/trunc_gen.hpp @@ -45,7 +45,7 @@ namespace ccm if (exponent <= -1) { return FPBits_t::zero(bits.sign()).get_val(); } // Perform the truncation - const int trimming_size = FPBits_t::fraction_length - exponent; + 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/internal/math/generic/func/power/pow_impl.hpp b/include/ccmath/internal/math/generic/func/power/pow_impl.hpp index 8200c9ac..6d285d30 100644 --- a/include/ccmath/internal/math/generic/func/power/pow_impl.hpp +++ b/include/ccmath/internal/math/generic/func/power/pow_impl.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. 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 171ecc32..86de2949 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,9 @@ #pragma once -#include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/math/generic/func/power/pow_gen.hpp" #include "ccmath/internal/math/runtime/simd/func/pow.hpp" +#include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/fenv/rounding_mode.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" @@ -61,7 +61,10 @@ namespace ccm::rt 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::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 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. diff --git a/include/ccmath/internal/math/runtime/pp/simd.hpp b/include/ccmath/internal/math/runtime/pp/simd.hpp index f07e9e1b..bc85ae57 100644 --- a/include/ccmath/internal/math/runtime/pp/simd.hpp +++ b/include/ccmath/internal/math/runtime/pp/simd.hpp @@ -2,105 +2,103 @@ #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 + #define CCMATH_SIMD_HAVE_NEON 1 #else -#define CCMATH_SIMD_HAVE_NEON 0 + #define CCMATH_SIMD_HAVE_NEON 0 #endif #if defined __ARM_NEON && (__ARM_ARCH >= 8 || defined __aarch64__) -#define CCMATH_SIMD_HAVE_NEON_A32 1 + #define CCMATH_SIMD_HAVE_NEON_A32 1 #else -#define CCMATH_SIMD_HAVE_NEON_A32 0 + #define CCMATH_SIMD_HAVE_NEON_A32 0 #endif #if defined __ARM_NEON && defined __aarch64__ -#define CCMATH_SIMD_HAVE_NEON_A64 1 + #define CCMATH_SIMD_HAVE_NEON_A64 1 #else -#define CCMATH_SIMD_HAVE_NEON_A64 0 + #define CCMATH_SIMD_HAVE_NEON_A64 0 #endif // x86 SIMD Extensions #if defined __SSE2__ || defined __x86_64__ -#define CCMATH_SIMD_HAVE_SSE2 1 + #define CCMATH_SIMD_HAVE_SSE2 1 #else -#define CCMATH_SIMD_HAVE_SSE2 0 + #define CCMATH_SIMD_HAVE_SSE2 0 #endif #ifdef __SSE4_2__ -#define CCMATH_SIMD_HAVE_SSE4_2 1 + #define CCMATH_SIMD_HAVE_SSE4_2 1 #else -#define CCMATH_SIMD_HAVE_SSE4_2 0 + #define CCMATH_SIMD_HAVE_SSE4_2 0 #endif #ifdef __AVX2__ -#define CCMATH_SIMD_HAVE_AVX2 1 + #define CCMATH_SIMD_HAVE_AVX2 1 #else -#define CCMATH_SIMD_HAVE_AVX2 0 + #define CCMATH_SIMD_HAVE_AVX2 0 #endif #ifdef __BMI__ -#define CCMATH_SIMD_HAVE_BMI1 1 + #define CCMATH_SIMD_HAVE_BMI1 1 #else -#define CCMATH_SIMD_HAVE_BMI1 0 + #define CCMATH_SIMD_HAVE_BMI1 0 #endif #ifdef __BMI2__ -#define CCMATH_SIMD_HAVE_BMI2 1 + #define CCMATH_SIMD_HAVE_BMI2 1 #else -#define CCMATH_SIMD_HAVE_BMI2 0 + #define CCMATH_SIMD_HAVE_BMI2 0 #endif #ifdef __FMA__ -#define CCMATH_SIMD_HAVE_FMA 1 + #define CCMATH_SIMD_HAVE_FMA 1 #else -#define CCMATH_SIMD_HAVE_FMA 0 + #define CCMATH_SIMD_HAVE_FMA 0 #endif #ifdef __FMA4__ -#define CCMATH_SIMD_HAVE_FMA4 1 + #define CCMATH_SIMD_HAVE_FMA4 1 #else -#define CCMATH_SIMD_HAVE_FMA4 0 + #define CCMATH_SIMD_HAVE_FMA4 0 #endif #ifdef __F16C__ -#define CCMATH_SIMD_HAVE_F16C 1 + #define CCMATH_SIMD_HAVE_F16C 1 #else -#define CCMATH_SIMD_HAVE_F16C 0 + #define CCMATH_SIMD_HAVE_F16C 0 #endif #ifdef __POPCNT__ -#define CCMATH_SIMD_HAVE_POPCNT 1 + #define CCMATH_SIMD_HAVE_POPCNT 1 #else -#define CCMATH_SIMD_HAVE_POPCNT 0 + #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 + #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 + #define CCM_SIMD_INTRINSIC [[gnu::always_inline, gnu::artificial]] inline #else // Other compilers -#define CCM_SIMD_INTRINSIC inline + #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 + #define CCMATH_SIMD_IS_X86 1 #else -#define CCMATH_SIMD_IS_X86 0 + #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 + #define CCMATH_SIMD_IS_ARM 1 #else -#define CCMATH_SIMD_IS_ARM 0 + #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 + #if __cplusplus >= 202002L + #define CCM_CPP20_EXPLICIT(EXPR) explicit(EXPR) + #else + #define CCM_CPP20_EXPLICIT(EXPR) + #endif #endif - namespace ccm::pp { template @@ -116,36 +114,35 @@ namespace ccm::pp template inline constexpr bool is_vectorizable_v = is_vectorizable::value; - template > > + template >> using Vectorizable = T; - template > + template > struct is_bitmask : std::false_type { }; template - struct is_bitmask() = std::declval() & 1u)> > : std::true_type + 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 = 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; + 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 = @@ -170,41 +167,26 @@ namespace ccm::pp #endif // clang-format on - template - constexpr size_t - vectorized_sizeof() + constexpr size_t vectorized_sizeof() { - if constexpr (!is_vectorizable_v) - { - return 0; - } + if constexpr (!is_vectorizable_v) { return 0; } if constexpr (sizeof(T) <= 8) { // X86: - if constexpr (have_avx2) - { - return 32; - } + if constexpr (have_avx2) { return 32; } - if constexpr (have_sse2) - { - return 16; - } + 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)) + 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; } @@ -213,7 +195,6 @@ namespace ccm::pp return sizeof(T); } - namespace simd_abi { template @@ -227,16 +208,13 @@ namespace ccm::pp }; template - struct is_valid_size_for : std::bool_constant<( - UsedBytes / sizeof(T) > 1 && - UsedBytes % sizeof(T) == 0 && - UsedBytes <= vectorized_sizeof() && - UsedBytes <= 32)> + 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 > + struct is_valid : std::conjunction, is_valid_size_for> { }; @@ -246,7 +224,6 @@ namespace ccm::pp // https://github.com/VcDevel/std-simd/blob/a0054893e8f0dc89d4f694c63a080e4b2e32850b/experimental/bits/simd_builtin.h#L954 }; - template struct scalar { @@ -272,19 +249,19 @@ namespace ccm::pp { }; - #if CCMATH_SIMD_HAVE_NEON +#if CCMATH_SIMD_HAVE_NEON using native = neon; - #elif CCMATH_SIMD_HAVE_AVX2 +#elif CCMATH_SIMD_HAVE_AVX2 using native = avx2; - #elif CCMATH_SIMD_HAVE_SSE4_2 +#elif CCMATH_SIMD_HAVE_SSE4_2 using native = sse4_2; - #elif CCMATH_SIMD_HAVE_SSE2 +#elif CCMATH_SIMD_HAVE_SSE2 using native = sse2; - #else +#else using native = scalar; - #endif +#endif - } + } // namespace simd_abi // https://isocpp.org/files/papers/P1928R15.pdf // page 42 @@ -292,11 +269,11 @@ namespace ccm::pp struct basic_simd { using value_type = T; - using mask_type = basic_simd_mask; - using abi_type = Abi; + using mask_type = basic_simd_mask; + using abi_type = Abi; // static constexpr integral_constant> size { - //static constexpr std::integral_constant<> + // static constexpr std::integral_constant<> constexpr basic_simd() noexcept = default; @@ -311,8 +288,6 @@ namespace ccm::pp constexpr CCM_CPP20_EXPLICIT(true) basic_simd(basic_simd const & value) noexcept { } - - }; template @@ -323,8 +298,7 @@ namespace ccm::pp template using simd = basic_simd; -} - +} // namespace ccm::pp // Cleanup global namespace #undef CCMATH_SIMD_HAVE_NEON 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 index 6bcdb788..771f2932 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/avx2/pow.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/avx2/pow.hpp @@ -27,7 +27,6 @@ namespace ccm::intrin { // NOLINTNEXTLINE(modernize-return-braced-init-list) return simd(_mm256_pow_pd(a.get(), b.get())); - } } // namespace ccm::intrin 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 633efbe9..f8d9895c 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 @@ -16,7 +16,7 @@ namespace ccm::intrin { template - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd pow(simd const& a, simd const& b) + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd pow(simd const & a, simd const & b) { return simd(gen::pow_gen(a.get(), b.get())); } diff --git a/include/ccmath/internal/math/runtime/simd/func/impl/scalar/sqrt.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/sqrt.hpp index 63bc9b41..eab4ccc0 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/scalar/sqrt.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/scalar/sqrt.hpp @@ -16,7 +16,7 @@ namespace ccm::intrin { template - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd sqrt(simd const& a) + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd sqrt(simd const & a) { return simd(ccm::gen::sqrt_gen(a.get())); } 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 f094830e..aa67cbcd 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. @@ -48,5 +48,5 @@ namespace ccm::intrin } } // 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 2af02622..20f83052 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. @@ -48,5 +48,5 @@ namespace ccm::intrin } } // 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/func/impl/vector_size/sqrt.hpp b/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/sqrt.hpp index 81aecc7e..1bb9fd08 100644 --- a/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/sqrt.hpp +++ b/include/ccmath/internal/math/runtime/simd/func/impl/vector_size/sqrt.hpp @@ -24,7 +24,7 @@ namespace ccm::intrin 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) + // CCM_SIMD_VECTORIZE for (int i = 0; i < a.size(); ++i) //{ // result.get()[i] = sqrt(a[i]); //} diff --git a/include/ccmath/internal/math/runtime/simd/func/pow.hpp b/include/ccmath/internal/math/runtime/simd/func/pow.hpp index 24ae874a..fc12fe5f 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. @@ -44,9 +44,9 @@ #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 +// 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 diff --git a/include/ccmath/internal/math/runtime/simd/instructions/avx.hpp b/include/ccmath/internal/math/runtime/simd/instructions/avx.hpp index 985dfe14..7aadcfd3 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/avx.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/avx.hpp @@ -32,11 +32,12 @@ namespace ccm::intrin struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::avx; + using value_type = bool; + 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)))) { } // NOLINT + 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) {} // NOLINT [[nodiscard]] constexpr __m256 get() const { return m_value; } @@ -62,17 +63,18 @@ namespace ccm::intrin struct simd { - using value_type = float; - using abi_type = abi::avx; - using mask_type = simd_mask; - using storage_type = simd_storage; + using value_type = float; + using abi_type = abi::avx; + using mask_type = simd_mask; + 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)) {} // 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()); } // NOLINT + 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()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -82,7 +84,8 @@ namespace ccm::intrin CCM_ALWAYS_INLINE simd(float const * ptr, Flags /*flags*/) : m_value(_mm256_loadu_ps(ptr)) { } - CCM_ALWAYS_INLINE simd(float const * ptr, int stride) + 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]) // NOLINT { } @@ -96,21 +99,14 @@ namespace ccm::intrin CCM_ALWAYS_INLINE void copy_to(float * ptr, element_aligned_tag /*unused*/) const { _mm256_storeu_ps(ptr, m_value); } [[nodiscard]] constexpr __m256 get() const { return m_value; } [[nodiscard]] CCM_ALWAYS_INLINE float convert() const { return _mm256_cvtss_f32(m_value); } - CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const - { - return {_mm256_cmp_ps(m_value, other.m_value, _CMP_LT_OS)}; - } - CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const - { - return {_mm256_cmp_ps(m_value, other.m_value, _CMP_EQ_OS)}; - } + CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const { return {_mm256_cmp_ps(m_value, other.m_value, _CMP_LT_OS)}; } + CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const { return {_mm256_cmp_ps(m_value, other.m_value, _CMP_EQ_OS)}; } private: __m256 m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, simd const & c) { return {_mm256_blendv_ps(c.get(), b.get(), a.get())}; } @@ -118,11 +114,12 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::avx; + using value_type = bool; + 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)))) { } // NOLINT + 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) {} // NOLINT [[nodiscard]] constexpr __m256d get() const { return m_value; } @@ -149,19 +146,22 @@ namespace ccm::intrin { public: - using value_type = double; - using abi_type = abi::avx; - 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::avx; + 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; CCM_ALWAYS_INLINE static constexpr int size() { return 4; } - 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()); } // NOLINT + 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()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -171,8 +171,9 @@ 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]) {} // NOLINT - CCM_ALWAYS_INLINE constexpr simd(__m256d const & value_in) : m_value(value_in) {} // NOLINT + 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)}; } @@ -182,21 +183,14 @@ namespace ccm::intrin CCM_ALWAYS_INLINE void copy_to(double * ptr, element_aligned_tag /*unused*/) const { _mm256_storeu_pd(ptr, m_value); } [[nodiscard]] CCM_ALWAYS_INLINE constexpr __m256d get() const { return m_value; } [[nodiscard]] CCM_ALWAYS_INLINE double convert() const { return _mm256_cvtsd_f64(m_value); } - CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const - { - return {_mm256_cmp_pd(m_value, other.m_value, _CMP_LT_OS)}; - } - CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const - { - return {_mm256_cmp_pd(m_value, other.m_value, _CMP_EQ_OS)}; - } + CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const { return {_mm256_cmp_pd(m_value, other.m_value, _CMP_LT_OS)}; } + CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const { return {_mm256_cmp_pd(m_value, other.m_value, _CMP_EQ_OS)}; } private: __m256d m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, simd const & c) { return {_mm256_blendv_pd(c.get(), b.get(), a.get())}; } diff --git a/include/ccmath/internal/math/runtime/simd/instructions/avx2.hpp b/include/ccmath/internal/math/runtime/simd/instructions/avx2.hpp index 89b773bc..043f8684 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/avx2.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/avx2.hpp @@ -14,193 +14,188 @@ #include "ccmath/internal/math/runtime/simd/common.hpp" #ifdef CCMATH_HAS_SIMD - #ifdef CCMATH_HAS_SIMD_AVX2 - #include + #ifdef CCMATH_HAS_SIMD_AVX2 + #include namespace ccm::intrin { - namespace abi - { - - struct avx2 - { - }; - - } // namespace abi - - template <> - struct simd_mask - { - - using value_type = bool; - 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)))) { } // NOLINT - static constexpr int size() { return 8; } - 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)}; } - CCM_ALWAYS_INLINE simd_mask operator!() const { return {_mm256_andnot_ps(m_value, simd_mask(true).get())}; } - - private: - __m256 m_value; - }; - - CCM_ALWAYS_INLINE bool all_of(simd_mask const & a) - { - return _mm256_testc_ps(a.get(), simd_mask(true).get()) != 0; - } - - CCM_ALWAYS_INLINE bool any_of(simd_mask const & a) - { - return _mm256_testc_ps(simd_mask(false).get(), a.get()) == 0; - } - - template <> - struct simd - { - - using value_type = float; - using abi_type = abi::avx2; - using mask_type = simd_mask; - 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)) {} // 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()); } // NOLINT - 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(_mm256_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]) // NOLINT - { - } - 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)}; } - CCM_ALWAYS_INLINE simd operator-(simd const & other) const { return {_mm256_sub_ps(m_value, other.m_value)}; } - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd operator-() const { return {_mm256_sub_ps(_mm256_set1_ps(0.0F), m_value)}; } - CCM_ALWAYS_INLINE void copy_from(float const * ptr, element_aligned_tag /*unused*/) { m_value = _mm256_loadu_ps(ptr); } - CCM_ALWAYS_INLINE void copy_to(float * ptr, element_aligned_tag /*unused*/) const { _mm256_storeu_ps(ptr, m_value); } - [[nodiscard]] constexpr __m256 get() const { return m_value; } - [[nodiscard]] CCM_ALWAYS_INLINE float convert() const { return _mm256_cvtss_f32(m_value); } - CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const - { - return {_mm256_cmp_ps(m_value, other.m_value, _CMP_LT_OS)}; - } - CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const - { - return {_mm256_cmp_ps(m_value, other.m_value, _CMP_EQ_OS)}; - } - - private: - __m256 m_value; - }; - - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) - { - return {_mm256_blendv_ps(c.get(), b.get(), a.get())}; - } - - template <> - struct simd_mask - { - using value_type = bool; - 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)))) { } // NOLINT - CCM_ALWAYS_INLINE static constexpr int size() { return 4; } - 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)}; } - CCM_ALWAYS_INLINE simd_mask operator!() const { return {_mm256_andnot_pd(m_value, simd_mask(true).get())}; } - - private: - __m256d m_value; - }; - - CCM_ALWAYS_INLINE bool all_of(simd_mask const & a) - { - return _mm256_testc_pd(a.get(), simd_mask(true).get()) != 0; - } - - CCM_ALWAYS_INLINE bool any_of(simd_mask const & a) - { - return _mm256_testc_pd(simd_mask(false).get(), a.get()) == 0; - } - - template <> - struct simd // NOLINT - { - - public: - using value_type = double; - using abi_type = abi::avx2; - 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 static constexpr int size() { return 4; } - 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()); } // NOLINT - 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(_mm256_loadu_pd(ptr)) - { - } - 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)}; } - CCM_ALWAYS_INLINE simd operator-(simd const & other) const { return {_mm256_sub_pd(m_value, other.m_value)}; } - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd operator-() const { return {_mm256_sub_pd(_mm256_set1_pd(0.0), m_value)}; } - CCM_ALWAYS_INLINE void copy_from(double const * ptr, element_aligned_tag /*unused*/) { m_value = _mm256_loadu_pd(ptr); } - CCM_ALWAYS_INLINE void copy_to(double * ptr, element_aligned_tag /*unused*/) const { _mm256_storeu_pd(ptr, m_value); } - [[nodiscard]] CCM_ALWAYS_INLINE constexpr __m256d get() const { return m_value; } - [[nodiscard]] CCM_ALWAYS_INLINE double convert() const { return _mm256_cvtsd_f64(m_value); } - CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const - { - return {_mm256_cmp_pd(m_value, other.m_value, _CMP_LT_OS)}; - } - CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const - { - return {_mm256_cmp_pd(m_value, other.m_value, _CMP_EQ_OS)}; - } - - private: - __m256d m_value; - }; - - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) - { - return {_mm256_blendv_pd(c.get(), b.get(), a.get())}; - } + namespace abi + { + + struct avx2 + { + }; + + } // namespace abi + + template <> + struct simd_mask + { + + using value_type = bool; + 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)))) {} // NOLINT + static constexpr int size() { return 8; } + 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)}; } + CCM_ALWAYS_INLINE simd_mask operator!() const { return {_mm256_andnot_ps(m_value, simd_mask(true).get())}; } + + private: + __m256 m_value; + }; + + CCM_ALWAYS_INLINE bool all_of(simd_mask const & a) + { + return _mm256_testc_ps(a.get(), simd_mask(true).get()) != 0; + } + + CCM_ALWAYS_INLINE bool any_of(simd_mask const & a) + { + return _mm256_testc_ps(simd_mask(false).get(), a.get()) == 0; + } + + template <> + struct simd + { + + using value_type = float; + using abi_type = abi::avx2; + using mask_type = simd_mask; + 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)) {} // 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()); } // NOLINT + 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(_mm256_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]) // NOLINT + { + } + 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)}; } + CCM_ALWAYS_INLINE simd operator-(simd const & other) const { return {_mm256_sub_ps(m_value, other.m_value)}; } + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd operator-() const { return {_mm256_sub_ps(_mm256_set1_ps(0.0F), m_value)}; } + CCM_ALWAYS_INLINE void copy_from(float const * ptr, element_aligned_tag /*unused*/) { m_value = _mm256_loadu_ps(ptr); } + CCM_ALWAYS_INLINE void copy_to(float * ptr, element_aligned_tag /*unused*/) const { _mm256_storeu_ps(ptr, m_value); } + [[nodiscard]] constexpr __m256 get() const { return m_value; } + [[nodiscard]] CCM_ALWAYS_INLINE float convert() const { return _mm256_cvtss_f32(m_value); } + CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const { return {_mm256_cmp_ps(m_value, other.m_value, _CMP_LT_OS)}; } + CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const { return {_mm256_cmp_ps(m_value, other.m_value, _CMP_EQ_OS)}; } + + private: + __m256 m_value; + }; + + CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, simd const & c) + { + return {_mm256_blendv_ps(c.get(), b.get(), a.get())}; + } + + template <> + struct simd_mask + { + using value_type = bool; + 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)))) {} // NOLINT + CCM_ALWAYS_INLINE static constexpr int size() { return 4; } + 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)}; } + CCM_ALWAYS_INLINE simd_mask operator!() const { return {_mm256_andnot_pd(m_value, simd_mask(true).get())}; } + + private: + __m256d m_value; + }; + + CCM_ALWAYS_INLINE bool all_of(simd_mask const & a) + { + return _mm256_testc_pd(a.get(), simd_mask(true).get()) != 0; + } + + CCM_ALWAYS_INLINE bool any_of(simd_mask const & a) + { + return _mm256_testc_pd(simd_mask(false).get(), a.get()) == 0; + } + + template <> + struct simd // NOLINT + { + + public: + using value_type = double; + using abi_type = abi::avx2; + 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 static constexpr int size() { return 4; } + 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()); } // NOLINT + 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(_mm256_loadu_pd(ptr)) + { + } + 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)}; } + CCM_ALWAYS_INLINE simd operator-(simd const & other) const { return {_mm256_sub_pd(m_value, other.m_value)}; } + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd operator-() const { return {_mm256_sub_pd(_mm256_set1_pd(0.0), m_value)}; } + CCM_ALWAYS_INLINE void copy_from(double const * ptr, element_aligned_tag /*unused*/) { m_value = _mm256_loadu_pd(ptr); } + CCM_ALWAYS_INLINE void copy_to(double * ptr, element_aligned_tag /*unused*/) const { _mm256_storeu_pd(ptr, m_value); } + [[nodiscard]] CCM_ALWAYS_INLINE constexpr __m256d get() const { return m_value; } + [[nodiscard]] CCM_ALWAYS_INLINE double convert() const { return _mm256_cvtsd_f64(m_value); } + CCM_ALWAYS_INLINE simd_mask operator<(simd const & other) const { return {_mm256_cmp_pd(m_value, other.m_value, _CMP_LT_OS)}; } + CCM_ALWAYS_INLINE simd_mask operator==(simd const & other) const { return {_mm256_cmp_pd(m_value, other.m_value, _CMP_EQ_OS)}; } + + private: + __m256d m_value; + }; + + CCM_ALWAYS_INLINE simd + choose(simd_mask const & a, simd const & b, simd const & c) + { + return {_mm256_blendv_pd(c.get(), b.get(), a.get())}; + } } // namespace ccm::intrin - #endif // CCMATH_HAS_SIMD_AVX2 + #endif // CCMATH_HAS_SIMD_AVX2 #endif // CCMATH_HAS_SIMD diff --git a/include/ccmath/internal/math/runtime/simd/instructions/neon.hpp b/include/ccmath/internal/math/runtime/simd/instructions/neon.hpp index 0f0702c9..7d38be5b 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/neon.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/neon.hpp @@ -31,11 +31,12 @@ namespace ccm::intrin struct simd_mask { - using value_type = bool; - using simd_type = simd_mask; - using abi_type = abi::neon; + using value_type = bool; + using simd_type = simd_mask; + using abi_type = abi::neon; CCM_ALWAYS_INLINE simd_mask() = default; - CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(vreinterpretq_u32_s32(vdupq_n_s32(-int(value)))) {} + CCM_ALWAYS_INLINE + simd_mask(bool value) : m_value(vreinterpretq_u32_s32(vdupq_n_s32(-int(value)))) {} static constexpr int size() { return 4; } CCM_ALWAYS_INLINE constexpr simd_mask(uint32x4_t const & value_in) : m_value(value_in) {} [[nodiscard]] CCM_ALWAYS_INLINE constexpr uint32x4_t get() const { return m_value; } @@ -60,15 +61,18 @@ namespace ccm::intrin template <> struct simd { - using value_type = float; - using abi_type = abi::neon; - using mask_type = simd_mask; - using storage_type = simd_storage; + using value_type = float; + using abi_type = abi::neon; + 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(vdupq_n_f32(value)) {} - CCM_ALWAYS_INLINE simd(float a, float b, float c, float d) : m_value((float32x4_t){a, b, c, d}) {} - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE + simd(float value) : m_value(vdupq_n_f32(value)) {} + CCM_ALWAYS_INLINE + simd(float a, float b, float c, float d) : m_value((float32x4_t){a, b, c, d}) {} + 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()); @@ -79,7 +83,8 @@ namespace ccm::intrin { copy_from(ptr, flags); } - CCM_ALWAYS_INLINE simd(float const * ptr, int stride) : simd(ptr[0], ptr[stride], ptr[2 * stride], ptr[3 * stride]) {} + 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(float32x4_t const & value_in) : m_value(value_in) {} CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return simd(vmulq_f32(m_value, other.m_value)); } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return simd(vdivq_f32(m_value, other.m_value)); } @@ -103,8 +108,7 @@ namespace ccm::intrin float32x4_t m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, simd const & c) { return simd(vreinterpretq_f32_u32(vbslq_u32(a.get(), vreinterpretq_u32_f32(b.get()), vreinterpretq_u32_f32(c.get())))); } @@ -112,11 +116,12 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::neon; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::neon; CCM_ALWAYS_INLINE simd_mask() = default; - CCM_ALWAYS_INLINE simd_mask(bool value) : m_value(vreinterpretq_u64_s64(vdupq_n_s64(-std::int64_t(value)))) {} + CCM_ALWAYS_INLINE + simd_mask(bool value) : m_value(vreinterpretq_u64_s64(vdupq_n_s64(-std::int64_t(value)))) {} static constexpr int size() { return 4; } CCM_ALWAYS_INLINE constexpr simd_mask(uint64x2_t const & value_in) : m_value(value_in) {} [[nodiscard]] CCM_ALWAYS_INLINE constexpr uint64x2_t get() const { return m_value; } @@ -141,19 +146,22 @@ namespace ccm::intrin template <> struct simd { - using value_type = double; - using abi_type = abi::neon; - 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::neon; + 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(vdupq_n_f64(value)) {} - CCM_ALWAYS_INLINE simd(double a, double b) : m_value((float64x2_t){a, b}) {} - CCM_ALWAYS_INLINE simd(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); } + CCM_ALWAYS_INLINE + simd(double value) : m_value(vdupq_n_f64(value)) {} + CCM_ALWAYS_INLINE + simd(double a, double b) : m_value((float64x2_t){a, b}) {} + 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()); @@ -164,7 +172,8 @@ namespace ccm::intrin { copy_from(ptr, flags); } - CCM_ALWAYS_INLINE simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride]) {} + CCM_ALWAYS_INLINE + simd(double const * ptr, int stride) : simd(ptr[0], ptr[stride]) {} CCM_ALWAYS_INLINE constexpr simd(float64x2_t const & value_in) : m_value(value_in) {} CCM_ALWAYS_INLINE simd operator*(simd const & other) const { return simd(vmulq_f64(m_value, other.m_value)); } CCM_ALWAYS_INLINE simd operator/(simd const & other) const { return simd(vdivq_f64(m_value, other.m_value)); } @@ -188,8 +197,8 @@ namespace ccm::intrin float64x2_t m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd + choose(simd_mask const & a, simd const & b, simd const & c) { return simd(vreinterpretq_f64_u64(vbslq_u64(a.get(), vreinterpretq_u64_f64(b.get()), vreinterpretq_u64_f64(c.get())))); } diff --git a/include/ccmath/internal/math/runtime/simd/instructions/scalar.hpp b/include/ccmath/internal/math/runtime/simd/instructions/scalar.hpp index ef00ca5a..a45e7e87 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/scalar.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/scalar.hpp @@ -24,9 +24,9 @@ namespace ccm::intrin template struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::scalar; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::scalar; CCM_ALWAYS_INLINE simd_mask() = default; CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE static constexpr int size() { return 1; } CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE explicit simd_mask(bool value) : m_value(value) {} @@ -46,8 +46,8 @@ namespace ccm::intrin using Abi = abi::scalar; public: - using value_type = T; - using simd_type = simd; + using value_type = T; + using simd_type = simd; CCM_ALWAYS_INLINE simd_storage() = default; static constexpr int size() { return simd::size(); } CCM_ALWAYS_INLINE explicit CCM_GPU_HOST_DEVICE simd_storage(simd const & value) CCM_GPU_HOST_DEVICE @@ -67,7 +67,6 @@ namespace ccm::intrin private: T m_value; - }; template @@ -86,18 +85,21 @@ namespace ccm::intrin // NOLINTNEXTLINE struct simd { - using value_type = T; - using abi_type = abi::scalar; - 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 = T; + using abi_type = abi::scalar; + 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; 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) {} // 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(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()); @@ -108,7 +110,8 @@ namespace ccm::intrin { copy_from(ptr, flags); } - 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(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); } @@ -133,8 +136,8 @@ namespace ccm::intrin }; template - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd + choose(simd_mask const & a, simd const & b, simd const & c) { return simd(choose(a.get(), b.get(), c.get())); } diff --git a/include/ccmath/internal/math/runtime/simd/instructions/sse2.hpp b/include/ccmath/internal/math/runtime/simd/instructions/sse2.hpp index f0ec9547..238cf62f 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/sse2.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/sse2.hpp @@ -34,9 +34,9 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::sse2; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::sse2; 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; } @@ -63,15 +63,18 @@ namespace ccm::intrin template <> struct simd { - using value_type = float; - using abi_type = abi::sse2; - using mask_type = simd_mask; - using storage_type = simd_storage; + using value_type = float; + using abi_type = abi::sse2; + 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)) {} // 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()); } // NOLINT + 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()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -81,8 +84,9 @@ 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]) {} // NOLINT - CCM_ALWAYS_INLINE constexpr simd(__m128 const & value_in) : m_value(value_in) {} // NOLINT(google-explicit-constructor) + 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)}; } @@ -105,8 +109,7 @@ namespace ccm::intrin __m128 m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, 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()))); @@ -115,9 +118,9 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::sse2; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::sse2; 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; } @@ -144,19 +147,25 @@ namespace ccm::intrin template <> struct simd // NOLINT { - using value_type = double; - using abi_type = abi::sse2; - 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::sse2; + 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)) {} // 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()); } // NOLINT(google-explicit-constructor, cppcoreguidelines-pro-type-member-init) + 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()); + } // 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()); @@ -166,7 +175,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]) {} // NOLINT + 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)}; } @@ -191,8 +201,8 @@ namespace ccm::intrin __m128d m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd + choose(simd_mask const & a, simd const & b, 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/math/runtime/simd/instructions/sse3.hpp b/include/ccmath/internal/math/runtime/simd/instructions/sse3.hpp index dc1a7e7b..ecfb9bce 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/sse3.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/sse3.hpp @@ -22,7 +22,7 @@ namespace ccm::intrin { - + namespace abi { struct sse3 @@ -34,9 +34,9 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::sse3; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::sse3; 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; } @@ -63,15 +63,18 @@ namespace ccm::intrin template <> struct simd { - using value_type = float; - using abi_type = abi::sse3; - using mask_type = simd_mask; - using storage_type = simd_storage; + using value_type = float; + using abi_type = abi::sse3; + 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 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(float value) : m_value(_mm_set1_ps(value)) {} + 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 & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -81,7 +84,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 + 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 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)}; } @@ -105,8 +109,7 @@ namespace ccm::intrin __m128 m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, 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()))); @@ -115,9 +118,9 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::sse3; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::sse3; 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; } @@ -144,19 +147,22 @@ namespace ccm::intrin template <> struct simd { - using value_type = double; - using abi_type = abi::sse3; - 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::sse3; + 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 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(double value) : m_value(_mm_set1_pd(value)) {} + 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 & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -166,7 +172,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 + 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 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)}; } @@ -191,8 +198,8 @@ namespace ccm::intrin __m128d m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd + choose(simd_mask const & a, simd const & b, 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/math/runtime/simd/instructions/sse4.hpp b/include/ccmath/internal/math/runtime/simd/instructions/sse4.hpp index bceb2ea9..b3b47ee8 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/sse4.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/sse4.hpp @@ -15,15 +15,15 @@ #ifdef CCMATH_HAS_SIMD #ifdef CCMATH_HAS_SIMD_SSE4 - #include // SSE4.1 #include // SSE4.2 + #include // SSE4.1 #endif #ifdef CCMATH_HAS_SIMD_SSE4 namespace ccm::intrin { - + namespace abi { struct sse4 @@ -35,9 +35,9 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::sse4; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::sse4; 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; } @@ -64,15 +64,18 @@ namespace ccm::intrin template <> struct simd { - using value_type = float; - using abi_type = abi::sse4; - using mask_type = simd_mask; - using storage_type = simd_storage; + using value_type = float; + using abi_type = abi::sse4; + 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 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(float value) : m_value(_mm_set1_ps(value)) {} + 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 & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -82,7 +85,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 + 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 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)}; } @@ -106,8 +110,7 @@ namespace ccm::intrin __m128 m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, 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()))); @@ -116,9 +119,9 @@ namespace ccm::intrin template <> struct simd_mask { - using value_type = bool; - using simd_type = simd; - using abi_type = abi::sse4; + using value_type = bool; + using simd_type = simd; + using abi_type = abi::sse4; 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; } @@ -145,19 +148,22 @@ namespace ccm::intrin template <> struct simd { - using value_type = double; - using abi_type = abi::sse4; - 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::sse4; + 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 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(double value) : m_value(_mm_set1_pd(value)) {} + 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 & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -167,7 +173,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 + 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 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)}; } @@ -192,8 +199,8 @@ namespace ccm::intrin __m128d m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd + choose(simd_mask const & a, simd const & b, 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/math/runtime/simd/instructions/ssse3.hpp b/include/ccmath/internal/math/runtime/simd/instructions/ssse3.hpp index ecb764e6..58659570 100644 --- a/include/ccmath/internal/math/runtime/simd/instructions/ssse3.hpp +++ b/include/ccmath/internal/math/runtime/simd/instructions/ssse3.hpp @@ -70,9 +70,12 @@ 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)) {} // 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()); } // NOLINT + 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()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -82,8 +85,9 @@ 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]) {} // NOLINT - CCM_ALWAYS_INLINE constexpr simd(__m128 const & value_in) : m_value(value_in) {} // NOLINT + 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)}; } @@ -106,8 +110,8 @@ namespace ccm::intrin __m128 m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd + choose(simd_mask const & a, simd const & b, 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()))); @@ -155,9 +159,12 @@ 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)) {} // 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()); } // NOLINT + 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()); } // NOLINT CCM_ALWAYS_INLINE simd & operator=(storage_type const & value) { copy_from(value.data(), element_aligned_tag()); @@ -167,8 +174,9 @@ 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]) {} // NOLINT - CCM_ALWAYS_INLINE constexpr simd(__m128d const & value_in) : m_value(value_in) {} // NOLINT + 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)}; } @@ -192,8 +200,8 @@ namespace ccm::intrin __m128d m_value; }; - CCM_ALWAYS_INLINE simd choose(simd_mask const & a, simd const & b, - simd const & c) + CCM_ALWAYS_INLINE simd + choose(simd_mask const & a, simd const & b, 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/math/runtime/simd/pack.hpp b/include/ccmath/internal/math/runtime/simd/pack.hpp index b91b2668..ba197139 100644 --- a/include/ccmath/internal/math/runtime/simd/pack.hpp +++ b/include/ccmath/internal/math/runtime/simd/pack.hpp @@ -26,9 +26,9 @@ namespace ccm::intrin template struct simd_mask> { - using value_type = bool; - using simd_type = simd>; - using abi_type = abi::pack; + using value_type = bool; + using simd_type = simd>; + using abi_type = abi::pack; CCM_ALWAYS_INLINE simd_mask() = default; [[nodiscard]] static constexpr int size() { return N; } CCM_ALWAYS_INLINE explicit simd_mask(bool value) @@ -75,9 +75,9 @@ namespace ccm::intrin template struct simd_mask> { - using value_type = bool; - using simd_type = simd>; - using abi_type = abi::pack; + using value_type = bool; + using simd_type = simd>; + using abi_type = abi::pack; CCM_ALWAYS_INLINE simd_mask() = default; [[nodiscard]] static constexpr int size() { return N; } CCM_ALWAYS_INLINE explicit simd_mask(bool value) @@ -147,10 +147,10 @@ namespace ccm::intrin struct simd> { - using value_type = T; - using abi_type = abi::pack; - using mask_type = simd_mask; - using storage_type = simd_storage; + using value_type = T; + using abi_type = abi::pack; + using mask_type = simd_mask; + using storage_type = simd_storage; CCM_ALWAYS_INLINE simd() = default; [[nodiscard]] static constexpr int size() { return N; } CCM_ALWAYS_INLINE explicit simd(T value) @@ -256,8 +256,8 @@ namespace ccm::intrin }; template - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd> choose(simd_mask> const & a, simd> const & b, - simd> const & c) + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd> + choose(simd_mask> const & a, simd> const & b, simd> const & c) { simd> result; CCM_SIMD_VECTORIZE for (int i = 0; i < a.size(); ++i) diff --git a/include/ccmath/internal/math/runtime/simd/simd.hpp b/include/ccmath/internal/math/runtime/simd/simd.hpp index b6613f5f..64aa728f 100644 --- a/include/ccmath/internal/math/runtime/simd/simd.hpp +++ b/include/ccmath/internal/math/runtime/simd/simd.hpp @@ -11,7 +11,6 @@ #pragma once #include "ccmath/internal/config/arch/check_simd_support.hpp" - #include "ccmath/internal/math/runtime/simd/instructions/scalar.hpp" #include "common.hpp" #include "pack.hpp" diff --git a/include/ccmath/internal/math/runtime/simd/simd_vectorize.hpp b/include/ccmath/internal/math/runtime/simd/simd_vectorize.hpp index a4122e46..68837354 100644 --- a/include/ccmath/internal/math/runtime/simd/simd_vectorize.hpp +++ b/include/ccmath/internal/math/runtime/simd/simd_vectorize.hpp @@ -13,7 +13,7 @@ #ifndef CCM_SIMD_VECTORIZE #if defined(_OPENMP) #define CCM_SIMD_VECTORIZE _Pragma("omp simd") -// msvc + // msvc #elif defined(_MSC_VER) && !defined(__clang__) #define CCM_SIMD_VECTORIZE __pragma(loop(ivdep)) #elif defined(__clang__) diff --git a/include/ccmath/internal/math/runtime/simd/vector_size.hpp b/include/ccmath/internal/math/runtime/simd/vector_size.hpp index 5323c8ae..11481f57 100644 --- a/include/ccmath/internal/math/runtime/simd/vector_size.hpp +++ b/include/ccmath/internal/math/runtime/simd/vector_size.hpp @@ -39,9 +39,9 @@ namespace ccm::intrin __attribute__((__vector_size__(N / (sizeof(T) / sizeof(int)) * sizeof(int)))) int __attribute__((vector_size(N / (sizeof(T) / sizeof(int))))); public: - using value_type = bool; - using simd_type = simd>; - using abi_type = abi::vector_size; + using value_type = bool; + using simd_type = simd>; + using abi_type = abi::vector_size; CCM_ALWAYS_INLINE simd_mask() = default; static constexpr int size() { return N / sizeof(T); } CCM_ALWAYS_INLINE explicit simd_mask(bool value) : m_value(static_cast(value)) {} @@ -63,9 +63,9 @@ namespace ccm::intrin using native_type = __attribute__((__vector_size__(N * sizeof(long long)))) long long __attribute__((vector_size(N))); public: - using value_type = bool; - using simd_type = simd>; - using abi_type = abi::vector_size; + using value_type = bool; + using simd_type = simd>; + using abi_type = abi::vector_size; CCM_ALWAYS_INLINE simd_mask() = default; static constexpr int size() { return N / sizeof(long long); } CCM_ALWAYS_INLINE explicit simd_mask(bool value) : m_value(static_cast(value)) {} @@ -109,10 +109,10 @@ namespace ccm::intrin using native_type = __attribute__((__vector_size__(N * sizeof(T)))) T __attribute__((vector_size(N))); public: - using value_type = T; - using abi_type = abi::vector_size; - using mask_type = simd_mask; - using storage_type = simd_storage; + using value_type = T; + using abi_type = abi::vector_size; + using mask_type = simd_mask; + using storage_type = simd_storage; CCM_ALWAYS_INLINE simd() = default; static constexpr int size() { return N / sizeof(T); } CCM_ALWAYS_INLINE explicit simd(T value) @@ -180,15 +180,13 @@ namespace ccm::intrin } template - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd> max(simd> const & a, - simd> const & b) + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd> max(simd> const & a, simd> const & b) { return choose(b < a, a, b); } template - CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd> min(simd> const & a, - simd> const & b) + CCM_ALWAYS_INLINE CCM_GPU_HOST_DEVICE simd> min(simd> const & a, simd> const & b) { return choose(a < b, a, b); } diff --git a/include/ccmath/internal/predef/assume.hpp b/include/ccmath/internal/predef/assume.hpp index fb18d815..cd426624 100644 --- a/include/ccmath/internal/predef/assume.hpp +++ b/include/ccmath/internal/predef/assume.hpp @@ -19,9 +19,9 @@ // If we don't have access to the standard implementation of [[assume()]] then try to check for compiler intrinsics/attributes #ifndef CCM_ASSUME -// Be aware that CLion Nova's C++ Engine does not recognize __builtin_assume as a valid symbol. -// It is incorrect and this is a known bug that is fixed in CLion 2024.2. -// The code will work fine, so ignore the warning it may emit. + // Be aware that CLion Nova's C++ Engine does not recognize __builtin_assume as a valid symbol. + // It is incorrect and this is a known bug that is fixed in CLion 2024.2. + // The code will work fine, so ignore the warning it may emit. #if defined(__clang__) #define CCM_ASSUME(...) \ do { \ diff --git a/include/ccmath/internal/predef/attributes/always_inline.hpp b/include/ccmath/internal/predef/attributes/always_inline.hpp index 6e7b7ce5..b1b67139 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. diff --git a/include/ccmath/internal/predef/attributes/gsl_suppress.hpp b/include/ccmath/internal/predef/attributes/gsl_suppress.hpp index fd731aee..5be823ea 100644 --- a/include/ccmath/internal/predef/attributes/gsl_suppress.hpp +++ b/include/ccmath/internal/predef/attributes/gsl_suppress.hpp @@ -18,4 +18,4 @@ #else #define CCM_SUPPRESS(x) #endif // _MSC_VER -#endif // __clang__ +#endif // __clang__ diff --git a/include/ccmath/internal/predef/attributes/optnone.hpp b/include/ccmath/internal/predef/attributes/optnone.hpp index 1b911512..6c0b4d73 100644 --- a/include/ccmath/internal/predef/attributes/optnone.hpp +++ b/include/ccmath/internal/predef/attributes/optnone.hpp @@ -26,4 +26,3 @@ #else #define CCM_ATTR_OPTNONE #endif - diff --git a/include/ccmath/internal/predef/compiler_suppression/clang_compiler_suppression.hpp b/include/ccmath/internal/predef/compiler_suppression/clang_compiler_suppression.hpp index 51735484..e8f2cc18 100644 --- a/include/ccmath/internal/predef/compiler_suppression/clang_compiler_suppression.hpp +++ b/include/ccmath/internal/predef/compiler_suppression/clang_compiler_suppression.hpp @@ -53,7 +53,7 @@ #define CCM_DISABLE_CLANG_WARNING(w) \ _Pragma("clang diagnostic push") _Pragma(CCM_CLANG_WHELP2(-Wunknown-warning-option)) _Pragma(CCM_CLANG_WHELP2(w)) // clang-format on -#else + #else // If not on Clang, this macro does nothing. // Must be called before CCM_RESTORE_CLANG_WARNING(). #define CCM_DISABLE_CLANG_WARNING(w) @@ -117,9 +117,9 @@ #ifndef CCM_ENABLE_CLANG_WARNING_AS_ERROR #if defined(__clang__) // Helper macros - #define CCM_CLANG_WERROR_HELP0(x) #x // Helper macros - do not use directly + #define CCM_CLANG_WERROR_HELP0(x) #x // Helper macros - do not use directly #define CCM_CLANG_WERROR_HELP1(x) CCM_CLANG_WERROR_HELP0(clang diagnostic error x) // Helper macros - do not use directly - #define CCM_CLANG_WERROR_HELP2(x) CCM_CLANG_WERROR_HELP1(#x) // Helper macros - do not use directly + #define CCM_CLANG_WERROR_HELP2(x) CCM_CLANG_WERROR_HELP1(#x) // Helper macros - do not use directly // This will enable a warning as an error for clang. This should be written as -Wwarning-name and not as a string. // Must be called before CCM_DISABLE_CLANG_WARNING_AS_ERROR(). diff --git a/include/ccmath/internal/predef/has_const_builtin.hpp b/include/ccmath/internal/predef/has_const_builtin.hpp index deae1f86..50beb2bc 100644 --- a/include/ccmath/internal/predef/has_const_builtin.hpp +++ b/include/ccmath/internal/predef/has_const_builtin.hpp @@ -17,4 +17,4 @@ #else #define CCM_HAS_CONST_BUILTIN(BUILTIN) 0 #endif // defined(__has_constexpr_builtin) -#endif // CCM_HAS_CONST_BUILTIN +#endif // CCM_HAS_CONST_BUILTIN diff --git a/include/ccmath/internal/predef/versioning/arm_version.hpp b/include/ccmath/internal/predef/versioning/arm_version.hpp index ce3db3ac..7a537a40 100644 --- a/include/ccmath/internal/predef/versioning/arm_version.hpp +++ b/include/ccmath/internal/predef/versioning/arm_version.hpp @@ -9,4 +9,3 @@ */ #pragma once - diff --git a/include/ccmath/internal/setup.hpp b/include/ccmath/internal/setup.hpp index d3de17a7..d2a91a51 100644 --- a/include/ccmath/internal/setup.hpp +++ b/include/ccmath/internal/setup.hpp @@ -17,5 +17,3 @@ #ifndef INTERNAL_STRINGIFY #define INTERNAL_STRINGIFY(x) INTERNAL_PRIMITIVE_STRINGIFY(x) #endif - - diff --git a/include/ccmath/internal/support/bits.hpp b/include/ccmath/internal/support/bits.hpp index 7dde8bf0..cf620532 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 diff --git a/include/ccmath/internal/support/ctz.hpp b/include/ccmath/internal/support/ctz.hpp index b2edf2dc..de2ea7ca 100644 --- a/include/ccmath/internal/support/ctz.hpp +++ b/include/ccmath/internal/support/ctz.hpp @@ -10,8 +10,8 @@ #pragma once -#include "ccmath/internal/predef/has_builtin.hpp" #include "ccmath/internal/config/type_support.hpp" +#include "ccmath/internal/predef/has_builtin.hpp" #include "ccmath/internal/support/type_traits.hpp" #include "ccmath/internal/types/float128.hpp" @@ -49,11 +49,11 @@ namespace ccm::support template && traits::ccm_is_unsigned_v && !std::is_same_v, bool> = true> constexpr int ctz(T value) noexcept { - #if CCM_HAS_BUILTIN(__builtin_ctzg) - return __builtin_ctzg(value); - #else +#if CCM_HAS_BUILTIN(__builtin_ctzg) + return __builtin_ctzg(value); +#else return internal::generic_ctz(value); - #endif +#endif } template <> diff --git a/include/ccmath/internal/support/endian.hpp b/include/ccmath/internal/support/endian.hpp index ada4beed..bae54fa2 100644 --- a/include/ccmath/internal/support/endian.hpp +++ b/include/ccmath/internal/support/endian.hpp @@ -16,18 +16,16 @@ namespace ccm::helpers { enum class endian : std::uint16_t { - // TODO: Add support for other compilers besides just MSVC, GCC, and Clang. + // TODO: Add support for other compilers besides just MSVC, GCC, and Clang. #if defined(_MSC_VER) && !defined(__clang__) little = 0, - big = 1, + big = 1, native = little #else little = __ORDER_LITTLE_ENDIAN__, - big = __ORDER_BIG_ENDIAN__, + big = __ORDER_BIG_ENDIAN__, native = __BYTE_ORDER__ #endif }; } // namespace ccm::helpers - - diff --git a/include/ccmath/internal/support/fenv/fenv_support.hpp b/include/ccmath/internal/support/fenv/fenv_support.hpp index 87fc6ac0..88c94499 100644 --- a/include/ccmath/internal/support/fenv/fenv_support.hpp +++ b/include/ccmath/internal/support/fenv/fenv_support.hpp @@ -21,7 +21,7 @@ #include #if defined(_MSC_VER) && !defined(__clang__) -#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" + #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code #endif @@ -112,11 +112,11 @@ namespace ccm::support::fenv constexpr bool is_errno_enabled() { - #if defined(__FAST_MATH__) || defined(CCM_CONFIG_DISABLE_ERRNO) +#if defined(__FAST_MATH__) || defined(CCM_CONFIG_DISABLE_ERRNO) return false; - #else +#else return true; - #endif +#endif } // Helper function to convert the enum class to an integer to enable bitwise operations. @@ -125,8 +125,6 @@ namespace ccm::support::fenv return static_cast(mode); } - - constexpr int ccm_math_err_handling() { #if defined(__FAST_MATH__) || defined(CCM_CONFIG_DISABLE_ERRNO) @@ -144,7 +142,7 @@ namespace ccm::support::fenv inline int set_except_if_required(const int 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 (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); } @@ -156,7 +154,7 @@ namespace ccm::support::fenv inline int raise_except_if_required(const int 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 (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); } diff --git a/include/ccmath/internal/support/fenv/rounding_mode.hpp b/include/ccmath/internal/support/fenv/rounding_mode.hpp index 9bba0a8d..cfb1e136 100644 --- a/include/ccmath/internal/support/fenv/rounding_mode.hpp +++ b/include/ccmath/internal/support/fenv/rounding_mode.hpp @@ -34,7 +34,7 @@ namespace ccm::support::fenv inline bool rt_rounding_mode_is_round_to_nearest() { static volatile const float x = 0x1.0p-24F; - float const y = x; + float const y = x; return (1.5F + y == 1.5F - y); } @@ -42,15 +42,15 @@ namespace ccm::support::fenv { static volatile const float x = 0x1.0p-24F; - const float y = x; + const float y = x; return ((0x1.000002p0F + y) + (-1.0F - y) == 0x1.0p-23F); } inline int rt_get_rounding_mode() { static volatile const float x = 0x1.0p-24F; - float const y = x; - float const z = (0x1.000002p0F + y) + (-1.0F - y); + float const y = x; + float const z = (0x1.000002p0F + y) + (-1.0F - y); if (z == 0.0F) { return FE_DOWNWARD; } if (z == 0x1.0p-23F) { return FE_TOWARDZERO; } diff --git a/include/ccmath/internal/support/fp/directional_rounding_utils.hpp b/include/ccmath/internal/support/fp/directional_rounding_utils.hpp index 0b619625..8b91dd63 100644 --- a/include/ccmath/internal/support/fp/directional_rounding_utils.hpp +++ b/include/ccmath/internal/support/fp/directional_rounding_utils.hpp @@ -75,7 +75,7 @@ namespace ccm::support::fp } auto trimming_length = static_cast(FPBits_t::fraction_length - exponent); - FPBits_t new_bits = bits; + FPBits_t new_bits = bits; new_bits.set_mantissa((bits.get_mantissa() >> trimming_length) << trimming_length); T truncated_value = new_bits.get_val(); @@ -112,13 +112,17 @@ namespace ccm::support::fp } // Helper func to set results for exceptional cases. - template constexpr T round_result_slightly_down(T value_rn) { + template + constexpr T round_result_slightly_down(T value_rn) + { volatile T tmp = value_rn; tmp -= FPBits::min_normal().get_val(); return tmp; } - template constexpr T round_result_slightly_up(T value_rn) { + template + constexpr T round_result_slightly_up(T value_rn) + { volatile T tmp = value_rn; tmp += FPBits::min_normal().get_val(); return tmp; diff --git a/include/ccmath/internal/support/fp/fp_bits.hpp b/include/ccmath/internal/support/fp/fp_bits.hpp index f1423f31..991894f7 100644 --- a/include/ccmath/internal/support/fp/fp_bits.hpp +++ b/include/ccmath/internal/support/fp/fp_bits.hpp @@ -49,41 +49,41 @@ namespace ccm::support::fp template <> struct FPLayout { - using storage_type = std::uint32_t; - static constexpr std::int_fast32_t sign_length = 1; - static constexpr std::int_fast32_t exponent_length = 8; + using storage_type = std::uint32_t; + static constexpr std::int_fast32_t sign_length = 1; + static constexpr std::int_fast32_t exponent_length = 8; static constexpr std::int_fast32_t significand_length = 23; - static constexpr std::int_fast32_t fraction_length = significand_length; + static constexpr std::int_fast32_t fraction_length = significand_length; }; template <> struct FPLayout { - using storage_type = std::uint64_t; - static constexpr std::int_fast32_t sign_length = 1; - static constexpr std::int_fast32_t exponent_length = 11; + using storage_type = std::uint64_t; + static constexpr std::int_fast32_t sign_length = 1; + static constexpr std::int_fast32_t exponent_length = 11; static constexpr std::int_fast32_t significand_length = 52; - static constexpr std::int_fast32_t fraction_length = significand_length; + static constexpr std::int_fast32_t fraction_length = significand_length; }; template <> struct FPLayout { - using storage_type = types::uint128_t; - static constexpr std::int_fast32_t sign_length = 1; - static constexpr std::int_fast32_t exponent_length = 15; + using storage_type = types::uint128_t; + static constexpr std::int_fast32_t sign_length = 1; + static constexpr std::int_fast32_t exponent_length = 15; static constexpr std::int_fast32_t significand_length = 64; - static constexpr std::int_fast32_t fraction_length = significand_length - 1; + static constexpr std::int_fast32_t fraction_length = significand_length - 1; }; template <> struct FPLayout { - using storage_type = types::uint128_t; - static constexpr std::int_fast32_t sign_length = 1; - static constexpr std::int_fast32_t exponent_length = 15; + using storage_type = types::uint128_t; + static constexpr std::int_fast32_t sign_length = 1; + static constexpr std::int_fast32_t exponent_length = 15; static constexpr std::int_fast32_t significand_length = 112; - static constexpr std::int_fast32_t fraction_length = significand_length; + static constexpr std::int_fast32_t fraction_length = significand_length; }; template @@ -218,13 +218,9 @@ namespace ccm::support::fp using BASE::BASE; static constexpr auto subnormal() { return Exponent(-exponent_bias); } - static constexpr auto min() { return Exponent(1 - exponent_bias); } - static constexpr auto zero() { return Exponent(0); } - static constexpr auto max() { return Exponent(exponent_bias); } - static constexpr auto inf() { return Exponent(exponent_bias + 1); } }; @@ -293,18 +289,13 @@ namespace ccm::support::fp friend constexpr Significand operator>>(const Significand a, int shift) { return Significand(storage_type(a.to_storage_type() >> shift)); } static constexpr auto zero() { return Significand(storage_type(0)); } - static constexpr auto lsb() { return Significand(storage_type(1)); } - static constexpr auto msb() { return Significand(storage_type(1) << (significand_length - 1)); } - static constexpr auto bits_all_ones() { return Significand(significand_mask); } }; static constexpr storage_type encode(BiasedExponent exp) { return (exp.to_storage_type() << significand_length) & exponent_mask; } - static constexpr storage_type encode(Significand value) { return value.to_storage_type() & significand_mask; } - static constexpr storage_type encode(BiasedExponent exp, Significand sig) { return encode(exp) | encode(sig); } static constexpr storage_type encode(types::Sign sign, BiasedExponent exp, Significand sig) @@ -321,9 +312,7 @@ namespace ccm::support::fp /// Observer Functions [[nodiscard]] constexpr storage_type exp_bits() const { return bits & exponent_mask; } - [[nodiscard]] constexpr storage_type sig_bits() const { return bits & significand_mask; } - [[nodiscard]] constexpr storage_type exp_sig_bits() const { return bits & exponent_significand_mask; } /// Parts of the floating point number @@ -375,9 +364,7 @@ namespace ccm::support::fp /// Builder Functions static constexpr RetT zero(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::subnormal(), Significand::zero())); } - static constexpr RetT one(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::zero(), Significand::zero())); } - static constexpr RetT min_subnormal(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::subnormal(), Significand::lsb())); } static constexpr RetT max_subnormal(types::Sign sign = types::Sign::POS) @@ -386,9 +373,7 @@ namespace ccm::support::fp } static constexpr RetT min_normal(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::min(), Significand::zero())); } - static constexpr RetT max_normal(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::max(), Significand::bits_all_ones())); } - static constexpr RetT inf(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::inf(), Significand::zero())); } static constexpr RetT signaling_nan(types::Sign sign = types::Sign::POS, storage_type v = 0) @@ -404,19 +389,12 @@ namespace ccm::support::fp /// Observer Functions [[nodiscard]] constexpr bool is_zero() const { return exp_sig_bits() == 0; } - [[nodiscard]] constexpr bool is_nan() const { return exp_sig_bits() > encode(Exponent::inf(), Significand::zero()); } - [[nodiscard]] constexpr bool is_quiet_nan() const { return exp_sig_bits() >= encode(Exponent::inf(), Significand::msb()); } - [[nodiscard]] constexpr bool is_signaling_nan() const { return is_nan() && !is_quiet_nan(); } - [[nodiscard]] constexpr bool is_inf() const { return exp_sig_bits() == encode(Exponent::inf(), Significand::zero()); } - [[nodiscard]] constexpr bool is_finite() const { return exp_bits() != encode(Exponent::inf()); } - [[nodiscard]] constexpr bool is_subnormal() const { return exp_bits() == encode(Exponent::subnormal()); } - [[nodiscard]] constexpr bool is_normal() const { return is_finite() && !is_subnormal(); } constexpr RetT next_toward_inf() const @@ -472,9 +450,7 @@ namespace ccm::support::fp /// Builder Functions static constexpr RetT zero(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::subnormal(), Significand::zero())); } - static constexpr RetT one(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::zero(), Significand::msb())); } - static constexpr RetT min_subnormal(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::subnormal(), Significand::lsb())); } static constexpr RetT max_subnormal(types::Sign sign = types::Sign::POS) @@ -483,9 +459,7 @@ namespace ccm::support::fp } static constexpr RetT min_normal(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::min(), Significand::msb())); } - static constexpr RetT max_normal(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::max(), Significand::bits_all_ones())); } - static constexpr RetT inf(types::Sign sign = types::Sign::POS) { return RetT(encode(sign, Exponent::inf(), Significand::msb())); } static constexpr RetT signaling_nan(types::Sign sign = types::Sign::POS, storage_type v = 0) @@ -538,13 +512,9 @@ namespace ccm::support::fp } [[nodiscard]] constexpr bool is_signaling_nan() const { return is_nan() && !is_quiet_nan(); } - [[nodiscard]] constexpr bool is_inf() const { return exp_sig_bits() == encode(Exponent::inf(), Significand::msb()); } - [[nodiscard]] constexpr bool is_finite() const { return !is_inf() && !is_nan(); } - [[nodiscard]] constexpr bool is_subnormal() const { return exp_bits() == encode(Exponent::subnormal()); } - [[nodiscard]] constexpr bool is_normal() const { if (const auto exp = exp_bits(); exp == encode(Exponent::subnormal()) || exp == encode(Exponent::inf())) { return false; } diff --git a/include/ccmath/internal/support/helpers/digit_to_int.hpp b/include/ccmath/internal/support/helpers/digit_to_int.hpp index 97ebb434..86a902cd 100644 --- a/include/ccmath/internal/support/helpers/digit_to_int.hpp +++ b/include/ccmath/internal/support/helpers/digit_to_int.hpp @@ -14,18 +14,9 @@ namespace ccm::support::helpers { constexpr int digit_to_int(int c) { - if ('0' <= c && c <= '9') - { - return (c - '0'); - } - if ('A' <= c && c <= 'F') - { - return (c - 'A' + 10); - } - if ('a' <= c && c <= 'f') - { - return (c - 'a' + 10); - } + if ('0' <= c && c <= '9') { return (c - '0'); } + if ('A' <= c && c <= 'F') { return (c - 'A' + 10); } + if ('a' <= c && c <= 'f') { return (c - 'a' + 10); } return 0; } } // namespace ccm::support::helpers diff --git a/include/ccmath/internal/support/helpers/exp10.hpp b/include/ccmath/internal/support/helpers/exp10.hpp index 5e3ca3b4..aa452d90 100644 --- a/include/ccmath/internal/support/helpers/exp10.hpp +++ b/include/ccmath/internal/support/helpers/exp10.hpp @@ -11,14 +11,13 @@ #pragma once #include "ccmath/internal/support/multiply_add.hpp" +#include "ccmath/internal/support/poly_eval.hpp" #include "ccmath/internal/types/double_double.hpp" #include "ccmath/internal/types/triple_double.hpp" #include "ccmath/math/expo/log2.hpp" #include -#include "ccmath/internal/support/poly_eval.hpp" - namespace ccm::support::helpers { namespace impl diff --git a/include/ccmath/internal/support/helpers/exp_helpers.hpp b/include/ccmath/internal/support/helpers/exp_helpers.hpp index 68992d52..4071e6e3 100644 --- a/include/ccmath/internal/support/helpers/exp_helpers.hpp +++ b/include/ccmath/internal/support/helpers/exp_helpers.hpp @@ -12,6 +12,7 @@ #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/support/meta_compare.hpp" + #include #include diff --git a/include/ccmath/internal/support/helpers/fpclassify_helper.hpp b/include/ccmath/internal/support/helpers/fpclassify_helper.hpp index 818b0425..fe8783ff 100644 --- a/include/ccmath/internal/support/helpers/fpclassify_helper.hpp +++ b/include/ccmath/internal/support/helpers/fpclassify_helper.hpp @@ -28,37 +28,37 @@ namespace ccm::support::helpers struct floating_point_defines { #if defined(CCMATH_COMPILER_MSVC) // Mirrors the corecrt definitions - static constexpr int eFP_NAN = 2; - static constexpr int eFP_INFINITE = 1; - static constexpr int eFP_ZERO = 0; + 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; + static constexpr int eFP_NORMAL = -1; #elif defined(CCMATH_COMPILER_APPLE_CLANG) // Apple Clang has a different set of defines than Clang - static constexpr int eFP_NAN = 1; - static constexpr int eFP_INFINITE = 2; - static constexpr int eFP_ZERO = 3; + static constexpr int eFP_NAN = 1; + static constexpr int eFP_INFINITE = 2; + static constexpr int eFP_ZERO = 3; static constexpr int eFP_SUBNORMAL = 5; - static constexpr int eFP_NORMAL = 4; -#elif defined(CCMATH_COMPILER_NVIDIA_HPC) // Nvidia HPC SDK has a different set of defines than GCC - static constexpr int eFP_NAN = 0; - static constexpr int eFP_INFINITE = 1; - static constexpr int eFP_ZERO = 2; + static constexpr int eFP_NORMAL = 4; +#elif defined(CCMATH_COMPILER_NVIDIA_HPC) // Nvidia HPC SDK has a different set of defines than GCC + static constexpr int eFP_NAN = 0; + static constexpr int eFP_INFINITE = 1; + 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_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; + 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; - static constexpr int eFP_ZERO = 2; + static constexpr int eFP_NAN = 0; + static constexpr int eFP_INFINITE = 1; + static constexpr int eFP_ZERO = 2; static constexpr int eFP_SUBNORMAL = 3; - static constexpr int eFP_NORMAL = 4; + static constexpr int eFP_NORMAL = 4; #else - #error "FP_* macros are extremely implementation specific and are not defined for this compiler. Please add support for this compiler." + #error "FP_* macros are extremely implementation specific and are not defined for this compiler. Please add support for this compiler." #endif }; } // 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 b4107cb8..e180d7a3 100644 --- a/include/ccmath/internal/support/helpers/internal_ldexp.hpp +++ b/include/ccmath/internal/support/helpers/internal_ldexp.hpp @@ -10,8 +10,6 @@ #pragma once -#include - #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/support/fenv/fenv_support.hpp" @@ -19,6 +17,8 @@ #include "ccmath/internal/support/fp/fp_bits.hpp" #include "ccmath/internal/types/dyadic_float.hpp" +#include + namespace ccm::support::helpers { template , int> = 0> diff --git a/include/ccmath/internal/support/integer_literals.hpp b/include/ccmath/internal/support/integer_literals.hpp index eaafe6e3..2242d4c8 100644 --- a/include/ccmath/internal/support/integer_literals.hpp +++ b/include/ccmath/internal/support/integer_literals.hpp @@ -105,7 +105,6 @@ namespace ccm::support } CCM_RESTORE_MSVC_WARNING() - // Adds a single character to this buffer. constexpr void push(char c) { diff --git a/include/ccmath/internal/support/is_constant_evaluated.hpp b/include/ccmath/internal/support/is_constant_evaluated.hpp index 3e101dbc..ac0b1b3f 100644 --- a/include/ccmath/internal/support/is_constant_evaluated.hpp +++ b/include/ccmath/internal/support/is_constant_evaluated.hpp @@ -23,17 +23,17 @@ // Visual Studio 2019 and later supports __builtin_is_constant_evaluated #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 192528326) - # define CCMATH_HAS_BUILTIN_IS_CONSTANT_EVALUATED + #define CCMATH_HAS_BUILTIN_IS_CONSTANT_EVALUATED #endif namespace ccm::support { constexpr bool is_constant_evaluated() noexcept { - #if defined(CCMATH_HAS_BUILTIN_IS_CONSTANT_EVALUATED) +#if defined(CCMATH_HAS_BUILTIN_IS_CONSTANT_EVALUATED) return __builtin_is_constant_evaluated(); - #else +#else return false; - #endif +#endif } } // namespace ccm::support diff --git a/include/ccmath/internal/support/math_support.hpp b/include/ccmath/internal/support/math_support.hpp index d2e9e211..32a53bb6 100644 --- a/include/ccmath/internal/support/math_support.hpp +++ b/include/ccmath/internal/support/math_support.hpp @@ -15,7 +15,6 @@ #include "ccmath/internal/support/is_constant_evaluated.hpp" #include "ccmath/internal/support/type_traits.hpp" - #include namespace ccm::support diff --git a/include/ccmath/internal/support/poly_eval.hpp b/include/ccmath/internal/support/poly_eval.hpp index 6a052021..769f6393 100644 --- a/include/ccmath/internal/support/poly_eval.hpp +++ b/include/ccmath/internal/support/poly_eval.hpp @@ -27,44 +27,31 @@ namespace ccm::support // Code borrowed from LLVM template - constexpr std::enable_if_t<(sizeof(T) > sizeof(void *)), T> - polyeval(const T & /*unused*/, const T &a0) + constexpr std::enable_if_t<(sizeof(T) > sizeof(void *)), T> polyeval(const T & /*unused*/, const T & a0) { return a0; } template - constexpr std::enable_if_t<(sizeof(T) <= sizeof(void *)), T> - polyeval(T /*unused*/, T a0) + constexpr std::enable_if_t<(sizeof(T) <= sizeof(void *)), T> polyeval(T /*unused*/, T a0) { return a0; } template - constexpr std::enable_if_t<(sizeof(T) > sizeof(void *)), T> - polyeval(const T &x, const T &a0, const Ts &...a) + constexpr std::enable_if_t<(sizeof(T) > sizeof(void *)), T> polyeval(const T & x, const T & a0, const Ts &... a) { return multiply_add(x, polyeval(x, a...), a0); } template - constexpr std::enable_if_t<(sizeof(T) <= sizeof(void *)), T> - polyeval(T x, T a0, Ts... a) + constexpr std::enable_if_t<(sizeof(T) <= sizeof(void *)), T> polyeval(T x, T a0, Ts... a) { return multiply_add(x, polyeval(x, a...), a0); } struct fp_helpers { - }; - - - - - - - - } // namespace ccm::support diff --git a/include/ccmath/internal/support/type_traits.hpp b/include/ccmath/internal/support/type_traits.hpp index a40fb359..cb457190 100644 --- a/include/ccmath/internal/support/type_traits.hpp +++ b/include/ccmath/internal/support/type_traits.hpp @@ -171,9 +171,7 @@ template <> struct ccm_make_signed<__int128_t> : type_identity<__int128_t> {}; template <> struct ccm_make_signed<__uint128_t> : type_identity<__int128_t> {}; #endif template using ccm_make_signed_t = typename ccm_make_signed::type; - // clang-format on - } // namespace ccm::support::traits diff --git a/include/ccmath/internal/types/big_int.hpp b/include/ccmath/internal/types/big_int.hpp index 6104124d..ea011ea8 100644 --- a/include/ccmath/internal/types/big_int.hpp +++ b/include/ccmath/internal/types/big_int.hpp @@ -33,7 +33,7 @@ #include #if defined(_MSC_VER) && !defined(__clang__) -#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" + #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code #endif @@ -41,7 +41,6 @@ namespace ccm::types { namespace multiword { - /** * @brief Type trait that maps unsigned integers to their corresponding half-width types. * @@ -1570,8 +1569,10 @@ namespace ccm::support 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 - for (std::size_t i = 0; i <= QUOTIENT; ++i) { out[i] = i < QUOTIENT ? -1 : mask_trailing_ones(); } + using word_size_t = traits::type_identity_t; + for (std::size_t i = 0; i <= QUOTIENT; ++i) { out[i] = i < QUOTIENT ? static_cast(-1) : mask_trailing_ones(); } return out; } diff --git a/include/ccmath/internal/types/double_double.hpp b/include/ccmath/internal/types/double_double.hpp index 590d48e1..5db83db9 100644 --- a/include/ccmath/internal/types/double_double.hpp +++ b/include/ccmath/internal/types/double_double.hpp @@ -64,20 +64,20 @@ namespace ccm { DoubleDouble r{0.0, 0.0}; - // If we have builtin FMA, we can use it to get the exact product. - #if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) +// If we have builtin FMA, we can use it to get the exact product. +#if defined(__GNUC__) && (__GNUC__ > 6 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1)) && !defined(__clang__) r.hi = a * b; r.lo = support::multiply_add(a, b, -r.hi); - #else +#else // Dekker's Product. const DoubleDouble as = split(a); const DoubleDouble bs = split(b); r.hi = a * b; - const double t1 = as.hi * bs.hi - r.hi; - const double t2 = as.hi * bs.lo + t1; - const double t3 = as.lo * bs.hi + t2; - r.lo = as.lo * bs.lo + t3; - #endif + const double t1 = (as.hi * bs.hi) - r.hi; + const double t2 = (as.hi * bs.lo) + t1; + const double t3 = (as.lo * bs.hi) + t2; + r.lo = (as.lo * bs.lo) + t3; +#endif return r; } diff --git a/include/ccmath/internal/types/dyadic_float.hpp b/include/ccmath/internal/types/dyadic_float.hpp index f9d14b58..21967041 100644 --- a/include/ccmath/internal/types/dyadic_float.hpp +++ b/include/ccmath/internal/types/dyadic_float.hpp @@ -46,9 +46,9 @@ namespace ccm::types { using mantissa_type = UInt; - Sign sign = Sign::POS; - int exponent = 0; - mantissa_type mantissa = mantissa_type(0); + Sign sign = Sign::POS; + int exponent = 0; + mantissa_type mantissa = mantissa_type(0); constexpr DyadicFloat() = default; @@ -135,13 +135,14 @@ namespace ccm::types * @tparam T The target floating-point type. * @return The floating-point representation of the DyadicFloat. */ - template && (support::fp::FPBits::fraction_length < Bits), void>> + template && (support::fp::FPBits::fraction_length < Bits), void>> explicit constexpr operator T() const { if (CCM_UNLIKELY(mantissa.is_zero())) { return support::fp::FPBits::zero(sign).get_val(); } // Assume normalized input and output. - constexpr uint32_t desired_precision = support::fp::FPBits::fraction_length + 1; + constexpr uint32_t desired_precision = support::fp::FPBits::fraction_length + 1; using output_bits_t = typename support::fp::FPBits::storage_type; constexpr output_bits_t implicit_mask = support::fp::FPBits::significand_mask - support::fp::FPBits::fraction_mask; @@ -171,10 +172,11 @@ namespace ccm::types mantissa_type m_hi = shift >= mantissa_len ? mantissa_type(0) : mantissa >> shift; - T d_hi = - support::fp::FPBits::create_value(sign, static_cast(exp_hi), (static_cast(m_hi) & support::fp::FPBits::significand_mask) | implicit_mask).get_val(); + T d_hi = support::fp::FPBits::create_value(sign, static_cast(exp_hi), + (static_cast(m_hi) & support::fp::FPBits::significand_mask) | implicit_mask) + .get_val(); - mantissa_type round_mask = shift > mantissa_len ? 0 : mantissa_type(1) << (shift - 1); + mantissa_type round_mask = shift > mantissa_len ? 0 : mantissa_type(1) << (shift - 1); mantissa_type sticky_mask = round_mask - mantissa_type(1); bool round_bit = !(mantissa & round_mask).is_zero(); @@ -187,8 +189,14 @@ namespace ccm::types { // d_lo is denormal, but the output is normal. int scale_up_exponent = 2 * desired_precision; - T scale_up_factor = support::fp::FPBits::create_value(sign, support::fp::FPBits::exponent_bias + static_cast(scale_up_exponent), implicit_mask).get_val(); - T scale_down_factor = support::fp::FPBits::create_value(sign, support::fp::FPBits::exponent_bias - static_cast(scale_up_exponent), implicit_mask).get_val(); + T scale_up_factor = + support::fp::FPBits::create_value(sign, support::fp::FPBits::exponent_bias + static_cast(scale_up_exponent), + implicit_mask) + .get_val(); + T scale_down_factor = + support::fp::FPBits::create_value(sign, support::fp::FPBits::exponent_bias - static_cast(scale_up_exponent), + implicit_mask) + .get_val(); d_lo = support::fp::FPBits::create_value(sign, static_cast(exp_lo + scale_up_exponent), implicit_mask).get_val(); diff --git a/include/ccmath/internal/types/float128.hpp b/include/ccmath/internal/types/float128.hpp index 384a8234..2affc2fa 100644 --- a/include/ccmath/internal/types/float128.hpp +++ b/include/ccmath/internal/types/float128.hpp @@ -10,7 +10,6 @@ #pragma once - namespace ccm::types { diff --git a/include/ccmath/internal/types/fp_types.hpp b/include/ccmath/internal/types/fp_types.hpp index 902cfb07..8a5b92e6 100644 --- a/include/ccmath/internal/types/fp_types.hpp +++ b/include/ccmath/internal/types/fp_types.hpp @@ -15,21 +15,21 @@ // Mirror float_t and double_t from to avoid having a dependency of . #ifdef FLT_EVAL_METHOD - # if FLT_EVAL_METHOD == -1 - # define CCM_FLT_EVAL_METHOD 2 - # else - # define CCM_FLT_EVAL_METHOD FLT_EVAL_METHOD - # endif + #if FLT_EVAL_METHOD == -1 + #define CCM_FLT_EVAL_METHOD 2 + #else + #define CCM_FLT_EVAL_METHOD FLT_EVAL_METHOD + #endif #elif defined __x86_64__ - # define CCM_FLT_EVAL_METHOD 0 + #define CCM_FLT_EVAL_METHOD 0 #else - # define CCM_FLT_EVAL_METHOD 2 + #define CCM_FLT_EVAL_METHOD 2 #endif namespace ccm { #if CCM_FLT_EVAL_METHOD == 0 || CCM_FLT_EVAL_METHOD == 16 - using float_t = float; + using float_t = float; using double_t = double; #elif CCM_FLT_EVAL_METHOD == 1 typedef double float_t; @@ -37,7 +37,7 @@ namespace ccm #elif CCM_FLT_EVAL_METHOD == 2 typedef long double float_t; typedef long double double_t; -# else - # error "Unknown CCM_FLT_EVAL_METHOD" -# endif +#else + #error "Unknown CCM_FLT_EVAL_METHOD" +#endif } // namespace ccm diff --git a/include/ccmath/internal/types/normalized_float.hpp b/include/ccmath/internal/types/normalized_float.hpp index b6781dbc..c27bad15 100644 --- a/include/ccmath/internal/types/normalized_float.hpp +++ b/include/ccmath/internal/types/normalized_float.hpp @@ -22,4 +22,3 @@ namespace ccm::types { }; } // namespace ccm::types - diff --git a/include/ccmath/math/basic/fabs.hpp b/include/ccmath/math/basic/fabs.hpp index 61b02924..fd0ea694 100644 --- a/include/ccmath/math/basic/fabs.hpp +++ b/include/ccmath/math/basic/fabs.hpp @@ -10,8 +10,8 @@ #pragma once -#include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/math/generic/builtins/basic/fabs.hpp" +#include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" #include @@ -24,7 +24,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 constexpr (ccm::builtin::has_constexpr_abs) { return ccm::builtin::abs(num); } @@ -50,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. @@ -63,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 @@ -84,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); @@ -96,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 a3d4181e..1ce82a72 100644 --- a/include/ccmath/math/basic/fdim.hpp +++ b/include/ccmath/math/basic/fdim.hpp @@ -10,8 +10,8 @@ #pragma once -#include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/math/generic/builtins/basic/fdim.hpp" +#include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/fp/fp_bits.hpp" #include @@ -29,10 +29,7 @@ namespace ccm template , bool> = true> constexpr T fdim(T x, T y) { - if constexpr (builtin::has_constexpr_fdim) - { - return builtin::fdim(x, y); - } + if constexpr (builtin::has_constexpr_fdim) { return builtin::fdim(x, y); } else { using FPBits_t = typename ccm::support::fp::FPBits; diff --git a/include/ccmath/math/basic/fma.hpp b/include/ccmath/math/basic/fma.hpp index 7e9cf8a2..9545dd43 100644 --- a/include/ccmath/math/basic/fma.hpp +++ b/include/ccmath/math/basic/fma.hpp @@ -10,11 +10,11 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/basic/fma.hpp" #include "ccmath/internal/predef/unlikely.hpp" #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 @@ -33,33 +33,27 @@ namespace ccm 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__) +// 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 +#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))) { // ...z is NaN, return +NaN... - if (ccm::isnan(z)) - { - return std::numeric_limits::quiet_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(); } // 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 (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(); } diff --git a/include/ccmath/math/basic/impl/nan_double_impl.hpp b/include/ccmath/math/basic/impl/nan_double_impl.hpp index d08f769d..726dffa6 100644 --- a/include/ccmath/math/basic/impl/nan_double_impl.hpp +++ b/include/ccmath/math/basic/impl/nan_double_impl.hpp @@ -10,10 +10,9 @@ #pragma once -#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 "ccmath/internal/support/bits.hpp" +#include "ccmath/internal/support/helpers/digit_to_int.hpp" #include #include @@ -25,10 +24,7 @@ namespace ccm::internal::impl constexpr double nan_double_impl(const char * arg) noexcept { - if constexpr (!std::numeric_limits::is_iec559) - { - return 0.0; - } + if constexpr (!std::numeric_limits::is_iec559) { return 0.0; } #if defined(_MSC_VER) && !defined(__clang__) // Currently, MSVC always returns a Quiet NaN no matter if a payload is diff --git a/include/ccmath/math/basic/impl/nan_float_impl.hpp b/include/ccmath/math/basic/impl/nan_float_impl.hpp index 4879a0eb..48debd3a 100644 --- a/include/ccmath/math/basic/impl/nan_float_impl.hpp +++ b/include/ccmath/math/basic/impl/nan_float_impl.hpp @@ -10,8 +10,8 @@ #pragma once -#include "ccmath/internal/support/helpers/digit_to_int.hpp" #include "ccmath/internal/support/bits.hpp" +#include "ccmath/internal/support/helpers/digit_to_int.hpp" #include #include @@ -20,10 +20,7 @@ namespace ccm::internal::impl { constexpr float nan_float_impl(const char * arg) noexcept { - if constexpr (!std::numeric_limits::is_iec559) - { - return 0.0F; - } + if constexpr (!std::numeric_limits::is_iec559) { return 0.0F; } #if defined(_MSC_VER) && !defined(__clang__) // Currently, MSVC always returns a Quiet NaN no matter if a payload is diff --git a/include/ccmath/math/basic/impl/nan_ldouble_impl.hpp b/include/ccmath/math/basic/impl/nan_ldouble_impl.hpp index 96b20d28..999a4f66 100644 --- a/include/ccmath/math/basic/impl/nan_ldouble_impl.hpp +++ b/include/ccmath/math/basic/impl/nan_ldouble_impl.hpp @@ -10,14 +10,13 @@ #pragma once -#include "ccmath/internal/support/helpers/digit_to_int.hpp" #include "ccmath/internal/support/bits.hpp" +#include "ccmath/internal/support/helpers/digit_to_int.hpp" #include "ccmath/internal/types/int128_types.hpp" #include #include - namespace ccm::internal::impl { constexpr long double nan_ldouble_impl(const char * arg) noexcept; @@ -26,19 +25,16 @@ namespace ccm::internal::impl constexpr long double nan_ldouble_impl(const char * arg) noexcept { - if constexpr (!std::numeric_limits::is_iec559) - { - return 0.0; - } + if constexpr (!std::numeric_limits::is_iec559) { return 0.0; } -#if defined(_MSC_VER) && !defined(__clang__) + #if defined(_MSC_VER) && !defined(__clang__) // Currently, MSVC always returns a Quiet NaN no matter if a payload is // provided or not. This is different from GCC and Clang which do allow payloads to be set. // 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 -#endif + #endif if (arg == nullptr) { diff --git a/include/ccmath/math/basic/impl/remquo_float_impl.hpp b/include/ccmath/math/basic/impl/remquo_float_impl.hpp index 352ce521..3acb2913 100644 --- a/include/ccmath/math/basic/impl/remquo_float_impl.hpp +++ b/include/ccmath/math/basic/impl/remquo_float_impl.hpp @@ -10,14 +10,14 @@ #pragma once -#include -#include - #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/basic/fmod.hpp" +#include +#include + namespace ccm::internal { namespace impl diff --git a/include/ccmath/math/basic/impl/remquo_ldouble_impl.hpp b/include/ccmath/math/basic/impl/remquo_ldouble_impl.hpp index 56818b8a..7d86260f 100644 --- a/include/ccmath/math/basic/impl/remquo_ldouble_impl.hpp +++ b/include/ccmath/math/basic/impl/remquo_ldouble_impl.hpp @@ -10,33 +10,33 @@ #pragma once -#include -#include - #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/math/basic/fabs.hpp" #include "ccmath/math/basic/fmod.hpp" +#include +#include + namespace ccm::internal { namespace impl { constexpr long double remquo_ldouble_impl(long double x, long double y, int * quo) noexcept { - /* - std::int32_t x_exponent{}; - std::int32_t y_exponent{}; - std::int32_t x_int32{}; - std::int32_t y_int32{}; - - std::uint32_t x_sign{}; - std::uint32_t y_msb{}; - std::uint32_t x_lsb{}; - - int quotient_sign{}; - int computed_quotient{}; - */ + /* + std::int32_t x_exponent{}; + std::int32_t y_exponent{}; + std::int32_t x_int32{}; + std::int32_t y_int32{}; + + std::uint32_t x_sign{}; + std::uint32_t y_msb{}; + std::uint32_t x_lsb{}; + + int quotient_sign{}; + int computed_quotient{}; + */ // TODO: For the time being this is mega on hold until we have access to // necessary implementations of int128_t. Without them extracting the // needed bits to perform the necessary operations would be extremely challenging diff --git a/include/ccmath/math/compare/fpclassify.hpp b/include/ccmath/math/compare/fpclassify.hpp index 0303c657..ebdf0c5a 100644 --- a/include/ccmath/math/compare/fpclassify.hpp +++ b/include/ccmath/math/compare/fpclassify.hpp @@ -30,10 +30,7 @@ namespace ccm if (ccm::isnan(num)) { return ccm::support::helpers::floating_point_defines::eFP_NAN; } if (ccm::isinf(num)) { return ccm::support::helpers::floating_point_defines::eFP_INFINITE; } if (num == static_cast(0)) { return ccm::support::helpers::floating_point_defines::eFP_ZERO; } - if (ccm::abs(num) < std::numeric_limits::min() && ccm::abs(num) > 0) - { - return ccm::support::helpers::floating_point_defines::eFP_SUBNORMAL; - } + if (ccm::abs(num) < std::numeric_limits::min() && ccm::abs(num) > 0) { return ccm::support::helpers::floating_point_defines::eFP_SUBNORMAL; } return ccm::support::helpers::floating_point_defines::eFP_NORMAL; } } // namespace ccm diff --git a/include/ccmath/math/compare/isfinite.hpp b/include/ccmath/math/compare/isfinite.hpp index 0c18055b..bfd56d5a 100644 --- a/include/ccmath/math/compare/isfinite.hpp +++ b/include/ccmath/math/compare/isfinite.hpp @@ -10,9 +10,8 @@ #pragma once -#include "ccmath/internal/support/fp/fp_bits.hpp" #include "ccmath/internal/math/generic/builtins/compare/isfinite.hpp" - +#include "ccmath/internal/support/fp/fp_bits.hpp" namespace ccm { diff --git a/include/ccmath/math/compare/isgreater.hpp b/include/ccmath/math/compare/isgreater.hpp index 54ea8bc0..8962fe39 100644 --- a/include/ccmath/math/compare/isgreater.hpp +++ b/include/ccmath/math/compare/isgreater.hpp @@ -10,11 +10,11 @@ #pragma once -#include - #include "ccmath/internal/math/generic/builtins/compare/isgreater.hpp" #include "ccmath/math/compare/isunordered.hpp" +#include + namespace ccm { /** diff --git a/include/ccmath/math/compare/isgreaterequal.hpp b/include/ccmath/math/compare/isgreaterequal.hpp index 5cbbe920..1c3875d0 100644 --- a/include/ccmath/math/compare/isgreaterequal.hpp +++ b/include/ccmath/math/compare/isgreaterequal.hpp @@ -28,10 +28,7 @@ namespace ccm constexpr bool isgreaterequal(T x, T y) noexcept { if constexpr (ccm::builtin::has_constexpr_isgreaterequal) { return ccm::builtin::isgreaterequal(x, y); } - else - { - return !ccm::isunordered(x,y) && (x >= y); - } + else { return !ccm::isunordered(x, y) && (x >= y); } } /** diff --git a/include/ccmath/math/compare/isinf.hpp b/include/ccmath/math/compare/isinf.hpp index 0230865f..f89fb5f9 100644 --- a/include/ccmath/math/compare/isinf.hpp +++ b/include/ccmath/math/compare/isinf.hpp @@ -10,8 +10,8 @@ #pragma once -#include "ccmath/internal/support/fp/fp_bits.hpp" #include "ccmath/internal/math/generic/builtins/compare/isinf.hpp" +#include "ccmath/internal/support/fp/fp_bits.hpp" #include #include diff --git a/include/ccmath/math/compare/isnan.hpp b/include/ccmath/math/compare/isnan.hpp index a71107c2..b7cc1609 100644 --- a/include/ccmath/math/compare/isnan.hpp +++ b/include/ccmath/math/compare/isnan.hpp @@ -12,7 +12,6 @@ #include "ccmath/internal/math/generic/builtins/compare/isnan.hpp" - #include namespace ccm diff --git a/include/ccmath/math/compare/isnormal.hpp b/include/ccmath/math/compare/isnormal.hpp index 6a671e4d..e208a753 100644 --- a/include/ccmath/math/compare/isnormal.hpp +++ b/include/ccmath/math/compare/isnormal.hpp @@ -10,11 +10,10 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/compare/isnormal.hpp" #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 { @@ -28,10 +27,7 @@ namespace ccm constexpr bool isnormal(T num) noexcept { 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(); - } + 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/signbit.hpp b/include/ccmath/math/compare/signbit.hpp index 3c3b77dc..6c705a91 100644 --- a/include/ccmath/math/compare/signbit.hpp +++ b/include/ccmath/math/compare/signbit.hpp @@ -32,10 +32,7 @@ namespace ccm template , bool> = true> [[nodiscard]] constexpr bool signbit(T num) noexcept { - if constexpr (builtin::has_constexpr_signbit) - { - return builtin::signbit(num); - } + if constexpr (builtin::has_constexpr_signbit) { return builtin::signbit(num); } else { // Check for the sign of +0.0 and -0.0 with bit_cast diff --git a/include/ccmath/math/expo/exp.hpp b/include/ccmath/math/expo/exp.hpp index 236c8596..7ecee61c 100644 --- a/include/ccmath/math/expo/exp.hpp +++ b/include/ccmath/math/expo/exp.hpp @@ -10,13 +10,12 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/expo/exp.hpp" #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" + #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code #endif diff --git a/include/ccmath/math/expo/exp2.hpp b/include/ccmath/math/expo/exp2.hpp index 1c58c12d..dd798fa5 100644 --- a/include/ccmath/math/expo/exp2.hpp +++ b/include/ccmath/math/expo/exp2.hpp @@ -11,16 +11,15 @@ #pragma once #include "ccmath/internal/config/builtin/exp2_support.hpp" +#include "ccmath/internal/math/generic/builtins/expo/exp2.hpp" #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 #if defined(_MSC_VER) && !defined(__clang__) -#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" + #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code #endif @@ -81,4 +80,3 @@ namespace ccm #if defined(_MSC_VER) && !defined(__clang__) CCM_RESTORE_MSVC_WARNING() #endif - diff --git a/include/ccmath/math/expo/impl/exp2_data.hpp b/include/ccmath/math/expo/impl/exp2_data.hpp index e70139e0..a99c33d4 100644 --- a/include/ccmath/math/expo/impl/exp2_data.hpp +++ b/include/ccmath/math/expo/impl/exp2_data.hpp @@ -25,8 +25,8 @@ namespace ccm::internal template <> struct exp2_data // NOLINT { - static constexpr std::size_t table_bits = 5; - static constexpr std::size_t poly_order = 3; + static constexpr std::size_t table_bits = 5; + static constexpr std::size_t poly_order = 3; static constexpr std::uint64_t shifted_table_bits = (1 << table_bits); double shift_scaled{0x1.8p+52 / shifted_table_bits}; @@ -48,11 +48,10 @@ namespace ccm::internal template <> struct exp2_data { - static constexpr std::size_t table_bits = 7; - static constexpr std::size_t poly_order = 5; + static constexpr std::size_t table_bits = 7; + static constexpr std::size_t poly_order = 5; static constexpr std::size_t shifted_table_bits = (1 << table_bits); - private: static constexpr std::size_t internal_table_size = static_cast(2 * shifted_table_bits); diff --git a/include/ccmath/math/expo/impl/exp2_double_impl.hpp b/include/ccmath/math/expo/impl/exp2_double_impl.hpp index 114f6281..d4fbd85d 100644 --- a/include/ccmath/math/expo/impl/exp2_double_impl.hpp +++ b/include/ccmath/math/expo/impl/exp2_double_impl.hpp @@ -10,14 +10,13 @@ #pragma once -#include "ccmath/internal/support/helpers/exp_helpers.hpp" #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/fp/bit_mask_traits.hpp" +#include "ccmath/internal/support/helpers/exp_helpers.hpp" #include "ccmath/internal/types/fp_types.hpp" #include "ccmath/math/expo/impl/exp2_data.hpp" #include - #include #include diff --git a/include/ccmath/math/expo/impl/exp2_float_impl.hpp b/include/ccmath/math/expo/impl/exp2_float_impl.hpp index 6c9f1ecc..a72e7196 100644 --- a/include/ccmath/math/expo/impl/exp2_float_impl.hpp +++ b/include/ccmath/math/expo/impl/exp2_float_impl.hpp @@ -10,13 +10,12 @@ #pragma once +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" #include "ccmath/internal/predef/unlikely.hpp" #include "ccmath/internal/support/bits.hpp" #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 diff --git a/include/ccmath/math/expo/impl/exp_double_impl.hpp b/include/ccmath/math/expo/impl/exp_double_impl.hpp index eac4330e..56600d5f 100644 --- a/include/ccmath/math/expo/impl/exp_double_impl.hpp +++ b/include/ccmath/math/expo/impl/exp_double_impl.hpp @@ -10,10 +10,11 @@ #pragma once -#include "ccmath/internal/support/helpers/exp_helpers.hpp" #include "ccmath/internal/predef/unlikely.hpp" +#include "ccmath/internal/support/helpers/exp_helpers.hpp" #include "ccmath/internal/types/fp_types.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 4cf76a8b..93ee1b83 100644 --- a/include/ccmath/math/expo/impl/exp_float_impl.hpp +++ b/include/ccmath/math/expo/impl/exp_float_impl.hpp @@ -10,13 +10,12 @@ #pragma once -#include "ccmath/internal/support/helpers/exp_helpers.hpp" +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" #include "ccmath/internal/predef/unlikely.hpp" +#include "ccmath/internal/support/helpers/exp_helpers.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. @@ -44,7 +43,7 @@ namespace ccm::internal::impl ccm::double_t result{}; ccm::double_t scale{}; - const auto x_dbl_t = static_cast(x); + const auto x_dbl_t = static_cast(x); const std::uint32_t abs_top = ccm::support::top12_bits_of_float(x) & 0x7ff; if (CCM_UNLIKELY(abs_top >= ccm::support::top12_bits_of_float(88.0F))) diff --git a/include/ccmath/math/expo/impl/log_data.hpp b/include/ccmath/math/expo/impl/log_data.hpp index d64ea266..8180b3e8 100644 --- a/include/ccmath/math/expo/impl/log_data.hpp +++ b/include/ccmath/math/expo/impl/log_data.hpp @@ -64,7 +64,7 @@ namespace ccm::internal // log(2) generated by Sollya with: // > a = 2^-43 * nearestint(2^43*log(2)); // LSB = 2^-43 is chosen so that e_x * ln2hi is exact for -1075 < e_x < 1024. - double ln2hi{0x1.62e42fefa3800p-1}; // LSB = 2^-43 + double ln2hi{0x1.62e42fefa3800p-1}; // LSB = 2^-43 double ln2lo{0x1.ef35793c76730p-45}; // LSB = 2^-97 // relative error: 0x1.926199e8p-56 diff --git a/include/ccmath/math/expo/log.hpp b/include/ccmath/math/expo/log.hpp index c66d38d9..db388478 100644 --- a/include/ccmath/math/expo/log.hpp +++ b/include/ccmath/math/expo/log.hpp @@ -10,14 +10,13 @@ #pragma once -#include "ccmath/math/expo/impl/log_double_impl.hpp" +#include "ccmath/internal/math/generic/builtins/expo/log.hpp" #include "ccmath/internal/math/generic/func/expo/log_gen.hpp" +#include "ccmath/math/expo/impl/log_double_impl.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" + #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" CCM_DISABLE_MSVC_WARNING(4702) #endif diff --git a/include/ccmath/math/expo/log1p.hpp b/include/ccmath/math/expo/log1p.hpp index 88294a1f..62c85308 100644 --- a/include/ccmath/math/expo/log1p.hpp +++ b/include/ccmath/math/expo/log1p.hpp @@ -10,10 +10,10 @@ #pragma once -#include - #include "ccmath/internal/math/generic/builtins/expo/log1p.hpp" +#include + namespace ccm { template , bool> = true> diff --git a/include/ccmath/math/expo/log2.hpp b/include/ccmath/math/expo/log2.hpp index 033657ee..26583833 100644 --- a/include/ccmath/math/expo/log2.hpp +++ b/include/ccmath/math/expo/log2.hpp @@ -10,19 +10,18 @@ #pragma once -#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/isnan.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 #if defined(_MSC_VER) && !defined(__clang__) -#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" + #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" CCM_DISABLE_MSVC_WARNING(4702) #endif @@ -37,10 +36,7 @@ namespace ccm template , bool> = true> constexpr T log2(T num) noexcept { - if constexpr (ccm::builtin::has_constexpr_log2) - { - return ccm::builtin::log2(num); - } + if constexpr (ccm::builtin::has_constexpr_log2) { return ccm::builtin::log2(num); } else { // If the argument is ±0, -∞ is returned @@ -50,17 +46,14 @@ namespace ccm if (num == static_cast(1)) { return 0; } // If the argument is NaN, NaN is returned. - if (ccm::isnan(num) || num == std::numeric_limits::infinity()) - { - return num; - } + 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 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 +#else // All other major compilers return -qNaN if (ccm::signbit(num)) { return -std::numeric_limits::quiet_NaN(); } - #endif +#endif // We cannot handle long double at this time due to problems // with long double being platform-dependent with its bit size. diff --git a/include/ccmath/math/fmanip/copysign.hpp b/include/ccmath/math/fmanip/copysign.hpp index 578f5b56..acbf0843 100644 --- a/include/ccmath/math/fmanip/copysign.hpp +++ b/include/ccmath/math/fmanip/copysign.hpp @@ -10,11 +10,10 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/fmanip/copysign.hpp" #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 { @@ -28,10 +27,7 @@ namespace ccm template , bool> = true> constexpr T copysign(T mag, T sgn) { - if constexpr (ccm::builtin::has_constexpr_copysign) - { - return ccm::builtin::copysign(mag, sgn); - } + if constexpr (ccm::builtin::has_constexpr_copysign) { return ccm::builtin::copysign(mag, sgn); } else { if (ccm::isnan(mag) || ccm::isnan(sgn)) diff --git a/include/ccmath/math/fmanip/frexp.hpp b/include/ccmath/math/fmanip/frexp.hpp index bf36d3a5..280b4f0b 100644 --- a/include/ccmath/math/fmanip/frexp.hpp +++ b/include/ccmath/math/fmanip/frexp.hpp @@ -17,20 +17,14 @@ namespace ccm { - template , int> = 0> + template , int> = 0> constexpr T frexp(T x, int & exp) { - if constexpr (ccm::builtin::has_constexpr_frexp) - { - return ccm::builtin::frexp(x, &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_inf_or_nan()) { return x; } if (bits.is_zero()) { exp = 0; diff --git a/include/ccmath/math/fmanip/impl/modf_double_impl.hpp b/include/ccmath/math/fmanip/impl/modf_double_impl.hpp index 696319ce..c2b59dff 100644 --- a/include/ccmath/math/fmanip/impl/modf_double_impl.hpp +++ b/include/ccmath/math/fmanip/impl/modf_double_impl.hpp @@ -14,7 +14,7 @@ namespace ccm::internal::impl { - constexpr double modf_double_impl(double x, double* iptr) noexcept + constexpr double modf_double_impl(double x, double * iptr) noexcept { const std::int64_t integerValue = support::double_to_int64(x); // NOLINTNEXTLINE @@ -46,10 +46,7 @@ namespace ccm::internal::impl *iptr = x * 1.0; // Handle the NaN's separately - if (exponent == 0x400 && ((static_cast(integerValue) & UINT64_C(0xfffffffffffff)) != 0U)) - { - return x * 1.0; - } + if (exponent == 0x400 && ((static_cast(integerValue) & UINT64_C(0xfffffffffffff)) != 0U)) { return x * 1.0; } // Return ±0 x = support::int64_to_double(static_cast(static_cast(integerValue) & UINT64_C(0x8000000000000000))); diff --git a/include/ccmath/math/fmanip/impl/modf_float_impl.hpp b/include/ccmath/math/fmanip/impl/modf_float_impl.hpp index ba8e3e50..5895ccd1 100644 --- a/include/ccmath/math/fmanip/impl/modf_float_impl.hpp +++ b/include/ccmath/math/fmanip/impl/modf_float_impl.hpp @@ -14,7 +14,7 @@ namespace ccm::internal::impl { - constexpr double modf_float_impl(float x, float* iptr) noexcept + constexpr double modf_float_impl(float x, float * iptr) noexcept { //__float128 q = x; diff --git a/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp b/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp index 2f729aa7..cc9b3795 100644 --- a/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp +++ b/include/ccmath/math/fmanip/impl/scalbn_float_impl.hpp @@ -10,14 +10,13 @@ #pragma once +#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" #include "ccmath/internal/support/bits.hpp" #include "ccmath/internal/types/fp_types.hpp" #include "ccmath/math/basic/max.hpp" #include "ccmath/math/basic/min.hpp" #include - -#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" CCM_DISABLE_MSVC_WARNING(4756) // 4756: overflow in constant arithmetic namespace ccm::internal diff --git a/include/ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp b/include/ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp index 4daebe28..8292cb7c 100644 --- a/include/ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp +++ b/include/ccmath/math/fmanip/impl/scalbn_ldouble_impl.hpp @@ -15,6 +15,7 @@ #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 #include "ccmath/math/compare/isinf.hpp" #include "ccmath/math/compare/isnan.hpp" + #include #endif @@ -24,9 +25,9 @@ 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 +#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(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 +#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. // Need to benchmark it. @@ -66,10 +67,10 @@ namespace ccm::internal } } return arg; - #else +#else // This should never be called, but since we are not using templates here can can not static_assert it. return 0; - #endif +#endif } } // namespace impl diff --git a/include/ccmath/math/fmanip/ldexp.hpp b/include/ccmath/math/fmanip/ldexp.hpp index aab6dd2d..b9ad7dd0 100644 --- a/include/ccmath/math/fmanip/ldexp.hpp +++ b/include/ccmath/math/fmanip/ldexp.hpp @@ -16,7 +16,6 @@ #include "ccmath/internal/predef/has_const_builtin.hpp" #include "ccmath/internal/support/helpers/internal_ldexp.hpp" - namespace ccm { /** diff --git a/include/ccmath/math/fmanip/modf.hpp b/include/ccmath/math/fmanip/modf.hpp index aead3b61..87370f3d 100644 --- a/include/ccmath/math/fmanip/modf.hpp +++ b/include/ccmath/math/fmanip/modf.hpp @@ -15,15 +15,9 @@ namespace ccm { template - constexpr T modf(T x, T* iptr) noexcept + constexpr T modf(T x, T * iptr) noexcept { - if constexpr (ccm::builtin::has_constexpr_modf) - { - return ccm::builtin::modf(x, iptr); - } - else - { - 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 dd28df3f..23f630fd 100644 --- a/include/ccmath/math/fmanip/nextafter.hpp +++ b/include/ccmath/math/fmanip/nextafter.hpp @@ -10,9 +10,8 @@ #pragma once -#include "ccmath/internal/math/generic/func/fmanip/nextafter_gen.hpp" #include "ccmath/internal/math/generic/builtins/fmanip/nextafter.hpp" - +#include "ccmath/internal/math/generic/func/fmanip/nextafter_gen.hpp" #include diff --git a/include/ccmath/math/fmanip/nexttoward.hpp b/include/ccmath/math/fmanip/nexttoward.hpp index 6b5160f8..4edbc517 100644 --- a/include/ccmath/math/fmanip/nexttoward.hpp +++ b/include/ccmath/math/fmanip/nexttoward.hpp @@ -13,7 +13,6 @@ #include "ccmath/internal/math/generic/builtins/fmanip/nexttoward.hpp" #include "ccmath/internal/math/generic/func/fmanip/nextafter_gen.hpp" - #include namespace ccm diff --git a/include/ccmath/math/fmanip/scalbn.hpp b/include/ccmath/math/fmanip/scalbn.hpp index 4f439fb9..94c74e8a 100644 --- a/include/ccmath/math/fmanip/scalbn.hpp +++ b/include/ccmath/math/fmanip/scalbn.hpp @@ -15,9 +15,8 @@ #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" + #include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" CCM_DISABLE_MSVC_WARNING(4702) // 4702: unreachable code #endif diff --git a/include/ccmath/math/nearest/floor.hpp b/include/ccmath/math/nearest/floor.hpp index 792b0ca8..b6e69675 100644 --- a/include/ccmath/math/nearest/floor.hpp +++ b/include/ccmath/math/nearest/floor.hpp @@ -10,9 +10,9 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/nearest/floor.hpp" #include "ccmath/math/compare/isinf.hpp" #include "ccmath/math/compare/isnan.hpp" -#include "ccmath/internal/math/generic/builtins/nearest/floor.hpp" #include #include @@ -73,7 +73,6 @@ namespace ccm } } // namespace internal::impl - /** * @brief Computes the largest integer value not greater than num. * @tparam T The type of the number. diff --git a/include/ccmath/math/nearest/trunc.hpp b/include/ccmath/math/nearest/trunc.hpp index fb13f193..35ad02f5 100644 --- a/include/ccmath/math/nearest/trunc.hpp +++ b/include/ccmath/math/nearest/trunc.hpp @@ -10,10 +10,9 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/nearest/trunc.hpp" #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 { @@ -50,7 +49,7 @@ namespace ccm if (exponent <= -1) { return FPBits_t::zero(bits.sign()).get_val(); } // Perform the truncation - const int trimming_size = FPBits_t::fraction_length - exponent; + 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 91ea37a3..5c612091 100644 --- a/include/ccmath/math/power/pow.hpp +++ b/include/ccmath/math/power/pow.hpp @@ -10,11 +10,10 @@ #pragma once +#include "ccmath/internal/math/generic/builtins/power/pow.hpp" #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 diff --git a/test/basic/abs_test.cpp b/test/basic/abs_test.cpp index 119e2bc7..1e030b95 100644 --- a/test/basic/abs_test.cpp +++ b/test/basic/abs_test.cpp @@ -8,15 +8,15 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include #include +#include #include #include // NOLINTBEGIN #if defined(_MSC_VER) && !defined(__clang__) -#include "ccmath/internal/predef/compiler_suppression/msvc_compiler_suppression.hpp" + #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 diff --git a/test/basic/fdim_test.cpp b/test/basic/fdim_test.cpp index 1d46b046..0019ed47 100644 --- a/test/basic/fdim_test.cpp +++ b/test/basic/fdim_test.cpp @@ -8,9 +8,8 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include #include diff --git a/test/basic/fma_test.cpp b/test/basic/fma_test.cpp index 2eed827e..c5bcdc7f 100644 --- a/test/basic/fma_test.cpp +++ b/test/basic/fma_test.cpp @@ -8,9 +8,8 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include #include diff --git a/test/basic/fmod_test.cpp b/test/basic/fmod_test.cpp index 835a257e..d67b683a 100644 --- a/test/basic/fmod_test.cpp +++ b/test/basic/fmod_test.cpp @@ -8,9 +8,8 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include #include @@ -20,22 +19,19 @@ TEST(CcmathBasicTests, Fmod) // Test that fmod works with static_assert static_assert(ccm::fmod(1, 2) == 1, "fmod has failed testing that it is static_assert-able!"); - - // Test fmod with floating point numbers - EXPECT_FLOAT_EQ(ccm::fmod(10.0F, 3.0F), std::fmod(10.0F, 3.0F)); - EXPECT_FLOAT_EQ(ccm::fmod(10.0F, -3.0F), std::fmod(10.0F, -3.0F)); - EXPECT_FLOAT_EQ(ccm::fmod(-10.0F, 3.0F), std::fmod(-10.0F, 3.0F)); - EXPECT_FLOAT_EQ(ccm::fmod(-10.0F, -3.0F), std::fmod(-10.0F, -3.0F)); + // Test fmod with floating point numbers + EXPECT_FLOAT_EQ(ccm::fmod(10.0F, 3.0F), std::fmod(10.0F, 3.0F)); + EXPECT_FLOAT_EQ(ccm::fmod(10.0F, -3.0F), std::fmod(10.0F, -3.0F)); + EXPECT_FLOAT_EQ(ccm::fmod(-10.0F, 3.0F), std::fmod(-10.0F, 3.0F)); + EXPECT_FLOAT_EQ(ccm::fmod(-10.0F, -3.0F), std::fmod(-10.0F, -3.0F)); EXPECT_FLOAT_EQ(ccm::fmod(0.0F, 3.0F), std::fmod(0.0F, 3.0F)); - // This is a tough test as it forces rounding precision issues. - //EXPECT_FLOAT_EQ(ccm::fmod(30.508474576271183309f, 6.1016949152542370172f), std::fmod(30.508474576271183309f, 6.1016949152542370172f)); + // EXPECT_FLOAT_EQ(ccm::fmod(30.508474576271183309f, 6.1016949152542370172f), std::fmod(30.508474576271183309f, 6.1016949152542370172f)); // Test fmod with integer numbers EXPECT_EQ(ccm::fmod(10, 3), std::fmod(10, 3)); - /// Test Edge Cases // Test for edge case where if x is ±0 and y is not zero, ±0 is returned. @@ -43,14 +39,14 @@ TEST(CcmathBasicTests, Fmod) EXPECT_FLOAT_EQ(ccm::fmod(-0.0F, 1.0F), std::fmod(-0.0F, 1.0F)); // Test for edge case where if x is ±∞ and y is not NaN, NaN is returned. - const auto testForNanCcmIfXIsInfAndYIsNotNan = std::isnan(ccm::fmod(10.0F, 0.0F)); - const auto testForNanStdIfXIsInfAndYIsNotNan = std::isnan(std::fmod(10.0F, 0.0F)); + const auto testForNanCcmIfXIsInfAndYIsNotNan = std::isnan(ccm::fmod(10.0F, 0.0F)); + const auto testForNanStdIfXIsInfAndYIsNotNan = std::isnan(std::fmod(10.0F, 0.0F)); const bool isCcmNanSameAsStdNanIfXIsInfAndYIsNotNan = testForNanCcmIfXIsInfAndYIsNotNan == testForNanStdIfXIsInfAndYIsNotNan; EXPECT_TRUE(isCcmNanSameAsStdNanIfXIsInfAndYIsNotNan); // Test for edge case where if y is ±0 and x is not NaN, NaN is returned. - const auto testForNanCcmIfYIsZeroAndXIsNotNan = std::isnan(ccm::fmod(10.0F, 0.0F)); - const auto testForNanStdIfYIsZeroAndXIsNotNan = std::isnan(std::fmod(10.0F, 0.0F)); + const auto testForNanCcmIfYIsZeroAndXIsNotNan = std::isnan(ccm::fmod(10.0F, 0.0F)); + const auto testForNanStdIfYIsZeroAndXIsNotNan = std::isnan(std::fmod(10.0F, 0.0F)); const bool isCcmNanSameAsStdNanIfYIsZeroAndXIsNotNan = testForNanCcmIfYIsZeroAndXIsNotNan == testForNanStdIfYIsZeroAndXIsNotNan; EXPECT_TRUE(isCcmNanSameAsStdNanIfYIsZeroAndXIsNotNan); @@ -59,19 +55,13 @@ TEST(CcmathBasicTests, Fmod) EXPECT_FLOAT_EQ(ccm::fmod(10.0F, -std::numeric_limits::infinity()), std::fmod(10.0F, -std::numeric_limits::infinity())); // Test for edge case where if either argument is NaN, NaN is returned. - auto testForNanCcmIfEitherArgumentIsNan = std::isnan(ccm::fmod(std::numeric_limits::quiet_NaN(), 10.0F)); - auto testForNanStdIfEitherArgumentIsNan = std::isnan(std::fmod(std::numeric_limits::quiet_NaN(), 10.0F)); + auto testForNanCcmIfEitherArgumentIsNan = std::isnan(ccm::fmod(std::numeric_limits::quiet_NaN(), 10.0F)); + auto testForNanStdIfEitherArgumentIsNan = std::isnan(std::fmod(std::numeric_limits::quiet_NaN(), 10.0F)); bool isCcmNanSameAsStdNanIfEitherArgumentIsNan = testForNanCcmIfEitherArgumentIsNan == testForNanStdIfEitherArgumentIsNan; EXPECT_TRUE(isCcmNanSameAsStdNanIfEitherArgumentIsNan); - testForNanCcmIfEitherArgumentIsNan = std::isnan(ccm::fmod(10.0F, std::numeric_limits::quiet_NaN())); - testForNanStdIfEitherArgumentIsNan = std::isnan(std::fmod(10.0F, std::numeric_limits::quiet_NaN())); + testForNanCcmIfEitherArgumentIsNan = std::isnan(ccm::fmod(10.0F, std::numeric_limits::quiet_NaN())); + testForNanStdIfEitherArgumentIsNan = std::isnan(std::fmod(10.0F, std::numeric_limits::quiet_NaN())); isCcmNanSameAsStdNanIfEitherArgumentIsNan = testForNanCcmIfEitherArgumentIsNan == testForNanStdIfEitherArgumentIsNan; EXPECT_TRUE(isCcmNanSameAsStdNanIfEitherArgumentIsNan); - - - - - - } diff --git a/test/basic/max_test.cpp b/test/basic/max_test.cpp index fb9e5d9f..f0c9faa4 100644 --- a/test/basic/max_test.cpp +++ b/test/basic/max_test.cpp @@ -8,37 +8,39 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include #include - TEST(CcmathBasicTests, Fmax) { // Test that fmax works with static_assert static_assert(ccm::max(1.0, 2.0) == 2, "max has failed testing that it is static_assert-able!"); - EXPECT_EQ(ccm::fmax(1.0, 2.0), std::fmax(1.0, 2.0)); - EXPECT_EQ(ccm::fmax(2.0, 1.0), std::fmax(2.0, 1.0)); - EXPECT_EQ(ccm::fmax(1.0, 1.0), std::fmax(1.0, 1.0)); - EXPECT_EQ(ccm::fmax(std::numeric_limits::infinity(), 1.0), std::fmax(std::numeric_limits::infinity(), 1.0)); + EXPECT_EQ(ccm::fmax(1.0, 2.0), std::fmax(1.0, 2.0)); + EXPECT_EQ(ccm::fmax(2.0, 1.0), std::fmax(2.0, 1.0)); + EXPECT_EQ(ccm::fmax(1.0, 1.0), std::fmax(1.0, 1.0)); + EXPECT_EQ(ccm::fmax(std::numeric_limits::infinity(), 1.0), std::fmax(std::numeric_limits::infinity(), 1.0)); EXPECT_EQ(ccm::fmax(1.0, std::numeric_limits::infinity()), std::fmax(1.0, std::numeric_limits::infinity())); - EXPECT_EQ(ccm::fmax(std::numeric_limits::infinity(), std::numeric_limits::infinity()), std::fmax(std::numeric_limits::infinity(), std::numeric_limits::infinity())); + EXPECT_EQ(ccm::fmax(std::numeric_limits::infinity(), std::numeric_limits::infinity()), + std::fmax(std::numeric_limits::infinity(), std::numeric_limits::infinity())); EXPECT_EQ(ccm::fmax(-std::numeric_limits::infinity(), 1.0), std::fmax(-std::numeric_limits::infinity(), 1.0)); EXPECT_EQ(ccm::fmax(1.0, -std::numeric_limits::infinity()), std::fmax(1.0, -std::numeric_limits::infinity())); - EXPECT_EQ(ccm::fmax(-std::numeric_limits::infinity(), -std::numeric_limits::infinity()), std::fmax(-std::numeric_limits::infinity(), -std::numeric_limits::infinity())); + EXPECT_EQ(ccm::fmax(-std::numeric_limits::infinity(), -std::numeric_limits::infinity()), + std::fmax(-std::numeric_limits::infinity(), -std::numeric_limits::infinity())); EXPECT_EQ(ccm::fmax(std::numeric_limits::quiet_NaN(), 1.0), std::fmax(std::numeric_limits::quiet_NaN(), 1.0)); EXPECT_EQ(ccm::fmax(1.0, std::numeric_limits::quiet_NaN()), std::fmax(1.0, std::numeric_limits::quiet_NaN())); - bool CcmFmaxWhenPassedPositiveNanReturnsNan = std::isnan(ccm::fmax(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); - bool StdFmaxWhenPassedPositiveNanReturnsNan = std::isnan(std::fmax(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); + bool const CcmFmaxWhenPassedPositiveNanReturnsNan = + std::isnan(ccm::fmax(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); + bool const StdFmaxWhenPassedPositiveNanReturnsNan = + std::isnan(std::fmax(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); EXPECT_EQ(CcmFmaxWhenPassedPositiveNanReturnsNan, StdFmaxWhenPassedPositiveNanReturnsNan); - bool CcmFmaxWhenPassedNegativeNanReturnsNan = std::isnan(ccm::fmax(-std::numeric_limits::quiet_NaN(), -std::numeric_limits::quiet_NaN())); - bool StdFmaxWhenPassedNegativeNanReturnsNan = std::isnan(std::fmax(-std::numeric_limits::quiet_NaN(), -std::numeric_limits::quiet_NaN())); + bool const CcmFmaxWhenPassedNegativeNanReturnsNan = + std::isnan(ccm::fmax(-std::numeric_limits::quiet_NaN(), -std::numeric_limits::quiet_NaN())); + bool const StdFmaxWhenPassedNegativeNanReturnsNan = + std::isnan(std::fmax(-std::numeric_limits::quiet_NaN(), -std::numeric_limits::quiet_NaN())); EXPECT_EQ(CcmFmaxWhenPassedNegativeNanReturnsNan, StdFmaxWhenPassedNegativeNanReturnsNan); - - } diff --git a/test/basic/min_test.cpp b/test/basic/min_test.cpp index da305bae..0927063f 100644 --- a/test/basic/min_test.cpp +++ b/test/basic/min_test.cpp @@ -8,13 +8,11 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include #include - TEST(CcmathBasicTests, Min) { // Verify that ccm::min works with static_assert @@ -46,5 +44,4 @@ TEST(CcmathBasicTests, Min) EXPECT_EQ(ccm::fmin(-1, 0.0f), std::fmin(-1, 0.0f)); EXPECT_EQ(ccm::fmin(0.0f, -1), std::fmin(0.0f, -1)); EXPECT_EQ(ccm::fmin(-1.0f, -1), std::fmin(-1.0f, -1)); - } diff --git a/test/basic/nan_test.cpp b/test/basic/nan_test.cpp index 3227c5b4..cb56df14 100644 --- a/test/basic/nan_test.cpp +++ b/test/basic/nan_test.cpp @@ -8,17 +8,16 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/internal/types/float128.hpp" #include +#include #include #include #include #include #include -#include "ccmath/internal/types/float128.hpp" - // TODO: The nan func are quite brittle and the test cases are extremely forgiving to the func. // At some point we should improve these test cases and the nan func to handle all edge cases. @@ -29,7 +28,7 @@ TEST(CcmathBasicTests, NanStaticAssert) static_assert(ccm::isnan(ccm::nan("")), "ccm::nan() 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!"); + // static_assert(ccm::isnan(ccm::nanl("")), "ccm::nanl() is NOT static assertable!"); } TEST(CcmathBasicTests, Nan_Double) @@ -111,7 +110,7 @@ TEST(CcmathBasicTests, Nan_Double) // 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) + #if (LDBL_MANT_DIG == 53) TEST(CcmathBasicTests, Nan_LDouble64bit) { @@ -166,8 +165,8 @@ TEST(CcmathBasicTests, Nan_LDouble64bit) EXPECT_EQ(ccmNanBits, stdNanBits); } -// If our long double is 128 bits, then don't run this test as it would not be correct due to padding removal. -#elif LDBL_MANT_DIG == 64 + // If our long double is 128 bits, then don't run this test as it would not be correct due to padding removal. + #elif LDBL_MANT_DIG == 64 /* * 80 bit long doubles have padding bits that are not determinable. @@ -248,7 +247,7 @@ TEST(CcmathBasicTests, Nan_LDouble80bit) EXPECT_EQ(ccm_nan_bits, std_nan_bits); } -#elif LDBL_MANT_DIG == 113 + #elif LDBL_MANT_DIG == 113 // Does not strip padding as there shouldn't be any if ldouble is 128 bits template @@ -311,11 +310,11 @@ TEST(CcmathBasicTests, Nan_LDouble128bit) std_nan_bits = ldoubleToByteArray(std::nanl("000000000000000000000000000000000000000000000000000000002")); EXPECT_EQ(ccm_nan_bits, std_nan_bits); } -#else + #else 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 #endif // !(defined(SYCL_LANGUAGE_VERSION) || defined(__INTEL_LLVM_COMPILER)) diff --git a/test/basic/remainder_test.cpp b/test/basic/remainder_test.cpp index 6fc9ce00..a756d40a 100644 --- a/test/basic/remainder_test.cpp +++ b/test/basic/remainder_test.cpp @@ -8,24 +8,20 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include - TEST(CcmathBasicTests, Remainder) { - static_assert(ccm::remainder(1.0, 1.0) == 0.0, "remainder has failed testing that it is static_assert-able!"); + static_assert(ccm::remainder(1.0, 1.0) == 0.0, "remainder has failed testing that it is static_assert-able!"); EXPECT_EQ(ccm::remainder(1.0, 1.0), std::remainder(1.0, 1.0)); - EXPECT_EQ(std::isnan(ccm::remainder(1.0, 0.0)), std::isnan(std::remainder(1.0, 0.0))); - EXPECT_EQ(std::isnan(ccm::remainder(0.0, 1.0)), std::isnan(std::remainder(0.0, 1.0))); - EXPECT_EQ(std::isnan(ccm::remainder(0.0, 0.0)), std::isnan(std::remainder(0.0, 0.0))); - EXPECT_EQ(ccm::remainder(-1.0, 1.0), std::remainder(-1.0, 1.0)); - EXPECT_EQ(ccm::remainder(1.0, -1.0), std::remainder(1.0, -1.0)); - EXPECT_EQ(ccm::remainder(-1.0, -1.0), std::remainder(-1.0, -1.0)); - EXPECT_EQ(std::isnan(ccm::remainder(-1.0, 0.0)), std::isnan(std::remainder(-1.0, 0.0))); - - + EXPECT_EQ(std::isnan(ccm::remainder(1.0, 0.0)), std::isnan(std::remainder(1.0, 0.0))); + EXPECT_EQ(std::isnan(ccm::remainder(0.0, 1.0)), std::isnan(std::remainder(0.0, 1.0))); + EXPECT_EQ(std::isnan(ccm::remainder(0.0, 0.0)), std::isnan(std::remainder(0.0, 0.0))); + EXPECT_EQ(ccm::remainder(-1.0, 1.0), std::remainder(-1.0, 1.0)); + EXPECT_EQ(ccm::remainder(1.0, -1.0), std::remainder(1.0, -1.0)); + EXPECT_EQ(ccm::remainder(-1.0, -1.0), std::remainder(-1.0, -1.0)); + EXPECT_EQ(std::isnan(ccm::remainder(-1.0, 0.0)), std::isnan(std::remainder(-1.0, 0.0))); } diff --git a/test/basic/remquo_test.cpp b/test/basic/remquo_test.cpp index 829889e4..379e2277 100644 --- a/test/basic/remquo_test.cpp +++ b/test/basic/remquo_test.cpp @@ -8,37 +8,35 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include #include - constexpr double get_ccm_rem(double x, double y) { - int quotient {0}; + int quotient{0}; double remainder = ccm::remquo(x, y, "ient); return remainder; } constexpr int get_ccm_quo(double x, double y) { - int quotient {0}; + int quotient{0}; ccm::remquo(x, y, "ient); // remainder = 1 return quotient; } double get_std_rem(double x, double y) { - int quotient {0}; + int quotient{0}; double remainder = std::remquo(x, y, "ient); return remainder; } int get_std_quo(double x, double y) { - int quotient {0}; + int quotient{0}; std::remquo(x, y, "ient); return quotient; } @@ -46,9 +44,9 @@ int get_std_quo(double x, double y) TEST(CcmathBasicTests, Remquo) { // Test that remquo can be uses in a static_assert - constexpr double sa_x = -7.0; - constexpr double sa_y = 2.0; - constexpr int sa_quotient = get_ccm_quo(sa_x, sa_y); // quotient = -4 + constexpr double sa_x = -7.0; + constexpr double sa_y = 2.0; + constexpr int sa_quotient = get_ccm_quo(sa_x, sa_y); // quotient = -4 constexpr double sa_remainder = get_ccm_rem(sa_x, sa_y); // remainder = 1 static_assert(sa_quotient == -4, "sa_quotient == -4"); static_assert(sa_remainder == 1, "sa_quotient == 1"); @@ -85,20 +83,21 @@ TEST(CcmathBasicTests, Remquo) EXPECT_EQ(get_ccm_quo(-std::numeric_limits::infinity(), 2.0), get_std_quo(-std::numeric_limits::infinity(), 2.0)); // Test with NaN - bool isCcmLeftNanNegative = (std::signbit(get_ccm_rem(std::numeric_limits::quiet_NaN(), 2.0)) == true && std::isnan(get_ccm_rem(std::numeric_limits::quiet_NaN(), 2.0)) == true); // NOLINT - bool isStdLeftNanNegative = (std::signbit(get_std_rem(std::numeric_limits::quiet_NaN(), 2.0)) == true && std::isnan(get_std_rem(std::numeric_limits::quiet_NaN(), 2.0)) == true); // NOLINT - bool didCcmLeftNanReturnNan = std::isnan(get_ccm_rem(std::numeric_limits::quiet_NaN(), 2.0)); - bool didStdLeftNanReturnNan = std::isnan(get_std_rem(std::numeric_limits::quiet_NaN(), 2.0)); - EXPECT_EQ(isCcmLeftNanNegative, isStdLeftNanNegative); + bool isCcmLeftNanNegative = (std::signbit(get_ccm_rem(std::numeric_limits::quiet_NaN(), 2.0)) == true && + std::isnan(get_ccm_rem(std::numeric_limits::quiet_NaN(), 2.0)) == true); // NOLINT bool isStdLeftNanNegative = + (std::signbit(get_std_rem(std::numeric_limits::quiet_NaN(), 2.0)) == true && std::isnan(get_std_rem(std::numeric_limits::quiet_NaN(), 2.0)) + == true); // NOLINT bool didCcmLeftNanReturnNan = std::isnan(get_ccm_rem(std::numeric_limits::quiet_NaN(), 2.0)); bool didStdLeftNanReturnNan = + std::isnan(get_std_rem(std::numeric_limits::quiet_NaN(), 2.0)); EXPECT_EQ(isCcmLeftNanNegative, isStdLeftNanNegative); EXPECT_EQ(didCcmLeftNanReturnNan, didStdLeftNanReturnNan); EXPECT_EQ(get_ccm_quo(std::numeric_limits::quiet_NaN(), 2.0), get_std_quo(std::numeric_limits::quiet_NaN(), 2.0)); // Test with negative NaN - bool isCcmLeftNegativeNanNegative = (std::signbit(get_ccm_rem(-std::numeric_limits::quiet_NaN(), 2.0)) == true && std::isnan(get_ccm_rem(-std::numeric_limits::quiet_NaN(), 2.0)) == true); // NOLINT - bool isStdLeftNegativeNanNegative = (std::signbit(get_std_rem(-std::numeric_limits::quiet_NaN(), 2.0)) == true && std::isnan(get_std_rem(-std::numeric_limits::quiet_NaN(), 2.0)) == true); // NOLINT - bool didCcmLeftNegativeNanReturnNan = std::isnan(get_ccm_rem(-std::numeric_limits::quiet_NaN(), 2.0)); - bool didStdLeftNegativeNanReturnNan = std::isnan(get_std_rem(-std::numeric_limits::quiet_NaN(), 2.0)); - EXPECT_EQ(isCcmLeftNegativeNanNegative, isStdLeftNegativeNanNegative); + bool isCcmLeftNegativeNanNegative = (std::signbit(get_ccm_rem(-std::numeric_limits::quiet_NaN(), 2.0)) == true && + std::isnan(get_ccm_rem(-std::numeric_limits::quiet_NaN(), 2.0)) == true); // NOLINT bool isStdLeftNegativeNanNegative = + (std::signbit(get_std_rem(-std::numeric_limits::quiet_NaN(), 2.0)) == true && + std::isnan(get_std_rem(-std::numeric_limits::quiet_NaN(), 2.0)) == true); // NOLINT bool didCcmLeftNegativeNanReturnNan = + std::isnan(get_ccm_rem(-std::numeric_limits::quiet_NaN(), 2.0)); bool didStdLeftNegativeNanReturnNan = + std::isnan(get_std_rem(-std::numeric_limits::quiet_NaN(), 2.0)); EXPECT_EQ(isCcmLeftNegativeNanNegative, isStdLeftNegativeNanNegative); EXPECT_EQ(didCcmLeftNegativeNanReturnNan, didStdLeftNegativeNanReturnNan); EXPECT_EQ(get_ccm_quo(-std::numeric_limits::quiet_NaN(), 2.0), get_std_quo(-std::numeric_limits::quiet_NaN(), 2.0)); diff --git a/test/ccmath_test_main.cpp b/test/ccmath_test_main.cpp index c33e7558..785c9fd4 100644 --- a/test/ccmath_test_main.cpp +++ b/test/ccmath_test_main.cpp @@ -10,7 +10,7 @@ #include -int main(int argc, char** argv) +int main(int argc, char ** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/test/compare/fpclassify_test.cpp b/test/compare/fpclassify_test.cpp index 655a481b..4529f5ad 100644 --- a/test/compare/fpclassify_test.cpp +++ b/test/compare/fpclassify_test.cpp @@ -8,11 +8,10 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include - #include #include -#include TEST(CcmathCompareTests, Fpclassify) { @@ -22,20 +21,20 @@ TEST(CcmathCompareTests, Fpclassify) static_assert(ccm::fpclassify(1.0) > -100, "fpclassify has failed testing that it is static_assert-able!"); EXPECT_EQ(ccm::fpclassify(1.0), std::fpclassify(1.0)); - EXPECT_EQ(ccm::fpclassify(0.0), std::fpclassify(0.0)); - EXPECT_EQ(ccm::fpclassify(-1.0), std::fpclassify(-1.0)); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::infinity()), std::fpclassify(std::numeric_limits::infinity())); - EXPECT_EQ(ccm::fpclassify(-std::numeric_limits::infinity()), std::fpclassify(-std::numeric_limits::infinity())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::quiet_NaN()), std::fpclassify(std::numeric_limits::quiet_NaN())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::signaling_NaN()), std::fpclassify(std::numeric_limits::signaling_NaN())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::denorm_min()), std::fpclassify(std::numeric_limits::denorm_min())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::min()), std::fpclassify(std::numeric_limits::min())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::max()), std::fpclassify(std::numeric_limits::max())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::epsilon()), std::fpclassify(std::numeric_limits::epsilon())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::round_error()), std::fpclassify(std::numeric_limits::round_error())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::infinity()), std::fpclassify(std::numeric_limits::infinity())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::min()), std::fpclassify(std::numeric_limits::min())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::max()), std::fpclassify(std::numeric_limits::max())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::epsilon()), std::fpclassify(std::numeric_limits::epsilon())); - EXPECT_EQ(ccm::fpclassify(std::numeric_limits::round_error()), std::fpclassify(std::numeric_limits::round_error())); + EXPECT_EQ(ccm::fpclassify(0.0), std::fpclassify(0.0)); + EXPECT_EQ(ccm::fpclassify(-1.0), std::fpclassify(-1.0)); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::infinity()), std::fpclassify(std::numeric_limits::infinity())); + EXPECT_EQ(ccm::fpclassify(-std::numeric_limits::infinity()), std::fpclassify(-std::numeric_limits::infinity())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::quiet_NaN()), std::fpclassify(std::numeric_limits::quiet_NaN())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::signaling_NaN()), std::fpclassify(std::numeric_limits::signaling_NaN())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::denorm_min()), std::fpclassify(std::numeric_limits::denorm_min())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::min()), std::fpclassify(std::numeric_limits::min())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::max()), std::fpclassify(std::numeric_limits::max())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::epsilon()), std::fpclassify(std::numeric_limits::epsilon())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::round_error()), std::fpclassify(std::numeric_limits::round_error())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::infinity()), std::fpclassify(std::numeric_limits::infinity())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::min()), std::fpclassify(std::numeric_limits::min())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::max()), std::fpclassify(std::numeric_limits::max())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::epsilon()), std::fpclassify(std::numeric_limits::epsilon())); + EXPECT_EQ(ccm::fpclassify(std::numeric_limits::round_error()), std::fpclassify(std::numeric_limits::round_error())); } diff --git a/test/compare/isfinite_test.cpp b/test/compare/isfinite_test.cpp index 87c1dfe8..96395e3c 100644 --- a/test/compare/isfinite_test.cpp +++ b/test/compare/isfinite_test.cpp @@ -8,9 +8,8 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include #include @@ -22,5 +21,4 @@ TEST(CcmathCompareTests, IsFinite) static_assert(ccm::isfinite(1.0), "isfinite has failed testing that it is static_assert-able!"); EXPECT_EQ(ccm::isfinite(1.0), std::isfinite(1.0)); - } diff --git a/test/compare/isgreater_test.cpp b/test/compare/isgreater_test.cpp index fae08623..c20961e7 100644 --- a/test/compare/isgreater_test.cpp +++ b/test/compare/isgreater_test.cpp @@ -8,9 +8,8 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include #include @@ -20,7 +19,7 @@ TEST(CcmathCompareTests, IsGreater) static_assert(ccm::isgreater(1.0, 0.0) == true, "isgreater has failed testing that it is static_assert-able!"); // Test the basic functionality of isgreater - EXPECT_EQ(ccm::isgreater(1.0, 0.0), std::isgreater(1.0, 0.0)); + EXPECT_EQ(ccm::isgreater(1.0, 0.0), std::isgreater(1.0, 0.0)); EXPECT_EQ(ccm::isgreater(0.0, 1.0), std::isgreater(0.0, 1.0)); EXPECT_EQ(ccm::isgreater(0.0, 0.0), std::isgreater(0.0, 0.0)); EXPECT_EQ(ccm::isgreater(1.0, 1.0), std::isgreater(1.0, 1.0)); diff --git a/test/compare/isgreaterequal_test.cpp b/test/compare/isgreaterequal_test.cpp index ecb727da..56a3649a 100644 --- a/test/compare/isgreaterequal_test.cpp +++ b/test/compare/isgreaterequal_test.cpp @@ -8,16 +8,15 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include - #include #include -#include TEST(CcmathCompareTests, IsGreaterEqual) { // Test that isgreaterequal is static_assert-able - static_assert(ccm::isgreaterequal(1.0, 0.0) == true, "isgreaterequal has failed testing that it is static_assert-able!"); + static_assert(ccm::isgreaterequal(1.0, 0.0) == true, "isgreaterequal has failed testing that it is static_assert-able!"); EXPECT_EQ(ccm::isgreaterequal(1.0, 1.0), std::isgreaterequal(1.0, 1.0)); EXPECT_EQ(ccm::isgreaterequal(1.0, 0.0), std::isgreaterequal(1.0, 0.0)); @@ -26,5 +25,4 @@ TEST(CcmathCompareTests, IsGreaterEqual) EXPECT_EQ(ccm::isgreaterequal(-1.0, 0.0), std::isgreaterequal(-1.0, 0.0)); EXPECT_EQ(ccm::isgreaterequal(0.0, -1.0), std::isgreaterequal(0.0, -1.0)); EXPECT_EQ(ccm::isgreaterequal(-1.0, -1.0), std::isgreaterequal(-1.0, -1.0)); - } diff --git a/test/compare/isinf_test.cpp b/test/compare/isinf_test.cpp index ab6d21fd..205e86c2 100644 --- a/test/compare/isinf_test.cpp +++ b/test/compare/isinf_test.cpp @@ -8,11 +8,10 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include - #include #include -#include // TODO: add more tests for isinf @@ -26,5 +25,4 @@ TEST(CcmathCompareTests, IsInf) EXPECT_EQ(ccm::isinf(-1.0), std::isinf(-1.0)); EXPECT_EQ(ccm::isinf(std::numeric_limits::infinity()), std::isinf(std::numeric_limits::infinity())); EXPECT_EQ(ccm::isinf(-std::numeric_limits::infinity()), std::isinf(-std::numeric_limits::infinity())); - } diff --git a/test/compare/isless_test.cpp b/test/compare/isless_test.cpp index ce699cdf..1135c4b1 100644 --- a/test/compare/isless_test.cpp +++ b/test/compare/isless_test.cpp @@ -8,16 +8,15 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include - #include #include -#include TEST(CcmathCompareTests, IsLess) { // Test that isless is static_assert-able - static_assert(ccm::isless(1.0, 0.0) == false, "isless has failed testing that it is static_assert-able!"); + static_assert(ccm::isless(1.0, 0.0) == false, "isless has failed testing that it is static_assert-able!"); EXPECT_EQ(ccm::isless(1.0, 1.0), std::isless(1.0, 1.0)); EXPECT_EQ(ccm::isless(1.0, 0.0), std::isless(1.0, 0.0)); @@ -26,5 +25,4 @@ TEST(CcmathCompareTests, IsLess) EXPECT_EQ(ccm::isless(-1.0, 0.0), std::isless(-1.0, 0.0)); EXPECT_EQ(ccm::isless(0.0, -1.0), std::isless(0.0, -1.0)); EXPECT_EQ(ccm::isless(-1.0, -1.0), std::isless(-1.0, -1.0)); - } diff --git a/test/compare/islessequal_test.cpp b/test/compare/islessequal_test.cpp index 56db5568..d079c421 100644 --- a/test/compare/islessequal_test.cpp +++ b/test/compare/islessequal_test.cpp @@ -8,16 +8,15 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include - #include #include -#include TEST(CcmathCompareTests, IsLessEqual) { // Test that islessequal is static_assert-able - static_assert(ccm::islessequal(1.0, 0.0) == false, "islessequal has failed testing that it is static_assert-able!"); + static_assert(ccm::islessequal(1.0, 0.0) == false, "islessequal has failed testing that it is static_assert-able!"); EXPECT_EQ(ccm::islessequal(1.0, 1.0), std::islessequal(1.0, 1.0)); EXPECT_EQ(ccm::islessequal(1.0, 0.0), std::islessequal(1.0, 0.0)); @@ -26,5 +25,4 @@ TEST(CcmathCompareTests, IsLessEqual) EXPECT_EQ(ccm::islessequal(-1.0, 0.0), std::islessequal(-1.0, 0.0)); EXPECT_EQ(ccm::islessequal(0.0, -1.0), std::islessequal(0.0, -1.0)); EXPECT_EQ(ccm::islessequal(-1.0, -1.0), std::islessequal(-1.0, -1.0)); - } diff --git a/test/compare/islessgreater_test.cpp b/test/compare/islessgreater_test.cpp index 15040889..96bea97a 100644 --- a/test/compare/islessgreater_test.cpp +++ b/test/compare/islessgreater_test.cpp @@ -8,22 +8,21 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include - #include #include -#include TEST(CcmathCompareTests, IsLessGreater) { // Test that islessgreater is static_assert-able - static_assert(ccm::islessgreater(1.0, 0.0) == true, "islessgreater has failed testing that it is static_assert-able!"); + static_assert(ccm::islessgreater(1.0, 0.0) == true, "islessgreater has failed testing that it is static_assert-able!"); EXPECT_EQ(ccm::islessgreater(1.0, 1.0), std::islessgreater(1.0, 1.0)); - EXPECT_EQ(ccm::islessgreater(1.0, 0.0), std::islessgreater(1.0, 0.0)); - EXPECT_EQ(ccm::islessgreater(0.0, 1.0), std::islessgreater(0.0, 1.0)); - EXPECT_EQ(ccm::islessgreater(0.0, 0.0), std::islessgreater(0.0, 0.0)); - EXPECT_EQ(ccm::islessgreater(-1.0, 0.0), std::islessgreater(-1.0, 0.0)); - EXPECT_EQ(ccm::islessgreater(0.0, -1.0), std::islessgreater(0.0, -1.0)); - EXPECT_EQ(ccm::islessgreater(-1.0, -1.0), std::islessgreater(-1.0, -1.0)); + EXPECT_EQ(ccm::islessgreater(1.0, 0.0), std::islessgreater(1.0, 0.0)); + EXPECT_EQ(ccm::islessgreater(0.0, 1.0), std::islessgreater(0.0, 1.0)); + EXPECT_EQ(ccm::islessgreater(0.0, 0.0), std::islessgreater(0.0, 0.0)); + EXPECT_EQ(ccm::islessgreater(-1.0, 0.0), std::islessgreater(-1.0, 0.0)); + EXPECT_EQ(ccm::islessgreater(0.0, -1.0), std::islessgreater(0.0, -1.0)); + EXPECT_EQ(ccm::islessgreater(-1.0, -1.0), std::islessgreater(-1.0, -1.0)); } diff --git a/test/compare/isnan_test.cpp b/test/compare/isnan_test.cpp index 3192cfb9..eb477c2d 100644 --- a/test/compare/isnan_test.cpp +++ b/test/compare/isnan_test.cpp @@ -8,16 +8,15 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include - #include #include -#include TEST(CcmathCompareTests, IsNan) { // Test that isnan is static_assert-able - static_assert(ccm::isnan(1.0) == false, "isnan has failed testing that it is static_assert-able!"); + static_assert(ccm::isnan(1.0) == false, "isnan has failed testing that it is static_assert-able!"); EXPECT_EQ(ccm::isnan(1.0), std::isnan(1.0)); EXPECT_EQ(ccm::isnan(0.0), std::isnan(0.0)); @@ -26,5 +25,4 @@ TEST(CcmathCompareTests, IsNan) EXPECT_EQ(ccm::isnan(-std::numeric_limits::infinity()), std::isnan(-std::numeric_limits::infinity())); EXPECT_EQ(ccm::isnan(std::numeric_limits::quiet_NaN()), std::isnan(std::numeric_limits::quiet_NaN())); EXPECT_EQ(ccm::isnan(std::numeric_limits::signaling_NaN()), std::isnan(std::numeric_limits::signaling_NaN())); - } diff --git a/test/compare/isnormal_test.cpp b/test/compare/isnormal_test.cpp index 72bcf635..3f7e4da0 100644 --- a/test/compare/isnormal_test.cpp +++ b/test/compare/isnormal_test.cpp @@ -8,23 +8,23 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include - #include #include -#include TEST(CcmathCompareTests, IsNormal) { // Test that isnormal is static_assert-able - static_assert(ccm::isnormal(1.0) == true, "isnormal has failed testing that it is static_assert-able!"); + static_assert(ccm::isnormal(1.0) == true, "isnormal has failed testing that it is static_assert-able!"); // TODO: Add more tests for isnormal EXPECT_EQ(ccm::isnormal(1.0), std::isnormal(1.0)); - EXPECT_EQ(ccm::isnormal(0.0), std::isnormal(0.0)); - EXPECT_EQ(ccm::isnormal(-1.0), std::isnormal(-1.0)); - EXPECT_EQ(ccm::isnormal(std::numeric_limits::infinity()), std::isnormal(std::numeric_limits::infinity())); - EXPECT_EQ(ccm::isnormal(-std::numeric_limits::infinity()), std::isnormal(-std::numeric_limits::infinity())); - EXPECT_EQ(ccm::isnormal(std::numeric_limits::quiet_NaN()), std::isnormal(std::numeric_limits::quiet_NaN())); - //EXPECT_EQ(ccm::isnormal(std::numeric_limits::signaling_NaN()), std::isnormal(std::numeric_limits::signaling_NaN)); // Won't work with std::isnormal + EXPECT_EQ(ccm::isnormal(0.0), std::isnormal(0.0)); + EXPECT_EQ(ccm::isnormal(-1.0), std::isnormal(-1.0)); + EXPECT_EQ(ccm::isnormal(std::numeric_limits::infinity()), std::isnormal(std::numeric_limits::infinity())); + EXPECT_EQ(ccm::isnormal(-std::numeric_limits::infinity()), std::isnormal(-std::numeric_limits::infinity())); + EXPECT_EQ(ccm::isnormal(std::numeric_limits::quiet_NaN()), std::isnormal(std::numeric_limits::quiet_NaN())); + // EXPECT_EQ(ccm::isnormal(std::numeric_limits::signaling_NaN()), std::isnormal(std::numeric_limits::signaling_NaN)); // Won't work with + // std::isnormal } diff --git a/test/compare/isunordered_test.cpp b/test/compare/isunordered_test.cpp index 5357baa7..fac22ab2 100644 --- a/test/compare/isunordered_test.cpp +++ b/test/compare/isunordered_test.cpp @@ -8,28 +8,27 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include - #include #include -#include TEST(CcmathCompareTests, IsUnordered) { // Test that isunordered is static_assert-able - static_assert(ccm::isunordered(1.0, 0.0) == false, "isunordered has failed testing that it is static_assert-able!"); + static_assert(ccm::isunordered(1.0, 0.0) == false, "isunordered has failed testing that it is static_assert-able!"); EXPECT_EQ(ccm::isunordered(1.0, 1.0), std::isunordered(1.0, 1.0)); - EXPECT_EQ(ccm::isunordered(1.0, 0.0), std::isunordered(1.0, 0.0)); - EXPECT_EQ(ccm::isunordered(0.0, 1.0), std::isunordered(0.0, 1.0)); - EXPECT_EQ(ccm::isunordered(0.0, 0.0), std::isunordered(0.0, 0.0)); - EXPECT_EQ(ccm::isunordered(-1.0, 0.0), std::isunordered(-1.0, 0.0)); - EXPECT_EQ(ccm::isunordered(0.0, -1.0), std::isunordered(0.0, -1.0)); - EXPECT_EQ(ccm::isunordered(-1.0, -1.0), std::isunordered(-1.0, -1.0)); + EXPECT_EQ(ccm::isunordered(1.0, 0.0), std::isunordered(1.0, 0.0)); + EXPECT_EQ(ccm::isunordered(0.0, 1.0), std::isunordered(0.0, 1.0)); + EXPECT_EQ(ccm::isunordered(0.0, 0.0), std::isunordered(0.0, 0.0)); + EXPECT_EQ(ccm::isunordered(-1.0, 0.0), std::isunordered(-1.0, 0.0)); + EXPECT_EQ(ccm::isunordered(0.0, -1.0), std::isunordered(0.0, -1.0)); + EXPECT_EQ(ccm::isunordered(-1.0, -1.0), std::isunordered(-1.0, -1.0)); // Check for NaN EXPECT_EQ(ccm::isunordered(std::numeric_limits::quiet_NaN(), 1.0), std::isunordered(std::numeric_limits::quiet_NaN(), 1.0)); EXPECT_EQ(ccm::isunordered(1.0, std::numeric_limits::quiet_NaN()), std::isunordered(1.0, std::numeric_limits::quiet_NaN())); - EXPECT_EQ(ccm::isunordered(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()), std::isunordered(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); - + EXPECT_EQ(ccm::isunordered(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()), + std::isunordered(std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN())); } diff --git a/test/compare/signbit_test.cpp b/test/compare/signbit_test.cpp index 090d31d0..a13bad2e 100644 --- a/test/compare/signbit_test.cpp +++ b/test/compare/signbit_test.cpp @@ -8,23 +8,22 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include #include #include -#include #include - TEST(CcmathCompareTests, Signbit) { // Test that signbit is static_assert-able - static_assert(!ccm::signbit(1.0), "signbit has failed testing that it is static_assert-able!"); + static_assert(!ccm::signbit(1.0), "signbit has failed testing that it is static_assert-able!"); // MSVC has issues when std::signbit is called using an integer due to ambiguity EXPECT_EQ(ccm::signbit(1.0), std::signbit(1.0)); - EXPECT_EQ(ccm::signbit(-1.0), std::signbit(-1.0)); - EXPECT_EQ(ccm::signbit(0.0), std::signbit(0.0)); - EXPECT_EQ(ccm::signbit(-0.0), std::signbit(-0.0)); - EXPECT_EQ(ccm::signbit(std::numeric_limits::infinity()), std::signbit(std::numeric_limits::infinity())); + EXPECT_EQ(ccm::signbit(-1.0), std::signbit(-1.0)); + EXPECT_EQ(ccm::signbit(0.0), std::signbit(0.0)); + EXPECT_EQ(ccm::signbit(-0.0), std::signbit(-0.0)); + EXPECT_EQ(ccm::signbit(std::numeric_limits::infinity()), std::signbit(std::numeric_limits::infinity())); EXPECT_EQ(ccm::signbit(-std::numeric_limits::infinity()), std::signbit(-std::numeric_limits::infinity())); EXPECT_EQ(ccm::signbit(std::numeric_limits::quiet_NaN()), std::signbit(std::numeric_limits::quiet_NaN())); EXPECT_EQ(ccm::signbit(-std::numeric_limits::quiet_NaN()), std::signbit(-std::numeric_limits::quiet_NaN())); diff --git a/test/exponential/exp2_test.cpp b/test/exponential/exp2_test.cpp index 5710ed19..d26b84d1 100644 --- a/test/exponential/exp2_test.cpp +++ b/test/exponential/exp2_test.cpp @@ -8,10 +8,9 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include "ccmath/ccmath.hpp" +#include #include #include @@ -34,8 +33,6 @@ TEST(CcmathExponentialTests, Exp2_Double_ValidInput) // Test that exp2 is mathematically the same as exp( X * log(2) ) EXPECT_DOUBLE_EQ(ccm::exp2(4.0), std::exp(4.0 * std::log(2.0))); EXPECT_DOUBLE_EQ(ccm::exp2(4.0), ccm::exp(4.0 * ccm::log(2.0))); - - } TEST(CcmathExponentialTests, Exp2_Double_EdgeCases) @@ -60,8 +57,6 @@ TEST(CcmathExponentialTests, Exp2_Double_EdgeCases) EXPECT_EQ(testCcmExp2ThatNanIsPositive, testStdExp2ThatNanIsPositive); } - - TEST(CcmathExponentialTests, Exp2_Float) { EXPECT_EQ(ccm::exp2(1.0F), std::exp2(1.0F)); @@ -93,4 +88,3 @@ TEST(CcmathExponentialTests, Exp2_Float_EdgeCases) EXPECT_EQ(testCcmExp2ThatNanReturnsNan, testStdExp2ThatNanReturnsNan); EXPECT_EQ(testCcmExp2ThatNanIsPositive, testStdExp2ThatNanIsPositive); } - diff --git a/test/exponential/exp_test.cpp b/test/exponential/exp_test.cpp index 73a3a0e9..83eafeb3 100644 --- a/test/exponential/exp_test.cpp +++ b/test/exponential/exp_test.cpp @@ -8,12 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "../../include/ccmath/math/numbers.hpp" +#include "ccmath/ccmath.hpp" +#include #include #include -#include "../../include/ccmath/math/numbers.hpp" -#include "ccmath/ccmath.hpp" TEST(CcmathExponentialTests, Exp) { @@ -38,17 +38,15 @@ TEST(CcmathExponentialTests, Exp) * Also the issue only appears with the value 128.0 and only on MSVC under windows. * The same test passes on GCC and Clang on both Linux and MacOS without issue so I am allowing this test to fail. */ - //EXPECT_EQ(ccm::exp(128.0), std::exp(128.0)); + // EXPECT_EQ(ccm::exp(128.0), std::exp(128.0)); EXPECT_EQ(ccm::exp(256.0), std::exp(256.0)); EXPECT_EQ(ccm::exp(512.0), std::exp(512.0)); EXPECT_EQ(ccm::exp(1024.0), std::exp(1024.0)); EXPECT_EQ(ccm::exp(2048.0), std::exp(2048.0)); EXPECT_EQ(ccm::exp(4096.0), std::exp(4096.0)); - EXPECT_EQ(ccm::exp(4096.0) * ccm::exp(4096.0), std::exp(4096.0) * std::exp(4096.0)); - // Test Edge Cases EXPECT_EQ(ccm::exp(0.0), std::exp(0.0)); @@ -72,7 +70,7 @@ TEST(CcmathExponentialTests, Exp) EXPECT_EQ(ccm::exp(16.0F), std::exp(16.0F)); EXPECT_EQ(ccm::exp(32.0F), std::exp(32.0F)); EXPECT_EQ(ccm::exp(64.0F), std::exp(64.0F)); - //EXPECT_EQ(ccm::exp(128.0F), std::exp(128.0F)); // See above. + // EXPECT_EQ(ccm::exp(128.0F), std::exp(128.0F)); // See above. EXPECT_EQ(ccm::exp(256.0F), std::exp(256.0F)); EXPECT_EQ(ccm::exp(512.0F), std::exp(512.0F)); EXPECT_EQ(ccm::exp(1024.0F), std::exp(1024.0F)); @@ -92,6 +90,4 @@ TEST(CcmathExponentialTests, Exp) bool testStdExpThatNanIsPositiveF = std::signbit(std::exp(std::numeric_limits::quiet_NaN())); EXPECT_EQ(testCcmExpThatNanReturnsNanF, testStdExpThatNanReturnsNanF); EXPECT_EQ(testCcmExpThatNanIsPositiveF, testStdExpThatNanIsPositiveF); - - } diff --git a/test/exponential/expm1_test.cpp b/test/exponential/expm1_test.cpp index 4bb48ba6..1dd0626c 100644 --- a/test/exponential/expm1_test.cpp +++ b/test/exponential/expm1_test.cpp @@ -8,13 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathExponentialTests, Expm1) { - } diff --git a/test/exponential/log10_test.cpp b/test/exponential/log10_test.cpp index d3e82036..e4f22073 100644 --- a/test/exponential/log10_test.cpp +++ b/test/exponential/log10_test.cpp @@ -8,13 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathExponentialTests, Log10) { - } diff --git a/test/exponential/log1p_test.cpp b/test/exponential/log1p_test.cpp index 83ea6c8e..6b5968b9 100644 --- a/test/exponential/log1p_test.cpp +++ b/test/exponential/log1p_test.cpp @@ -8,13 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathExponentialTests, Log1p) { - } diff --git a/test/exponential/log2_test.cpp b/test/exponential/log2_test.cpp index d1331582..66e77ef6 100644 --- a/test/exponential/log2_test.cpp +++ b/test/exponential/log2_test.cpp @@ -8,11 +8,11 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathExponentialTests, Log2) { @@ -52,21 +52,21 @@ TEST(CcmathExponentialTests, Log2) EXPECT_EQ(ccm::log2(-0.0), std::log2(-0.0)); EXPECT_EQ(ccm::log2(std::numeric_limits::infinity()), std::log2(std::numeric_limits::infinity())); - bool testCcmLog2ThatNegInfReturnsNan = std::isnan(ccm::log2(-std::numeric_limits::infinity())); - bool testStdLog2ThatNegInfReturnsNan = std::isnan(std::log2(-std::numeric_limits::infinity())); + bool const testCcmLog2ThatNegInfReturnsNan = std::isnan(ccm::log2(-std::numeric_limits::infinity())); + bool const testStdLog2ThatNegInfReturnsNan = std::isnan(std::log2(-std::numeric_limits::infinity())); EXPECT_EQ(testCcmLog2ThatNegInfReturnsNan, testStdLog2ThatNegInfReturnsNan); - bool testCcmLog2ThatQuietNanReturnsNan = std::isnan(ccm::log2(std::numeric_limits::quiet_NaN())); - bool testStdLog2ThatQuietNanReturnsNan = std::isnan(std::log2(std::numeric_limits::quiet_NaN())); - bool testCcmLog2ThatPosQuietNanHasSameSign = std::signbit(ccm::log2(std::numeric_limits::quiet_NaN())); - bool testStdLog2ThatPosQuietNanHasSameSign = std::signbit(std::log2(std::numeric_limits::quiet_NaN())); + bool const testCcmLog2ThatQuietNanReturnsNan = std::isnan(ccm::log2(std::numeric_limits::quiet_NaN())); + bool const testStdLog2ThatQuietNanReturnsNan = std::isnan(std::log2(std::numeric_limits::quiet_NaN())); + bool const testCcmLog2ThatPosQuietNanHasSameSign = std::signbit(ccm::log2(std::numeric_limits::quiet_NaN())); + bool const testStdLog2ThatPosQuietNanHasSameSign = std::signbit(std::log2(std::numeric_limits::quiet_NaN())); EXPECT_EQ(testCcmLog2ThatQuietNanReturnsNan, testStdLog2ThatQuietNanReturnsNan); EXPECT_EQ(testCcmLog2ThatPosQuietNanHasSameSign, testStdLog2ThatPosQuietNanHasSameSign); - bool testCcmLog2ThatNegQuietNanReturnsNan = std::isnan(ccm::log2(-std::numeric_limits::quiet_NaN())); - bool testStdLog2ThatNegQuietNanReturnsNan = std::isnan(std::log2(-std::numeric_limits::quiet_NaN())); - bool testCcmLog2ThatNegQuietNanIsNegative = std::signbit(ccm::log2(-std::numeric_limits::quiet_NaN())); - bool testStdLog2ThatNegQuietNanIsNegative = std::signbit(std::log2(-std::numeric_limits::quiet_NaN())); + bool const testCcmLog2ThatNegQuietNanReturnsNan = std::isnan(ccm::log2(-std::numeric_limits::quiet_NaN())); + bool const testStdLog2ThatNegQuietNanReturnsNan = std::isnan(std::log2(-std::numeric_limits::quiet_NaN())); + bool const testCcmLog2ThatNegQuietNanIsNegative = std::signbit(ccm::log2(-std::numeric_limits::quiet_NaN())); + bool const testStdLog2ThatNegQuietNanIsNegative = std::signbit(std::log2(-std::numeric_limits::quiet_NaN())); EXPECT_EQ(testCcmLog2ThatNegQuietNanReturnsNan, testStdLog2ThatNegQuietNanReturnsNan); EXPECT_EQ(testCcmLog2ThatNegQuietNanIsNegative, testStdLog2ThatNegQuietNanIsNegative); } diff --git a/test/exponential/log_test.cpp b/test/exponential/log_test.cpp index 4da7e01c..0ad42f77 100644 --- a/test/exponential/log_test.cpp +++ b/test/exponential/log_test.cpp @@ -8,12 +8,11 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" - TEST(CcmathExponentialTests, Log) { @@ -43,7 +42,6 @@ TEST(CcmathExponentialTests, Log) EXPECT_EQ(ccm::log(524288.0), std::log(524288.0)); EXPECT_EQ(ccm::log(1048576.0), std::log(1048576.0)); - // Check for edge cases bool ccmCheckForNan = std::isnan(ccm::log(std::numeric_limits::quiet_NaN())); bool stdCheckForNan = std::isnan(std::log(std::numeric_limits::quiet_NaN())); @@ -54,6 +52,4 @@ TEST(CcmathExponentialTests, Log) EXPECT_EQ(ccmCheckForNegativeNan, stdCheckForNegativeNan); EXPECT_EQ(ccm::log(0.0), std::log(0.0)); EXPECT_EQ(ccm::log(-0.0), std::log(-0.0)); - - } diff --git a/test/fmanip/copysign_test.cpp b/test/fmanip/copysign_test.cpp index fd95241b..a78b3b91 100644 --- a/test/fmanip/copysign_test.cpp +++ b/test/fmanip/copysign_test.cpp @@ -8,11 +8,11 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathFmanipTests, Copysign) { @@ -20,13 +20,12 @@ TEST(CcmathFmanipTests, Copysign) EXPECT_EQ(ccm::copysign(1.0, -2.0), std::copysign(1.0, -2.0)); EXPECT_EQ(ccm::copysign(std::numeric_limits::infinity(), -2.0), std::copysign(std::numeric_limits::infinity(), -2.0)); - bool isCcmCopysignNan = std::isnan(ccm::copysign(std::numeric_limits::quiet_NaN(), -2.0)); - bool isStdCopysignNan = std::isnan(std::copysign(std::numeric_limits::quiet_NaN(), -2.0)); - bool isCcmCopysignNanNegative = std::signbit(ccm::copysign(std::numeric_limits::quiet_NaN(), -2.0)); - bool isStdCopysignNanNegative = std::signbit(std::copysign(std::numeric_limits::quiet_NaN(), -2.0)); + bool const isCcmCopysignNan = std::isnan(ccm::copysign(std::numeric_limits::quiet_NaN(), -2.0)); + bool const isStdCopysignNan = std::isnan(std::copysign(std::numeric_limits::quiet_NaN(), -2.0)); + bool const isCcmCopysignNanNegative = std::signbit(ccm::copysign(std::numeric_limits::quiet_NaN(), -2.0)); + bool const isStdCopysignNanNegative = std::signbit(std::copysign(std::numeric_limits::quiet_NaN(), -2.0)); EXPECT_EQ(isCcmCopysignNan, isStdCopysignNan); EXPECT_EQ(isCcmCopysignNanNegative, isStdCopysignNanNegative); // TODO: Add more tests } - diff --git a/test/fmanip/frexp_test.cpp b/test/fmanip/frexp_test.cpp index 126cf2ea..0bcdb77a 100644 --- a/test/fmanip/frexp_test.cpp +++ b/test/fmanip/frexp_test.cpp @@ -8,14 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathFmanipTests, Frexp) { - } - diff --git a/test/fmanip/ilogb_test.cpp b/test/fmanip/ilogb_test.cpp index d412caa8..6b13fddb 100644 --- a/test/fmanip/ilogb_test.cpp +++ b/test/fmanip/ilogb_test.cpp @@ -8,14 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathFmanipTests, ILogb) { - } - diff --git a/test/fmanip/ldexp_test.cpp b/test/fmanip/ldexp_test.cpp index c9457d02..e43cb272 100644 --- a/test/fmanip/ldexp_test.cpp +++ b/test/fmanip/ldexp_test.cpp @@ -8,11 +8,11 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathFmanipTests, Ldexp) { @@ -40,36 +40,35 @@ TEST(CcmathFmanipTests, Ldexp) EXPECT_EQ(std::ldexp(1.f, 1024), ccm::ldexp(1.f, 1024)); EXPECT_EQ(std::ldexp(std::numeric_limits::max(), std::numeric_limits::max()), - ccm::ldexp(std::numeric_limits::max(), std::numeric_limits::max())); + ccm::ldexp(std::numeric_limits::max(), std::numeric_limits::max())); EXPECT_EQ(std::ldexp(std::numeric_limits::max(), std::numeric_limits::max()), - ccm::ldexp(std::numeric_limits::max(), std::numeric_limits::max())); + ccm::ldexp(std::numeric_limits::max(), std::numeric_limits::max())); EXPECT_EQ(std::ldexp(std::numeric_limits::min(), std::numeric_limits::min()), - ccm::ldexp(std::numeric_limits::min(), std::numeric_limits::min())); + ccm::ldexp(std::numeric_limits::min(), std::numeric_limits::min())); EXPECT_EQ(std::ldexp(std::numeric_limits::min(), std::numeric_limits::min()), - ccm::ldexp(std::numeric_limits::min(), std::numeric_limits::min())); + ccm::ldexp(std::numeric_limits::min(), std::numeric_limits::min())); EXPECT_EQ(std::ldexp(std::numeric_limits::min(), std::numeric_limits::max()), - ccm::ldexp(std::numeric_limits::min(), std::numeric_limits::max())); + ccm::ldexp(std::numeric_limits::min(), std::numeric_limits::max())); EXPECT_EQ(std::ldexp(std::numeric_limits::min(), std::numeric_limits::max()), - ccm::ldexp(std::numeric_limits::min(), std::numeric_limits::max())); + ccm::ldexp(std::numeric_limits::min(), std::numeric_limits::max())); EXPECT_EQ(std::ldexp(std::numeric_limits::max(), std::numeric_limits::min()), - ccm::ldexp(std::numeric_limits::max(), std::numeric_limits::min())); + ccm::ldexp(std::numeric_limits::max(), std::numeric_limits::min())); EXPECT_EQ(std::ldexp(std::numeric_limits::max(), std::numeric_limits::min()), - ccm::ldexp(std::numeric_limits::max(), std::numeric_limits::min())); + ccm::ldexp(std::numeric_limits::max(), std::numeric_limits::min())); EXPECT_EQ(ccm::ldexp(std::numeric_limits::infinity(), 10), std::ldexp(std::numeric_limits::infinity(), 10)); EXPECT_EQ(ccm::ldexp(std::numeric_limits::infinity(), 10), std::ldexp(std::numeric_limits::infinity(), 10)); // Test for edge case where if either argument is NaN, NaN is returned. - auto testForNanCcmIfEitherArgumentIsNand = std::isnan(ccm::ldexp(std::numeric_limits::quiet_NaN(), 10)); - auto testForNanStdIfEitherArgumentIsNand = std::isnan(std::ldexp(std::numeric_limits::quiet_NaN(), 10)); - bool isCcmNanSameAsStdNanIfEitherArgumentIsNand = testForNanCcmIfEitherArgumentIsNand == testForNanStdIfEitherArgumentIsNand; + auto testForNanCcmIfEitherArgumentIsNand = std::isnan(ccm::ldexp(std::numeric_limits::quiet_NaN(), 10)); + auto testForNanStdIfEitherArgumentIsNand = std::isnan(std::ldexp(std::numeric_limits::quiet_NaN(), 10)); + bool const isCcmNanSameAsStdNanIfEitherArgumentIsNand = testForNanCcmIfEitherArgumentIsNand == testForNanStdIfEitherArgumentIsNand; EXPECT_TRUE(isCcmNanSameAsStdNanIfEitherArgumentIsNand); - auto testForNanCcmIfEitherArgumentIsNanf = std::isnan(ccm::ldexp(std::numeric_limits::quiet_NaN(), 10)); - auto testForNanStdIfEitherArgumentIsNanf = std::isnan(std::ldexp(std::numeric_limits::quiet_NaN(), 10)); - bool isCcmNanSameAsStdNanIfEitherArgumentIsNanf = testForNanCcmIfEitherArgumentIsNanf == testForNanStdIfEitherArgumentIsNanf; + auto testForNanCcmIfEitherArgumentIsNanf = std::isnan(ccm::ldexp(std::numeric_limits::quiet_NaN(), 10)); + auto testForNanStdIfEitherArgumentIsNanf = std::isnan(std::ldexp(std::numeric_limits::quiet_NaN(), 10)); + bool const isCcmNanSameAsStdNanIfEitherArgumentIsNanf = testForNanCcmIfEitherArgumentIsNanf == testForNanStdIfEitherArgumentIsNanf; EXPECT_TRUE(isCcmNanSameAsStdNanIfEitherArgumentIsNanf); } - diff --git a/test/fmanip/logb_test.cpp b/test/fmanip/logb_test.cpp index 267aa6d5..4e3b3bd3 100644 --- a/test/fmanip/logb_test.cpp +++ b/test/fmanip/logb_test.cpp @@ -8,14 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathFmanipTests, Logb) { - } - diff --git a/test/fmanip/modf_test.cpp b/test/fmanip/modf_test.cpp index 67c15155..cd8d7816 100644 --- a/test/fmanip/modf_test.cpp +++ b/test/fmanip/modf_test.cpp @@ -8,14 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathFmanipTests, Modf) { - } - diff --git a/test/fmanip/nextafter_test.cpp b/test/fmanip/nextafter_test.cpp index 42653493..15f28be4 100644 --- a/test/fmanip/nextafter_test.cpp +++ b/test/fmanip/nextafter_test.cpp @@ -8,14 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" TEST(CcmathFmanipTests, Nextafter) { - } - diff --git a/test/fmanip/nexttoward_test.cpp b/test/fmanip/nexttoward_test.cpp index 9bc8f21a..4ccc33cf 100644 --- a/test/fmanip/nexttoward_test.cpp +++ b/test/fmanip/nexttoward_test.cpp @@ -8,16 +8,13 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include "ccmath/ccmath.hpp" +#include #include #include TEST(CcmathFmanipTests, Nexttoward) { EXPECT_EQ(ccm::nexttoward(1.0, 2.0), std::nexttoward(1.0, 2.0)); - } - diff --git a/test/fmanip/scalbn_test.cpp b/test/fmanip/scalbn_test.cpp index e7e3c05c..45f19d8f 100644 --- a/test/fmanip/scalbn_test.cpp +++ b/test/fmanip/scalbn_test.cpp @@ -8,9 +8,9 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include "ccmath/ccmath.hpp" + +#include #include #include @@ -22,7 +22,6 @@ TEST(CcmathFmanipTests, ScalbnDouble) EXPECT_EQ(ccm::scalbn(-0.0, 10), std::scalbn(-0.0, 10)); EXPECT_EQ(ccm::scalbn(-std::numeric_limits::infinity(), -1), std::scalbn(-std::numeric_limits::infinity(), -1)); EXPECT_EQ(ccm::scalbn(1.0, 1024), std::scalbn(1.0, 1024)); - } TEST(CcmathFmanipTests, ScalbnFloat) @@ -33,7 +32,6 @@ TEST(CcmathFmanipTests, ScalbnFloat) EXPECT_EQ(ccm::scalbn(-0.0F, 10), std::scalbn(-0.0F, 10)); EXPECT_EQ(ccm::scalbn(-std::numeric_limits::infinity(), -1), std::scalbn(-std::numeric_limits::infinity(), -1)); EXPECT_EQ(ccm::scalbn(1.0F, 1024), std::scalbn(1.0F, 1024)); - } TEST(CcmathFmanipTests, ScalbnLongDouble) @@ -42,11 +40,10 @@ TEST(CcmathFmanipTests, ScalbnLongDouble) // This is due to technical challenges with being able to interact with the bits of a long double. /* EXPECT_EQ(ccm::scalbn(7.0L, -4), std::scalbn(7.0L, -4)); - EXPECT_EQ(ccm::scalbn(1.0L, -1074), std::scalbn(1.0L, -1074)); - EXPECT_EQ(ccm::scalbn(std::nextafter(1, 0), 1024), std::scalbn(std::nextafter(1, 0), 1024)); - EXPECT_EQ(ccm::scalbn(-0.0L, 10), std::scalbn(-0.0L, 10)); - EXPECT_EQ(ccm::scalbn(-std::numeric_limits::infinity(), -1), std::scalbn(-std::numeric_limits::infinity(), -1)); - EXPECT_EQ(ccm::scalbn(1.0L, 1024), std::scalbn(1.0L, 1024)); - */ + EXPECT_EQ(ccm::scalbn(1.0L, -1074), std::scalbn(1.0L, -1074)); + EXPECT_EQ(ccm::scalbn(std::nextafter(1, 0), 1024), std::scalbn(std::nextafter(1, 0), 1024)); + EXPECT_EQ(ccm::scalbn(-0.0L, 10), std::scalbn(-0.0L, 10)); + EXPECT_EQ(ccm::scalbn(-std::numeric_limits::infinity(), -1), std::scalbn(-std::numeric_limits::infinity(), -1)); + EXPECT_EQ(ccm::scalbn(1.0L, 1024), std::scalbn(1.0L, 1024)); + */ } - diff --git a/test/hyperbolic/_test.cpp b/test/hyperbolic/_test.cpp index 68836aba..40b05a86 100644 --- a/test/hyperbolic/_test.cpp +++ b/test/hyperbolic/_test.cpp @@ -8,14 +8,12 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/detail/fmanip/copysign.hpp" +#include #include #include -#include "ccmath/detail/fmanip/copysign.hpp" TEST(CcmathFmanipTests, Copysign) { - } - diff --git a/test/internal/types/big_int_test.cpp b/test/internal/types/big_int_test.cpp index 89bf8ccb..c579878b 100644 --- a/test/internal/types/big_int_test.cpp +++ b/test/internal/types/big_int_test.cpp @@ -13,11 +13,10 @@ TEST(CcmathInternalTypesTests, BigIntTest) { - //ccm::BigInt<64, false> a; - //auto t1 = ccm::BigInt<64, false>::bits; - //auto t2 = ccm::BigInt<64, false>::is_signed; + // ccm::BigInt<64, false> a; + // auto t1 = ccm::BigInt<64, false>::bits; + // auto t2 = ccm::BigInt<64, false>::is_signed; - //EXPECT_EQ(t1, 64); - //EXPECT_EQ(t2, false); + // EXPECT_EQ(t1, 64); + // EXPECT_EQ(t2, false); } - diff --git a/test/misc/lerp_test_no_std.cpp b/test/misc/lerp_test_no_std.cpp index aeb0704a..8c6ec9d3 100644 --- a/test/misc/lerp_test_no_std.cpp +++ b/test/misc/lerp_test_no_std.cpp @@ -8,12 +8,10 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include -#include - +#include #include +#include /* TEST(CcmathBasicTests, LerpStaticAssert) @@ -35,9 +33,9 @@ TEST(CcmathBasicTests, LerpFloat) std::array expected_values = { -5.0F, -2.5F, 0.0F, 2.5F, 5.0F, 7.5F, 10.0F, 12.5F, 15.0F }; for (float t = -2.0; t <= 2.0; t += static_cast(0.5)) { - // Testing extrapolation - // Expected values are: -5 -2.5 0 2.5 5 7.5 10 12.5 15 - EXPECT_EQ(ccm::lerp(5.0, 10.0, t), expected_values.at(i)) << "ccm::lerp and std::lerp are not the same with t = " << t; + // Testing extrapolation + // Expected values are: -5 -2.5 0 2.5 5 7.5 10 12.5 15 + EXPECT_EQ(ccm::lerp(5.0, 10.0, t), expected_values.at(i)) << "ccm::lerp and std::lerp are not the same with t = " << t; i++; } // NOLINTEND diff --git a/test/misc/lerp_test_std.cpp b/test/misc/lerp_test_std.cpp index facbc46a..b976ee93 100644 --- a/test/misc/lerp_test_std.cpp +++ b/test/misc/lerp_test_std.cpp @@ -8,25 +8,23 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include +#include #include TEST(CcmathBasicTests, LerpStaticAssert) { - static_assert(ccm::lerp(1, 2, 0.5) == 1.5, "lerp has failed testing that it is static_assert-able!"); + static_assert(ccm::lerp(1, 2, 0.5) == 1.5, "lerp has failed testing that it is static_assert-able!"); } TEST(CcmathBasicTests, LerpFloat) { - EXPECT_EQ(ccm::lerp(1.0F, 2.0F, 0.0F), std::lerp(1.0F, 2.0F, 0.0F)); + EXPECT_EQ(ccm::lerp(1.0F, 2.0F, 0.0F), std::lerp(1.0F, 2.0F, 0.0F)); EXPECT_EQ(ccm::lerp(1.0F, 2.0F, 1.0F), std::lerp(1.0F, 2.0F, 1.0F)); EXPECT_EQ(ccm::lerp(4.0F, 4.0F, 0.5F), std::lerp(4.0F, 4.0F, 0.5F)); EXPECT_EQ(ccm::lerp(1e8F, 1.0F, 0.5F), std::lerp(1e8F, 1.0F, 0.5F)); - // NOLINTBEGIN for (float t = -2.0; t <= 2.0; t += static_cast(0.5)) { diff --git a/test/nearest/floor_test.cpp b/test/nearest/floor_test.cpp index 3ac1c065..dae8442d 100644 --- a/test/nearest/floor_test.cpp +++ b/test/nearest/floor_test.cpp @@ -8,11 +8,11 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include +#include "ccmath/ccmath.hpp" +#include #include #include -#include "ccmath/ccmath.hpp" namespace { diff --git a/test/nearest/nearbyint_test.cpp b/test/nearest/nearbyint_test.cpp index 98e7e39e..6c6df945 100644 --- a/test/nearest/nearbyint_test.cpp +++ b/test/nearest/nearbyint_test.cpp @@ -9,9 +9,7 @@ */ #include - #include - #include #include diff --git a/test/nearest/trunc_test.cpp b/test/nearest/trunc_test.cpp index 4609395e..7ca47efc 100644 --- a/test/nearest/trunc_test.cpp +++ b/test/nearest/trunc_test.cpp @@ -8,18 +8,17 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include "ccmath/ccmath.hpp" +#include #include #include // Disabling test case ccm::truncl if run on clang linux. #ifdef __clang__ -#ifdef __linux__ -#define CLANG_LINUX -#endif + #ifdef __linux__ + #define CLANG_LINUX + #endif #endif namespace @@ -207,5 +206,5 @@ TEST(CcmathNearestTests, CcmTrunclCanBeEvaluatedAtCompileTime) // Undefining clang linux macro #ifdef CLANG_LINUX -#undef CLANG_LINUX + #undef CLANG_LINUX #endif diff --git a/test/power/pow_test.cpp b/test/power/pow_test.cpp index 04086fa2..4d1cd6f0 100644 --- a/test/power/pow_test.cpp +++ b/test/power/pow_test.cpp @@ -8,19 +8,20 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ -#include - #include "ccmath/ccmath.hpp" +#include #include #include -namespace { +namespace +{ // Equivelant to EXPECT_EQ but allows for NaN values to be equal. - bool IsNanOrEquivalent(double a, double b) { + bool IsNanOrEquivalent(double a, double b) + { return (std::isnan(a) && std::isnan(b)) || (a == b); } -} +} // namespace /* TEST(CcmathPowerTests, Pow_Double_SpecialCases) diff --git a/test/power/sqrt_test.cpp b/test/power/sqrt_test.cpp index cbc68c51..aa0865a2 100644 --- a/test/power/sqrt_test.cpp +++ b/test/power/sqrt_test.cpp @@ -12,10 +12,9 @@ // https://github.com/actions/runner-images/issues/10004# // NOLINTNEXTLINE -#include - #include "ccmath/ccmath.hpp" +#include #include #include