[otbn,dv] Avoid integer overflow in coverpoint expression
The expression "1 << (32 - 1)" that you get when evaluating
DEF_SIGN_CP(name, value, 32) isn't representable as a signed 32-bit
integer and VCS emits warnings in the build log:
Warning-[CPBRM] Precision or Sign Mismatch
../src/lowrisc_dv_otbn_env_0.1/otbn_env_cov.sv, 977
Potential precision or sign mismatch in range values of user defined bin neg
of coverpoint sign_a_cp in covergroup
otbn_env_pkg::otbn_env_cov::insn_addsub_cg
Source info: bins neg = { [(1 << 31):32'hffffffff] } ;. Values outside the
valid coverpoint range will either be deleted(singleton values) or
adjusted(ranges) as per the precision semantics.
Intriguingly, it doesn't warn about the (1 << (32 - 1)) - 1.
Apparently, the conversion to signed 32-bit integer only happens at
the root of the expression tree.
Make the "1" an explicit width to avoid the problem.
Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
diff --git a/hw/ip/otbn/dv/uvm/env/otbn_env_cov.sv b/hw/ip/otbn/dv/uvm/env/otbn_env_cov.sv
index 55741d9..3834bbe 100644
--- a/hw/ip/otbn/dv/uvm/env/otbn_env_cov.sv
+++ b/hw/ip/otbn/dv/uvm/env/otbn_env_cov.sv
@@ -203,11 +203,11 @@
// A macro to define a coverpoint based on the sign of a value (assumed to be represented by an
// unsigned SystemVerilog expression).
-`define DEF_SIGN_CP(NAME, VALUE, WIDTH) \
- NAME: coverpoint VALUE { \
- bins zero = {0}; \
- bins pos = {[1:(1 << (WIDTH - 1))-1]}; \
- bins neg = {[1 << (WIDTH - 1):$]}; \
+`define DEF_SIGN_CP(NAME, VALUE, WIDTH) \
+ NAME: coverpoint VALUE { \
+ bins zero = {0}; \
+ bins pos = {[1:(WIDTH'd1 << (WIDTH - 1))-1]}; \
+ bins neg = {[WIDTH'd1 << (WIDTH - 1):$]}; \
}
// A macro to define a coverpoint based on whether a value is zero or not (assumed to be