Skip to content

Commit

Permalink
Remove the converter decorator
Browse files Browse the repository at this point in the history
They were used too few and were too confusing.
  • Loading branch information
jtlap authored May 6, 2024
1 parent 18bcfaf commit 9728083
Show file tree
Hide file tree
Showing 66 changed files with 377 additions and 1,524 deletions.
2 changes: 1 addition & 1 deletion benchmarks/module/combinatorial/gcd/regular/gcd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main()
auto arg0 = eve::bench::random_<EVE_VALUE>(lmin,lmax);
auto arg1 = eve::bench::random_<EVE_VALUE>(lmin,lmax);

auto std__gcd = [](auto x, auto y){return std::gcd(eve::int_(x), eve::int_(y)); };
auto std__gcd = [](auto x, auto y){return std::gcd(eve::convert(x, int_from<decltype(x)), eve::convert(y, int_from<decltype(y))); };
auto eve__gcd = [](auto x, auto y){return eve::gcd(eve::trunc(x), eve::trunc(y)); };

eve::bench::experiment xp;
Expand Down
7 changes: 7 additions & 0 deletions include/eve/as_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ namespace eve
constexpr as_element() noexcept {}
explicit constexpr as_element(T const&) noexcept {}
};

template <typename T> using int_from = as_element<as_integer_t<T, signed>>;
template <typename T> using uint_from = as_element<as_integer_t<T, unsigned>>;
template <typename T> using floating_from = as_element<as_floating_point_t<T>>;
template <typename T> using upgraded_from = detail::upgrade_t<element_type_t<T>>;
template <typename T> using downgraded_from = detail::downgrade_t<element_type_t<T>>;

}
2 changes: 1 addition & 1 deletion include/eve/module/combinatorial/regular/fibonacci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ inline constexpr auto fibonacci = functor<fibonacci_t>;

if constexpr(std::same_as<T, U>)
{
auto nm1 = to_<eli_t>((n));
auto nm1 = convert(n, uint_from<eli_t>());
auto c2 = fms(gold, a, b) * oneosqrt5;
auto c1 = a - c2;
auto f = fma(c1, eve::pow(gold, nm1), c2 * eve::pow(goldbar, nm1));
Expand Down
42 changes: 18 additions & 24 deletions include/eve/module/combinatorial/regular/gcd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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

Expand Down Expand Up @@ -70,13 +71,17 @@ inline constexpr auto gcd = functor<gcd_t>;

namespace detail
{
template<typename T, callable_options O>
constexpr auto gcd_(EVE_REQUIRES(cpu_), O const&, T a, T b)
template<typename T, typename U, callable_options O>
constexpr auto gcd_(EVE_REQUIRES(cpu_), O const&, T aa, U bb)
{
using r_t = common_value_t<T, U>;
r_t a = r_t(aa);
r_t b = r_t(bb);
a = eve::abs(a);
b = eve::abs(b);

if constexpr(O::contains(raw2))
{
a = eve::abs(a);
b = eve::abs(b);
if constexpr( scalar_value<T> )
{
while( b )
Expand Down Expand Up @@ -105,8 +110,6 @@ inline constexpr auto gcd = functor<gcd_t>;
{
if constexpr(integral_scalar_value<T>)
{
a = eve::abs(a);
b = eve::abs(b);
while( b )
{
auto r = a % b;
Expand All @@ -117,8 +120,6 @@ inline constexpr auto gcd = functor<gcd_t>;
}
else if constexpr(integral_simd_value<T>)
{
a = abs(a);
b = abs(b);
using elt_t = element_type_t<T>;
if constexpr( sizeof(elt_t) == 8 )
{
Expand All @@ -134,32 +135,25 @@ inline constexpr auto gcd = functor<gcd_t>;
}
return a;
}
else if constexpr( sizeof(elt_t) == 4 )
{
auto r = gcd[raw](float64(a), float64(b));
if constexpr( std::is_signed_v<elt_t> ) return int32(r);
else return uint32(r);
}
else if constexpr( sizeof(elt_t) <= 2 )
else
{
auto r = gcd[raw](float32(a), float32(b));
if constexpr( sizeof(elt_t) == 2 )
if constexpr( sizeof(elt_t) == 4 )
{
if constexpr( std::is_signed_v<elt_t> ) return int16(r);
else return uint16(r);
auto r = gcd[raw](convert(a, as<double>()), convert(b, as<double>()));
if constexpr( std::is_signed_v<elt_t> ) return convert(r, int_from<T>());
else return convert(r, uint_from<T>());
}
else
else if constexpr( sizeof(elt_t) <= 2 )
{
if constexpr( std::is_signed_v<elt_t> ) return int8(r);
else return uint8(r);
auto r = gcd[raw](convert(a, as<float>()), convert(b, as<float>()));
if constexpr( std::is_signed_v<elt_t> ) return convert(r, int_from<T>());
else return convert(r, uint_from<T>());
}
}
}
else if constexpr(floating_value<T>)
{
EVE_ASSERT(eve::all(is_flint(a) && is_flint(b)), "gcd: some entries are not flint");
a = abs(a);
b = abs(b);
if constexpr( scalar_value<T> )
{
while( b )
Expand Down
10 changes: 5 additions & 5 deletions include/eve/module/combinatorial/regular/nth_prime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,10 +1273,10 @@ inline constexpr auto nth_prime = functor<nth_prime_t>;
};
// clang-format on

auto n = uint16(inc(nn));
auto n = convert(inc(nn), as<uint16_t>());
if constexpr( scalar_value<T> )
{
if constexpr( sizeof(T) == 1 ) { return uint8(a1[n > 54u ? 0 : n]); }
if constexpr( sizeof(T) == 1 ) { return convert(a1[n > 54u ? 0 : n], as<int8_t>()); }
else if constexpr( sizeof(T) == 2 ) { return a1[n > 6542u ? 0 : n]; }
else
{
Expand All @@ -1292,12 +1292,12 @@ inline constexpr auto nth_prime = functor<nth_prime_t>;
if constexpr( sizeof(elt_t) == 1 )
{
tmp = if_else(n > 54u, zero, tmp);
return uint8(tmp);
return convert(tmp, as<uint8_t>());
}
else if constexpr( sizeof(elt_t) == 2 )
{
tmp = if_else(n > 6542u, zero, tmp);
return uint16(tmp);
return convert(tmp, as<uint16_t>());
}
else { return add[convert(n, as<elt_t>()) > 6542u](convert(tmp, as<elt_t>()), T(0xffffu)); }
}
Expand All @@ -1314,7 +1314,7 @@ inline constexpr auto nth_prime = functor<nth_prime_t>;
constexpr EVE_FORCEINLINE auto
nth_prime_(EVE_REQUIRES(cpu_), O const&, T n, as<U> const & target) noexcept
{
auto r = convert(nth_prime(uint32(n)), target);
auto r = convert(nth_prime(convert(n, as<uint32_t>())), target);
return if_else(is_eqz(r), allbits, r);
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/eve/module/combinatorial/regular/prime_ceil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ namespace eve
constexpr EVE_FORCEINLINE auto
prime_ceil_(EVE_REQUIRES(cpu_), O const&, T n, as<U> const & target) noexcept
{
return convert(prime_ceil(uint32(n)), target);
return convert(prime_ceil(convert(n, as<uint32_t>())), target);
}

template<unsigned_value T, floating_scalar_value U, callable_options O>
constexpr EVE_FORCEINLINE auto
prime_ceil_(EVE_REQUIRES(cpu_), O const&, T n, as<U> const & target) noexcept
{
auto r = convert(prime_ceil(uint32(n)), target);
auto r = convert(prime_ceil(convert(n, as<uint32_t>())), target);
return if_else(is_eqz(r), allbits, r);
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/eve/module/combinatorial/regular/prime_floor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ namespace eve
constexpr EVE_FORCEINLINE auto
prime_floor_(EVE_REQUIRES(cpu_), O const&, T n, as<U> const & target) noexcept
{
return convert(prime_floor(uint32(n)), target);
return convert(prime_floor(convert(n, as<uint32_t>())), target);
}

template<unsigned_value T, floating_scalar_value U, callable_options O>
constexpr EVE_FORCEINLINE auto
prime_floor_(EVE_REQUIRES(cpu_), O const&, T n, as<U> const & target) noexcept
{
auto r = convert(prime_floor(uint32(n)), target);
auto r = convert(prime_floor(convert(n, as<uint32_t>())), target);
return if_else(is_eqz(r), allbits, r);
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/eve/module/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
//!
//! @}
//==================================================================================================

#include <eve/module/core/compress/core.hpp>
#include <eve/module/core/constant/core.hpp>
#include <eve/module/core/decorator/core.hpp>
Expand All @@ -112,3 +111,4 @@
#include <eve/module/core/saturated/core.hpp>
#include <eve/wide.hpp>
#include <eve/arch/nofs.hpp>
#include <eve/as_element.hpp>
4 changes: 2 additions & 2 deletions include/eve/module/core/regular/bit_floor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ namespace eve
}
else if constexpr( signed_integral_value<T> )
{
auto uz = bit_floor(uint_(v));
return if_else(is_ltz(v), zero, to_<T>(uz));
auto uz = bit_floor(convert(v, uint_from<T>()));
return if_else(is_ltz(v), zero, convert(uz, as<element_type_t<T>>()));
}
else
{
Expand Down
Loading

0 comments on commit 9728083

Please sign in to comment.