Skip to content

Fix || vs && mismatch in order_book.sv latency latch#4

Open
pauliano22 wants to merge 1 commit into
mainfrom
fix/order-book-latency-latch
Open

Fix || vs && mismatch in order_book.sv latency latch#4
pauliano22 wants to merge 1 commit into
mainfrom
fix/order-book-latency-latch

Conversation

@pauliano22

Copy link
Copy Markdown
Owner

Summary

src/rtl/order_book.sv's r_latency update was gated on r_best_bid != 0 || r_best_ask != 0, but the comment directly above it says latency should be recorded "to when both sides are valid" — and book_valid (a few lines down) correctly uses && for that same condition. With ||, r_latency gets overwritten on almost every Add message rather than only once both sides first become valid.

This is currently inert: top.sv wires order_book's latency_cycles output to ob_latency_cycles but explicitly ignores it (comment: // unused; top counts separately). So no reported number changes today, but it's a genuine bug that would produce wrong values the moment this signal is actually consumed.

Test plan

  • verilator --lint-only -Wall -y ../../src/rtl ../../src/rtl/top.sv — clean
  • Built sim/verilator and ran ./obj_dir/Vtop --file ../../data/sample.itch --no-vcd --limit 50000 before and after this change — identical throughput, latency percentiles (p50/p95/p99/max), and golden-model comparison counts in both cases, confirming this only touches the currently-unused internal register and doesn't regress anything

Generated by Claude Code

The comment above this line says latency should be recorded "to when
both sides are valid", and book_valid (line 170) correctly uses &&
for that same condition. This line used ||, so r_latency was
overwritten on almost every Add message instead of only once both
sides first became valid.

Currently inert: top.sv wires ob_latency_cycles but explicitly
ignores it ("unused; top counts separately"), so this doesn't affect
any latency numbers reported today - but it's a real bug that would
produce wrong values the moment this signal is used.

Verified: `verilator --lint-only` clean, and a 50K-message run through
sim/verilator/obj_dir/Vtop produces identical throughput, latency
percentiles, and golden-model comparison counts before and after
(expected, since this only changes an unused internal register).
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