pub fn shiftElementsRight(vec: anytype, comptime amount: VectorCount(@TypeOf(vec)), shift_in: std.meta.Child(@TypeOf(vec))) @TypeOf(vec) vecamount: VectorCount(@TypeOf(vec))shift_in: std.meta.Child(@TypeOf(vec))259
260
261
262
263
264
265
266
267pub fn shiftElementsRight(vec: anytype, comptime amount: VectorCount(@TypeOf(vec)), shift_in: std.meta.Child(@TypeOf(vec))) @TypeOf(vec) {
// It may be possible to implement shifts and rotates with a runtime-friendly slice of two joined vectors, as the length of the
// slice would be comptime-known. This would permit vector shifts and rotates by a non-comptime-known amount.
// However, I am unsure whether compiler optimizations would handle that well enough on all platforms.
const V = @TypeOf(vec);
const len = vectorLength(V);
return mergeShift(@as(V, @splat(shift_in)), vec, len - amount);
}
Elements are shifted rightwards (towards higher indices). New elements are added to the left, and the rightmost elements are cut off so that the length of the vector stays the same.