Repository navigation
Monomorphized CPU and shared pretty-printing on stdlib bits (stacked on #2) - #3
Conversation
Use rocq-stdlib's `bits n` (`Zmod (2^n)`, stdlib >= 9.1) as the carrier of `type.Bits` instead of std++'s `bv n`, so that quartz shares one bit-vector type with the other mit-plv projects. This removes the rocq-stdpp-bitvector dependency and, since `vec` was the only remaining use, std++ altogether. Widths are `Z` again, as they were before the std++ port: stdlib's `bits` is indexed by `Z`, and `type.wf` already carries the `0 <= sz` side condition that the stdlib range lemmas need. The operations map directly: `Zmod.add/sub/opp/and/or/xor/not`, shifts `Zmod.slu/sru/srs` by the unsigned value of the amount, `Zmod.eqb` for `IsZero`/`EqBits`, `bits.of_Z` of the signed/unsigned value for `Resize`, and `Zmod.firstn l (Zmod.skipn s v)` for `Slice s l`. `App` is `Zmod.app` again, with result type `Bits (n + m)` and the first operand in the low bits. The std++ port had made `App` take an explicit result width and put the first operand in the high bits, which contradicted the C++ and SystemVerilog printers (both emit the first operand low); the printers were right, so the Rocq semantics returns to them and `Concat` in Processor.v resizes `App lo hi`. `type.pack` is built from bare `Zmod.app` in the same order. The boolean helpers (`embed_bool`, `nonzero`, `bool_cases`, ...) live in a module named `Zmod` in domain.v, so they read as `Zmod.embed_bool` next to the stdlib operations. That module only adds names: it defines nothing that stdlib's `Zmod` modules define, so `Zmod.add`, `Zmod.eqb`, `Zmod.of_Z`, ... still resolve to the stdlib constants without any `ZmodDef.` prefix. The case analyses come from `Zmod.in_elements`. `unsigned_resize_id`, which restated `Zmod.of_Z_unsigned`, is gone. The tests use `bits.of_Z` and `Zmod.zero` for constants, keep the harness directive comment on their first line, and gain the bit-semantics tests from the andreser/monomorphize-Zmod branch. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJbiRBkJtM7x6PvYV6hmEm
Every test is checked on all three evaluators (the Rocq interpreter, slang on the SystemVerilog output, and the compiled C++ output), so a test whose expected value differs between two candidate semantics pins down which one the language has. Add tests for the operations where the stdlib port and the andreser/monomorphize-Zmod branch differ, with operands chosen so that the other reading would produce another value: - test_app_asym: `App` of a 2-bit 1 and a 3-bit 5 is 5'h15, so the first operand is in the low bits and the width is n + m (the other operand order gives 5'hd). - test_app_resize: the same `App` under an `UnsignedResize` to 8 bits is 8'h15, the shape `Concat` in Processor.v uses. - test_slice_mid: `Slice 3 4` of 8'hb5 is 4'h6, so the slice starts at bit s and takes l bits (swapping firstn and skipn gives 0). - test_slice_overrun: `Slice 5 8` of 8'hb5 is 8'h5, so a slice that reaches past the operand zero-extends. - test_xor: 4'hc xor 4'ha is 4'h6 (and gives 4'h8, or gives 4'he); the branch has no `Xor`. test_all_ops shifted by the full 32-bit operand 0xbad1dea5. The interpreter computes `Zmod.slu` through `Z.shiftl`, so producing its expected output meant building a three-billion-bit integer, and the test's `.out` rule ran out of memory (on main as well). Shift by the 16-bit resized value 0xbeef instead, as the branch's version of this test does: the amount is still larger than the width, so the test keeps checking that oversized shifts saturate to zero and to the sign bit on both backends. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJbiRBkJtM7x6PvYV6hmEm
… casts TAG=agy CONV=61f80615-7bc0-4a21-b389-dbf384e77dbe (cherry picked from commit f0a59e7)
(cherry picked from commit c912c27)
(cherry picked from commit de65160)
| Fixpoint ident (s : string) : string := | ||
| match s with | ||
| | EmptyString => EmptyString | ||
| | String c s => String (if isalpha c || isdigit c || (c =? "_"%char)%Z then c else "_"%char) (ident s) |
There was a problem hiding this comment.
No! this is not injective. It is fine to reject bad identifiers like already done in other cases, but collapsing two different identifiers into one is no good.
There was a problem hiding this comment.
Will do: the printers will reject such names like the other cases, and the offending binders (dp', valid', ...) get renamed at the source so the CPU tests pass. Fix coming on this branch.
Written by Claude Fable 5.1 via Claude Code (session https://claude.ai/code/session_01YJbiRBkJtM7x6PvYV6hmEm).
There was a problem hiding this comment.
Replaced in 0b5b9e0: the printers now pass let/bind names through the same valid_ident check that struct and field names get, so an invalid name makes both backends reject the program (new test_bad_binder.v, cpp:reject sv:reject). The four primed binders in Processor.v are renamed (dp_next, valid_upd, targets_upd, tags_upd). Let names carry a per-function counter, plugin functions are <const>_specialization_<n>, and struct mangling keeps the source name, so nothing else can collapse two names. 67 tests pass.
Written by Claude Fable 5.1 via Claude Code (session https://claude.ai/code/session_01YJbiRBkJtM7x6PvYV6hmEm).
Let-bound names now come from the Rocq binders, and a name such as dp' is a valid Rocq identifier but not a C++ or SystemVerilog one. Both printers now run the binder name through valid_ident, the same check that struct and field names get, so such a program is rejected by the backend compilers instead of producing code that fails to parse. test_bad_binder covers the rejection on both backends; the four primed binders in Processor.v are renamed so the processor tests print. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJbiRBkJtM7x6PvYV6hmEm
201186a to
0b5b9e0
Compare
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJbiRBkJtM7x6PvYV6hmEm
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJbiRBkJtM7x6PvYV6hmEm
Bump the quartz submodule to fable/monomorphize (201186a), which stacks Andres's monomorphization work on the stdlib-bits port. Two things in that work reach granite. lang/let_lift.v is gone, so QuartzImpl_helpers no longer imports it. The cpu program in Processor.v now calls the helper constants directly (fifo1.full, btb.predPc, ...) instead of going through the record implementations, so making fifo1.impl and the other records opaque no longer keeps quartz's side of the lowering lemmas folded while granite's simulation specs still spell the record projections. QuartzImpl makes the constants opaque instead: with the records transparent both sides reduce to the same fn.interp of the constant, and the proof scripts go through unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJbiRBkJtM7x6PvYV6hmEm
Stacked on #2 (the first commits here are #2's; the diff against #2 is the last four). Brings the work from
andreser/monomorphize-stdpp(shared pretty-printing utilities, CPU monomorphization, binder names) up to date with the stdlib bits port: conflicts resolved in favour of #2's spellings (App low-first,Module Zmod, pack layout, the shared tests); the unused riscv-tests submodule from that branch is dropped. Andres's commits keep his authorship; one added commit makes the C++ and SystemVerilog printers reject binder names that are not valid target identifiers (through the existingvalid_identcheck) and renames the four primed binders in Processor.v.67 tests pass (43 existing + 21 new + 3 helper modules); no admits. The C++ driver of the CPU tests needs
ulimit -s unlimited. granite is being checked against this tip; a stacked granite PR follows if it needs changes.Written by Claude Fable 5.1.
🤖 Generated with Claude Code
https://claude.ai/code/session_01YJbiRBkJtM7x6PvYV6hmEm