function
byte_swap
byte_swap[type: DType, simd_width: Int](val: SIMD[type, simd_width]) -> SIMD[$0, $1]
Byte-swaps a SIMD vector of integer values with an even number of bytes.
Byte swap an integer value or vector of integer values with an even number
of bytes (positive multiple of 16 bits). This is equivalent to llvm.bswap
intrinsic that has the following semantics:
The llvm.bswap.i16
intrinsic returns an i16 value that has the high and
low byte of the input i16 swapped. Similarly, the llvm.bswap.i32
intrinsic
returns an i32 value that has the four bytes of the input i32 swapped, so
that if the input bytes are numbered 0, 1, 2, 3 then the returned i32 will
have its bytes in 3, 2, 1, 0 order. The llvm.bswap.i48
, llvm.bswap.i64
and other intrinsics extend this concept to additional even-byte lengths (6
bytes, 8 bytes and more, respectively).
Constraints:
The element type of the input vector must be an integral type with an even number of bytes (Bitwidth % 16 == 0).
Parameters:
- type (
DType
):dtype
used for the computation. - simd_width (
Int
): SIMD width used for the computation.
Args:
- val (
SIMD[type, simd_width]
): The input value.
Returns:
A SIMD value where the element at position i
is the value of the element at position i
of the input value with its bytes swapped.