5. Zero-Branching Execution Model

menu_book Spatioz Engine — Technical Reference

Zero-Branching Execution Model

Traditional AI systems and controllers rely heavily on conditional branching (if-else blocks, state machines). This introduces significant pipeline stalls, increases execution latency on modern CPUs/GPUs, and makes correctness validation hard. Spatioz operates on a Zero-Branching (No If-Then) Execution Paradigm.

1. The Core Principle

Every logical check is converted into a mathematical operation (multiplication, masking, array dispatch). By doing so, the compiler can generate linear, branchless instruction streams that are highly cache-friendly and easily vectorizable (SIMD).


2. Implementation Equivalents

Here is how Spatioz replaces conditional statements with branchless mathematical alternatives:

A. Replacing Simple Conditions with Math Masking

Instead of:

let force = 0;
if (distance < 10.0) {
    force = 5.0;
}

Spatioz evaluates:

// +(condition) casts a boolean to 1 or 0 in JS
let force = 5.0 * +(distance < 10.0);

B. Replacing Switch/If-Else Chains with Array Dispatch

Instead of:

if (state === 'CHASE') {
    runChase();
} else if (state === 'EVADE') {
    runEvade();
} else {
    runIdle();
}

Spatioz uses a numeric state index and dispatches directly:

const actions = [runIdle, runChase, runEvade];
actions[state_index]();

C. Continuous Interpolation (Soft Transitions)

Instead of hard switching, Spatioz blends intents continuously:

$$Output = (v{\text{condition}} \cdot A) + ((1 - v{\text{condition}}) \cdot B)$$

This guarantees smooth transitions between states (e.g., smoothly transitioning from cruising to emergency stops as obstacles become visible) with zero branch penalties.