Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorten precomputed_sine_table #309

Open
orottier opened this issue Jun 25, 2023 · 2 comments
Open

Shorten precomputed_sine_table #309

orottier opened this issue Jun 25, 2023 · 2 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@orottier
Copy link
Owner

let table: Vec<f32> = (0..TABLE_LENGTH_USIZE)
    .map(|x| ((x as f32) * 2.0 * PI * (1. / (TABLE_LENGTH_F32))).sin())
    .collect();

This computes the full sine wave from t=0 to t=2PI.
We can use the symmetries of the sine wave to store only the part of t=0 to t=PI/2 and derive the other ranges from it:
https://www.electronics-notes.com/images/waveform-sine-wave-02.png

This will reduce the general memory usage so we can utilize the caches for other things which may improve the libs performance

@orottier orottier added the good first issue Good for newcomers label Jun 25, 2023
@orottier orottier changed the title Improve pre-computed SINETABLE Shorten pre-computed SINETABLE Jul 15, 2023
@orottier orottier changed the title Shorten pre-computed SINETABLE Shorten precomputed_sine_table Jul 15, 2023
@b-ma
Copy link
Collaborator

b-ma commented Jul 17, 2023

This could also introduce some if/else branching in loops which might not be that good for perfs no?

@orottier orottier self-assigned this Jul 24, 2023
@orottier
Copy link
Owner Author

orottier commented Jul 24, 2023

Good point, so I put some effort in a branchless version for tables with a power-of-two size: https://godbolt.org/z/9Yhs6hPoh
I'm no assembly hero, but I think we can see it is branchless because there are no labels and jump instructions present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants