packed_simd
packed_simd copied to clipboard
Finer-grained lane-wise casts
Currently, .cast() performs a "numeric cast" for each vector lane that's semantically equivalent to as for primitive scalars. The RFC 2484 proposes a couple of cast methods to replace as. While that RFC is a bit in the air, I think it would be useful to do the ground work for it already, by adding more finer grained cast methods for vectors with equal number of lanes:
.truncate()(for signed and unsigned integer vectors and masks): truncates a vector into a shorter vector by dropping the MSBs of each lane..zero_extend()(for unsigned integer vectors): extends a vector into a larger vector by zero-extending each lane..sign_extend()(for signed integer vectors): extends a vector into a larger vector by sign-extending each lane..round_{mode}()(for floating point vectors): rounds a floating-point vector into one of a different lane type according to the rounding-mode.
Once we have this, implementing "nicer" APIs on top of this functionality should be trivial.