Sprint 202: Advanced 3D Math SIMD Expansion ⚡
Welcome to Sprint 202! Following our success with compile-time auto-vectorization in Sprint 200, we have expanded our SIMD capabilities. The compiler's optimization pass and the Stack-VM are now equipped with full vector math execution, bringing parallel addition, subtraction, and dot products to KnotenCore.
⚡ The new SimdOp Enum
To cleanly scale the compiler's vectorization capabilities, we introduced the SimdOp enum inside src/vm/opcode.rs. Instead of creating separate bytecode instructions for each vector operation, the compiler now emits a unified OpCode::SimdExec carrying the target operations:
pub enum SimdOp {
Scale,
Add,
Subtract,
Dot,
}
⚙️ Machine Handler Execution
The Stack-VM handles these operations using raw glam::Vec4 hardware registers:
SimdOp::Scale: Multiplies a vector by a scalar factor (Vec4 * factor).SimdOp::Add/Subtract: Performs element-wise vector addition or subtraction (Vec4 + Vec4/Vec4 - Vec4) in a single CPU cycle.SimdOp::Dot: Computes the mathematical dot product (Vec4::dot()), collapsing the vector into a singleRelType::Floatscalar. This is highly useful for fast raycasting and shader preprocessing.
🧪 Verification & Testing
We added dedicated unit tests to verify the correctness of our expansion:
test_simd_vector_addition_applied and test_simd_dot_product_applied.
Both tests verify that the optimizer successfully collapses sequential instructions into the new parallel operations and executes them correctly inside the VM.