113 definitions in 14 files, 0 with an encoding diagram. src/isa/spirv
| File | Definitions | Other | What |
|---|---|---|---|
| package.lisp | 0 | 0 | the ISA.SPIRV package: host target SPIR-V: encodings, semantics, module builder. |
| grammar.lisp | 0 | 7 | the SPIR-V grammar as compile-time tables. |
| gen/kinds.lisp | 0 | 0 | SPIR-V operand kinds and their enumerants (generated, do not edit). |
| gen/insts.lisp | 0 | 0 | every SPIR-V instruction: opcode, operands, requirements (generated, do not edit). |
| gen/glsl450.lisp | 0 | 0 | the GLSL.std.450 extended instruction set (generated, do not edit). |
| sem.lisp | 0 | 12 | DEFSPV: SPIR-V instruction semantics in the core vocabulary. |
| int.lisp | 46 | 0 | semantics of SPIR-V's integer, bit, logical and select operations. |
| flt.lisp | 26 | 0 | semantics of SPIR-V's floating-point arithmetic, comparisons, conversions. |
| comp.lisp | 8 | 0 | semantics of SPIR-V's composite and vector operations. |
| ext450.lisp | 33 | 0 | semantics of the GLSL.std.450 extended instructions used for selection. |
| emit.lisp | 0 | 10 | building SPIR-V modules at run time: sections, ids, instruction words. |
| shade.lisp | 0 | 58 | the abstract programmable pipeline (src/core/shade.lisp) spelled in SPIR-V, at run time. |
| cost.lisp | 0 | 11 | what each SPIR-V operation costs under the selected GPU model. |
| cost/gt1030.lisp | 0 | 0 | SPIR-V cost model gt1030, NVIDIA GeForce GT 1030 (generated, do not edit). |
Package ISA.SPIRV. SPIR-V is the GPU host's shader ISA (XSPE_GPU=vk):
SPU code becomes SPIR-V compute work. SPIR-V is never emulated here. Its
description lets ctil find, for each SPU operation, the cheapest SPIR-V
operations with the same meaning (docs/isel.md). The
same grammar also drives the run-time encoder that writes modules.
| File | Role |
|---|---|
gen/kinds.lisp, gen/insts.lisp, gen/glsl450.lisp | Generated from SPIRV-Headers by tools/spvgen: every operand kind and enumerant, every instruction, GLSL.std.450 |
grammar.lisp | Compile-time tables for the generated forms, plus spv-opcode and spv-enum |
sem.lisp | defspv, the value model, instantiation, and the forms for open behaviour |
int.lisp | Integer arithmetic, bits, comparisons, bools, select, integer conversions |
flt.lisp | Float arithmetic, comparisons and conversions, under Vulkan's float environment |
comp.lisp | Composite and vector operations, OpBitcast |
ext450.lisp | GLSL.std.450: FindUMsb, SAbs, FClamp, Fma, rounding, ... |
emit.lisp | The run-time module builder and encoder |
cost/gt1030.lisp | The GT 1030 cost model, transliterated from ucas's prelude by tools/costgen; the build loads XSPE_COST_GPU (default gt1030) |
cost.lisp | spv-op-cost: ucas's class of each operation (from its spirv.c) and price (docs/cost.md) |
(spv-kind "StorageClass" :value-enum
("UniformConstant" 0 :version "1.0") ...)
(spv-inst "OpIAdd" 128 "Arithmetic"
(("IdResultType") ("IdResult") ("IdRef" "Operand 1") ("IdRef" "Operand 2")) :version "1.0")
(spv-ext-inst "GLSL.std.450" "FindUMsb" 75 (("IdRef" "Value")))
Each call registers its entry at compile time and expands to nothing at
run time. Names are the grammar's own and are looked up without case:
(spv-opcode OpIAdd) gives 128, (spv-enum StorageClass StorageBuffer)
gives 12, (spv-enum ImageOperands Bias Lod) gives 3, and
(spv-enum Dim "1D") gives 0. Aliases are accepted. Do not edit gen/.
Instead, configure with -DXSPE_REGEN=ON and build spirv_gen. The
spirv_gen_fresh test checks that the committed files match a fresh run.
Every SPIR-V value is its bit pattern, stored as an integer:
(unsigned-byte w).
Floats are IEEE bits.u1, with 1 meaning true.v4i32 is therefore a v128 whose (lane 32 v i) is component i, and
componentwise operations on it are core vmaps.Signedness belongs to the operation, never to the type. So (:int 32)
covers both OpTypeInt 32 0 and OpTypeInt 32 1.
Type designators: (:int w), (:float w), (:bool), (:vec n T),
(:struct T...) and (:array n T). Shorthands are i32, u8, f64,
bool, v4i32, v2f64 and v3bool.
defspv(defspv OpIAdd (a b)
(:int (w) (wrap w (+ a b))))
(defspv OpShiftLeftLogical (base shift)
"The result is undefined if Shift >= the bit width of Base's components."
(:int (w) (if (>= shift w) (spv-undef w) (wrap w (ash base shift)))))
(defspv OpIAddCarry (a b) ; struct result: one form per member
(:int (w) (spv-members (wrap w (+ a b)) (carry-out w a b))))
(defspv OpFAdd (a b) (:float (w) (fop w (a b) (fadd (ffmt w) :rne a b))))
(defspv (glsl FindUMsb) (value)
(:int (w) :require (= w 32) (if (= value 0) (ones w) (- (1- w) (clz w value)))))
* operand is written &rest. defspv checks them
against the grammar.(:int ...), (:float ...) and (:bool ...)
are chosen by the first operand's component class. Each one is a template
over its parameters (w rw n): the operand component width, the result
component width and the component count. The body sees one component of
each operand. A scalar operand next to vector ones (the Offset and Count
of OpBitField*) is the same for every lane. :require states which
types are valid.(:expand (rt ts lits) body...) is compile-time code. Given the
result type, the operand types and the literal operands, it returns the
form. Composites, OpSelect and OpBitcast use it.fadd,
fround-int, flt, fnan-p ...); (ffmt w) in a template is the format
keyword of width w (:f32). (fop w (vars) expr options...) is a float
operation under the float environment (see below). Its options are
:result :bool/:int (a 1/0 or an integer instead of float bits),
:rw, :ulp tenths, :inexact and :guard (test result).
(fnonfinite w x) is an infinity or NaN made on purpose (undefined in the
:fast environment).Instantiation gives the canonical tree that the matcher sees:
(spv-sem-lambda 'OpIAdd 'v4i32)
;; => (lambda (a b) (declare ...) (vmap 32 (lambda (a b) (wrap 32 (+ a b))) a b))
(spv-sem-lambda 'OpFAdd 'f32 :fenv '(:denorm :preserve :nan :preserve))
;; => (lambda (a b) (declare ...) (fadd :f32 :rne a b))
(spv-eval (OpVectorShuffle v4i32 :ops (v4i32 v2i32) :lits (5 0 4 3)) x y)
(define-spv-fn iadd-v4 (OpIAdd v4i32))
:ops gives the value operand types (the default is the result type for
each), :lits the literal operands, and :fenv the float environment.
These stay as calls in the tree. The reference evaluator (ECL, ctil
--eval) picks one allowed outcome and records it in *spv-undefined*.
| Form | Meaning | Reference |
|---|---|---|
(spv-undef w) | any w-bit value ("the result is undefined") | 0, sets 1 |
(spv-ub) | undefined behaviour ("behavior is undefined") | 0, sets 2 |
(spv-either x y) | either value | x |
(spv-ulp w tenths x) | within tenths/10 ULP of x | x |
(spv-inexact w x) | precision inherited from other operations | x |
:fenv is (:denorm D :nan N). Rounding is always to nearest even.
:denorm :any is the Vulkan default: any denormal input or result may
be flushed. :flush corresponds to DenormFlushToZero and :preserve
to DenormPreserve.:nan :fast is the Vulkan default: an operation on or producing an
infinity or NaN gives an undefined value, and the sign of zero is
either. :preserve corresponds to SignedZeroInfNanPreserve.Rounding is to nearest even (:rne). Exact operations (the primitive
itself) are OpFAdd, OpFSub, OpFMul, comparisons, conversions,
FAbs, FMin/FMax/FClamp and NMin/NMax/NClamp (GLSL's
definitions with the primitive's <, not IEEE minimum/maximum), Floor,
Ceil, Trunc, RoundEven (fround-int), and Round (either tie rule).
OpFDiv is within 2.5 ULP (x / 0 exact), InverseSqrt within 2 ULP:
spv-ulp around the primitive formula. OpFRem, OpFMod, Fma
(fused or not), FMix, Fract and Sqrt are inherited, and the
transcendental functions (Exp2, Log2, Sin, Cos, Pow) bounded by
[VKSPEC]: spv-inexact around the formula. A NaN result is the
primitives' default NaN (Vulkan leaves the payload open). The
transcendentals use fexp2 flog2 fsin fcos fpow, local helpers in
src/core/shade.lisp until float.lisp has IEEE 754-2019's recommended
operations.
emit.lisp(let ((m (make-spv-module)) (out (make-spv-words)))
(spv-op m OpCapability 'Shader)
(let* ((u32 (spv-op m OpTypeInt :new 32 0))
(var (spv-op-in m :types OpVariable ptr :new 'StorageBuffer)))
(spv-op m OpDecorate var 'Binding 0) ; an enumerant and its parameter
(spv-op m OpEntryPoint 'GLCompute main "main" gid)) ; a literal string
(spv-finish m out #x00010300)) ; -> the word count
spv-op encodes the instruction at expansion time from the grammar and
checks the number and kind of its operands. 'Name is an enumerant, and
its parameters follow it. A literal string is turned into words.
(:u64 x) writes two words. :new allocates the result id and
spv-op returns it.
Each instruction goes to its section of the module layout: capabilities,
extensions, imports, memory model, entry points, execution modes, debug,
annotations, types/constants/globals, and code. Each section is a
fixed-size (simple-array u32 (N)), so instructions can be written in any
order. spv-op-in names the section explicitly. You must use it for
OpVariable and OpUndef. spv-open / spv-put / spv-close write an
instruction whose length is only known at run time. A full section sets
spvm-overflow, and spv-finish then returns 0.
tests/isa/spirv)| Test | What |
|---|---|
spirv_grammar | opcodes, enumerants, aliases, operands |
spirv_sem | sample values and canonical trees |
spirv_semall | every componentwise semantics on many types and environments, with vector lanes checked against scalar instances |
spirv_module | a compute module's words |
spirv_module_val | the module ctil writes, compared byte for byte with tests/golden/spirv_module_val.spv (and ECL's under XSPE_ECL_ORACLE), then checked with spirv-val --target-env vulkan1.1 |
spirv_gen_fresh | gen/ against a fresh spvgen run (-DXSPE_REGEN=ON) |
RoundingModeRTZ.OpDot, matrix operations, OpQuantizeToF16, OpSatConvert*, the
Kernel-only OpIsFinite/OpOrdered/..., packing, Step, and the other
transcendentals.Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.