Constraint random generation for ISS

I am trying to write the Constraint randomize based test to verify the the ISS (Instruction simulator ) for my processor.
Since its ISS can take assembly instruction in input but Assembly language does not provide the randomization so i used system verilog language/

how to write the constraint to replicate the below instruction.

--> IF.<condition> A <LABEL1>
     ..<next instruction>
     ......
    ENDIF

LABEL1 :

Example :- IF.nz A LABEL1 ( nz – non zero)

where IF is opcode, and if condition is met with A then it will go to next instruction and end with ENDIF else go to offset (LABEL1)

typedef enum bit [3:0] { IF=’h20, ELSE, ENDIF, ENDLOOP, .......... } flow_control_pipe_t;

class operand;      
      rand RegType RegType_t; 
      rand int  Regnum;
      rand flow_control_pipe flow_control_pipe_t;
  Constraint   abc_c {
     if (flow_control_pipe_t == IF ) 
        if (A == 0)   --> condition met  
            ?????
          else 
             ???? condition not met

Kindly suggest me the how to write the code for above scenario ?

|

In reply to rupeshblr:

I am trying to write the Constraint randomize based test to verify the the ISS (Instruction simulator ) for my processor.
Since its ISS can take assembly instruction in input but Assembly language does not provide the randomization so i used system verilog language/
how to write the constraint to replicate the below instruction.

--> IF.<condition> A <LABEL1>
..<next instruction>
......
ENDIF
LABEL1 :

Example :- IF.nz A LABEL1 ( nz – non zero)
where IF is opcode, and if condition is met with A then it will go to next instruction and end with ENDIF else go to offset (LABEL1)

typedef enum bit [3:0] { IF=’h20, ELSE, ENDIF, ENDLOOP, .......... } flow_control_pipe_t;
class operand;      
rand RegType RegType_t; 
rand int  Regnum;
rand flow_control_pipe flow_control_pipe_t;
Constraint   abc_c {
if (flow_control_pipe_t == IF ) 
if (A == 0)   --> condition met  
?????
else 
???? condition not met

Kindly suggest me the how to write the code for above scenario ?
|

In such cases, it is less randomization and more of proper sequencing.
Use SV’s randsequences for such a problem.
There are many articles and here is one of them:

In reply to shatrish:

Thank you :)

In reply to rupeshblr:

[quote]In reply to shatrish:

I have gone through the article and other randsequence concept but still i am not clear that how to write the above scenario using randsequences.
Can you give me small example ?

In reply to rupeshblr:

You’ve been asked to fill out some more details on several other questions without following through. In what form do you expect instructions to be fed to your design? Real hardware does not understand assembly instruction—only binary data.

In reply to rupeshblr:

[quote]In reply to rupeshblr:

Please look at the following example code.

module x;
  initial begin
  randsequence(main)
    main: code_block1 code_block2;
  code_block1: { 
    			$display("IF.nz LABEL1"); 
    			$display("..<next instruction>"); 
    $display("ENDIF\n"); 
    			} ;
  code_block2: {
    			$display("LABEL1");     			
    $display("rest of the instructions under LABEL1\n");     					   };
  endsequence
  end
endmodule

What is shown here is probably 1% of what randsequence can do. Please go through randsequence thouroughly in order to understand how to randomize etc.

In reply to shatrish:

[quote]In reply to rupeshblr:

Thank you :)
let me explain in other way ,

Specification :- i am writtting the sv based random test for ISS.

System verilog based random test (Input) and use the $display function to make assembly instruction format(.asm) --------> <<>> ------> generate the binaray code(.bin) ----> <<<<> final output(TXT File)

So i am trying to write the “System verilog based random test (Input) and use the $display function to make assembly instruction format(.asm)”

To get the above, i am writing the System verilog code constrained code and Output (basically the $display to make assembly kind program) will be Assembly code format

Lets say i want to verify the “ADD ” instruction. here my input (src0 and src1) are image input so it will have many other field which need to be constrained and randomized (thats why i choosed the SV)

Example :-ADD_.v1 <{options}>
output Should be** :-
ADD_s16.v1 mR4 [[0,0],[8,8],1] mR0 [[0,0],[8,8],2] 0 {dstmod.nml,dstszm…}

Where below field has to be randomized
format : { u8 | u16 | u32 | u64 …}
dst : …]
src0 : [[0,0],[dispX,dispY],1]
src1 : [[x,y],[dispX,dispY],1] : For sR, mR

RegType : { sR | mR }
RegNum0 to RegNum2 : { For mR, 0 to 127 | For sR, 0 to 31 }
immediate : { 0 to FFFFh }
x : { For 1D, 0 to 63 | For 2D, 0 to 7 }
y : { For 1D, always 0 | For 2D, 0 to 7 }

So like ADD, i have 200 instruction set which need to be tested.
Another example is “IF.nz A36 LABEL1”

Since i can not generate all the instruction field by writing direct test thus i am using the randomization function.

In reply to rupeshblr:

Any suggest would be appreciated . Looking forward to see some solution here.

In reply to rupeshblr:

Now what you are doing makes more more sense. You are trying to write code that outputs assembly language text that will be compiled in a later step. What you have shown is informal syntax.

You need to understand the format of the assembly code from the the perspective of the compiler and express it in formal BNF production terms. Only then you can begin to use randsequence to generate random sequences of instructions based on the BNF rules. The LRM has a very simple example of this

randsequence( main )
  main : first second gen ;
  first : add | dec ;
  second : pop | push ;
  add : gen("add") ;
  dec : gen("dec") ;
  pop : gen("pop") ;
  push : gen("push") ;
  gen( string s = "done" ) : { $display( s ); } ;
endsequence

You can add random repetition and registers to this with

randsequence( main )
main : statements;
statements: repeat ($urandom_range(100,1) statement;
statement: first second gen ;
first : add | dec ;
second : pop | push ;
add : gen("add") sReg dReg endline;
dec : gen("dec") dReg endline;
pop : gen("pop\n") ;
push : gen("push\n") ;
sReg  : gen($sformatf("[s%0d]",$urandom_range(127,1))) ;
dReg  : gen($sformatf("[d%0d]",$urandom_range(16,1))) ;
endline : gen("\n"); 
gen( string s = "done" ) : { $write( s ); } ;
endsequence

In reply to dave_59:

In reply to rupeshblr:
Now what you are doing makes more more sense. You are trying to write code that outputs assembly language text that will be compiled in a later step. What you have shown is informal syntax.
You need to understand the format of the assembly code from the the perspective of the compiler and express it in formal BNF production terms. Only then you can begin to use randsequence to generate random sequences of instructions based on the BNF rules. The LRM has a very simple example of this

randsequence( main )
main : first second gen ;
first : add | dec ;
second : pop | push ;
add : gen("add") ;
dec : gen("dec") ;
pop : gen("pop") ;
push : gen("push") ;
gen( string s = "done" ) : { $display( s ); } ;
endsequence

You can add random repetition and registers to this with

randsequence( main )
main : statements;
statements: repeat ($urandom_range(100,1) statement;
statement: first second gen ;
first : add | dec ;
second : pop | push ;
add : gen("add") sReg dReg endline;
dec : gen("dec") dReg endline;
pop : gen("pop\n") ;
push : gen("push\n") ;
sReg  : gen($sformatf("[s%0d]",$urandom_range(127,1))) ;
dReg  : gen($sformatf("[d%0d]",$urandom_range(16,1))) ;
endline : gen("\n"); 
gen( string s = "done" ) : { $write( s ); } ;
endsequence

Thanks Dave .

i am implementing above scenario in the below manner.

Is it not the right approach.

  1. created the base class.
    typedef enum bit [4:0] {ADD=’h00, SUB, MUL, DIV, …} compute_path_pipe ;
    typedef enum bit [3:0] { IF=’h20, ELSE, ENDIF, …} flow_control_pipe;

typedef enum bit [1:0] {MOVI=’h40, …} move_pipe;

…like i classified all the instruction

typedef enum bit [1:0] {vec1_64,…} instruction_length ;

//TYPE FORMAT
typedef enum bit[3:0] [u8,u16,…] format;

//TYPE OF REGISTER
typedef enum {sR, mR} RegType;

// 1D and 2D
typedef enum [one_D, two_D] dimesion ;

//dstmod
typedef enum {nml, sat} dstmod

//variable for declare for DDL (0 to 63)
rand logic[63:0] DDL ;

// variable for src0mod (nml | neg | abs | nabs},)
typedef enum bit[1:0] {nml, neg,…} src0mod;

//variable for emd (0,1)
rand logic emd ;

// variable for bd
rand logic bd;

class operand; (BAse class definition )
rand format format_t;
rand RegType RegType_t;
rand int Regnum;
rand int x,y,dispX,dispY,p;
rand int w,z ;
rand compute_path_pipe compute_path_pipe_t;
rand flow_control_pipe flow_control_pipe_t;

    ........
  rand dimesion dimesion_t;
  rand src0mod src0mod_t ;
  rand dstmod dstmod_t;

constraint operand_constraint {
// x inside {[0:31]}; y inside {[0:31]}; dispX inside {[0:31]}; dispY inside {[0:31]};
// knobs is a packagege
format dist {u8:=knobs::W1,s8:= knobs::W1,u16 := knobs::W1,u32:= knobs::W1,s16:= knobs::W1,s32:= knobs::W1,f32:= knobs::W1,u64:= knobs::W1,f64 := knobs::W1};

// write constraint for regnumber wrt mR and sR
constraint regnumber_range_c { 
   solve Regtype before Regnum;
   (Regtype_t == sR) -> Regnum inside {[0:31]};
   (Regtype_t == mR) -> Regnum inside {[0:127]};
}


constraint xandy_c {
 if (dimesion_t == one_D) 
       x inside {[0:63]};
	   Y
	   = 0;
	   
 else if (dimesion_t == two_D)
       x inside {[0:7]};
	   y inside {[0:7]};

}

endclass

now i am creating the child component based the instruction (who has similar instruction field grouped all gather )

Example :-
class add_type extends operand ;


 endclass

so like that creating the multiple child class based the instruction.

After that from top level, will create the object of child class and will randomize and will display based on Instruction mnemonics.

add_type C1;
initial begin
c1=new;
repeat(1) begin
c1.randomize();

$display(“c1.format=%d c1.Regtype=%d, c1.Regnum=%d, c1.x=%d,
c1.y=%d\n” ,c1.format,c1.Regtype,c1.Regnum,c1.x,c1.y);
end
end

So is this approach is correct way to achieve that.

Kindly suggest me.
Looking forward to your reply :)

In reply to rupeshblr:

Hi Dave,

Can you suggest something here ?

Am i doing right ?

In reply to rupeshblr:

Without a specification for what your instruction set looks like (and some valid example solutions), it is difficult to answer. And probably to much detail to be addressed in this forum. I suggest you look for some local help.

In reply to dave_59:

In reply to rupeshblr:
Without a specification for what your instruction set looks like (and some valid example solutions), it is difficult to answer. And probably to much detail to be addressed in this forum. I suggest you look for some local help.

I am writing the randomize constraint Sv test for ISS (Instruction Simulator) (which basically takes the binary input ). to verify the my ISS(software platform) which has been design to verify the processor instruction properly or not

i will write the SV code and using $display i will covert it as a assembly level code.(since assembly language i cant randomize the instruction field that is why i choosed the system verilog )

Write now i am writing Manually Assembly code one by one to verify the ISS.

Objective :- SV has to generate this code

Examample :-
MOVI_u16.v1 sR1 [[0,0],[1,1],1] 0x1
MOV_u16.v1 A36 [[0,0],[1,1],1] sR1 [[0,0],[1,1],1] {inv.0,predsel.simd,chanIndexEn.0,rep.0,walkSz.disp,emd.1,bd.0,RLT.1D}
IF.nz A36 LABEL1
MOVI_u16.v1 mR0 [[0,0],[8,8],1] 0x2f
STORE_u16.v1 mR0 OB[0] [[0,0],[8,8],1] {IMOD.disp_thrd,IFMT.indx,IDIM.2d,immIndxFmt.indx,ARE.0,ARI.0,2x2.0,RLT.TD,IMMX.0,IMMY.0,lock.0,emd.0,indx_sign.0,bd.0,ARM.nml,bufIDIndexEn.0,indexBankOff.0,strideSel.0,elemFmtSel.0,invalidateEn.0}
ENDIF A36
EOT

Here MOVI is Opcode and after everything is instruction field and it can be randomize like u16 can be any value like [u8,u16,u32,u64,s8,s16,s32,s64,f32,f64]… like all instruction feild can be randomazie based on specification.

Generic format :
MOV_. {options}

Format, dimension, dst, src,—> has to be randomize

So i have to create the Class based test which can generate the assembly code.

After randomization i will display the instruction into my Input format (which will be my assembly code ) based on the specification i can write the $display and here i am displaying only few field but i can add all instruction field so the $display will print like :-

Like:-

$display(“c1.format=%d c1.Regtype=%d, c1.Regnum=%d, c1.x=%d,
c1.y=%d\n” ,c1.format,c1.Regtype,c1.Regnum,c1.x,c1.y);
end

Output :- MOVI_u16.v1 sR1 [[0,0],[1,1],1] 0x1

I believe, whatever i wrote is making sense of what i trying to implement.

Kindly guide me whether my approach(mentioned in the above Reply ) is correct or not ?