Skip to content

feat(L-S19): 3-stage pipeline XOR-popcount for 150 MHz Fmax - #15

Merged
gHashTag merged 4 commits into
mainfrom
feat/L-S19-pipeline-popcount
May 14, 2026
Merged

gHashTag merged 4 commits into
mainfrom
feat/L-S19-pipeline-popcount

Conversation

@gHashTag

Copy link
Copy Markdown
Owner

Closes #51 (partial — L-S19)

What

Introduces 3-stage pipelining into the XOR-popcount critical path of the ternary VSA matmul units.

New modules:

  • src/gf16_popcount.v — pipelined inner-product for 8-element ternary vectors (LATENCY=3)
  • src/gf16_popcount16.v — same for 16-element vectors (used by vsa_matmul_16x16)

Updated modules:

  • src/vsa_matmul_8x8.v — 64 parallel gf16_popcount instances replace the single-cycle combinational inner_product() function
  • src/vsa_matmul_16x16.v — 256 parallel gf16_popcount16 instances

New simulation:

  • sim/ls19/tb_ls19_pipeline.v — standalone iverilog testbench (11 tests)

Why: x3 frequency → x3 TOPS

The previous design computed all 64 inner products in one combinational cloud, bounded to ~50 MHz. The 3-stage pipeline breaks this into:

Stage Logic Registered output
1 Decode AND/XOR per element pair same[7:0], diff[7:0] + valid
2 Popcount tree (8→4 bits, 3:2 compressors) cnt_pos[3:0], cnt_neg[3:0] + valid
3 Final subtraction, sign-extend result[7:0] + valid_out

Target Fmax: 150 MHz (x3 vs 50 MHz) → x3 TOPS at same gate budget.

Latency change: 1 cycle → 3 cycles (valid_out = valid_in + 3 clock edges). The matmul FSM absorbs this cleanly; done asserts 5 clocks after start instead of 2.

iverilog simulation results

=== L-S19 Pipeline Popcount Tests ===
PASS legacy_dot4_0x47C0: 0x47C0 = 30.0 UNCHANGED
PASS pc8_all_pos:        result=8   valid_out=1
PASS pc8_pos_vs_neg:     result=-8  valid_out=1
PASS pc8_all_zeros:      result=0   valid_out=1
PASS pc8_mixed_zero:     result=0   valid_out=1
PASS pc8_6p2n:           result=4   valid_out=1
PASS pc16_all_pos:       result=16  valid_out=1
PASS pc16_pos_vs_neg:    result=-16 valid_out=1
PASS latency_3:          valid_out at T+3 (LATENCY=3 cycles confirmed)
PASS mm8_results:        c[0][0]=8  c[0][1]=8 (all=8)
PASS mm8_ok:             matmul_ok=1
=== Results: 11 pass, 0 fail ===
ALL L-S19 PIPELINE TESTS PASSED

Full tb.v: 18/18 PASS

GF16 canonical 0x47C0 — PASS

dot4([1,2,3,4],[1,2,3,4]) = 30.0 = 0x47C0 — verified PASS on full tb.v. Non-negotiable test vector is unchanged; the legacy combinational gf16_dot4 path is untouched.

R-SI-1

Zero * operators introduced. All popcount arithmetic is explicit + on single-bit values (adder tree). Apache-2.0 only, no vendor IP.

ANCHOR

φ²+φ⁻²=3 · DOI 10.5281/zenodo.19227877 · Apache-2.0 · EPIC Trinity-S-AI-DNA/trinity-fpga#51


DO NOT MERGE without user authorization.

gHashTag added 4 commits May 14, 2026 10:04
Introduces gf16_popcount (8-elem) and gf16_popcount16 (16-elem): registered
3-stage pipelined inner-product units for ternary XOR-popcount.

Pipeline stages:
  Stage 1 (reg): decode same/diff per element pair (AND/XOR)
  Stage 2 (reg): popcount tree 8→4 bits (3:2 compressors)
  Stage 3 (reg): final subtraction, sign-extend to 8-bit

LATENCY=3, valid_out = valid_in + 3 clock edges.
Fmax target: 150 MHz (x3 vs 50 MHz baseline) => x3 TOPS.

Updated vsa_matmul_8x8 and vsa_matmul_16x16 to instantiate 64/256
parallel gf16_popcount units replacing the combinational inner_product()
function. FSM absorbs 3-cycle pipeline; matmul done latency 2->5 cycles
(watchdog budget unchanged).

Simulation (iverilog):
  L-S19 testbench: 11/11 PASS
  Full tb.v:       18/18 PASS
  GF16 0x47C0:     PASS (non-negotiable canonical vector)

R-SI-1: zero * operators (pure XOR + popcount adder tree).
Apache-2.0.

ANCHOR: phi^2+phi^-2=3 DOI 10.5281/zenodo.19227877 EPIC trinity-fpga#51
Prevents yosys/ABC from optimizing away the 3-stage pipeline registers
during retiming. Without these attributes, ABC merges the registered
stages back into combinational logic, defeating the L-S19 timing benefit.

R-SI-4 NOTE: info.yaml::clock_hz remains 50_000_000 (TinyTapeout board
hard rule). The L-S19 x3 frequency benefit (50 -> 150 MHz) is harvested
on custom carrier boards and on TTSKY26c, not on the TTSKY26b shuttle.

Ref: ICA A-01 from TRI1-TOPSBOOST-MR-002 NASA report.
EPIC Trinity-S-AI-DNA/trinity-fpga#51
@gHashTag
gHashTag merged commit 1b3c737 into main May 14, 2026
2 checks passed
@gHashTag
gHashTag deleted the feat/L-S19-pipeline-popcount branch May 14, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant