0Pricing
Mojo Academy · Lesson

Meet the SIMD Type

A vector of values handled together.

Meet the SIMD Type is a free Mojo Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Mojo Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

One Value at a Time Is Slow

A normal Int holds a single number, so math happens one value at a time. For AI you often need to crunch many numbers at once.

Meet SIMD

SIMD means Single Instruction, Multiple Data: one operation applied to a whole pack of numbers in a single step.

A Vector of Values

In Mojo the SIMD type holds several values of the same kind together, like a tiny fixed-size vector handled as one unit.

var v = SIMD[DType.float32, 4](1, 2, 3, 4)

Two Type Parameters

A SIMD type takes two parameters in brackets: the element DType and how many lanes it holds, like SIMD[DType.int32, 4].

alias Pack = SIMD[DType.int32, 4]

DType Picks the Element Kind

The first parameter is a DType such as float32 or int32. It decides what each lane stores and how big it is.

var x = SIMD[DType.float32, 4](0.5, 1.5, 2.5, 3.5)

Width Is the Lane Count

The second parameter is the width: the number of values packed side by side. A width of 4 means four numbers travel together.

var four = SIMD[DType.int32, 4](10, 20, 30, 40)

Width Is a Power of Two

SIMD widths are powers of two like 1, 2, 4, 8, or 16. This maps cleanly onto the lanes your CPU offers.

var eight = SIMD[DType.float32, 8](0)

A Scalar Is Width One

Even a plain number is really a SIMD of width 1 in Mojo. Scalars and vectors share the same underlying type.

var one = SIMD[DType.float32, 1](3.14)

Indexing the Lanes

You can read a single lane by index just like a list. Lane 0 is the first value in the vector.

var v = SIMD[DType.int32, 4](5, 6, 7, 8)
print(v[0])

Fill Every Lane at Once

Passing one value fills all lanes with it. This is a quick way to make a SIMD vector of constant values.

var zeros = SIMD[DType.float32, 4](0)

Why SIMD Is Fast

Because the CPU acts on a whole pack in one instruction, SIMD does more work per cycle. That is the heart of vectorization.

Quick Check

You declare SIMD[DType.float32, 4]. What do those two parameters mean?

Recap

SIMD packs several same-typed values into one vector set by a DType and a power-of-two width, so one instruction touches them all. 🚀

Frequently asked questions

Is the “Meet the SIMD Type” lesson free?

Yes — the full text of “Meet the SIMD Type” is free to read here on the web, and the Mojo Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Mojo Academy course, upgrade to CoddyKit PRO.

What will I learn in “Meet the SIMD Type”?

A vector of values handled together. You practise Mojo Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Mojo Academy?

No prior experience is required. Mojo Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Meet the SIMD Type” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Mojo Academy lesson?

Yes. Every Mojo Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Meet the SIMD Type
  2. Element-Wise SIMD Math
  3. Choosing a SIMD Width
  4. Vectorizing a Loop
← Back to Mojo Academy