Documentation

Sparkle.IR.Semantics

@[reducible, inline]
Equations
Instances For
    @[reducible, inline]
    Equations
    Instances For

      Truncate to w bits.

      Equations
      Instances For

        Two's-complement interpretation of a masked value, for signed ops.

        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
          Instances For
            def Sparkle.IR.Semantics.evalOp (we : WEnv) (operator : AST.Operator) (args : List AST.Expr) (vals : List Nat) (w : Nat) :

            Evaluate one operator over already-evaluated, already-masked operand values. w is the result's context width.

            Equations
            Instances For

              Total evaluator for the scalar fragment. none = outside the fragment (symbolic widths, memory reads) or malformed arity.

              Equations
              Instances For
                Equations
                Instances For
                  Equations
                  Instances For
                    @[reducible, inline]

                    Memory state: array contents by memory name.

                    Equations
                    Instances For
                      def Sparkle.IR.Semantics.comboReads (we : WEnv) (mems : MEnv) (name : String) (aw dw : Nat) :

                      Combinational read ports: extend the env with rd ↦ mem[addr], in port order (mirrors the emitted assign per port).

                      Equations
                      Instances For
                        Equations
                        Instances For

                          Encode a register's reset value the way evalExpr encodes constants.

                          Equations
                          Instances For
                            def Sparkle.IR.Semantics.syncReadLatches (we : WEnv) (mems : MEnv) (name : String) (aw dw : Nat) :

                            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
                              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
                                Instances For
                                  Equations
                                  Instances For
                                    theorem Sparkle.IR.Semantics.extractReads_mono {arr : String} (e : AST.Expr) (k0 : Nat) :
                                    k0 ≤ (extractReads arr e k0).snd.snd

                                    Counter monotonicity: extraction never decreases the counter.

                                    theorem Sparkle.IR.Semantics.extractReads_names {arr : String} (e : AST.Expr) (k0 : Nat) (p : String × AST.Expr) :
                                    p ∈ (extractReads arr e k0).snd.fst → ∃ (j : Nat), k0 ≤ j ∧ j < (extractReads arr e k0).snd.snd ∧ p.fst = toString "__memread_" ++ toString arr ++ toString "_" ++ toString j

                                    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.

                                    def Sparkle.IR.Semantics.spliceReads (we : WEnv) (mems : MEnv) (env : Env) (arr : String) (aw dw : Nat) :

                                    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
                                    Instances For
                                      def Sparkle.IR.Semantics.weWithReads (we : WEnv) (arr : String) (dw n : Nat) :

                                      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
                                        theorem Sparkle.IR.Semantics.weWithReads_zero (we : WEnv) (arr : String) (dw : Nat) :
                                        weWithReads we arr dw 0 = we

                                        Extending for zero placeholders changes nothing.

                                        def Sparkle.IR.Semantics.evalPayload (we : WEnv) (mems : MEnv) (env : Env) (arr : String) (aw dw : Nat) (e : AST.Expr) :
                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          def Sparkle.IR.Semantics.memWritePorts (we : WEnv) (mems0 : MEnv) (env : Env) (name : String) (aw dw : Nat) :

                                          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
                                          Instances For

                                            Memory state after this cycle's writes, evaluated under the post-elaboration env.

                                            Equations
                                            Instances For
                                              def Sparkle.IR.Semantics.stepModule (we : WEnv) (body : List AST.Stmt) (env0 : Env) (mems : MEnv := fun (x : String) (x_1 : Nat) => 0) :

                                              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
                                                Instances For

                                                  Apply a register-update list to a state.

                                                  Equations
                                                  Instances For
                                                    def Sparkle.IR.Semantics.runModule (we : WEnv) (body : List AST.Stmt) (seed : Nat → (String → Nat) → Env) :
                                                    Nat → (String → Nat) → MEnv → Option (List Env)

                                                    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
                                                    Instances For