Skip to content

feat: add qualified Popcount and round-robin PYC primitives - #71

Open
HKU-LiBoyu wants to merge 1 commit into
mainfrom
feature/pyc-qualified-primitive-binding
Open

feat: add qualified Popcount and round-robin PYC primitives#71
HKU-LiBoyu wants to merge 1 commit into
mainfrom
feature/pyc-qualified-primitive-binding

Conversation

@HKU-LiBoyu

Copy link
Copy Markdown
Collaborator

Summary

This PR adds the pyCircuit implementation half of the qualified primitive vertical slice paired with PTO-ISA/agentic-circuit#18:

  • Add pyc.popcount and pyc.rr_arbiter to the PYC MLIR dialect with verifier checks for integer widths, legal popcount result width, arbiter request/grant width, cursor width, and the supported 2..64 input range.
  • Extend the C++ emitter with pyc::cpp::popcount<OutWidth, InWidth> and pyc::cpp::rr_arbiter<NumInputs, PointerWidth> calls.
  • Extend the Verilog emitter and pycc primitive packaging so generated RTL instantiates the parameterized primitives and includes their source files.
  • Add reusable C++ runtime helpers and synthesizable Verilog implementations for population count and non-power-of-two-safe round-robin one-hot arbitration.

Files changed

  • PYC dialect definition/verifiers: compiler/mlir/include/pyc/Dialect/PYC/PYCOps.td, compiler/mlir/lib/Dialect/PYC/PYCOps.cpp
  • C++/Verilog emitters: compiler/mlir/lib/Emit/CppEmitter.cpp, compiler/mlir/lib/Emit/VerilogEmitter.cpp
  • Primitive packaging: compiler/mlir/tools/pycc.cpp
  • C++ runtime: runtime/cpp/pyc_primitives.hpp
  • Verilog RTL: runtime/verilog/pyc_popcount.v, runtime/verilog/pyc_rr_arbiter.v

Contract

  • pyc.popcount: integer input width W produces ceil(log2(W + 1)) bits.
  • pyc.rr_arbiter: packed req[N-1:0], packed cursor[ceil(log2(N))-1:0], one-hot grant[N-1:0], with 2 <= N <= 64; invalid cursor values normalize to zero for non-power-of-two N.
  • Cursor state remains owned by the surrounding PYC graph; the primitive is combinational.

Validation

  • C++ smoke: N=4 (64 vectors), N=3 (32 vectors), all passed.
  • Verilator exhaustive simulation and lint: N=4/N=3 passed.
  • Yosys prep/check/stat: 0 problems.
  • LLVM 22 mlir-tblgen PYC dialect syntax check: passed.

The paired agentic-circuit lowering and ACIR fixtures are in PTO-ISA/agentic-circuit#18.

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.

2 participants