Skip to content

Commit

Permalink
Adapted math functions to new constant API
Browse files Browse the repository at this point in the history
jtlap authored Jan 7, 2024
1 parent 32ff9be commit 536bbc5
Showing 249 changed files with 7,823 additions and 4,149 deletions.
70 changes: 33 additions & 37 deletions include/eve/module/core/constant/allbits.hpp
Original file line number Diff line number Diff line change
@@ -7,21 +7,38 @@
//==================================================================================================
#pragma once

#include <eve/as.hpp>
#include <eve/detail/function/bit_cast.hpp>
#include <eve/detail/implementation.hpp>
#include <eve/module/core/decorator/roundings.hpp>
#include <eve/traits/as_integer.hpp>

#include <type_traits>
#include <eve/arch.hpp>
#include <eve/traits/overload.hpp>
#include <eve/module/core/decorator/core.hpp>

namespace eve
{
template<typename Options>
struct allbits_t : constant_callable<allbits_t, Options, downward_option, upward_option>
{
template<typename T>
static EVE_FORCEINLINE T value(eve::as<T> const&, auto const&)
{
using e_t = element_type_t<T>;
using i_t = as_integer_t<e_t, unsigned>;
constexpr auto mask = ~0ULL;

if constexpr( std::integral<e_t> ) return T(mask);
else return T(bit_cast(i_t(mask), as<e_t>()));
}

template<typename T>
requires(plain_scalar_value<element_type_t<T>>)
EVE_FORCEINLINE T operator()(as<T> const& v) const { return EVE_DISPATCH_CALL(v); }

EVE_CALLABLE_OBJECT(allbits_t, allbits_);
};

//================================================================================================
//! @addtogroup core_constants
//! @{
//! @var allbits
//! @brief Computes the constant with all bits set.
//! @brief Computes a constant with all bits set.
//!
//! **Defined in Header**
//!
@@ -34,46 +51,25 @@ namespace eve
//! @code
//! namespace eve
//! {
//! template< eve::value T >
//! T allbits(as<T> x) noexcept;
//! template<eve::value T> constexpr T allbits(as<T> x) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `x` : [Type wrapper](@ref eve::as) instance embedding the type of the constant.
//!
//! **Return value**
//! **Return value**
//!
//! The call `eve::allbits(as<T>())` returns a value of type T with all bits set.
//! The call `eve::allbits(as<T>())` returns a value of type `T` with all bits set.
//!
//! @groupheader{Example}
//! @groupheader{Example}
//!
//! @godbolt{doc/core/constant/allbits.cpp}
//! @godbolt{doc/core/constant/allbits.cpp}
//! @}
//================================================================================================
EVE_MAKE_CALLABLE(allbits_, allbits);
inline constexpr auto allbits = functor<allbits_t>;

namespace detail
{
template<typename T>
requires(plain_scalar_value<element_type_t<T>>)
EVE_FORCEINLINE constexpr auto allbits_(EVE_SUPPORTS(cpu_), as<T> const&) noexcept
{
using t_t = element_type_t<T>;
using i_t = as_integer_t<t_t, unsigned>;
constexpr auto mask = ~0ULL;

if constexpr( std::is_integral_v<t_t> ) return T(mask);
else return T(bit_cast(i_t(mask), as<t_t>()));
}

template<typename T, typename D>
requires(is_one_of<D>(types<upward_type, downward_type> {}))
EVE_FORCEINLINE constexpr auto allbits_(EVE_SUPPORTS(cpu_), D const&, as<T> const&) noexcept
-> decltype(allbits(as<T>()))
{
return allbits(as<T>());
}
}
// Required for if_else optimisation detections
using callable_allbits_ = tag_t<allbits>;
}
70 changes: 31 additions & 39 deletions include/eve/module/core/constant/bitincrement.hpp
Original file line number Diff line number Diff line change
@@ -7,22 +7,37 @@
//==================================================================================================
#pragma once

#include <eve/as.hpp>
#include <eve/concept/value.hpp>
#include <eve/detail/implementation.hpp>
#include <eve/detail/meta.hpp>
#include <eve/module/core/constant/constant.hpp>
#include <eve/module/core/decorator/roundings.hpp>

#include <type_traits>
#include <eve/arch.hpp>
#include <eve/traits/overload.hpp>
#include <eve/module/core/decorator/core.hpp>

namespace eve
{
template<typename Options>
struct bitincrement_t : constant_callable<bitincrement_t, Options, downward_option, upward_option>
{
template<typename T>
static EVE_FORCEINLINE constexpr T value(eve::as<T> const&, auto const&)
{
using e_t = element_type_t<T>;

if constexpr(std::integral<e_t> ) return T(1);
else if constexpr(std::same_as<e_t, float> ) return T(0x1p-149);
else if constexpr(std::same_as<e_t, double> ) return T(0x0.0000000000001p-1022);
}

template<typename T>
requires(plain_scalar_value<element_type_t<T>>)
EVE_FORCEINLINE constexpr T operator()(as<T> const& v) const { return EVE_DISPATCH_CALL(v); }

EVE_CALLABLE_OBJECT(bitincrement_t, bitincrement_);
};

//================================================================================================
//! @addtogroup core_constants
//! @{
//! @var bitincrement
//! @brief Computes the constant of type T in which the only bit set is the least significant
//! @brief Computes a constant with only the least significant bit set.
//!
//! **Defined in Header**
//!
@@ -35,46 +50,23 @@ namespace eve
//! @code
//! namespace eve
//! {
//! template< eve::value T >
//! T bitincrement(as<T> x) noexcept;
//! template< eve::value T > constexpr T bitincrement(as<T> x) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `x` : [Type wrapper](@ref eve::as) instance embedding the type of the constant.
//!
//! **Return value**
//! **Return value**
//!
//! The call `eve::bitincrement(as<T>())` returns a value of type T in which the only bit
//! set is the least significant
//! The call `eve::bitincrement(as<T>())` returns a value of type `T` with only the least significant
//! bit set.
//!
//! @groupheader{Example}
//! @groupheader{Example}
//!
//! @godbolt{doc/core/constant/bitincrement.cpp}
//! @godbolt{doc/core/constant/bitincrement.cpp}
//! @}
//================================================================================================
EVE_MAKE_CALLABLE(bitincrement_, bitincrement);

namespace detail
{
template<typename T>
requires(plain_scalar_value<element_type_t<T>>)
EVE_FORCEINLINE constexpr auto bitincrement_(EVE_SUPPORTS(cpu_), as<T> const&) noexcept
{
using t_t = element_type_t<T>;

if constexpr( std::is_integral_v<t_t> ) return T(1);
else if constexpr( std::is_same_v<t_t, float> ) return Constant<T, 0X1U>();
else if constexpr( std::is_same_v<t_t, double> ) return Constant<T, 0x1ULL>();
}

template<typename T, typename D>
requires(is_one_of<D>(types<upward_type, downward_type> {}))
EVE_FORCEINLINE constexpr auto bitincrement_(EVE_SUPPORTS(cpu_), D const&, as<T> const&) noexcept
-> decltype(bitincrement(as<T>()))
{
return bitincrement(as<T>());
}
}
inline constexpr auto bitincrement = functor<bitincrement_t>;
}
79 changes: 35 additions & 44 deletions include/eve/module/core/constant/eps.hpp
Original file line number Diff line number Diff line change
@@ -7,22 +7,37 @@
//==================================================================================================
#pragma once

#include <eve/as.hpp>
#include <eve/concept/value.hpp>
#include <eve/detail/implementation.hpp>
#include <eve/detail/meta.hpp>
#include <eve/module/core/constant/constant.hpp>
#include <eve/module/core/decorator/roundings.hpp>

#include <type_traits>
#include <eve/arch.hpp>
#include <eve/traits/overload.hpp>
#include <eve/module/core/decorator/core.hpp>

namespace eve
{
template<typename Options>
struct eps_t : constant_callable<eps_t, Options, downward_option, upward_option>
{
template<typename T>
static EVE_FORCEINLINE constexpr T value(eve::as<T> const&, auto const&)
{
using e_t = element_type_t<T>;

if constexpr(std::integral<e_t> ) return T(1);
else if constexpr(std::same_as<e_t, float> ) return T(0x1p-23);
else if constexpr(std::same_as<e_t, double> ) return T(0x1p-52);
}

template<typename T>
requires(plain_scalar_value<element_type_t<T>>)
EVE_FORCEINLINE constexpr T operator()(as<T> const& v) const { return EVE_DISPATCH_CALL(v); }

EVE_CALLABLE_OBJECT(eps_t, eps_);
};

//================================================================================================
//! @addtogroup core_constants
//! @{
//! @var eps
//! @brief Computes the the machine epsilon.
//! @brief Computes a constant to the machine epsilon.
//!
//! **Defined in Header**
//!
@@ -35,52 +50,28 @@ namespace eve
//! @code
//! namespace eve
//! {
//! template< eve::value T >
//! T $name$(as<T> x) noexcept;
//! template<eve::value T> constexpr T eps(as<T> x) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `x` : [Type wrapper](@ref eve::as) instance embedding the type of the constant.
//!
//! **Return value**
//! **Return value**
//!
//! the call `eve::eps(as<T>())` returns [elementwise](@ref glossary_elementwise), the smallest
//! positive value `x` of the type such that `1+x != x`.
//! The call `eve::eps(as<T>())` returns [elementwise](@ref glossary_elementwise), the smallest
//! positive value `x` of the type such that `1+x != x`.
//!
//! * If T is an [integral value](@ref eve::integral_value) the elements returned are equal to
//! one
//! * If T is a [floating value](@ref eve::floating_value) the elements returned are equal to
//! * 2.220446049250313e-16 if the [elements type](@ref eve::element_type) is float
//! * 1.1920929e-07f if the [elements type](@ref eve::element_type) is double
//! * If T is an [integral value](@ref eve::integral_value) the elements returned are equal to one.
//! * If T is a [floating value](@ref eve::floating_value) the elements returned are equal to:
//! * 2.220446049250313e-16 if the [elements type](@ref eve::element_type) is `float`.
//! * 1.1920929e-07f if the [elements type](@ref eve::element_type) is `double`.
//!
//! @groupheader{Example}
//! @groupheader{Example}
//!
//! @godbolt{doc/core/constant/eps.cpp}
//! @godbolt{doc/core/constant/eps.cpp}
//! @}
//================================================================================================
EVE_MAKE_CALLABLE(eps_, eps);

namespace detail
{
template<typename T>
requires(plain_scalar_value<element_type_t<T>>)
EVE_FORCEINLINE constexpr auto eps_(EVE_SUPPORTS(cpu_), as<T> const&) noexcept
{
using t_t = element_type_t<T>;

if constexpr( std::is_integral_v<t_t> ) return T(1);
else if constexpr( std::is_same_v<t_t, float> ) return Constant<T, 0X34000000U>();
else if constexpr( std::is_same_v<t_t, double> ) return Constant<T, 0x3CB0000000000000ULL>();
}

template<floating_value T, typename D>
requires(is_one_of<D>(types<upward_type, downward_type> {}))
EVE_FORCEINLINE constexpr auto eps_(EVE_SUPPORTS(cpu_), D const&, as<T> const&) noexcept
-> decltype(eps(as<T>()))
{
return eps(as<T>());
}
}
inline constexpr auto eps = functor<eps_t>;
}
45 changes: 25 additions & 20 deletions include/eve/module/core/constant/false.hpp
Original file line number Diff line number Diff line change
@@ -7,17 +7,33 @@
//==================================================================================================
#pragma once

#include <eve/as.hpp>
#include <eve/detail/implementation.hpp>
#include <eve/arch.hpp>
#include <eve/traits/as_logical.hpp>
#include <eve/traits/overload.hpp>
#include <eve/module/core/decorator/core.hpp>

namespace eve
{
template<typename Options>
struct false_t : constant_callable<false_t, Options, downward_option, upward_option>
{
template<typename T>
static EVE_FORCEINLINE auto value(eve::as<T> const&, auto const&)
{
return as_logical_t<T>(false);
}

template<typename T>
EVE_FORCEINLINE as_logical_t<T> operator()(as<T> const& v) const { return EVE_DISPATCH_CALL(v); }

EVE_CALLABLE_OBJECT(false_t, false__);
};

//================================================================================================
//! @addtogroup core_constants
//! @{
//! @var false_
//! @brief Computes the false logical value.
//! @brief Computes the false logical value.
//!
//! **Defined in Header**
//!
@@ -30,33 +46,22 @@ namespace eve
//! @code
//! namespace eve
//! {
//! template< eve::value T >
//! eve::as_logical<T> false_(as<T> x) noexcept;
//! template<eve::value T> constexpr eve::as_logical<T> false_(as<T> x) noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `x` : [Type wrapper](@ref eve::as) instance embedding the type of the constant.
//!
//! **Return value**
//! **Return value**
//!
//! the call `eve::false_(as<T>())` returns [elementwise](@ref glossary_elementwise), the false
//! logical value.
//! The call `eve::false_(as<T>())` returns the `false` logical value for type `T`.
//!
//! @groupheader{Example}
//! @groupheader{Example}
//!
//! @godbolt{doc/core/constant/false_.cpp}
//! @godbolt{doc/core/constant/false_.cpp}
//! @}
//================================================================================================
EVE_MAKE_CALLABLE(false__, false_);

namespace detail
{
template<typename T>
EVE_FORCEINLINE constexpr as_logical_t<T> false__(EVE_SUPPORTS(cpu_), as<T> const&) noexcept
{
return as_logical_t<T>(false);
}
}
inline constexpr auto false_ = functor<false_t>;
}
Loading

0 comments on commit 536bbc5

Please sign in to comment.