ISPC (C dialect / Intel)
The Intel Implicit SPMD Program Compiler: a C-based SPMD language whose program instances are mapped onto the lanes of CPU SIMD units, with an execution mask, uniform/varying types and maximal convergence defined in the language, which makes it the reference design for running shader-shaped code on a CPU.
| Field | Value |
|---|---|
| Language | ISPC: C99 plus uniform/varying, foreach, cif, launch/sync, soa<N>, references, templates, operator overloading |
| License | BSD-3-Clause (README.md) |
| Repository | ispc/ispc (pinned 553b773f, 2026-10-16) |
| Documentation | User's Guide docs/ispc.rst (8,096 lines); Performance Guide docs/perfguide.rst; ISPC for Xe; Pharr and Mark, InPar 2012 paper; Pharr, The Story of ISPC |
| Key authors | Matt Pharr and William R. Mark (original design, Intel, 2010–2011); Intel compiler team since |
| Category | Single-source peer: SPMD-on-SIMD for CPUs (and Intel GPUs), C-ABI-linked with the host program |
| Latest version | v1.32.0, 13 October 2026, "Based on a patched LLVM 23.1.2" (docs/ReleaseNotes.txt) |
| Targets | x86 SSE2–AVX10.2, ARM NEON, Intel Xe GPUs (SPIR-V or zebin); off by default: RISC-V RVV, ppc64le, WebAssembly, a generic target (CMakeLists.txt, src/target_enums.h) |
| Gang sizes | 4, 8, 16, 32, 64 (target-dependent): avx2-i32x8 is AVX2 with a 32-bit mask and 8 instances; avx512skx-x16 uses AVX-512 hardware masks |
| Graphics | None: no stages, no textures, no derivatives, no interface variables |
NOTE
ISPC is not a shading language and does not try to be one. It is in this catalog because sparkles plans an SPMD-on-SIMD CPU executor for shaders (after the scalar reference simulator), and ISPC is the most complete, longest-lived, production implementation of exactly that lowering. Everything below that concerns graphics is a gap analysis, not a feature description.
Overview
What it solves
Compilers do not reliably auto-vectorize serial code into SIMD, and intrinsics are unreadable and non-portable across vector widths. GPU programmers had a model that worked: write the program for one element and let the hardware run many in lockstep. ISPC brings that model to the CPU. A function is written for one program instance; a gang of instances (4–64) executes it together on the SIMD lanes of one core, with no threads created. The compiler, not the hardware, is responsible for divergence: it keeps an execution mask and emits both sides of a varying branch under it. Cores are used through a separate task model (launch/sync).
The original motivation is stated in Pharr's account of the project: the auto-vectorizer of the time would "fail unpredictably", and "as long as vectorization can fail (and it will) … you must come to deeply understand the auto-vectorizer" (The Story of ISPC). ISPC makes vectorization a property of the language rather than of an optimizer's heuristics: every varying operation is a vector operation by construction.
Design philosophy
From README.md:
"To provide a thin abstraction layer between the programmer and the hardware--in particular, to have an execution and data model where the programmer can cleanly reason about the mapping of their source program to compiled assembly language and the underlying hardware."
And on the relation to shaders, from the User's Guide (§ Basic Concepts):
"An
ispcprogram instance is thus similar to a CUDA* "thread" or an OpenCL* "work-item", and anispcgang is similar to a CUDA* "warp". … This implicit model is the same as that used for shaders in programmable graphics pipelines, OpenCL* kernels, and CUDA*."
Three choices follow and run through every section below: variability is a type qualifier checked by the front end, not a property inferred by analysis; control flow is maximally converged by definition; and the host ABI is C, so data is shared by pointer with no copies.
How it works
Program instances, gangs and the mask
// ispc — each instance computes one element; the gang computes programCount of them
export void scale(uniform float vin[], uniform float vout[], uniform int count) {
foreach (index = 0 ... count) {
float v = vin[index]; // varying: one value per lane
if (v < 3.) // varying test: both arms may run, masked
v = v * v;
else
v = sqrt(v);
vout[index] = v; // masked (or blended) store
}
}programCount is static const uniform int32 programCount = TARGET_WIDTH; and programIndex is a varying constant initialised to {0, 1, …} (stdlib/include/core.isph). Everything not marked uniform is varying and lowers to an LLVM vector <WIDTH x T>. The mask is a vector of MASK-sized integers on targets without hardware predication (the m4 macros WIDTH = 8 and MASK = i32 in builtins/target-avx2-i32x8.ll) and i1 lanes (k-registers) on AVX-512 and Xe.
The guide defines the semantics with a single gang-wide program counter and a per-instance mask (docs/ispc.rst, § Control Flow Within A Gang):
"1. The program counter will have a sequence of values corresponding to a conservative execution path through the function, wherein if any program instance wants to execute a statement, the program counter will pass through that statement. 2. At each statement the program counter passes through, the execution mask will be set such that its value for a particular program instance is "on" if and only if the program instance wants to execute that statement."
The masking is done in the front end
ISPC does not emit scalar LLVM IR and ask a vectorizer to widen it. Its front end (FunctionEmitContext, src/ctx.h) emits vector IR directly from the AST and keeps the mask as explicit state:
State (src/ctx.h) | Meaning |
|---|---|
functionMaskValue | mask at function entry; arrives as a hidden trailing __mask parameter |
internalMaskAddressInfo | mask contributed by varying control flow inside the function |
fullMaskAddressInfo | function & internal, the mask side effects obey (GetFullMask) |
breakLanesAddressInfo | lanes that executed break in the current loop iteration |
continueLanesAddressInfo | lanes that executed continue; restored at the loop step (RestoreContinuedLanes) |
returnedLanesAddressInfo | lanes that have executed return |
blockEntryMask | mask at the top of the loop body, compared against finished lanes |
Every non-unmasked, non-export function takes the mask as its last LLVM argument (llvmArgTypes.push_back(LLVMTypes::MaskType) in FunctionType::LLVMArgumentTypes, src/type.cpp); an export function called from C starts with SetFunctionMask(LLVMMaskAllOn) (src/func.cpp).
Execution model and stages
There is one execution model: a gang running an SPMD function, called from C/C++. No pipeline stages exist; the nearest analogue of a compute dispatch is launch[n] f(...), which queues n tasks to a user-replaceable task system (ISPCLaunch/ISPCSync/ISPCAlloc), each running a whole gang. taskIndex and taskCount play the role of workgroup IDs.
The defining guarantee is maximal convergence (docs/ispc.rst, § Gang Convergence Guarantees):
"Maximal convergence means that if two program instances follow the same control path, they are guaranteed to execute each program statement concurrently. If two program instances follow diverging control paths, it is guaranteed that they will reconverge as soon as possible in the function (if they do later reconverge)."
The guide spells out the consequences: an 8-wide gang may not be run as two 4-wide halves; if (programIndex == 0) while (true); hangs the whole gang; a varying function pointer call groups lanes by pointer value and calls each target once. The paper adds that "this property also can introduce a dependency on SIMD width; by definition, ordering changes if the gang size changes" (Pharr and Mark, §3).
What ISPC lacks, measured against the shader execution model:
| Shader concept | ISPC |
|---|---|
| Invocation / subgroup | program instance / gang (gang size fixed at compile time per target) |
Workgroup + barrier() | absent; no shared-memory barrier across gangs; tasks only sync at the launch level |
| Quad, helper invocations, derivatives | absent |
discard / demote | absent; a masked return is the nearest thing |
| Graphics stages, interface variables | absent |
A CPU executor for fragment shaders therefore has to add, on top of ISPC's model, quad-aligned lane groups, helper lanes that keep computing after demote, and derivative operations over them (see Derivative and Helper invocation).
Type system and generic programming
- Variability is a qualifier on every type.
uniform intis a scalar shared by the gang;int(varying) is a vector.uniformconverts implicitly tovarying; the reverse is a compile-time error. Arrays carry the variability of their elements (uniform float bar[10]is 10 floats;float foo[10]is 10 gang-wide vectors). - Pointers have two variabilities. "pointers are
varyingby default … However, the default variability of the pointed-to type isuniform" (guide, § Pointer Types).float *pis a vector of pointers to scalars (a gather/scatter);varying float * uniform pfis one pointer to a gang-wide vector (a vector load/store). Casting a varying pointer to a uniform one is forbidden. - Structs are AoS in memory, SoA by lane in registers. A
varying struct Nodehas each member widened, and the generated C header shows it asstruct Node { int count[8]; float pos[3][8]; };for an 8-wide target (guide, § Data Layout). soa<N>rewrites a struct array into hybrid SoA (soa<8> Point pts[...]isstruct { uniform float x[8], y[8], z[8]; }per element block) while indexing stays AoS-shaped.- Short vectors
float<3>are explicitly not a vectorization device: "ispcdoes not use these short vectors to facilitate program vectorization; they are purely a syntactic convenience" (guide, § Short Vector Types). Avarying float<3>is three gang-wide vectors.uniformshort vectors are stored at the natural vector alignment, so their layout differs between targets and the guide warns against sharing them with C. - Generics: function templates with type and non-type parameters (the length of
float<N>may be a template parameter), operator overloading, and overload resolution whose cost ladder includes "promotions from uniform to varying types" as explicit ranks (guide, § Function Overloading).
Resources, interfaces and memory layout
There are no descriptors, bindings or buffer blocks: an export function takes C pointers and C structs, and ispc -h writes the matching C header. Varying values may cross the boundary only behind a pointer (varying float * uniform), and with multi-target compilation such pointers become void * in the general header because the gang width is chosen at run time. Layout is C layout by design: "ispc tries to ensure that struct types and other complex data types are laid out in the same way in memory as they are in C/C++" (guide, § Data Layout). There is no std140 or std430.
Memory operations are where the vector model costs. A varying index or pointer produces a gather or scatter, emitted first as a pseudo-op (__pseudo_gather32_float, __pseudo_masked_store_i32; src/ctx.cpp) and then improved by late passes:
Pass (src/opt.cpp order) | Job |
|---|---|
ImproveMemoryOpsPass | turn an array of pointers into base + offsets; detect uniform or consecutive addresses → plain vector loads (header) |
ReplacePseudoMemoryOpsPass | remaining pseudo-ops → native gather/scatter or per-lane scalar code; masked stores to stack allocas → load-blend-store |
IntrinsicsOpt | fold movmsk of constants; blendv/masked load-store with all-on or all-off masks → plain ops (header) |
GatherCoalescePass | split all-on 32-bit gathers into wide loads + shuffles; coalesce across gathers (helps AoS) (header) |
ReplaceMaskedMemOpsPass | shorten masked loads/stores when only part of the vector is used |
The blend choice is explicit in ReplacePseudoMemoryOps.cpp: "We need to choose between doing the load + blend + store trick, or serializing the masked store. Even on targets with a native masked store instruction, this is preferable since it lets us keep values in registers rather than going out to the stack." It is only legal for memory the gang owns (a stack alloca of at least the stored width); a store through a user pointer stays a true masked store, because a blend would write lanes that are off.
Built-in library and intrinsics
The standard library (stdlib/stdlib.ispc) is written in ISPC over a target-specific builtin layer in m4-templated LLVM IR (builtins/target-*.ll); the target redesign document describes the split into dispatcher, target-independent and target-dependent parts, shipped as bitcode. The cross-lane vocabulary, which is what a shader's subgroup operations lower to on a CPU:
| Group | Functions (guide, § Cross-Program Instance Operations, § Reductions) | Shader counterpart |
|---|---|---|
| Mask queries | lanemask(), any, all, none, popcnt(bool), packmask | subgroupBallot, subgroupAny/All, WaveActiveCountBits |
| Lane movement | broadcast(v, uniform i), rotate, shift, shuffle(v, perm), two-source shuffle | subgroupBroadcast, subgroupShuffle* |
| Extract / insert | extract(x, uniform i), insert | subgroupBroadcast with a constant lane |
| Reductions and scans | reduce_add/min/max, reduce_equal, exclusive_scan_add/and/or | subgroupAdd, subgroupExclusiveAdd, WaveActiveAllEqual |
| Compaction | packed_store_active, packed_load_active | none (stream compaction is done with ballot + prefix) |
| Atomics | atomic_*_global and atomic_*_local (atomic across the gang only), memory_barrier | atomicAdd at device / subgroup scope |
| Math | full libm surface, SVML or ISPC implementations, --math-lib, half and sRGB8 conversions, pdep/pext | GLSL.std.450 |
All reductions act on the active lanes, which is the same contract as SPIR-V's non-uniform group operations. There is no texture sampling, no image type and no derivative function.
Control flow, memory model and restrictions
This is the part sparkles must reproduce, so it is given in full.
if. A uniform test emits an ordinary branch. A varying test goes through IfStmt::emitVaryingIf (src/stmt.cpp), which picks one of three shapes:
- Straight-line, both arms under the mask (
emitMaskedTrueAndFalse) when both arms are cheap (EstimateCostbelowPREDICATE_SAFE_IF_STATEMENT_COST) andSafeToRunWithMaskAllOff, so that an all-off arm has no observable effect. The comment gives the counter-example:if (index < count) array[index] = 0;must not be run unguarded. - Mixed (
emitMaskMixed): setmask = old & test, branch onany(mask)around the true arm, setmask = old & ~test, branch onany(mask)around the false arm, restore. - Coherent (
cif): first branch onall(fullMask); if all lanes are on,emitMaskAllOntestsall(test)→ true arm only with the mask known all-on,!any(test)→ false arm only, otherwise both arms masked. Setting the mask to the constantLLVMMaskAllOninside the specialised path is what lets later passes turn masked memory operations into plain ones.
Loops. for/while/do with a uniform test and no varying break/continue inside (lHasVaryingBreakOrContinue) are scalar loops. Otherwise the test is folded into the mask (SetInternalMaskAnd(mask, test)) and the loop runs while BranchIfMaskAny holds. break and continue under varying control flow do not jump: they OR the current mask into breakLanes/continueLanes and set the mask to all-off (FunctionEmitContext::Break/Continue, src/ctx.cpp). At the loop step, RestoreContinuedLanes re-enables continued lanes and ClearBreakLanes resets the per-iteration record. The coherent forms (cfor, cwhile, cdo, and a coherent break) add jumpIfAllLoopLanesAreDone, which compares returned | breaked | continued against blockEntryMask and jumps out early when every lane is finished. A loop whose test is varying is the case that costs most: the guide's example runs 1000 iterations with one lane on.
return. A varying return writes the return value with a masked store into the return slot ("this preserves the return values from other lanes that may have executed return statements previously", CurrentLanesReturned), records the lanes in returnedLanes, and continues execution with them off. Only when there is no varying control flow between the statement and the function entry does it emit a real ret.
foreach. foreach (j = 0 ... h, i = 0 ... w) maps a domain onto the gang. The emitter (ForeachStmt::EmitCode) treats the inner dimension specially: it runs from start to alignedEnd with the mask all on for that dimension (and with a separate code path depending on whether any outer dimension is in its ragged tail), then runs one masked iteration for the "ragged extra bits". foreach_tiled picks spans across dimensions (lGetSpans) for coherence over locality. break, return and nested foreach are illegal; continue is allowed.
Serialising constructs. foreach_active (i) runs the body once per active lane with only that lane on (continue legal, order undefined); foreach_unique (v in x) runs it once per distinct value with the matching lanes on; unmasked { } and the unmasked function qualifier restore all lanes, used to "change the axis of parallelism". goto is legal only where no varying control flow encloses it.
Memory model inside a gang. There are no barriers: "any side effect from one program instance is visible to other program instances in the gang after the next sequence point in the program" (guide, § Data Races Within a Gang). Two lanes storing to one address without an intervening sequence point is undefined; local atomics serialise it. A uniform variable assigned under varying control flow is not masked, so its value depends on whether any lane took the path. Loops with non-constant conditions are assumed to terminate; for (;;) and while (1) are not.
What the dynamic checks buy. The paper measures each optimisation by disabling it (geomean over the shipped workloads, Pharr and Mark, Table 1):
| Disabled optimisation | Performance when disabled |
|---|---|
| Uniform data and control flow | 0.45x |
| Uniform control flow | 0.91x |
| Gather/scatter improvements | 0.79x |
| Coherent control flow | 0.85x (aobench 0.33x) |
| "All on" mask improvements | 0.73x |
Compilation pipeline and targets
.ispc ─► preprocessor ─► parser (parse.yy) ─► AST + type check
─► FunctionEmitContext: vector LLVM IR with explicit masks and __pseudo_* memory ops
─► link builtins bitcode (target-*.ll, stdlib.ispc) for the chosen target/width
─► ISPC passes interleaved with LLVM's (opt.cpp): ImproveMemoryOps,
ReplacePseudoMemoryOps, IntrinsicsOpt, GatherCoalesce, ReplaceMaskedMemOps, …
─► LLVM CodeGen ─► .o / .s / .bc (Xe: SPIR-V via SPIRV-LLVM-Translator, or zebin)
+ C header (-h) describing exported functions and structsA target string is [ISA]-i[mask bits]x[gang size] without hardware masks (avx2-i32x8, sse4.2-i8x16) and [ISA]-x[gang size] with them (avx512skx-x16, xehpg-x16). The guide recommends "a mask size equal to the size of the most common data type in your programs". Several targets can be built into one object with a CPUID dispatcher (builtins/dispatch.c). ISPC carries LLVM patches in llvm_patches/ and builds against a pinned LLVM. For Xe, the default output is SPIR-V for the Intel VC backend: "The output from ispc for Xe targets is SPIR-V file by default" (docs/ispc_for_xe.rst), produced with LLVMSPIRVLib (src/module.cpp); there, emitXeHardwareMask() replaces software masking with the hardware execution mask through CM simdcf intrinsics. That SPIR-V is OpenCL-flavoured kernel SPIR-V, not Vulkan shader SPIR-V.
Host integration and CPU execution
CPU execution is ISPC's whole purpose, so the interesting question is the integration. An export function is an ordinary C symbol: "Functions that are intended to be called from C/C++ application code must have the export qualifier. This causes them to have regular C linkage" (guide, § Functions and Function Calls). Calls are direct, data is shared by pointer, and the application owns threading. extern "C" goes the other way (ISPC calling C, once per active lane via foreach_active or with uniform arguments). ispcrt adds a runtime that hides CPU vs Level Zero devices, and extern "SYCL" gives a SYCL-ABI-compatible entry (guide, § Interoperability Overview). There is also a JIT library interface (ISPCEngine).
Debugging is native: the program is a CPU binary, gdb steps it, and print prints per-lane values with inactive lanes shown "inside double parenthesis" (guide, § Output Functions).
What an LLVM-level whole-function vectorizer would need to reproduce
sparkles' D shaders reach LLVM as scalar per-invocation IR from LDC. An SPMD-on-SIMD CPU executor therefore cannot use ISPC's approach (masking in the front end); it has to recover what ISPC knows from types by analysis over the IR, as a whole-function vectorizer (WFV) does. Upstream LLVM has no such pass: its loop and SLP vectorizers do not widen a function body over an implicit lane dimension, although VFABIDemangler.cpp lets the loop vectorizer call vector variants that something else produced (llvm/lib/IR/VFABIDemangler.cpp). The research vectorizer RV (Saarland, LLVM-based, PLDI 2018 partial linearization) is the closest open implementation, and it maps onto ISPC piece by piece:
| ISPC mechanism | WFV equivalent over scalar IR | Prior art |
|---|---|---|
uniform / varying qualifiers | divergence analysis from the thread-ID builtins outward, plus a stride lattice (uniform, contiguous, strided, varying) per value | RV VectorShape (vectorShape.h); LLVM UniformityAnalysis |
| varying pointer → gather, uniform base → vector load | address shape analysis: strided(1) addresses become one vector load; others gather | RV shapes; ISPC ImproveMemoryOpsPass after the fact |
| execution mask state per block | block and edge predicates materialised as i1 vectors | RV maskExpander |
emitMaskMixed / emitMaskedTrueAndFalse | partial linearization: keep uniform branches, linearize divergent ones into a schedule with selects for φ-nodes | RV Linearizer (header, "Convertes divergent branches to data flow") |
breakLanes / continueLanes, loop until any | divergent-loop transform: a live mask φ, per-exit trackers that tunnel live-out values through "tracker PHI nodes", one uniform exit | RV guardedDivLoopTrans.h (header) |
returnedLanes + masked store to return slot | merge all returns into one block before linearizing | RV singleReturnTrans.h ("needed for linearization in case there is control divergence around returns") |
SafeToRunWithMaskAllOff, any(mask) guards | proof that a block has at least one live lane, else guard it | RV UndeadMaskAnalysis (header) |
cif / cfor: all-on fast path | BOSCC-style dynamic checks that branch to an all-on clone; a constant all-on mask in the clone | ISPC only; RV leaves it to the client |
| masked store vs load-blend-store | the same choice, keyed on whether the target memory is lane-private (alloca) or shared | ISPC ReplacePseudoMemoryOpsPass |
hidden __mask parameter, unmasked functions | vector function variants with a mask argument (VFABI M variants) and uniform-argument specialisation; inlining by default | VFABI, RV's former WFV mode |
| varying function pointer → once per unique target | a foreach_unique-style loop over distinct callees | ISPC |
| maximal convergence | a reconvergence point per divergent region equal to its immediate post-dominator; convergent operations (subgroup ops) placed by convergence tokens when present | LLVM ConvergenceAndUniformity.rst, ConvergentOperations.rst |
cross-lane library (broadcast, reduce_add, …) | llvm.spv.* / druntime subgroup intrinsics lowered to shuffles and reductions over the active lanes | RV rv_ballot, rv_shuffle, rv_compact (intrinsics.def) |
Three things neither ISPC nor RV provides, and a shader executor needs:
- Quads and helper lanes. Fragment derivatives (
dFdx, implicit-LOD sampling) are differences across a 2×2 quad. Lanes must be quad-aligned, helper lanes outside the primitive must execute (with stores suppressed), anddiscardmust behave likedemoteso neighbours still have values. The mask therefore splits into active-for-side-effects and alive-for-derivatives. - Workgroup barriers. A compute workgroup larger than one gang with
barrier()needs region splitting around the barrier (continuation-based synchronization, loop fission) or fibers. ISPC has no such construct; SYCL CPU implementations do (see SYCL). - Defined subgroup width. ISPC fixes the gang at compile time and lets results depend on it. Shaders that query
gl_SubgroupSizemust see the executor's width, and a conformance corpus must run at several widths to catch width-dependent code.
Structured input makes items 1–3 easier: if the D front end emits structured control flow (the recommendation in MLIR SPIR-V), the linearization is a walk over regions, as in ISPC, instead of a CFG analysis, as in RV.
Lessons for sparkles:shaders
- Adopt ISPC's semantics as the CPU executor's contract: one program counter per gang, an execution mask, maximal convergence, reconvergence at the immediate post-dominator. State it in the spec so the scalar reference simulator and the SIMD executor are tested against the same rule, and so subgroup results match Vulkan's
SPV_KHR_maximal_reconvergencebehaviour. - Adopt the all-on fast path as a first-class design point, not a later optimization. ISPC loses 27% (all-on) and 15% (coherent control flow) without it. For a fragment shader the common case is a fully covered quad set, so clone each divergent region with a constant all-on mask and branch to it on
all(mask). - Match the memory-op rules exactly: blend only for lane-private storage; masked stores for buffers and images; gather only when the address shape analysis says
varying. A test should compile a shader that writesbuf[i]underif (i < n)and prove the out-of-range lanes are never written (ISPC'sSafeToRunWithMaskAllOffcounter-example). - Keep variability out of the D vocabulary. ISPC needs
uniformbecause its front end does the masking; sparkles' front end emits scalar IR that the GPU consumes as is. Recover uniformity by analysis (shape lattice from the thread-ID andFragCoordbuiltins) and allow at most an optional@uniformhint that is checked, never trusted. - Make
Vector!(T, N)lane-agnostic and widen it SoA: a varyingvec4is four gang-wide registers, as ISPC'svarying float<3>is three. The project-wideVectortype should never be reinterpreted as a SIMD register by the CPU executor. - Test at several gang widths (4, 8, 16) and with an adversarial lane order. ISPC documents that cross-lane code can change with the gang size; a corpus run at one width hides that.
- Avoid ISPC's in-gang memory model (visibility at sequence points, unmasked
uniformstores). Shaders have none of this; the executor must model SPIR-V's invocation-private values and explicit scopes instead.
Strengths
- Fifteen years of production use (Embree, OSPRay, Unreal Engine's Chaos/Niagara via the
Intel ISPCplugin are commonly cited users; not verified against a pinned source). - A precise, documented execution model: program counter, mask, maximal convergence and in-gang visibility are all specified in the User's Guide.
- Predictable vectorization: every
varyingoperation is a vector operation; no heuristic can silently fall back to scalar code. - Zero-cost C interop: C linkage, shared pointers, generated headers, CPUID dispatch across ISAs in one object.
- Measured design: the paper quantifies each optimization's contribution.
Weaknesses
- No graphics: no stages, quads, derivatives, textures or interface model.
- Variability is in the user's face:
uniformplacement in pointer declarations is a known source of confusion, and misseduniformqualifiers cost up to 2.2x (0.45x). - No workgroup barrier and no shared memory between gangs; task parallelism is fork-join only.
- Results can depend on gang size by design;
foreachcannot nest;gotois restricted. - The masking lives in an AST-to-IR emitter tied to ISPC's language; none of it is a reusable LLVM pass that another front end could call.
- Tracks a patched, pinned LLVM.
Key design decisions and trade-offs
| Decision | Rationale | Trade-off |
|---|---|---|
| Mask management in the front end, vector IR from the AST | Vectorization cannot fail; the front end knows the structure of every branch and loop | Not reusable by other languages; every statement kind needs hand-written mask logic |
uniform/varying as type qualifiers | Uniform control flow and memory are known without analysis (0.45x without them) | Annotation burden; two pointer variabilities; overload ranks for variability conversion |
| Maximal convergence, single program counter | Cross-lane communication without barriers; deterministic reconvergence | Gang may not be split; results may depend on gang width |
cif/cfor coherence hints with all-on clones | Skip all-off arms; specialise all-on paths (0.85x and 0.73x without) | Code-size growth; a programmer-supplied hint |
| Load-blend-store for lane-private memory | Keeps values in registers, cheaper than native masked stores | Legal only for gang-owned storage; needs alias reasoning |
| Gang size and mask width fixed per target string | Lets the mask element match the dominant data type (i8x16, i32x8) | One binary per target; multi-target dispatch needed for portability |
| C ABI and C layout for exported functions | Shares data with the application without copies | Varying values cross only behind pointers; uniform short vectors are target-dependent |
| No barriers; visibility at sequence points | Simple, cheap in-gang communication | Data races are possible inside a gang; no workgroup model |
Sources
- ispc/ispc — GitHub repository
README.md— goals and design principlesdocs/ispc.rst— User's Guide: execution model, types, control flow, stdlib, interopdocs/perfguide.rst— Performance Guidedocs/ispc_for_xe.rst— Xe targets, SPIR-V outputdocs/ReleaseNotes.txt—v1.32.0release notesdocs/design/TargetRedesign.md— stdlib and builtins structuresrc/ctx.h,src/ctx.cpp—FunctionEmitContext, mask state,Break/Continue/CurrentLanesReturnedsrc/stmt.cpp—IfStmt::emitVaryingIf,ForStmt,ForeachStmtsrc/func.cpp,src/type.cpp— hidden__maskparametersrc/opt.cpp,ImproveMemoryOps.h,ReplacePseudoMemoryOps.cpp,GatherCoalescePass.h,IntrinsicsOptPass.hbuiltins/target-avx2-i32x8.ll,stdlib/include/core.isph,stdlib/stdlib.ispcCMakeLists.txt,src/target_enums.h,src/module.cpp- M. Pharr and W. R. Mark, ispc: A SPMD Compiler for High-Performance CPU Programming, InPar 2012
- M. Pharr, The Story of ISPC: Origins (Part 1), 2018-04-18
- RV, the Region Vectorizer:
README.md,vectorShape.h,Linearizer.h,guardedDivLoopTrans.h,UndeadMaskAnalysis.h,singleReturnTrans.h,intrinsics.def - LLVM:
ConvergenceAndUniformity.rst,ConvergentOperations.rst,UniformityAnalysis.cpp,VFABIDemangler.cpp - Related: SYCL · CUDA and HIP · VCC and Shady · MLIR SPIR-V · Concepts · Comparison · Index · sparkles:shaders spec