load_bytes
Mojo function 🡭
load_bytes
fn def load_bytes[dtype: DType, width: SIMDLength, o: Origin[mut=o.mut]](data: Span[UInt8, o]) -> SIMD[dtype, width]Reinterpret the first width lanes’ worth of data as a vector.
The counterpart of SIMD.from_bytes, for the case that one needs a
fixed-size Array and data does not have one: a span with a
runtime length. Reading through the span’s pointer avoids the copy that
staging the bytes into an array would cost, which matters in the
block-cipher inner loops this exists for.
Byte order is the target’s own — this is a raw memory reinterpretation,
so it round-trips with store_bytes but is not endianness-neutral. Use
SIMD.from_bytes[endian=...] or load_be where the wire order
matters.
Parameters:
- dtype (
DType): The lane type of the returned vector. - width (
SIMDLength): The number of lanes to read. - o (
Origin[mut=mut]): The origin of the byte span.
Args:
- data (
Span[UInt8, o]): The bytes to reinterpret; must hold at leastwidth * size_of[dtype]()of them.
Returns:
SIMD[dtype, width]: The first width * size_of[dtype]() bytes of data as a vector.