Parallelize in_place_bit_reverse_permute#562
Conversation
|
/bench |
Codex Code ReviewFound one issue:
No security issues found in the unsafe parallel swap logic given the documented power-of-two precondition. I could not run |
| if br > i { | ||
| // SAFETY: (i, br) uniquely identifies this pair (smaller index is owner), | ||
| // so no two threads race on the same `ptr.0.add(k)` slot. Both indices | ||
| // are in-bounds since i < n and br < n. |
There was a problem hiding this comment.
Low: redundant alias
SendPtr<E> is Copy, so ptr is already freely copyable inside the closure — the let p = ptr; binding serves no purpose.
| // are in-bounds since i < n and br < n. | |
| unsafe { | |
| core::ptr::swap(ptr.0.add(i), ptr.0.add(br)); | |
| } |
| for i in 0..input.len() { | ||
| let bit_reversed_index = reverse_index(i, input.len() as u64); | ||
| pub fn in_place_bit_reverse_permute<E: Send>(input: &mut [E]) { | ||
| let n = input.len(); |
There was a problem hiding this comment.
Low: missing invariant assertion before unsafe code
The entire function — including the doc comment — requires n to be a power of two. Violating that causes reverse_index to produce out-of-bounds indices, which is a silent panic in the serial path but undefined behaviour in the parallel path (raw pointer dereference out of bounds).
All call-sites in polynomial.rs and bowers_fft.rs already guard with is_power_of_two() before calling this function, but a debug_assert here makes the safety invariant explicit and catches future misuse:
| let n = input.len(); | |
| let n = input.len(); | |
| debug_assert!(n == 0 || n.is_power_of_two(), "input length must be a power of two"); |
Review: Parallelize
|
Benchmark — fib_iterative_8M (median of 5)Table parallelism: auto (cores / 3)
Commit: 3f8beac · Baseline: built from main · Runner: self-hosted bench |
|
/bench 10 |
1 similar comment
|
/bench 10 |
|
/bench k=1 |
|
/bench 5 |
No description provided.