Documentation

Sparkle.Backend.CSim

Build a name-to-type map from a module's ports and wires

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    Look up bit-width for a name in the type map

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Sanitize a name to be a valid C identifier

      Equations
      Instances For

        Convert HWType to a C scalar type string. For wide integers (> 64 bits) and arrays we return a base scalar type; the surrounding declaration adds the array dimensions (see emitFieldDecl).

        Equations
        Instances For

          Total array length suffix for a HWType, e.g. [3] for a 96-bit wide type, [8][3] for array 8 (bitVector 96), or empty for a single ≤ 64-bit scalar.

          Emit a C field/local declaration like uint32_t foo[3] — the type goes on the left, the array dimensions on the right of the name (C array syntax).

          Equations
          Instances For

            For situations where a parameter or declaration needs just the type and dimensions but no identifier, used by casts.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              True for widths that are not native C integer widths.

              Equations
              Instances For

                Emit a bit mask expression for the given width

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  Wrap an expression with a mask if the width requires it

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Check if an IR expression produces a result that is already correctly masked. Invariant: every assignment applies a mask, so .ref reads yield masked values.

                    Convert Operator to C operator symbol

                    Equations
                    Instances For

                      Get signed cast type for a given width

                      Equations
                      Instances For

                        Best-effort width inference for an expression

                        Convert IR expression to C expression.

                        Wide (> 64 bit) values are represented as uint32_t[N] arrays in declarations. In expression contexts an "rvalue array" doesn't really exist in C, so the only ways we produce wide expressions are:

                        • .ref to a wide variable — emits the bare identifier, which C decays to a pointer in most contexts; the wide-assign code below indexes it slot-by-slot rather than copying.
                        • .const with width > 64 — emits a C99 compound literal (uint32_t[N]){w0, w1, …}, which is a valid rvalue only at statement scope.
                        • .concat over wide totals — same compound-literal shape.

                        All wide assignments (see emitStmt) must therefore either: (a) be element-wise slot writes (lhs[j] = …), or (b) wrap the RHS in memcpy(lhs, RHS, sizeof(lhs)) when RHS is a compound literal — lhs = RHS on a C array is rejected by the compiler.

                        Parts of a C struct + helper-set generated from a single statement

                        Instances For
                          Equations
                          Instances For
                            Equations
                            • One or more equations did not get rendered due to their size.
                            Equations
                            Instances For
                              def Sparkle.Backend.CSim.emitInitScalar (initValue : Int) (width : Nat) :

                              Emit a C reset value for a register init.

                              For ≤ 64-bit widths returns a scalar cast.

                              For wide (> 64-bit) widths returns a list of slot assignments like lhs[0] = 0x…u; lhs[1] = 0x…u; since C does not let you assign a compound literal to an array-typed lvalue. The caller (register reset path) threads these through resetBody.

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                def Sparkle.Backend.CSim.emitInitWideLines (name : String) (initValue : Int) (width : Nat) :

                                Per-slot reset lines for a wide register name.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For
                                  def Sparkle.Backend.CSim.emitMuxAsIfElse (typeMap : List (String × IR.Type.HWType)) (lhsName : String) (width : Nat) (rhs : IR.AST.Expr) (minArms : Nat := 4) :

                                  Emit a MUX chain as if-else block for better branch prediction.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Split a statement into declaration/eval/tick/reset parts

                                    Collect all wire name references from an IR expression

                                    Collect all wire names referenced in tick() bodies.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      Emit a complete C struct + static helpers for a module. Returns the full C source fragment (no includes; callers add those at design level).

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        Convert a full design to C simulation code (no JIT wrapper)

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          Convert a single module to C simulation code with includes

                                          Equations
                                          Instances For

                                            JIT FFI wrapper #

                                            Each .so exports exactly ONE symbol — jit_vtable — which returns a pointer to a JitVTable containing function pointers for every operation. Everything else is static, so dlsym cannot reach it. This sidesteps the collision-on- shared-symbol problem from Issue #70: two .so files with the same internal jit_eval cannot conflict because neither publishes that name.

                                            Generate the self-contained JIT wrapper .c for a Design.

                                            The output is a single translation unit containing:

                                            • Per-module struct + static helpers from toCDesign.
                                            • The JitVTable struct definition.
                                            • Static trampolines that adapt void* ctx to the top-module's typed struct Top* and call the appropriate sparkle_<top>_* helper.
                                            • The JitVTable instance pre-populated with those trampolines.
                                            • The single externally-visible jit_vtable() accessor function.

                                            The top-level .so therefore exports jit_vtable and nothing else (other than the unavoidable glibc init/fini stubs).

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For