Equations
Instances For
Equations
Instances For
Width of an expression under a width environment (the proof-facing
twin of the backends' inferExprWidth; binary ops take the MAX of
their operands, matching hardware and the fixed CSim rule).
Equations
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.const value w) = w
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.ref n) = we n
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.mux [head, t, head_1]) = Sparkle.IR.Semantics.widthOf we t
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.mux args) = 0
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.eq args) = 1
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.lt_u args) = 1
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.lt_s args) = 1
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.le_u args) = 1
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.le_s args) = 1
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.gt_u args) = 1
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.gt_s args) = 1
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.ge_u args) = 1
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.ge_s args) = 1
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.not [a]) = Sparkle.IR.Semantics.widthOf we a
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.not args) = 0
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.shr [a, head]) = Sparkle.IR.Semantics.widthOf we a
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op Sparkle.IR.AST.Operator.shr args) = 0
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op operator [a, b]) = max (Sparkle.IR.Semantics.widthOf we a) (Sparkle.IR.Semantics.widthOf we b)
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op operator [a]) = Sparkle.IR.Semantics.widthOf we a
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.op operator args) = 0
- Sparkle.IR.Semantics.widthOf we (Sparkle.IR.AST.Expr.concat args) = Sparkle.IR.Semantics.widthOf.go we args
- Sparkle.IR.Semantics.widthOf we (expr.slice hi lo) = hi - lo + 1
- Sparkle.IR.Semantics.widthOf we (expr.sliceDim hi lo) = 0
- Sparkle.IR.Semantics.widthOf we (array.index idx) = 0
Instances For
Equations
- Sparkle.IR.Semantics.widthOf.go we [] = 0
- Sparkle.IR.Semantics.widthOf.go we (a :: rest) = Sparkle.IR.Semantics.widthOf we a + Sparkle.IR.Semantics.widthOf.go we rest
Instances For
Evaluate one operator over already-evaluated, already-masked operand
values. w is the result's context width.
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.and args [a, b] w = some (Sparkle.IR.Semantics.mask w (a &&& b))
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.or args [a, b] w = some (Sparkle.IR.Semantics.mask w (a ||| b))
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.xor args [a, b] w = some (Sparkle.IR.Semantics.mask w (a ^^^ b))
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.not [x] [a] w = some (Sparkle.IR.Semantics.mask (Sparkle.IR.Semantics.widthOf we x) (a ^^^ 2 ^ Sparkle.IR.Semantics.widthOf we x - 1))
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.add args [a, b] w = some (Sparkle.IR.Semantics.mask w (a + b))
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.sub args [a, b] w = some (Sparkle.IR.Semantics.mask w (a + (2 ^ w - Sparkle.IR.Semantics.mask w b)))
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.mul args [a, b] w = some (Sparkle.IR.Semantics.mask w (a * b))
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.eq args [a, b] w = some (if a = b then 1 else 0)
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.lt_u args [a, b] w = some (if a < b then 1 else 0)
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.le_u args [a, b] w = some (if a ≤ b then 1 else 0)
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.gt_u args [a, b] w = some (if b < a then 1 else 0)
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.ge_u args [a, b] w = some (if b ≤ a then 1 else 0)
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.shl args [a, b] w = some (Sparkle.IR.Semantics.mask w (a <<< b))
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.shr args [a, b] w = some (a >>> b)
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.mux args [c, t, f] w = some (if c ≠ 0 then t else f)
- Sparkle.IR.Semantics.evalOp we Sparkle.IR.AST.Operator.neg args [a] w = some (Sparkle.IR.Semantics.mask w (2 ^ w - Sparkle.IR.Semantics.mask w a))
- Sparkle.IR.Semantics.evalOp we operator args vals w = none
Instances For
Total evaluator for the scalar fragment. none = outside the
fragment (symbolic widths, memory reads) or malformed arity.
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.evalExpr we env (Sparkle.IR.AST.Expr.const v w) = some (Sparkle.IR.Semantics.mask w ((v % ↑(2 ^ w) + ↑(2 ^ w)) % ↑(2 ^ w)).toNat)
- Sparkle.IR.Semantics.evalExpr we env (Sparkle.IR.AST.Expr.ref n) = some (env n)
- Sparkle.IR.Semantics.evalExpr we env (Sparkle.IR.AST.Expr.concat args) = do let vals ← Sparkle.IR.Semantics.evalList we env args some (Sparkle.IR.Semantics.evalExpr.go we args vals)
- Sparkle.IR.Semantics.evalExpr we env (e.slice hi lo) = do let v ← Sparkle.IR.Semantics.evalExpr we env e some (Sparkle.IR.Semantics.mask (hi - lo + 1) (v >>> lo))
- Sparkle.IR.Semantics.evalExpr we env (expr.sliceDim hi lo) = none
- Sparkle.IR.Semantics.evalExpr we env (array.index idx) = none
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.evalExpr.go we a✝¹ a✝ = 0
Instances For
Equations
- Sparkle.IR.Semantics.evalList we env [] = some []
- Sparkle.IR.Semantics.evalList we env (a :: rest) = do let v ← Sparkle.IR.Semantics.evalExpr we env a let vs ← Sparkle.IR.Semantics.evalList we env rest some (v :: vs)
Instances For
Memory state: array contents by memory name.
Equations
- Sparkle.IR.Semantics.MEnv = (String → Nat → Nat)
Instances For
Combinational read ports: extend the env with rd ↦ mem[addr],
in port order (mirrors the emitted assign per port).
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.comboReads we mems name aw dw [] x✝ = some x✝
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.evalAssigns we mems [] x✝ = some x✝
- Sparkle.IR.Semantics.evalAssigns we mems (Sparkle.IR.AST.Stmt.register output clock reset input initValue :: rest) x✝ = Sparkle.IR.Semantics.evalAssigns we mems rest x✝
- Sparkle.IR.Semantics.evalAssigns we mems (Sparkle.IR.AST.Stmt.inst moduleName instName connections :: rest) x✝ = Sparkle.IR.Semantics.evalAssigns we mems rest x✝
Instances For
Synchronous read ports: latch mem[addr] (read-old — mems is the
pre-write state) into the register-update list.
Equations
Instances For
Next values for every register (and sync-read latch), under the post-elaboration env.
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.regNexts we mems [] x✝ = some []
- Sparkle.IR.Semantics.regNexts we mems (Sparkle.IR.AST.Stmt.assign lhs rhs :: rest) x✝ = Sparkle.IR.Semantics.regNexts we mems rest x✝
- Sparkle.IR.Semantics.regNexts we mems (Sparkle.IR.AST.Stmt.inst moduleName instName connections :: rest) x✝ = Sparkle.IR.Semantics.regNexts we mems rest x✝
Instances For
Extract reads of ONE array (.index (.ref arr) idx) from an IR
expression, replacing each with a placeholder ref (semantics-side
mirror of the lowering's extractArrayReads). Nested reads (an
index whose address itself reads the array) stay in place and make
the payload evaluation fail — outside the v1 model.
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.extractReads arr (Sparkle.IR.AST.Expr.op o args) x✝ = match Sparkle.IR.Semantics.extractReadsList arr args x✝ with | (args', l, k') => (Sparkle.IR.AST.Expr.op o args', l, k')
- Sparkle.IR.Semantics.extractReads arr (x_2.slice hi lo) x✝ = match Sparkle.IR.Semantics.extractReads arr x_2 x✝ with | (x', l, k') => (x'.slice hi lo, l, k')
- Sparkle.IR.Semantics.extractReads arr x✝¹ x✝ = (x✝¹, [], x✝)
Instances For
Counter monotonicity: extraction never decreases the counter.
Placeholder-name characterization: every read the extractor
collects is named __memread_arr_j with j inside the counter
window — the fact that lets a payload's splice facts and bounds be
established for names the extractor invented.
Evaluate a memory-port payload: reads of the memory's OWN array are resolved against the PRE-cycle memory state (nonblocking RHS evaluate before any write lands), then the payload evaluates as an ordinary expression with the read values spliced in as fresh names. Payloads without such reads evaluate exactly as before.
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.spliceReads we mems env arr aw dw [] x✝ = some x✝
Instances For
The width environment extended with a payload's read placeholders,
each at the memory's data width. extractReads invents these
names, so their widths are the extractor's to declare: a
placeholder holds a dw-bit word by construction. Leaving them to
we's default (0 under weOf) made the reference semantics mask an
arithmetic RMW like Mem[a] + Mem[a] by 2^0 — the sum of two 5s
in a 10-bit memory evaluated to 0 where Verilog computes 10.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extending for zero placeholders changes nothing.
Write ports of one memory, in port order: an enabled port stores
mask dw data at mask aw addr; a later port overwrites an earlier
one on the same address (the Verilog always_ff sequential-if
rule).
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.memWritePorts we mems0 env name aw dw [] x✝ = some x✝
Instances For
Memory state after this cycle's writes, evaluated under the post-elaboration env.
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.memNexts we [] x✝¹ x✝ = some x✝¹
- Sparkle.IR.Semantics.memNexts we (Sparkle.IR.AST.Stmt.assign lhs rhs :: rest) x✝¹ x✝ = Sparkle.IR.Semantics.memNexts we rest x✝¹ x✝
- Sparkle.IR.Semantics.memNexts we (Sparkle.IR.AST.Stmt.register output clock reset input initValue :: rest) x✝¹ x✝ = Sparkle.IR.Semantics.memNexts we rest x✝¹ x✝
- Sparkle.IR.Semantics.memNexts we (Sparkle.IR.AST.Stmt.inst moduleName instName connections :: rest) x✝¹ x✝ = Sparkle.IR.Semantics.memNexts we rest x✝¹ x✝
Instances For
One cycle: elaborate, then step the registers. Returns the final combinational environment (outputs are read from it) and the register updates.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Width-bounded environment: every name's value fits its width. Hardware invariant — inputs are port-width bounded and every write the semantics performs is masked. Recovers the env-dependent fragment side conditions (signed-compare value bounds, exact-elide range) for module-level use.
Equations
- Sparkle.IR.Semantics.Bounded we env = ∀ (n : String), env n < 2 ^ we n
Instances For
Apply a register-update list to a state.
Equations
Instances For
Run k cycles. seed t st builds cycle t's starting environment
from the register state (module plumbing — typically inputs overlaid
on registers — is the CALLER's, so the trace theorem quantifies over
every seeding discipline). Returns the per-cycle post-elaboration
environments, oldest first — the observable trace. (The cycle
index passed to seed counts DOWN from k-1; a caller wanting
wall-clock indices maps t ↦ k-1-t.)
Equations
- One or more equations did not get rendered due to their size.
- Sparkle.IR.Semantics.runModule we body seed 0 x✝¹ x✝ = some []