Cross Coverage

Bugs often hide in the interaction between two features. Cross coverage allows you to track these combinations, verifying that you have tested your design under complex, intersecting scenarios.

The Basic Cross

A cross creates a matrix of bins. It multiplies the bins of one coverpoint with the bins of another.

covergroup cg @(posedge clk);
    cp_cmd:  coverpoint cmd {
        bins read = {0};
        bins write = {1};
    }
    cp_mode: coverpoint mode {
        bins low_power = {0};
        bins turbo = {1};
    }

    // Creates 2 * 2 = 4 combinations:
    // read/low_power, read/turbo, write/low_power, write/turbo
    cx_cmd_mode: cross cp_cmd, cp_mode;
endgroup

Excluding Combinations (binsof)

Usually, not all combinations are valid. For example, maybe "Write" commands are impossible in "Low Power" mode. We must exclude them to get 100% meaningful coverage. We use binsof() and intersect.

cx_filtered: cross cp_cmd, cp_mode {
    // Ignore cases where cmd is Write AND mode is Low Power
    ignore_bins write_in_lp = binsof(cp_cmd.write) && binsof(cp_mode.low_power);
}

Advanced Filtering

You can combine logic to create precise exclusion rules.

  • binsof(cp.bin): Selects a specific bin from a coverpoint.
  • intersect {val}: Checks if the bin contains a specific value.
  • &&, ||: Logical operators.
covergroup cg_alu;
    cp_op: coverpoint opcode {
        bins arithmetic[] = {[0:3]};
        bins logical[]    = {[4:7]};
    }
    cp_val: coverpoint operand {
        bins zero = {0};
        bins max  = {15}; 
    }

    // Cross them
    cx_ops: cross cp_op, cp_val {
        // Ignore "Division by Zero" scenario if opcode 3 is DIV
        ignore_bins div_zero = binsof(cp_op) intersect {3} && binsof(cp_val.zero);
    }
endgroup

Common Interview Questions

Q: Why do we need cross coverage if we have random testing?
Random testing *generates* the scenarios, but it doesn't guarantee they happened. Cross coverage *measures* if the constrained random generator actually hit those specific corner-case combinations (like FIFO Full + Write Enable).
Q: Does crossing 3 coverpoints create a 3D matrix?
Conceptually, yes. The number of resulting bins is (Bins_A * Bins_B * Bins_C). This is why you must be careful—crossing three 10-bin coverpoints creates 1000 bins! Always filter irrelevant combinations.