mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-12 20:15:31 +08:00
Implement a multi-lane Content Addressable Memory (CAM) that scores rows by XNOR popcount against a query hash and returns the top-1 match. RTL modules: - popcount: parallel group-based population count - argmax_update: iterative best-match tracking with tie-break - cam_core: parameterized scanning engine (NUM_ROWS/HASH_BITS/LANES) with optional SIM_NOISE and SIM_DEBUG ifdef guards - cam_top: thin wrapper exposing cam_core ports Verification: - Python reference model (ref_model.py) for score-level golden comparison - cocotb testbench (test_cam_basic.py) covering write/query/reset and external noise mask scenarios with score debug verification - Noise sweep script (sweep_noise.py) measuring top-1 stability under configurable bit-flip rates - Verilator-oriented Makefile with parameterizable compile options
65 lines
1.6 KiB
Systemverilog
65 lines
1.6 KiB
Systemverilog
`timescale 1ns/1ps
|
|
|
|
module cam_top #(
|
|
parameter int NUM_ROWS = 512,
|
|
parameter int HASH_BITS = 512,
|
|
parameter int LANES = 16,
|
|
|
|
parameter int ROW_BITS = $clog2(NUM_ROWS),
|
|
parameter int SCORE_BITS = $clog2(HASH_BITS + 1)
|
|
) (
|
|
input logic clk,
|
|
input logic rst_n,
|
|
|
|
input logic wr_en,
|
|
input logic [ROW_BITS-1:0] wr_row,
|
|
input logic [HASH_BITS-1:0] wr_hash,
|
|
|
|
input logic query_valid,
|
|
output logic query_ready,
|
|
input logic [HASH_BITS-1:0] query_hash,
|
|
|
|
output logic result_valid,
|
|
input logic result_ready,
|
|
output logic [ROW_BITS-1:0] top1_index,
|
|
output logic [SCORE_BITS-1:0] top1_score,
|
|
|
|
`ifdef SIM_NOISE
|
|
input logic [LANES*HASH_BITS-1:0] noise_mask_lanes_flat,
|
|
`endif
|
|
|
|
`ifdef SIM_DEBUG
|
|
output logic [NUM_ROWS*SCORE_BITS-1:0] score_debug_flat,
|
|
`endif
|
|
|
|
output logic busy
|
|
);
|
|
cam_core #(
|
|
.NUM_ROWS(NUM_ROWS),
|
|
.HASH_BITS(HASH_BITS),
|
|
.LANES(LANES),
|
|
.ROW_BITS(ROW_BITS),
|
|
.SCORE_BITS(SCORE_BITS)
|
|
) u_core (
|
|
.clk(clk),
|
|
.rst_n(rst_n),
|
|
.wr_row(wr_row),
|
|
.wr_hash(wr_hash),
|
|
.wr_en(wr_en),
|
|
.query_valid(query_valid),
|
|
.query_ready(query_ready),
|
|
.query_hash(query_hash),
|
|
.result_valid(result_valid),
|
|
.result_ready(result_ready),
|
|
.top1_index(top1_index),
|
|
.top1_score(top1_score),
|
|
`ifdef SIM_NOISE
|
|
.noise_mask_lanes_flat(noise_mask_lanes_flat),
|
|
`endif
|
|
`ifdef SIM_DEBUG
|
|
.score_debug_flat(score_debug_flat),
|
|
`endif
|
|
.busy(busy)
|
|
);
|
|
endmodule
|