typestar

SIMD vectors in Mojo

SIMD is a fixed-width vector that maps straight onto a hardware register.

comptime F4 = SIMD[DType.float64, 4]


def main():
    var lane = F4(1.5, 2.5, 3.5, 4.5)
    print(lane)
    print(lane[0], lane[3])
    print(lane.size)

How it works

  1. SIMD[DType.float64, 4] names four lanes of 64-bit float.
  2. Lanes are read by index, exactly like a list.
  3. .size reports the lane count, which is known at compile time.

Keywords and builtins used here

The run, in numbers

Lines
8
Characters to type
137
Tokens
47
Three-star pace
75 tpm

At the three-star pace of 75 tokens a minute, this run takes about 38 seconds.

Type this snippet

Step 1 of 6 in SIMD, step 6 of 22 in Parameters & SIMD.

← Previous Next →