Skip to content

ram: add bit-line segmentation and per-slice mux 2 word-select buffering - #12281

Draft
tnguy19 wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
tnguy19:ram-bitline-seg-upstream
Draft

tnguy19 wants to merge 1 commit into
The-OpenROAD-Project:masterfrom
tnguy19:ram-bitline-seg-upstream

Conversation

@tnguy19

@tnguy19 tnguy19 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds bit-line segmentation to the RAM generator, and adds two options to control it. Also fixes a heavily loaded address net in mux 2 RAMs, and fix bug in the automatic latch cell choice for latch-based RAMs.

Currently in a column every stored bit drives one shared bit line, so the line is loaded by every row and gets slow as the RAM gets taller. Segmentation splits each column into groups of rows (segments). Each bit drives only the short line of its own segment and one extra buffer per segment switched by a segment select drives the shared line. Each line then has far fewer loads with one extra row of buffers per segment so the area grows very little with alot of delay decrease.

Segmentation is on automatically for RAMs with 32 or more rows, column mux 1 or 2, and one read/write port, without banking. This includes latch-based RAMs. The segment length is chosen automatically from the row count (about the square root of it, rounded to a power of two).

But this can be manually override using the flags:

  • -segmentation: turn segmentation off or on.
  • -rows_per_segment N: set the number of rows per segment (turns segmentation on unless -segmentation 0 is given).
  • If no flag is specified, the automatic rule above is applied

Mux 2 fix: In mux 2 RAMs, the word-select address signal drove every column group directly (about 580 loads on a 128×64 RAM). It is now buffered once per column group (about 72 loads).

Latch fix: With -use_latch 1 and no -storage_cell, the generator can pick negative latches instead of positive. Changes are made so that only positive latches are selected

Type of Change

  • Bug fix
  • New feature
  • Documentation update

Impact

  • RAMs that meet the automatic rule are now segmented by default, so their netlist, area and timing change. On a 128×64 mux 1 RAM the worst input-to-output path goes from 7.24 ns (off) to 4.30 ns (on). On latch-based 16-bit RAMs, segmentation cuts the maximum path delay by 20% at 32 rows up to 67% at 512 rows. Area grows by a few percent.
  • Unbanked mux 2 RAMs get the word-select buffers. On a 1 kB mux 2 RAM without segmentation, the worst read path goes from 10.56 ns to 7.29 ns.
  • Latch-based RAMs generated with default cells now use a working (positive) latch.
  • Forcing segmentation on an unsupported configuration (column mux 4, banked, multiple ports, AND/OR read, bit folding) is an error (RAM 112). A segment length that is too small or not smaller than the row count is an error (RAM 113). A -segmentation value other than 0 or 1 is an error (RAM 111).
  • Banked and multi-port RAMs are unchanged.
  • The new options are documented in README.md.

Verification

  • I have verified that the local build succeeds (./etc/Build.sh).
  • I have run the relevant tests and they pass.
  • My code follows the repository's formatting guidelines.
  • I have included tests to prevent regressions.
  • I have signed my commits (DCO).

Related Issues

This PR contaisn the OpenSTA integration code in #10784 which should be merged before this one

@rovinski

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces bit-line segmentation to the RAM generator, allowing for automatic or manual configuration of rows per segment via the new -segmentation and -rows_per_segment options. It also implements per-slice buffering for word-select address bits to reduce loading, and adds an extra check to ensure latches are positive-triggered. The review feedback highlights a potential null pointer dereference in the cell upsizing helper that should trigger a loud error, and suggests distributing segment-select AND gates across different slices to prevent physical placement congestion.

Comment thread src/ram/src/ram.cpp
Comment on lines +3495 to +3501
auto upsized = [&](dbMaster* base, int factor) -> dbMaster* {
const std::string name = base->getName();
size_t pos = name.size();
while (pos > 0 && std::isdigit(static_cast<unsigned char>(name[pos - 1]))) {
--pos;
}
if (pos == name.size() || pos == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If base is nullptr (for example, if and2_cell_ or tristate_cell_ is not found in the library), calling base->getName() will dereference a null pointer and cause a crash. To adhere to the repository's style guide, we should not use a silent guard but instead trigger a loud, early failure using logger_->error.

  auto upsized = [&](dbMaster* base, int factor) -> dbMaster* {
    if (!base) {
      logger_->error(RAM, 114, "Required cell is missing for upsizing.");
    }
    const std::string name = base->getName();
    size_t pos = name.size();
    while (pos > 0 && std::isdigit(static_cast<unsigned char>(name[pos - 1]))) {
      --pos;
    }
    if (pos == name.size() || pos == 0) {
References
  1. Never suggest a guard that hides an impossible state: a null check, an empty, zero or negative check, or a missing-key check that returns a default, skips, clamps, continues or logs a warning and carries on. A null dereference that is reachable is reported with its triggering input; the fix is logger_->error(...) or an assert, never a silent default. (link)

Comment thread src/ram/src/ram.cpp
continue;
}
dbNet* out = makeNet(sp, fmt::format("sel_and{}", j));
makeInst(ctl[0][0].get(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid physical placement congestion and potential overlaps in the select column of slice 0, consider distributing the segment-select AND gates across the select columns of the different slices instead of placing all of them in ctl[0][0]. Since slices_per_word is at least 1, you can use ctl[j % slices_per_word][0].get() to distribute them.

Suggested change
makeInst(ctl[0][0].get(),
makeInst(ctl[j % slices_per_word][0].get(),

@rovinski

Copy link
Copy Markdown
Collaborator

-segmentation is too generic. Please use something more specific like -bit_read_segmentation

Ideally with an optimizer this option will not be exposed to the user and instead automatically selected.

Also, please remember what I said about splitting separate concerns into separate PRs. The smaller a PR is, the easier it is to review.

Signed-off-by: Thinh Nguyen <nguyenthinh19011@gmail.com>
@tnguy19
tnguy19 force-pushed the ram-bitline-seg-upstream branch from a5a89af to c2957e8 Compare November 15, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants