byte-sum-narrow-accByte sum into an accumulator narrower than int64
Reported by --explain after a verdict.
mettle explain byte-sum-narrow-acc
Summing bytes has a very fast kernel (vpsadbw, 32 bytes per step), but it accumulates into int64: 32 lanes of a byte each can carry further than 32 bits, and the kernel will not silently give you a different answer from the scalar loop.
Example
var total: int64 = 0;
for i in 0..n {
total = total + (int64)data[i];
}
Fix: declare the accumulator int64. The report simulates that change, re-runs the optimizer, and only prints the advice once the loop really does vectorize with it.
Related
- call-in-bodyThe loop body calls a function
- extern-call-in-bodyThe loop body calls an external function
- indirect-callThe loop body calls through a function pointer
- alloc-in-bodyThe loop body allocates
- inline-asmThe loop body contains inline assembly
- control-flowThe loop body branches
- early-exitThe loop can leave before its trip count
- int16-elements16-bit integer elements have no kernel