Skip to content

Commit

Permalink
tweaks to avoiding exceptions in get_evaluation_domain logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dtebbs committed Oct 11, 2021
1 parent 20fc9bf commit fbbf6f5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 39 deletions.
13 changes: 3 additions & 10 deletions libfqfft/evaluation_domain/domains/basic_radix2_domain.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,13 @@ namespace libfqfft {
template<typename FieldT>
bool basic_radix2_domain<FieldT>::valid_for_size(const size_t m)
{
if ( m <= 1 )
if (m <= 1) {
return false;

// Will `get_root_of_unity` throw?
if (!std::is_same<FieldT, libff::Double>::value)
{
const size_t logm = libff::log2(m);

if (logm > FieldT::s)
return false;
}

if (get_root_of_unity_will_throw<FieldT>(m))
if (!libff::has_root_of_unity<FieldT>(m)) {
return false;
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ bool extended_radix2_domain<FieldT>::valid_for_size(const size_t m)

size_t small_m = m / 2;

if (get_root_of_unity_will_throw<FieldT>(small_m))
if (!libff::has_root_of_unity<FieldT>(small_m)) {
return false;
}

return true;
}
Expand Down
12 changes: 8 additions & 4 deletions libfqfft/evaluation_domain/domains/step_radix2_domain.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ namespace libfqfft {
template<typename FieldT>
bool step_radix2_domain<FieldT>::valid_for_size(const size_t m)
{
if (m <= 1)
if (m <= 1) {
return false;
}

const size_t big_m = 1ul<<(libff::log2(m)-1);
const size_t small_m = m - big_m;

if (small_m != 1ul<<libff::log2(small_m))
if (small_m != 1ul<<libff::log2(small_m)) {
return false;
}

// omega
if (get_root_of_unity_will_throw<FieldT>(1ul<<libff::log2(m)))
if (!libff::has_root_of_unity<FieldT>(1ul<<libff::log2(m))) {
return false;
}

// small_omega
if (get_root_of_unity_will_throw<FieldT>(1ul<<libff::log2(small_m)))
if (!libff::has_root_of_unity<FieldT>(1ul<<libff::log2(small_m))) {
return false;
}

return true;
}
Expand Down
24 changes: 0 additions & 24 deletions libfqfft/evaluation_domain/evaluation_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,6 @@

namespace libfqfft {

template<typename FieldT>
typename std::enable_if<std::is_same<FieldT, libff::Double>::value, bool>::type
get_root_of_unity_will_throw(const size_t /*n*/)
{
return false;
}


template<typename FieldT>
typename std::enable_if<!std::is_same<FieldT, libff::Double>::value, bool>::type
get_root_of_unity_will_throw(const size_t n)
{
const size_t logn = libff::log2(n);

if (n != (1u << logn))
return true;

if (logn > FieldT::s)
return true;

return false;
}


/**
* An evaluation domain.
*/
Expand Down

0 comments on commit fbbf6f5

Please sign in to comment.