Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/Optimize nonadjacent bank activation

Q010·Free·SystemVerilog

Optimize nonadjacent bank activation

Difficulty
Medium
Topic
Hardware Algorithms
Language
SV
Interview prompt

Question

Choose a maximum-benefit subset of static random-access memory (SRAM) banks when adjacent banks may not be active in the same maintenance interval. Return the total score and exact selection mask.

Candidate starting point

Implementation scaffold

module adjacent_bank_optimizer (
  input  logic        clk,
  input  logic        rst_n,
  input  logic        in_valid,
  input  logic        in_last,
  input  logic [7:0]  benefit,
  input  logic        result_ready,
  output logic        in_ready,
  output logic        result_valid,
  output logic [11:0] max_score,
  output logic [15:0] select_mask,
  output logic [4:0]  bank_count
);
  typedef enum logic [1:0] {S_INPUT, S_SEARCH, S_RESULT} state_t;
  state_t state_q;

  logic [7:0] benefit_q [0:15];
  logic [4:0] write_idx_q;
  logic [16:0] enum_q, limit_q;
  logic [11:0] best_score_q, result_score_q;
  logic [15:0] best_mask_q, result_mask_q;
  logic [4:0] best_count_q, result_count_q;

  logic cand_legal, cand_better, lower_index_preferred;
  logic [11:0] cand_score;
  logic [4:0] cand_count;
  logic first_difference;

  always_comb begin : evaluate_candidate
    // TODO: Implement evaluate_candidate using the supplied state and interface.
  end

  assign in_ready     = (state_q == S_INPUT);
  assign result_valid = (state_q == S_RESULT);
  assign max_score    = result_score_q;
  assign select_mask  = result_mask_q;
  assign bank_count   = result_count_q;

  always_ff @(posedge clk) begin : load_search_and_publish
    // TODO: Implement load_search_and_publish using the supplied state and interface.
  end
endmodule
Reviewed example

Trace one case

Input
benefit by bank = [5, 1, 4, 9, 2]
Expected output
max_score=14; select_mask=16'h0009; bank_count=2

Banks 0 and 3 are nonadjacent and total 14, which exceeds every other legal subset.

What to cover

Requirements

  1. Accept a frame of 1 to 16 unsigned eight-bit benefits; the first and last banks are not adjacent.
  2. Select no adjacent pair and maximize the total benefit.
  3. On a score tie, prefer fewer selected banks; if still tied, prefer the mask that selects the first differing lower-index bank.
  4. Clear mask bits above the frame length and return the selected-bank popcount.
  5. Hold the final score, mask, and count stable while stalled.
Exact question handoffPractice Q010

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessEach time you open this Solution, one Practice Credit is used; it is not permanently unlocked. Premium Solution content also uses one credit per opening.
Continue learning

RTL Synthesis and Proof

Review widths, parameterization, memory inference, pipelining, implementation pressure, and proof evidence.

  • Hardware Algorithms
  • Dynamic programming
  • Power
  • Tie-breaking
RTL Synthesis and Proof →
Continue practicing

Related questions

Q151 · Hardware AlgorithmsMinimize descriptor count for a payloadMedium→Q023 · RTL DatapathsFind a target-sum operand pairMedium→
ASIC.FYI · Learn silicon end to end.info@asic.fyi