Implement Randc Function Using Rand in System Verilog ?
Implement Randc Function Using Rand in System Verilog ?
Implement Randc Function Using Rand in System Verilog ?
System Verilog ?
Companies Related Questions, Functional Verification, System Verilog October
10, 2018DV admin 0 Comments
How do you implement randc function using rand in system verilog ?
Program :
randc : it is random number with no repetition for a cycle. it may repeat once it
complete one cycle.
module randc_function;
class rand_clas;
endfunction
list.push_back(myvar);
endfunction
endclass:rand_clas
initial
begin
int x;
if(rand_class.randomize());
end
end
endmodule:randc_function
output
************************************
sucsessfull : Var = 0
sucsessfull : Var = 2
sucsessfull : Var = 3
sucsessfull : Var = 1
sucsessfull : Var = 3
sucsessfull : Var = 2
sucsessfull : Var = 0
sucsessfull : Var = 1
sucsessfull : Var = 2
sucsessfull : Var = 0
sucsessfull : Var = 1
sucsessfull : Var = 3
sucsessfull : Var = 2
sucsessfull : Var = 3
sucsessfull : Var = 0
sucsessfull : Var = 1
sucsessfull : Var = 0
sucsessfull : Var = 1
sucsessfull : Var = 3
sucsessfull : Var = 2
sucsessfull : Var = 1
module unique_array;
class data;
rand bit [7:0] data[];
constraint data_values { foreach(data[i])
foreach(data[j])
if(i != j) data[i] != data [j] ;}
endclass
data cl_ob;
initial
begin
cl_ob = new();
cl_ob.data = new[5];
assert(cl_ob.randomize());
foreach(cl_ob.data[i])
$display(“%d”,cl_ob.data[i]);
end
endmodule
module fork_test;
initial begin
for (int j=0; j<3; j++)
begin
fork
$display(j);
join_none
end
end
endmodule
Output
3
3
3
It outputs 3 because there is only one variable j shared by all the threads, and its
value is 3 before any of the threads start executing. None of the threads spawned
by the fork/join_none start executing until the thread spawned by the initial
block finishes.
module fork_test1;
initial begin
for (int j=0; j<3; j++)
begin
#1;
fork
$display(j);
join_none
end
end
endmodule:fork_test1
if you put delay , thread will see different values of j ..but will miss first value .. 0
Output
1
2
3
Using AutoMatic
module fork_test;
initial begin
for (int j=0; j<3; j++)
begin
fork
automatic int k=j;
$display(k);
join_none
end
end
endmodule:fork_test
Output
0
1
2
Example 1
endfunction
endclass: BaseC
endfunction
endclass : DerivedC
BaseC P1 ;
DerivedC P2 = new;
initial begin
P1 = P2;
P1.func1;
end
endmodule
Output
func1 in DerivedC
Example 2
module poly_case2;
class BaseC;
virtual function void func1;
$display (“func1 in BaseC”);
func2;
endfunction
endclass: BaseC
endclass : DerivedC
BaseC P1 ;
DerivedC P2 = new;
initial begin
P1 = P2;
P1.func1;
end
endmodule:poly_case2
output
func1 in DerivedC
func2 in DerivedC
But Interface can’t be instantiated inside program block, class (or similar non-
module entity in SystemVerilog). But they needed to be driven from verification
environment like class. To solve this issue virtual interface concept was
introduced in SV.
SystemVerilog adds the clocking block that identifies clock signals and captures
the timing and synchronization requirements of the blocks being modeled. A
clocking block assembles signals that are synchronous to a particular clock and
makes their timing explicit. The clocking block is a key element in a cycle-based
methodology, which enables users to write testbenches at a higher level of
abstraction. Rather than focusing on signals and transitions in time, the test can
be defined in terms of cycles and transactions. Depending on the environment, a
testbench can contain one or more clocking blocks, each containing its own clock
plus an arbitrary number of signals. The clocking block separates the timing
and synchronization details from the structural, functional, and procedural
elements of a Testbench.
Thus, the timing for sampling and driving clocking block signals is implicit and
relative to the clocking block’s clock. This enables a set of key operations to be
written very succinctly, without explicitly using clocks or specifying timing.
These operations are as follows:
— Synchronous events
— Input sampling
— Synchronous drives
Clocking block in SystemVerilog are used for specifying the clock signal, timing,
and synchronization requirements of various blocks. It separates the timing
related information from structural, functional and procedural element of the TB.
There are quite a few links on clocking block in the internet.
Example :
01.Module Clocking (ck, enin, din, enout, dout);
02.input ck,enin;
03.input [31:0] din ;
04.output enout ;
05.output [31:0] dout ;
06.
07.clocking sd @(posedge ck);
08.input #2ns ein,din ;
09.output #3ns enout, dout;
10.endclocking:sd
11.
12.reg [7:0] sab ;
13.initial begin
14.sab = sd.din[7:0];
15.end
16.endmodule:Clocking
Home
AboutUs
Functional Verification
o System Verilog
o Verilog
o UVM
o Normal Adder UVM verification
o Synchronous fifo uvm testbench
o Memory UVM testbench
Formal Verification
o Introduction to Formal Verification
o Formal Verification
Companies Questions
Comp Architecture
Contact Us
HOME
ABOUTUS
FUNCTIONAL VERIFICATION
o SYSTEM VERILOG
o VERILOG
o UVM
o NORMAL ADDER UVM VERIFICATION
o SYNCHRONOUS FIFO UVM TESTBENCH
o MEMORY UVM TESTBENCH
FORMAL VERIFICATION
o INTRODUCTION TO FORMAL VERIFICATION
o FORMAL VERIFICATION
COMPANIES QUESTIONS
COMP ARCHITECTURE
CONTACT US
Home » Companies Related Questions » What is callback ?
What Is Callback ?
Companies Related Questions, System Verilog September 14, 2018DV admin 0
Comments
We can pass data member to any function. Now consider a case where you are
passing a function (say func1) as a data member to another function (say func2)
and you get what is called callback. The reason why it is called callback is that the
function func2 now can call anywhere in its code function func1.
From wikipedia
In computer programming, a callback is executable code that is passed as an
argument to other code. It allows a lower-level software layer to call a subroutine
(or function) defined in a higher-level layer.
Example:-
class abc_transactor;
virtual task pre_send(); endtask
virtual task post_send(); endtask
task xyz();
// Some code here
this.pre_send();
// Some more code here
this.post_send();
// And some more code here
endtask : xyz
endclass : abc_transactor
endclass : my_abc_transactor
Now let me explain how it is going to work. The base class abc_transactor has 3
tasks, 2 of which are declared virtual and are not implemented. But they are
being called from another task xyz() which is fully implemented. The
unimplemented virtual task are called callback class.
The child class, which extends from the base class, implements the previous
unimplemented tasks. It inherits the xyz() task from the base class and hence
doesn’t need to change it. By this we can inject executable code to a function
without modifying it.
Now the next question is why is done. There are many reasons for it.
1. The biggest advantage is that you can modify the behavior of task xyz()
without modifying it in the base or child class. It is a big advantage as no
one wants to fiddle with known good functioning code.
2. Consider a case where you are writing a base class which is going to be
used by multiple test environment, and for each test environment a known
part of the code, or a known function/task is going to change. The natural
choice is to implement those change-in-every-case functions/tasks as
callback method and let the user extend your base class with specifying
only that part of the code which need to be changed in his case.
Simple callback using the above approach does have some known
limitations, which can be solved using design patterns (from OOP land),
the details of which can be found at Janik’s article of vmm_callback.
Suppose if you are doing transmitting data using mailboxes, Once you are
send ing data to design from genetarator . The same data you need to put
back in score board for latter comparison. This is called callbacks
Home
AboutUs
Functional Verification
o System Verilog
o Verilog
o UVM
o Normal Adder UVM verification
o Synchronous fifo uvm testbench
o Memory UVM testbench
Formal Verification
o Introduction to Formal Verification
o Formal Verification
Companies Questions
Comp Architecture
Contact Us
HOME
ABOUTUS
FUNCTIONAL VERIFICATION
o SYSTEM VERILOG
o VERILOG
o UVM
o NORMAL ADDER UVM VERIFICATION
o SYNCHRONOUS FIFO UVM TESTBENCH
o MEMORY UVM TESTBENCH
FORMAL VERIFICATION
o INTRODUCTION TO FORMAL VERIFICATION
o FORMAL VERIFICATION
COMPANIES QUESTIONS
COMP ARCHITECTURE
CONTACT US
Home » Companies Related Questions » During a project if we observe high code coverage and low functional
coverage what can be inferred and other way around ?
3) There could be a possibility that tests and stimulus exists for covering all
features but those might be failing because of some bugs and hence being
excluded from the measurement for functional coverage.
HOME
ABOUTUS
FUNCTIONAL VERIFICATION
o SYSTEM VERILOG
o VERILOG
o UVM
o NORMAL ADDER UVM VERIFICATION
o SYNCHRONOUS FIFO UVM TESTBENCH
o MEMORY UVM TESTBENCH
FORMAL VERIFICATION
o INTRODUCTION TO FORMAL VERIFICATION
o FORMAL VERIFICATION
COMPANIES QUESTIONS
COMP ARCHITECTURE
CONTACT US
Home » Companies Related Questions » What is the practical application of associative arrays in SV? Can you
explain with a scenario?
When the size of the collection is unknown or the data space is sparse, an
associative array is used, which does not have any storage allocated until it is
used. That means, it is dynamically allocated, but has non-contiguous elements.
Associative array’s index expression is not restricted to integral expressions, but
can be of any type.
Practical Example
// This class is generated using static method and use of associative array !
db[name]= value;
endfunction
static function void get(input string name , ref T value);
value= db[name];
endfunction
foreach(db[i])
$diaplay(“db[%s} =%p”,i,db[i]);
endfunction
endclass
class Dv_testing;
int i,j;
endclass
int i=2;
int val;
real pi=3.14;
Dv_testing dv;
initial begin
uvm_type_of_config_db#(int)::set(“i”,i);
uvm_type_of_config_db#(real)::set(“pi,pi);
dv=new()
dv.i=8;
dv.j=6;
uvm_type_of_config_db#(Dv_testing)::set(“dv”,dv);
uvm_type_of_config_db#(int)::get(“i”,val);
uvm_type_of_config_db#(int)::print();
uvm_type_of_config_db#(real)::print();
uvm_type_of_config_db#(Dv_testing)::print();
end
like
Class myClass
int Func(int x) { }
int Func(string s) { }