Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
smu160 committed Jul 14, 2024
1 parent 8c24e08 commit b3568d3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rand::{
thread_rng, Rng,
};
use utilities::rustfft::num_complex::Complex;
use utilities::rustfft::{FftNum, FftPlanner};
use utilities::rustfft::FftPlanner;

const LENGTHS: &[usize] = &[
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
Expand Down
35 changes: 26 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,44 @@ macro_rules! impl_fft_with_opts_and_plan_for {
_ => (),
}

let mut filtered_twiddles_re = twiddles_re.clone();
let mut filtered_twiddles_im = twiddles_im.clone();
// 0th stage is special due to no need to filter twiddle factor
let dist = 1 << (n - 1);
let chunk_size = dist << 1;

if chunk_size > 4 {
if chunk_size >= $lanes * 2 {
$simd_butterfly_kernel(reals, imags, twiddles_re, twiddles_im, dist);
} else {
fft_chunk_n(reals, imags, twiddles_re, twiddles_im, dist);
}
}
else if chunk_size == 4 {
fft_chunk_4(reals, imags);
}
else if chunk_size == 2 {
fft_chunk_2(reals, imags);
}

let (mut filtered_twiddles_re, mut filtered_twiddles_im) = filter_twiddles(twiddles_re, twiddles_im);

for t in (0..n).rev() {
for t in (0..n - 1).rev() {
let dist = 1 << t;
let chunk_size = dist << 1;

if chunk_size > 4 {
if t < n - 1 {
(filtered_twiddles_re, filtered_twiddles_im) = filter_twiddles(&filtered_twiddles_re, &filtered_twiddles_im);
}
if chunk_size >= $lanes * 2 {
$simd_butterfly_kernel(reals, imags, &filtered_twiddles_re, &filtered_twiddles_im, dist);
} else {
fft_chunk_n(reals, imags, &filtered_twiddles_re, &filtered_twiddles_im, dist);
}
} else if chunk_size == 2 {
fft_chunk_2(reals, imags);
} else if chunk_size == 4 {
}
else if chunk_size == 4 {
fft_chunk_4(reals, imags);
}
else if chunk_size == 2 {
fft_chunk_2(reals, imags);
}
(filtered_twiddles_re, filtered_twiddles_im) = filter_twiddles(&filtered_twiddles_re, &filtered_twiddles_im);
}

if opts.multithreaded_bit_reversal {
Expand Down
28 changes: 28 additions & 0 deletions src/twiddles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,34 @@ mod tests {

use super::*;

// TODO(saveliy): use
#[test]
fn twiddles_cos_only() {
let n = 4;
let big_n = 1 << n;

let dist = big_n >> 1;

let (fwd_twiddles_re, fwd_twiddles_im) = if dist >= 8 * 2 {
generate_twiddles_simd_64(dist, Direction::Forward)
} else {
generate_twiddles(dist, Direction::Forward)
};

assert!(fwd_twiddles_re.len() == dist && fwd_twiddles_im.len() == dist);

for i in 0..dist {
let w_re = fwd_twiddles_re[i];

Check warning on line 237 in src/twiddles.rs

View workflow job for this annotation

GitHub Actions / Test

unused variable: `w_re`

Check warning on line 237 in src/twiddles.rs

View workflow job for this annotation

GitHub Actions / Test

unused variable: `w_re`
let expected_w_im = fwd_twiddles_im[i];

let actual_w_im = -fwd_twiddles_re[(i + dist / 2) % dist];
//assert_float_closeness(actual_w_im, expected_w_im, 1e-6);
print!("actual: {actual_w_im} expected: {expected_w_im}\n");
}
println!("{:?}", fwd_twiddles_re);
println!("{:?}", fwd_twiddles_im);
}

#[test]
fn twiddles_4() {
const N: usize = 4;
Expand Down

0 comments on commit b3568d3

Please sign in to comment.