Skip to content

Commit

Permalink
Continue major refactor and restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinzii committed Mar 17, 2024
1 parent b42afe1 commit bbd19b3
Showing 46 changed files with 205 additions and 212 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -32,6 +32,13 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL Clang OR CMAKE_CXX_COMPILER_ID STREQUAL GNU)
target_compile_options(${PROJECT_NAME}-compile-options INTERFACE
-Wall -Wextra -Wpedantic -Wconversion -Werror=return-type
)

# TODO: Remove this later.
# Some variables have been provided but are not currently being used, but it would not atm make sense to remove them.
# So to clean up the warnings we are just silencing these specific cases.
target_compile_options(${PROJECT_NAME}-compile-options INTERFACE
-Wno-unused-but-set-variable -Wno-unused-value
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL MSVC)
11 changes: 8 additions & 3 deletions benchmark/ccmath_benchmark_main.cpp
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@ std::vector<double> generateRandomDoubles(size_t count, unsigned int seed) {
return randomDouble;
}

/*
static void BM_std_fma(bm::State& state) {
for ([[maybe_unused]] auto _ : state) {
bm::DoNotOptimize(std::fma(state.range(0), state.range(1), state.range(2)));
@@ -58,8 +60,9 @@ static void BM_ccm_fma(bm::State& state) {
}
BENCHMARK(BM_ccm_fma)->Args({16, 16, 16})->Args({256, 256, 256})->Args({4096, 4096, 4096})->Args({65536, 65536, 65536})->Complexity();
*/


/*
// Benchmarking std::abs with the same set of random integers
static void BM_std_abs_rand_int(benchmark::State& state) {
auto randomIntegers = generateRandomIntegers(static_cast<size_t>(state.range(0)), DefaultSeed);
@@ -83,7 +86,7 @@ static void BM_ccm_abs_rand_int(benchmark::State& state) {
state.SetComplexityN(state.range(0));
}
BENCHMARK(BM_ccm_abs_rand_int)->Range(8, 8<<10)->Complexity();

*/
// Benchmarking std::abs with the same set of random integers
static void BM_std_abs_rand_double(benchmark::State& state) {
auto randomIntegers = generateRandomDoubles(static_cast<size_t>(state.range(0)), DefaultSeed);
@@ -125,6 +128,8 @@ static void BM_ccm_abs(benchmark::State& state) {
}
BENCHMARK(BM_ccm_abs)->Arg(16)->Arg(256)->Arg(4096)->Arg(65536)->Complexity();

/*
static void BM_std_log_rand_double(bm::State& state) {
auto randomDoubles = generateRandomDoubles(static_cast<size_t>(state.range(0)), DefaultSeed);
while (state.KeepRunning()) {
@@ -226,7 +231,7 @@ static void BM_std_lerp(bm::State& state) {
}
BENCHMARK(BM_std_lerp)->Args({16, 16, 16})->Args({256, 256, 256})->Args({4096, 4096, 4096})->Args({65536, 65536, 65536})->Complexity();

*/

BENCHMARK_MAIN();

42 changes: 20 additions & 22 deletions ccmath_headers.cmake
Original file line number Diff line number Diff line change
@@ -2,18 +2,19 @@
# Internal headers
##########################################

set(ccmath_internal_config_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/compiler_def.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/compiler_undef.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/builtin_support_def.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/config/builtin_support_undef.hpp
)

set(ccmath_internal_helpers_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/bits.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/endian.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/find_number.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/floating_point_type.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/fpclassify_helper.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/meta_compare.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/helpers/exp_helpers.hpp
)

set(ccmath_internal_predef_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/assume.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/compiler_warnings_and_errors_def.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/compiler_warnings_and_errors_undef.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/has_attribute.hpp
@@ -23,30 +24,27 @@ set(ccmath_internal_predef_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/predef/suppress.hpp
)

set(ccmath_internal_setup_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/setup/compiler_def.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/setup/compiler_undef.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/setup/builtin_support_def.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/setup/builtin_support_undef.hpp

)

set(ccmath_internal_typetraits_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/type_traits/is_constant_evaluated.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/type_traits/floating_point_traits.hpp
set(ccmath_internal_support_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/bits.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/endian.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/floating_point_traits.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/is_constant_evaluated.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/meta_compare.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/support/unreachable.hpp
)

set(ccmath_internal_utility_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/utility/unreachable.hpp
set(ccmath_internal_types_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/fp_types.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/types/int128.hpp
)


set(ccmath_internal_headers
${ccmath_internal_helpers_headers}
${ccmath_internal_predef_headers}
${ccmath_internal_setup_headers}
${ccmath_internal_typetraits_headers}
${ccmath_internal_utility_headers}
${ccmath_internal_config_headers}
${ccmath_internal_support_headers}
${ccmath_internal_types_headers}

${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/setup.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/version.hpp
2 changes: 1 addition & 1 deletion include/ccmath/ccmath.hpp
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ CCMATH REQUIREMENTS:
*/

// Includes ccm::float_t and ccm::double_t
#include "ccmath/internal/helpers/floating_point_type.hpp"
#include "ccmath/internal/types/fp_types.hpp"

/// Basic math functions
#include "ccmath/basic.hpp"
4 changes: 2 additions & 2 deletions include/ccmath/internal/helpers/exp_helpers.hpp
Original file line number Diff line number Diff line change
@@ -8,10 +8,10 @@

#pragma once

#include "ccmath/internal/support/bits.hpp"
#include "ccmath/internal/support/meta_compare.hpp"
#include <cfloat>
#include <type_traits>
#include "ccmath/internal/helpers/bits.hpp"
#include "ccmath/internal/helpers/meta_compare.hpp"

namespace ccm::helpers
{
36 changes: 0 additions & 36 deletions include/ccmath/internal/helpers/find_number.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions include/ccmath/internal/helpers/fpclassify_helper.hpp
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
// - Nvidia HPC SDK

// Identify the compiler
#include "ccmath/internal/setup/compiler_def.hpp"
#include "ccmath/internal/config/compiler_def.hpp"

namespace ccm::helpers
{
@@ -58,5 +58,5 @@ namespace ccm::helpers
}

// Clean up the global namespace
#include "ccmath/internal/setup/compiler_undef.hpp"
#include "ccmath/internal/config/compiler_undef.hpp"

22 changes: 0 additions & 22 deletions include/ccmath/internal/predef/assume.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -163,10 +163,15 @@
///
#ifndef CCM_DISABLE_IGNORE_GCC_WARNING
#if defined(__GNUC__) && !defined(__clang__)
#define CCM_GCC_IGNORE_DISABLE_HELP0(x) #x // Helper macros - do not use directly
#define CCM_GCC_IGNORE_DISABLE_HELP1(x) CCM_GCC_IGNORE_DISABLE_HELP0(GCC diagnostic warning x) // Helper macros - do not use directly
#define CCM_GCC_IGNORE_DISABLE_HELP2(x) CCM_GCC_IGNORE_DISABLE_HELP1(#x) // Helper macros - do not use directly

#ifndef CCM_GCC_IGNORE_DISABLE_HELP0
#define CCM_GCC_IGNORE_DISABLE_HELP0(x) #x // Helper macros - do not use directly
#endif
#ifndef CCM_GCC_IGNORE_DISABLE_HELP1
#define CCM_GCC_IGNORE_DISABLE_HELP1(x) CCM_GCC_IGNORE_DISABLE_HELP0(GCC diagnostic warning x) // Helper macros - do not use directly
#endif
#ifndef CCM_GCC_IGNORE_DISABLE_HELP2
#define CCM_GCC_IGNORE_DISABLE_HELP2(x) CCM_GCC_IGNORE_DISABLE_HELP1(#x) // Helper macros - do not use directly
#endif
// This will disable suppression of an ignored warning for GCC
// Must be called after CCM_ENABLE_IGNORE_GCC_WARNING(w).
#define CCM_DISABLE_IGNORE_GCC_WARNING(w) _Pragma(CCM_GCC_IGNORE_DISABLE_HELP2(w)) _Pragma("GCC diagnostic pop")
Original file line number Diff line number Diff line change
@@ -14,17 +14,17 @@
namespace ccm::helpers::traits
{
// clang-format off
template <typename T> struct is_char_type : std::false_type {};
template <> struct is_char_type<char> : std::true_type {};
template <> struct is_char_type<wchar_t> : std::true_type {};
template <typename T> struct is_char : std::false_type {};
template <> struct is_char<char> : std::true_type {};
template <> struct is_char<wchar_t> : std::true_type {};
#if (__cplusplus >= 202002L) || defined(__cpp_char8_t) || defined(__cpp_lib_char8_t) // C++20 defines char8_t
template <> struct is_char_type<char8_t> : std::true_type {};
template <> struct is_char<char8_t> : std::true_type {};
#endif
template <> struct is_char_type<char16_t> : std::true_type {};
template <> struct is_char_type<char32_t> : std::true_type {};
template <> struct is_char_type<signed char> : std::true_type {};
template <> struct is_char_type<unsigned char> : std::true_type {};
template <typename T> inline constexpr bool is_char_type_v = is_char_type<T>::value;
template <> struct is_char<char16_t> : std::true_type {};
template <> struct is_char<char32_t> : std::true_type {};
template <> struct is_char<signed char> : std::true_type {};
template <> struct is_char<unsigned char> : std::true_type {};
template <typename T> inline constexpr bool is_char_v = is_char<T>::value;
// clang-format on

} // namespace ccm::helpers::traits
@@ -49,23 +49,15 @@ namespace ccm::helpers
return __builtin_bit_cast(To, src);
}

template <class T, std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T> && !ccm::helpers::traits::is_char_type_v<T> && !std::is_same_v<T, bool>,
template <class T, std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T> && !ccm::helpers::traits::is_char_v<T> && !std::is_same_v<T, bool>,
bool> = true>
constexpr bool has_single_bit(T x) noexcept
{
return x && !(x & (x - 1));
}

inline constexpr std::uint32_t get_exponent_of_double(double x) noexcept
{
// Reinterpret the binary representation of x as an std::uint64_t
std::uint64_t bits = bit_cast<std::uint64_t>(x);

// Extract the exponent bits (bits 62-52) and remove bias (1023)
std::uint32_t exponent = static_cast<std::uint32_t>((bits >> 52) & 0x7FF) - 1023;

return exponent;
}

/**
* @brief Helper function to get the top 16-bits of a double.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -36,6 +36,6 @@ namespace ccm
typedef long double float_t;
typedef long double double_t;
# else
# error "Unknown __GLIBC_FLT_EVAL_METHOD"
# error "Unknown CCM_FLT_EVAL_METHOD"
# endif
}
File renamed without changes.
Loading

0 comments on commit bbd19b3

Please sign in to comment.