Vector Width and the Last Partial Block
A vector operation can process several data elements per instruction under its representation. The final elements need a rule when length is not a multiple of that width.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a width-four loop
Ten elements contain two full groups of four and a tail of two. The last group can use supported masking or scalar work. Fixed-size batches give the same quotient-and-tail structure.
Test small counts
Check zero, three, four, and five items under the actual bounds. A code path exercised only at exact multiples could miss elements beyond its last vector. See off-by-one errors.[1]
Process the tail outside full-width groups
Twelve full vector positions at width four cover indices zero through eleven. With fourteen total inputs, indices twelve and thirteen still need results. A masked final group or a scalar tail can do so under the supported runtime. See sequence slicing boundaries.
Input length 14, vector width 4
Full blocks [0,4), [4,8), [8,12)
Tail [12,14)
Total covered: 14 positions
Check bounds near exact multiples
An unguarded full-width read of the tail can cross the end. At exact multiples no tail is needed. Test length zero, shorter than width, exact width and width plus one.