# How to combine coverpoints

**URL:** <https://verificationacademy.com/forums/t/how-to-combine-coverpoints/40965>\
**Category:** Coverage\
**Tags:** coverpoint, Coverage, combine, merge\
**Created:** [November 1, 2022, 9:30pm UTC](https://verificationacademy.com/forums/t/how-to-combine-coverpoints/40965 "2022-11-01T21:30:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![atashinchi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@atashinchi](https://verificationacademy.com/forums/u/atashinchi)\
**Post date:** [November 1, 2022, 9:30pm UTC](https://verificationacademy.com/forums/t/how-to-combine-coverpoints/40965/1 "2022-11-01T21:30:07Z")

</div>

Hi, I have a simple question but can’t seem to find a straightforward answer from looking at other related questions. I have several coverpoints defined with their own bins and I just want to know how to create a new coverpoint that is the equivalent of a combined version of all the other coverpoints. I have listed an example below:

```verilog
cp_1 : coverpoint (opcode)
{
   bins cp_1_opcode_1 = {some_value};
   bins cp_1_opcode_2 = {some_value};
   bins cp_1_opcode_3 = {some_value};
}

cp_2 : coverpoint (opcode)
{
   bins cp_2_opcode_1 = {some_value};
   bins cp_2_opcode_2 = {some_value};
   bins cp_2_opcode_3 = {some_value};
}

cp_3 : coverpoint (opcode)
{
   bins cp_3_opcode_1 = {some_value};
   bins cp_3_opcode_2 = {some_value};
   bins cp_3_opcode_3 = {some_value};
}

cp_total : what should I put here?

cp_total_equivalent : coverpoint (opcode)
{
   bins cp_1_opcode_1 = {some_value};
   bins cp_1_opcode_2 = {some_value};
   bins cp_1_opcode_3 = {some_value};
   bins cp_2_opcode_1 = {some_value};
   bins cp_2_opcode_2 = {some_value};
   bins cp_2_opcode_3 = {some_value};
   bins cp_3_opcode_1 = {some_value};
   bins cp_3_opcode_2 = {some_value};
   bins cp_3_opcode_3 = {some_value};
}

```

I want to be able to cross the total as well as separate coverpoints with other coverpoints with minimum code, e.g.,

```verilog
cp_cross_example_1 : cross cp_1, some_other_cp_1;
cp_cross_example_2 : cross cp_total, some_other_cp_2;

```

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [November 3, 2022, 3:22am UTC](https://verificationacademy.com/forums/t/how-to-combine-coverpoints/40965/2 "2022-11-03T03:22:39Z")

</div>

_In reply to [atashinchi](https://verificationacademy.com/forums/t/how-to-combine-coverpoints/40965):_

You can use a combination of ‘bin set’ expressions and ‘bin with’ expressions

```verilog
  int set1[] = {1,2,3};
  int set2[] = {4,5,6};
  int set3[] = {7,8,9};
  int opcode;
  
  covergroup cg;
    cp_1 : coverpoint opcode {  
      bins cp_1_opcode[] = set1;
    }
    cp_2 : coverpoint opcode {
      bins cp_2_opcode[] = set2;
    }
    cp_3 : coverpoint opcode {
      bins cp_2_opcode[] = set2;
    }
    cp_total : coverpoint opcode {
      bins cp_total_opcode[] = cp_total with (item inside {set1,set2,set3});
    }
  endgroup

```

See sections _19.5.1.1 Coverpoint bin_ with _covergroup expressions_ and _19.5.1.2 Coverpoint bin set covergroup expressions_

---

<div class="post-metadata">

**Author:** ![hisingh](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@hisingh](https://verificationacademy.com/forums/u/hisingh)\
**Post date:** [January 18, 2023, 8:28am UTC](https://verificationacademy.com/forums/t/how-to-combine-coverpoints/40965/3 "2023-01-18T08:28:03Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/how-to-combine-coverpoints/40965/2):_

Hi Dave ,

Is the coverpoint label restricted to be used within the following 2 cases only ? :

1. The same coverpoint ( Eg : cover\_point\_identifier with ( with\_covergroup\_expression ) )
2. cross bin ( via binsof( cp\_label ) … )

I tried using it within a different coverpoint of same covergroup , however I observe a compilation error .

```verilog

  enum { SUB , ADD , MUL , DIV , POWER_OF } opcode ;
          
   covergroup cg ;
     
   cp_1 : coverpoint (opcode)
{
   bins substract = { SUB };
   bins addition = { ADD };   
}
 
cp_2 : coverpoint (opcode)
{
  bins multiply = { MUL };
  bins divide = { DIV };  
}
 
cp_3 : coverpoint (opcode)
{
  bins powerof = { POWER_OF };
}
 
cp_total_equivalent : coverpoint (opcode)
{
  bins sub = cp_1 with ( item inside { SUB } );
  bins add = cp_1 with ( item inside { ADD } );
  bins mul = cp_2 with ( item inside { MUL } );
  bins div = cp_2 with ( item inside { DIV } );
  bins power = cp_3 with ( item inside { POWER_OF } );
}   
   endgroup

```

Within coverpoint cp\_total\_equivalent if I replace labels cp\_1 , cp\_2 and cp\_3 with cp\_total\_equivalent , it works
