Skip to content

Conversation

@KonaeAkira
Copy link

The problems with the current implementation using the LUT:

  • Panics in case note is out of range. I don't think panicking for an invalid note is appropriate.
  • The index-out-of-bounds check introduces a conditional branch.
  • Requires memory access.

Some alternatives I explored: https://godbolt.org/z/8Txffr7d5

I decided to avoid all LUT-based implementations for this case because they either have a conditional branch or require the use of unsafe. Also, f32::exp2(x) compiles down to a single cvtsi2ss instruction on x86_64, so why not compute the pitch directly?

Computing the pitch is branchless and compute-bound instead of memory-bound. The CPU can probably find a way to slot the computation into its pipeline for free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant