Part 5 · Functional Coverage · Intermediate

binsof & intersect

Selecting cross subsets with binsof, intersect value filters, && / || / ! combinations, and named cross bins.

binsof — the cross selection language

Inside a cross body, binsof selects a slice of the product matrix. binsof(cp.bin_name) picks every cell whose cp coordinate is that bin — a full row or column of the matrix. binsof(cp) intersect {vals} picks the cells whose cp bin contains any of the listed values — selection by value rather than by bin name.

systemverilog
covergroup cg @(posedge clk iff valid);
  cp_op  : coverpoint opcode    { bins add = {OP_ADD}; bins sub = {OP_SUB};
                                  bins mul = {OP_MUL}; bins div = {OP_DIV}; }
  cp_len : coverpoint burst_len { bins single = {1};  bins short_b = {[2:4]};
                                  bins long_b = {[5:16]}; }

  x_op_len : cross cp_op, cp_len {
    // Select by bin name: the whole div row (3 cells -> 1 named bin)
    bins div_any = binsof(cp_op.div);

    // Select by value: any len bin containing 1..2 (single and short_b)
    bins short_ops = binsof(cp_len) intersect {[1:2]};

    // AND of selections: exactly the <div, long_b> cell
    bins div_long = binsof(cp_op.div) && binsof(cp_len.long_b);

    // OR of selections: union of the mul row and the div row
    bins muldiv = binsof(cp_op.mul) || binsof(cp_op.div);

    // Negation: every cell NOT in the add row
    bins not_add = !binsof(cp_op.add);
  }
endgroup

Selections drawn on the matrix

diagram
single   short_b   long_b
            ┌────────┬─────────┬────────┐
        add │        │         │        │   binsof(cp_op.div)
            ├────────┼─────────┼────────┤     = bottom row (3 cells)
        sub │        │         │        │
            ├────────┼─────────┼────────┤   binsof(cp_op.div) &&
        mul │        │         │        │   binsof(cp_len.long_b)
            ├────────┼─────────┼────────┤     = single cell <div,long_b>
        div │ ██████ │ ██████  │ ▓▓▓▓▓▓ │
            └────────┴─────────┴────────┘   !binsof(cp_op.add)
  ██ = div_any   ▓ = also div_long             = rows sub+mul+div (9 cells)
  && narrows (intersection of selections)
  || widens  (union of selections)
  !  inverts (complement of a selection)

Named cross bins change the counting

A named cross bin built from a selection is one bin , no matter how many cells it covers. The bin is hit when any cell in its selection is hit. This is the key behavioral difference: bins div_any = binsof(cp_op.div); closes after one div sample of any length, whereas the three auto bins it replaces would each need their own hits.

systemverilog
x_op_len : cross cp_op, cp_len {
  // ONE bin: closes when ANY div cell is hit
  bins div_any = binsof(cp_op.div);

  // THREE bins: the [] makes one bin per selected cell
  bins div_each[] = binsof(cp_op.div);
  // -> div_each[<div,single>], div_each[<div,short_b>], div_each[<div,long_b>]
}

Selection rules worth memorizing

  • binsof(cp.bin) — selects by bin name; survives bin renumbering of values inside that bin.

  • binsof(cp) intersect {v0, [lo:hi]} — selects every source bin that overlaps the value set, then takes those rows/columns.

  • && and || combine selections (set intersection / union) — they are not boolean operations on values.

  • ! complements a selection — useful for 'everything except the default-ish row'.

  • Appending [] to the bin name splits the selection into one bin per cell instead of one merged bin.

Interview angle: "What does binsof(cp_len) intersect {[1:2]} select when bin short_b = {[2:4]}?" — it selects short_b too, because intersect works on overlap, not containment. The value 2 is inside short_b, so the whole short_b column is in the selection. Candidates who think intersect filters individual values get this wrong.

Key takeaways

  • binsof selects rows/columns/cells of the cross matrix; && narrows, || widens, ! inverts the selection.

  • intersect selects source bins by value overlap — a bin is included if any of its values match.

  • A named selection is one bin unless you add [] to split it into per-cell bins.

  • Named cross bins replace the auto product for the cells they claim — what you name is what the goal counts.

Common pitfalls

  • Reading && as 'both values true' — it intersects selections of cells, a set operation.

  • Expecting intersect to trim values out of a bin — it selects whole bins that overlap the value set.

  • Forgetting [] and wondering why a 12-cell selection closed after one hit — a merged bin needs only one cell hit.

  • Defining named bins that overlap, then misreading hit counts — one sample can hit several named selections at once.