pub fn argmax_first_wins_f32(v: &[f32]) -> u32Expand description
Argmax over an f32 slice with the strict-> FIRST-index-wins tie-break.
SSOT for this pick: the verify path (spark-server’s
verify_pipeline_helper/argmax.rs) calls here too. The naive
if v > best { best = v; idx = i } loop carries a dependency through BOTH
the running value and the index, which blocks vectorisation — measured
1.19 ms for 4x248k on the verify path before the two-pass rewrite (5.95x).
Equivalence to that loop, including the awkward cases: > is false for
NaN in both passes so NaN never wins (all-NaN => -inf max, pass 2 finds no
equal, falls back to 0 — same as the loop); IEEE -0.0 == +0.0 so neither
> nor == separates them and the first zero encountered is returned
either way. f32::max is deliberately avoided (it returns the non-NaN
operand, which would let a NaN-adjacent value win where > ignored it).