Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring hot patch version 0.1.2 into main #18

Merged
merged 43 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
14efb39
Remove not_null (not used anymore)
Rinzii Mar 9, 2024
6ea7c01
Bring version 0.1.1 into main (#12) (#13)
Rinzii Mar 9, 2024
380ce23
Bring version 0.1.1 into main (#12) (#14)
Rinzii Mar 9, 2024
020d47f
Update bullet points for features of library
Rinzii Mar 11, 2024
5d81723
Remove unused helpers
Rinzii Mar 11, 2024
1d5f1db
add float_t and double_t to monolithic header
Rinzii Mar 11, 2024
8cecf8a
Cleanup and minor adjustments
Rinzii Mar 11, 2024
22df99d
Update sources to remove deleted headers
Rinzii Mar 11, 2024
1896c29
Fix ambiguity bug between float and integer
Rinzii Mar 11, 2024
11925d0
Fix ambiguity issues
Rinzii Mar 11, 2024
07dc8d8
Implement basic benchmarking for log and log2
Rinzii Mar 11, 2024
60469d0
Merge remote-tracking branch 'origin/dev' into dev
Rinzii Mar 11, 2024
c44cd13
Update all test suite to use the monolithic header instead of functio…
Rinzii Mar 12, 2024
a4f2b36
Setup some basic benchmark suites for log and abs
Rinzii Mar 12, 2024
dcca178
Minor cleanup
Rinzii Mar 12, 2024
44b97f3
Add first class support for Intel DPC++
Rinzii Mar 12, 2024
383aff7
Fix small bug with compiler identification
Rinzii Mar 12, 2024
96e6bc2
Add first class support to Nvidia HPC C++
Rinzii Mar 12, 2024
3e3ce75
Having internal issues with detection of NVidia HPC C++. Removing spe…
Rinzii Mar 12, 2024
a7c1720
Add support for Nvidia HPC and remove use of enums.
Rinzii Mar 12, 2024
10374f6
Fix minor bug with NVHPC
Rinzii Mar 12, 2024
022804c
Re-enable static_assert for fpclassify and verify it works with CI
Rinzii Mar 12, 2024
bbf336b
Re-enable static_assert for fpclassify and verify it works with CI
Rinzii Mar 12, 2024
dccc368
Add extra comment to static_assert
Rinzii Mar 12, 2024
6165ed5
rename the exponent details folder to impl
Rinzii Mar 13, 2024
0c8b23e
Cleanup the example mains
Rinzii Mar 13, 2024
eb9c197
Finish implementation of remquo
Rinzii Mar 13, 2024
81c40e5
Cleanup remquo test cases
Rinzii Mar 13, 2024
ce1d454
Update remquo to better handle specific edge cases
Rinzii Mar 13, 2024
6a7f244
Remove unused includes
Rinzii Mar 13, 2024
e9b9a6b
Temporarily remove problematic test cases.
Rinzii Mar 13, 2024
840a6b1
Layout some future functions for long double
Rinzii Mar 13, 2024
33a63d1
Implement copysign
Rinzii Mar 13, 2024
914966f
remove deleted file from headers
Rinzii Mar 13, 2024
afb01ec
Cleanup code and documentation
Rinzii Mar 14, 2024
bf2244d
Add last additional functions and documentation
Rinzii Mar 14, 2024
adf4ca6
Cleanup implementation details
Rinzii Mar 14, 2024
0519acb
Consolidate code and reduce code fragmentation along with minor refin…
Rinzii Mar 14, 2024
a453094
Fix missing SetComplexitN
Rinzii Mar 14, 2024
5241d3e
Minor cleanup
Rinzii Mar 14, 2024
252be05
Update README to reflect updated functions
Rinzii Mar 14, 2024
e52bccf
Update version number to 0.1.2 for upcoming hot patch
Rinzii Mar 14, 2024
525c125
Merge remote-tracking branch 'origin/main' into dev
Rinzii Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.18)

set(CCMATH_BUILD_VERSION 0.1.1)
set(CCMATH_BUILD_VERSION 0.1.2)
set(INTERNAL_PROJ_DEFAULT_NAME ccmath)

project(${INTERNAL_PROJ_DEFAULT_NAME} VERSION ${CCMATH_BUILD_VERSION})
Expand Down
202 changes: 101 additions & 101 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions benchmark/ccmath_benchmark_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static void BM_ccm_log(bm::State& state) {
for (auto _ : state) {
bm::DoNotOptimize(ccm::log(state.range(0)));
}
state.SetComplexityN(state.range(0));
}
BENCHMARK(BM_ccm_log)->Arg(16)->Arg(256)->Arg(4096)->Arg(65536)->Complexity();

Expand Down
36 changes: 28 additions & 8 deletions ccmath_headers.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
##########################################
# Internal headers
##########################################

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
Expand Down Expand Up @@ -39,7 +43,18 @@ set(ccmath_internal_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/internal/version.hpp
)


##########################################
# Detail headers
##########################################

set(ccmath_detail_basic_impl_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/basic/impl/remquo_float_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/basic/impl/remquo_double_impl.hpp
)

set(ccmath_detail_basic_headers
${ccmath_detail_basic_impl_headers}
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/basic/abs.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/basic/fdim.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/basic/fma.hpp
Expand All @@ -65,17 +80,17 @@ set(ccmath_detail_compare_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/compare/signbit.hpp
)

set(ccmath_detail_exponential_details_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log_float_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log_double_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log_data.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log2_float_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log2_double_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/details/log2_data.hpp
set(ccmath_detail_exponential_impl_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/impl/log_float_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/impl/log_double_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/impl/log_data.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/impl/log2_float_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/impl/log2_double_impl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/impl/log2_data.hpp
)

set(ccmath_detail_exponential_headers
${ccmath_detail_exponential_details_headers}
${ccmath_detail_exponential_impl_headers}
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/exp.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/exp2.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/detail/exponential/expm1.hpp
Expand Down Expand Up @@ -175,6 +190,11 @@ set(ccmath_detail_headers
${ccmath_detail_root_headers}
)


##########################################
# Root headers
##########################################

set(ccmath_root_headers
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/basic.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ccmath/compare.hpp
Expand Down
1 change: 0 additions & 1 deletion include/ccmath/detail/basic/abs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include "ccmath/detail/compare/isnan.hpp"

#include <limits>

namespace ccm
Expand Down
38 changes: 9 additions & 29 deletions include/ccmath/detail/basic/fdim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,10 @@

#include <limits>
#include <type_traits>

#include "ccmath/detail/compare/isnan.hpp"

namespace ccm
{
/// @cond MATH_DETAIL
namespace
{
namespace impl
{
template <typename T>
inline constexpr T fdim_impl(T x, T y)
{
if constexpr (std::is_floating_point_v<T>)
{
if (ccm::isnan(x)) { return x; }
if (ccm::isnan(y)) { return y; }
}

if (x <= y) { return T(+0.0); }
else if ((y < T(0.0)) && (x > (std::numeric_limits<T>::max() + y))) { return std::numeric_limits<T>::infinity(); }
else { return x - y; }
}

} // namespace impl
} // namespace
/// @endcond

/**
* @brief Computes the positive difference of two floating point values (max(0,x−y))
* @tparam T A floating-point type.
Expand All @@ -48,7 +24,11 @@ namespace ccm
template <typename T, std::enable_if_t<std::is_floating_point<T>::value, int> = 0>
inline constexpr T fdim(T x, T y)
{
return impl::fdim_impl(x, y);
if (ccm::isnan(x)) { return x; }
if (ccm::isnan(y)) { return y; }
if (x <= y) { return T(+0.0); }
else if ((y < T(0.0)) && (x > (std::numeric_limits<T>::max() + y))) { return std::numeric_limits<T>::infinity(); }
else { return x - y; }
}

/**
Expand All @@ -66,7 +46,7 @@ namespace ccm
using shared_type = std::common_type_t<T, U>;

// Convert the arguments to the common type
return fdim(static_cast<shared_type>(x), static_cast<shared_type>(y));
return fdim<shared_type>(static_cast<shared_type>(x), static_cast<shared_type>(y));
}

/**
Expand All @@ -79,7 +59,7 @@ namespace ccm
template <typename Integer, std::enable_if_t<std::is_integral<Integer>::value, int> = 0>
inline constexpr double fdim(Integer x, Integer y)
{
return fdim(static_cast<double>(x), static_cast<double>(y));
return fdim<double>(static_cast<double>(x), static_cast<double>(y));
}

/**
Expand All @@ -90,7 +70,7 @@ namespace ccm
*/
inline constexpr float fdimf(float x, float y)
{
return fdim(x, y);
return fdim<float>(x, y);
}

/**
Expand All @@ -101,7 +81,7 @@ namespace ccm
*/
inline constexpr long double fdiml(long double x, long double y)
{
return fdim(x, y);
return fdim<long double>(x, y);
}
} // namespace ccm

Expand Down
124 changes: 124 additions & 0 deletions include/ccmath/detail/basic/impl/remquo_double_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright (c) 2024-Present Ian Pike
* Copyright (c) 2024-Present ccmath contributors
*
* This library is provided under the MIT License.
* See LICENSE for more information.
*/

#pragma once

#include <cstdint>
#include <limits>

#include "ccmath/internal/helpers/bits.hpp"
#include "ccmath/internal/predef/unlikely.hpp"
#include "ccmath/detail/basic/abs.hpp"
#include "ccmath/detail/basic/fmod.hpp"

namespace ccm::internal
{
namespace
{
namespace impl
{
inline constexpr double remquo_double_impl(double x, double y, int * quo) noexcept
{
std::int64_t x_i64{};
std::int64_t y_i64{};
std::uint64_t x_sign{};
std::uint64_t quotient_sign{};
int computed_quotient{};

x_i64 = ccm::helpers::double_to_int64(x);
y_i64 = ccm::helpers::double_to_int64(y);

// Determine the signs of x and the quotient.
x_sign = static_cast<std::uint64_t>(x_i64) & 0x8000000000000000ULL;
quotient_sign = x_sign ^ (static_cast<std::uint64_t>(y_i64) & 0x8000000000000000ULL);

// Clear the sign bits from the int64_t representations of x and y.
x_i64 &= 0x7fffffffffffffffULL;
y_i64 &= 0x7fffffffffffffffULL;

// If y is zero.
if (CCM_UNLIKELY(y_i64 == 0)) { return (x * y) / (x * y); }

// If x is not finite or y is NaN.
if (CCM_UNLIKELY(x_i64 >= 0x7ff0000000000000ULL || y_i64 > 0x7ff0000000000000ULL)) { return (x * y) / (x * y); }

// b (or bit 54) represents the highest bit we can compare against for both signed and unsigned integers without causing an overflow.
// Here we are checking that if y_i64 is within the range of signed 64-bit integers that can be represented without setting the MSB (i.e.,
// positive or zero).
if (y_i64 <= 0x7fbfffffffffffffULL)
{
x = ccm::fmod(x, 8 * y); // now x < (8 * y)
}

if (CCM_UNLIKELY(x_i64 == y_i64))
{
*quo = quotient_sign ? -1 : 1;
return 0.0 * x;
}

x = ccm::fabs(x);
y = ccm::helpers::int64_to_double(y_i64);
computed_quotient = 0;

if (y_i64 <= 0x7fcfffffffffffffULL && x >= 4 * y)
{
x -= 4 * y;
computed_quotient += 4;
}

if (y_i64 <= 0x7fdfffffffffffffULL && x >= 2 * y)
{
x -= 2 * y;
computed_quotient += 2;
}

if (y_i64 < 0x0020000000000000ULL)
{
if (x + x > y)
{
x -= y;
++computed_quotient;
if (x + x >= y)
{
x -= y;
++computed_quotient;
}
}
}
else
{
double y_half = 0.5 * y;
if (x > y_half)
{
x -= y;
++computed_quotient;
if (x >= y_half)
{
x -= y;
++computed_quotient;
}
}
}

*quo = quotient_sign ? -computed_quotient : computed_quotient;

// Make sure that the correct sign of zero results in round down mode.
if (x == 0.0) { x = 0.0; }
if (x_sign) { x = -x; }

return x;
}
} // namespace impl
} // namespace

template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
inline constexpr T remquo_double(T x, T y, int * quo) noexcept
{
return static_cast<T>(impl::remquo_double_impl(x, y, quo));
}
} // namespace ccm::internal
Loading
Loading