Skip to content

Commit 1a51839

Browse files
committed
tweaks to avoiding exceptions in get_evaluation_domain logic
1 parent 903c840 commit 1a51839

File tree

5 files changed

+15
-41
lines changed

5 files changed

+15
-41
lines changed

libfqfft/evaluation_domain/domains/basic_radix2_domain.tcc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,13 @@ namespace libfqfft {
2525
template<typename FieldT>
2626
bool basic_radix2_domain<FieldT>::valid_for_size(const size_t m)
2727
{
28-
if ( m <= 1 )
28+
if (m <= 1) {
2929
return false;
30-
31-
// Will `get_root_of_unity` throw?
32-
if (!std::is_same<FieldT, libff::Double>::value)
33-
{
34-
const size_t logm = libff::log2(m);
35-
36-
if (logm > FieldT::s)
37-
return false;
3830
}
3931

40-
if (get_root_of_unity_will_throw<FieldT>(m))
32+
if (!libff::has_root_of_unity<FieldT>(m)) {
4133
return false;
34+
}
4235

4336
return true;
4437
}

libfqfft/evaluation_domain/domains/extended_radix2_domain.tcc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ bool extended_radix2_domain<FieldT>::valid_for_size(const size_t m)
3434

3535
size_t small_m = m / 2;
3636

37-
if (get_root_of_unity_will_throw<FieldT>(small_m))
37+
if (!libff::has_root_of_unity<FieldT>(small_m)) {
3838
return false;
39+
}
3940

4041
return true;
4142
}

libfqfft/evaluation_domain/domains/step_radix2_domain.tcc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@ namespace libfqfft {
2020
template<typename FieldT>
2121
bool step_radix2_domain<FieldT>::valid_for_size(const size_t m)
2222
{
23-
if (m <= 1)
23+
if (m <= 1) {
2424
return false;
25+
}
2526

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

29-
if (small_m != 1ul<<libff::log2(small_m))
30+
if (small_m != 1ul<<libff::log2(small_m)) {
3031
return false;
32+
}
3133

3234
// omega
33-
if (get_root_of_unity_will_throw<FieldT>(1ul<<libff::log2(m)))
35+
if (!libff::has_root_of_unity<FieldT>(1ul<<libff::log2(m))) {
3436
return false;
37+
}
3538

3639
// small_omega
37-
if (get_root_of_unity_will_throw<FieldT>(1ul<<libff::log2(small_m)))
40+
if (!libff::has_root_of_unity<FieldT>(1ul<<libff::log2(small_m))) {
3841
return false;
42+
}
3943

4044
return true;
4145
}

libfqfft/evaluation_domain/evaluation_domain.hpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,6 @@
3131

3232
namespace libfqfft {
3333

34-
template<typename FieldT>
35-
typename std::enable_if<std::is_same<FieldT, libff::Double>::value, bool>::type
36-
get_root_of_unity_will_throw(const size_t /*n*/)
37-
{
38-
return false;
39-
}
40-
41-
42-
template<typename FieldT>
43-
typename std::enable_if<!std::is_same<FieldT, libff::Double>::value, bool>::type
44-
get_root_of_unity_will_throw(const size_t n)
45-
{
46-
const size_t logn = libff::log2(n);
47-
48-
if (n != (1u << logn))
49-
return true;
50-
51-
if (logn > FieldT::s)
52-
return true;
53-
54-
return false;
55-
}
56-
57-
5834
/**
5935
* An evaluation domain.
6036
*/

libfqfft/evaluation_domain/get_evaluation_domain.tcc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ std::shared_ptr<evaluation_domain<FieldT> > get_evaluation_domain(const size_t m
3939
const size_t rounded_small = (1ul<<libff::log2(small));
4040

4141
if ( basic_radix2_domain<FieldT>::valid_for_size(min_size) ) {
42-
result.reset(new basic_radix2_domain<FieldT>(min_size));
42+
result.reset(new basic_radix2_domain<FieldT>(min_size));
4343
}
4444
else if ( extended_radix2_domain<FieldT>::valid_for_size(min_size) ) {
4545
result.reset(new extended_radix2_domain<FieldT>(min_size));
@@ -51,7 +51,7 @@ std::shared_ptr<evaluation_domain<FieldT> > get_evaluation_domain(const size_t m
5151
result.reset(new basic_radix2_domain<FieldT>(big + rounded_small));
5252
}
5353
else if ( extended_radix2_domain<FieldT>::valid_for_size(big + rounded_small) ) {
54-
result.reset(new extended_radix2_domain<FieldT>(big + rounded_small));
54+
result.reset(new extended_radix2_domain<FieldT>(big + rounded_small));
5555
}
5656
else if ( step_radix2_domain<FieldT>::valid_for_size(big + rounded_small) ) {
5757
result.reset(new step_radix2_domain<FieldT>(big + rounded_small));

0 commit comments

Comments
 (0)