My question is number of ones in 8 bit vector is more than 4
for example : a = 0101_1010 or 1111_0000 or 0111_1101
I am facing issue randomization failure because of constraints overlap
// Code your testbench here
// or browse Examples
class ones;
rand bit [7:0] a;
rand bit [2:0] l;
constraint l_c {
l > 4;
l < 6;
solve l before a;
}
constraint a_c {
count_ones(a) > l;
}
function int count_ones ( bit [9:0] w );
for( count_ones = 0; w != 0; w = w >> 1 )
count_ones += w & 1'b1;
endfunction
endclass
module top;
ones s;
initial
begin
s =new();
assert(s.randomize());
$display(" a= %b, b= %d", s.a, s.l);
end
endmodule
my transcript is below can any one help me solve this we can easly solve with $countones but I dont want to use that function.
output :
QuestaSim-64 vlog 2021.3 Compiler 2021.07 Jul 13 2021
Start time: 21:35:44 on Jul 29,2023
vlog -writetoplevels questa.tops -timescale 1ns/1ns design.sv testbench.sv
– Compiling package testbench_sv_unit
– Compiling module top
Top level modules:
top
End time: 21:35:44 on Jul 29,2023, Elapsed time: 0:00:00
Errors: 0, Warnings: 0
vsim top -batch -do “vsim -voptargs=+acc=npr; run -all; exit” -voptargs=“+acc=npr”
** Note: (vsim-7130) Enabling enhanced debug (-solvefaildebug=2) may generate a more descriptive constraint contradiction report and -solvefaildebug testcase.
** Note: (vsim-7106) Use vsim option ‘-solvefailtestcase[=filename]’ to generate a simplified testcase that will reproduce the failure.
** Warning: (vsim-7084) No solutions exist which satisfy the specified constraints; randomize() failed.
Calling user-defined function in constraints should be done carefully, because the function shall be called before constraints are solved (no back-track done by the solver to find proper function input), and this is a source potential constraints conflicts.