Remove fft_*_helper functions

This commit is contained in:
Ben Edgington 2021-02-03 07:34:37 +00:00
parent 6b01ba2b22
commit 80317b655e
5 changed files with 10 additions and 29 deletions

View File

@ -18,7 +18,6 @@ fft_g1_test: fft_g1.o fft_g1_test.c test_util.o fft_util.o Makefile
./$@
test: $(tests)
rm -f $(tests)
clean:
rm -f *.o

View File

@ -34,9 +34,9 @@ void fft_fr_slow(blst_fr *out, blst_fr *in, uint64_t stride, blst_fr *roots, uin
// Fast Fourier Transform
void fft_fr_fast(blst_fr *out, blst_fr *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l) {
uint64_t half = l / 2;
if (half > 0) {
fft_fr_helper(out, in, stride * 2, roots, roots_stride * 2, half);
fft_fr_helper(out + half, in + stride, stride * 2, roots, roots_stride * 2, half);
if (half > 2) { // TODO: Tunable parameter
fft_fr_fast(out, in, stride * 2, roots, roots_stride * 2, half);
fft_fr_fast(out + half, in + stride, stride * 2, roots, roots_stride * 2, half);
for (uint64_t i = 0; i < half; i++) {
blst_fr y_times_root;
blst_fr x = out[i];
@ -45,15 +45,7 @@ void fft_fr_fast(blst_fr *out, blst_fr *in, uint64_t stride, blst_fr *roots, uin
blst_fr_sub(&out[i + half], &x, &y_times_root);
}
} else {
blst_fr_mul(out, in, roots);
}
}
void fft_fr_helper(blst_fr *out, blst_fr *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l) {
if (l <= 4) { // TODO: Tunable parameter
fft_fr_slow(out, in, stride, roots, roots_stride, l);
} else {
fft_fr_fast(out, in, stride, roots, roots_stride, l);
}
}
@ -66,11 +58,11 @@ void fft_fr (blst_fr *out, blst_fr *in, FFTSettings *fs, bool inv, uint64_t n) {
blst_fr inv_len;
fr_from_uint64(&inv_len, n);
blst_fr_eucl_inverse(&inv_len, &inv_len);
fft_fr_helper(out, in, 1, fs->reverse_roots_of_unity, stride, fs->max_width);
fft_fr_fast(out, in, 1, fs->reverse_roots_of_unity, stride, fs->max_width);
for (uint64_t i = 0; i < fs->max_width; i++) {
blst_fr_mul(&out[i], &out[i], &inv_len);
}
} else {
fft_fr_helper(out, in, 1, fs->expanded_roots_of_unity, stride, fs->max_width);
fft_fr_fast(out, in, 1, fs->expanded_roots_of_unity, stride, fs->max_width);
}
}

View File

@ -19,5 +19,4 @@
void fft_fr_slow(blst_fr *out, blst_fr *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
void fft_fr_fast(blst_fr *out, blst_fr *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
void fft_fr_helper(blst_fr *out, blst_fr *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
void fft_fr (blst_fr *out, blst_fr *in, FFTSettings *fs, bool inv, uint64_t n);

View File

@ -47,9 +47,9 @@ void fft_g1_slow(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uin
// Fast Fourier Transform
void fft_g1_fast(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l) {
uint64_t half = l / 2;
if (half > 0) {
fft_g1_helper(out, in, stride * 2, roots, roots_stride * 2, half);
fft_g1_helper(out + half, in + stride, stride * 2, roots, roots_stride * 2, half);
if (half > 2) { // TODO: Tunable parameter
fft_g1_fast(out, in, stride * 2, roots, roots_stride * 2, half);
fft_g1_fast(out + half, in + stride, stride * 2, roots, roots_stride * 2, half);
for (uint64_t i = 0; i < half; i++) {
blst_p1 y_times_root;
blst_p1 x = out[i];
@ -58,15 +58,7 @@ void fft_g1_fast(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uin
p1_sub(&out[i + half], &x, &y_times_root);
}
} else {
p1_mul(out, in, roots);
}
}
void fft_g1_helper(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l) {
if (l <= 4) { // TODO: Tunable parameter
fft_g1_slow(out, in, stride, roots, roots_stride, l);
} else {
fft_g1_fast(out, in, stride, roots, roots_stride, l);
}
}
@ -79,11 +71,11 @@ void fft_g1 (blst_p1 *out, blst_p1 *in, FFTSettings *fs, bool inv, uint64_t n) {
blst_fr inv_len;
fr_from_uint64(&inv_len, n);
blst_fr_eucl_inverse(&inv_len, &inv_len);
fft_g1_helper(out, in, 1, fs->reverse_roots_of_unity, stride, fs->max_width);
fft_g1_fast(out, in, 1, fs->reverse_roots_of_unity, stride, fs->max_width);
for (uint64_t i = 0; i < fs->max_width; i++) {
p1_mul(&out[i], &out[i], &inv_len);
}
} else {
fft_g1_helper(out, in, 1, fs->expanded_roots_of_unity, stride, fs->max_width);
fft_g1_fast(out, in, 1, fs->expanded_roots_of_unity, stride, fs->max_width);
}
}

View File

@ -21,5 +21,4 @@ void p1_mul(blst_p1 *out, const blst_p1 *a, const blst_fr *b);
void p1_sub(blst_p1 *out, const blst_p1 *a, const blst_p1 *b);
void fft_g1_slow(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
void fft_g1_fast(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
void fft_g1_helper(blst_p1 *out, blst_p1 *in, uint64_t stride, blst_fr *roots, uint64_t roots_stride, uint64_t l);
void fft_g1 (blst_p1 *out, blst_p1 *in, FFTSettings *fs, bool inv, uint64_t n);