How to constraint the first byte of Dynamic array in system verilog

Hello,

rand bit[31:0] frame ;

in this case the element size of dynamic array is also dynamic.

I can to constraint the first byte of first element of dynamic array, so how can i do this ?

i have tried like

constraint frame_first_byte_const { frame[0][0:7] dist { 8’h00:=50, 8’h11:=50};}

but it didn’t work.

Thank you,
Rakesh

Rakesh,
The following code seems to work in Questa. Though we usually prefer not to this “single-step array randomization” during our training classes, this works on int/bit etc. fairly well.

Can you elaborate on what didn’t work for you?

Regards
Ajeetha, CVC


class test;
  rand bit [7:0] da[];
  constraint cst_len { da.size inside { 2, 4, 8 }; } 
  constraint cst_frame_first_byte { da[0] dist { 8'h00:=50, 8'h11:=50};}

  function void post_randomize;
    $display ("%p", this);
    $display ("da.size: %0d", da.size);
  endfunction : post_randomize
endclass : test

program p;
  test t0;

  initial begin : test
    t0 = new;
    repeat (10) a1: assert (t0.randomize);
    
  end : test
endprogram : p

‘{da:’{0, 234, 98, 79, 60, 75, 79, 35}}

da.size: 8

‘{da:’{17, 135}}

da.size: 2

‘{da:’{0, 193, 173, 221, 93, 31, 121, 225}}

da.size: 8

‘{da:’{17, 149, 162, 4}}

da.size: 4

‘{da:’{17, 239}}

da.size: 2

‘{da:’{17, 39, 75, 118}}

da.size: 4

‘{da:’{17, 119, 132, 96, 239, 47, 46, 101}}

da.size: 8

‘{da:’{0, 195}}

da.size: 2

‘{da:’{0, 218, 154, 8, 163, 43, 232, 31}}

da.size: 8

‘{da:’{0, 137, 221, 84}}

da.size: 4

In reply to ajeetha:

Hello Ajeetha,

Thank you for your reply. Now it works.

Rakesh

In reply to ajeetha:

I want to randomize transaction field and size of that field is configuration parameter.
How can I write the constraints for this field? I have written code like following. It is not working.

// Transaction field Stop bit
rand bit stop_bit;
// constraint for stop bit value
constraint stop_bit_c {
(stop_bit.size == 1) → stop_bit == 1’b1;
(stop_bit.size == 1) → stop_bit == 2’b11;
}

Hey Ajitha, hi have a dynamic array bit [15:0]data[variable_length_for_example_say10],

now I want to break the dynamic array into [15:0]data[0],[15:0]data[1],[15:0]data[2]…[15:0]data[10],

my goal is to send the dynamic array data bit by bit ie serially. first data[0] bits and the data[1] bits and so on.

could you help me how to access the dynamic array data in a loop;

Regards
Tanajirao