Asic Interview Questions
Asic Interview Questions
Labels
ASIC Flow (1) Showing posts with label ASIC SystemVerilog. Show all posts
ASIC Gate (3)
ASIC Logic (4) Thursday, November 4, 2010
ASIC SystemVerilog (10)
ASIC timing (2) SystemVerilog Q&A
ASIC Verification (1) 1. What's difference between static and automatic task/program?
C++ (2)
Design Complier (1) If you use static task for multiple places in your testbench, the local variables will share the common, static
Memory Interface (1) storage. In this case, different threads will step on each other's values.
Networking (2) By using atuotmic storage, it will make a copy of local variables and use them. Not a common static storage
perl (9) any more.
PLL (1)
Previous Interview Questions (1)
e.g. program automatic initialization;
PrimeTime (1)
SVA (2)
......
Verilog Interview Questions (6) endprogram
In this case, all 32 bits word are packed with 4 bytes. A packed array is handy if you need to convert to and
from scalars.
Visitor's counter
3. What's different between logic and wire?
Logic and wire are almost the same except wire can be driven by multiple sources. Logic can only driven by
Visitor Counter single source.
Posted by Roy Chan at 6:47 AM No comments:
Labels: ASIC SystemVerilog
About Me
Roy Chan Saturday, June 5, 2010
Polymorphism allows an entity to take a variety of representations. Polymorphism means the ability to
request that the same Operations be performed by a wide range of different types of things. Effectively, this
means that you can ask many different objects to perform the same action. Override polymorphism is an
override of existing code. Subclasses of existing classes are given a "replacement method" for methods in the
superclass. Superclass objects may also use the replacement methods when dealing with objects of the subtype.
The replacement method that a subclass provides has exactly the same signature as the original method in the
superclass.
RESULTS
This is class A
This is Extended class A
Answers:
There are 2 types of copy. Show copy or deep copy
program main;
initial
begin
B b1;
B b2;
b1 = new();
b1.i = 123;
b2 = b1; // b1 and b2 point to the same memory. The properties did not get copied.
$display( b2.i );
end
endprogram
RESULTS:
123
123
321
If the value of b1 change, it will also change the value of b1. It's because it's pointing to the same memory.
Deep Copy
A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. To
make a deep copy, you must write a copy constructor and overload the assignment operator, otherwise the
copy will point to the original, with disasterous consequences.
EXAMPLE:
class A;
int i;
endclass
class B;
A a;
task copy(A a);
this.a = new a;
endtask
endclass
program main;
initial
begin
B b1;
B b2;
b1 = new();
b1.a = new();
b1.a.i = 123;
b2 = new b1;
b2.copy(b1.a);
$display( b1.a.i );
$display( b2.a.i );
b1.a.i = 321;
$display( b1.a.i );
$display( b2.a.i );
end
endprogram
RESULTS:
123
123
321
123
The kill() task terminates the given process and all its sub-processes, that is, processes spawned using fork
statements by the process being killed. If the process to be terminated is not blocked waiting on some other
condition, such as an event, wait expression, or a delay then the process shall be terminated at some
unspecified time in the current time step.
Cross allows keeping track of information which is received simultaneous on more than one cover point. Cross
coverage is specified using the cross construct.
The program block does not allow always block. Only initial and methods are allowed, which are more
controllable.
SystemVerilog final blocks execute in an arbitrary but deterministic sequential order. This is possible because
final blocks are limited to the legal set of statements allowed for functions.
EXAMPLE :
module fini;
initial
#100 $finish;
final
$display(" END OF SIMULATION at %d ",$time);
endmodule
RESULTS:
Posted by Roy Chan at 9:29 PM No comments:
Labels: ASIC SystemVerilog
Answer:
Dynamic arrays are useful for dealing with contiguous collections of variables whose number changes
dynamically.
e.g. int array[];
When the size of the collection is unknown or the data space is sparse, an associative array is a better
option. In associative array, it uses the transaction names as the keys in associative array.
e.g. int array[string];
SystemVerilog introduces a new foreign language interface called the Direct Programming Interface (DPI). The
DPI provides a very simple, straightforward, and efficient way to connect SystemVerilog and foreign language
code unlike PLI or VPI.
A coverage-point bin associates a name and a count with a set of values or a sequence of value transitions. If
the bin designates a set of values, the count is incremented every time the coverage point matches one of the
values in the set. If the bin designates a sequence of value transitions, the count is incremented every time the
coverage point matches the entire sequence of value transitions.
e.g.
program main;
bit [0:2] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y
{ option.auto_bin_max = 4 ; }
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
Coverage Driven Verification is a result oriented approach to functional verification. The manager and
verification terms define functional coverage points, and then work on the detail of process.
Used effectively coverage driven verification focuses the Verification team on measurable progress toward an
agreed and comprehensive goal.
In pass by reference functions and tasks directly access the specified variables passed as arguments.Its like
passing pointer of the variable.
example:
task pass(int i) // task pass(var int i) pass by reference
{
delay(10);
i = 1;
printf(" i is changed to %d at %d\n",i,get_time(LO) );
delay(10);
i = 2;
printf(" i is changed to %d at %d\n",i,get_time(LO) );
}
The module is the basic building block in Verilog which works well for Design. However, for the testbench, a lot
of effort is spent getting the environment properly initialized and synchronized, avoiding races between the
design and the testbench, automating the generation of input stimuli, and reusing existing models and other
infrastructure.
Systemverilog adds a new type of block called program block. Systemverilog adds a new type of block called
program block. The program construct serves as a clear separator between design and testbench, and, more
importantly, it specifies specialized execution semantics in the Reactive region for all elements declared within
the program. Together with clocking blocks, the program construct provides for race-free interaction between
the design and the testbench, and enables cycle and transaction level abstractions.
8) Describe the difference between Code Coverage and Functional Coverage Which is more important and Why
we need them.
Code Coverage indicates the how much of RTL has been exercised. The Functional Coverage indicates which
features or functions has been executed. Both of them are very important. With only Code Coverage, it may
not present the real features coverage. On the other hand, the functional coverage may miss some unused RTL
coverage.
Answer:
The functionality of the seed arguments are different for $random and $urandom. The seed argument to
$random is an inout. It updates its seed argument after each call to $random. This means the internal random
number generator (RNG) state variable is a 32-bit number.
The seed argument to $urandom is an input. This seed is used to set the internal RNG to a value that is over 32-
bits (typically 96-bits or greater).
In SystemVerilog, each thread has its own RNG, so only use the the seed argument on the first call to $urandom
in each thread. There is also a way to set the seed without generated a random value by using the built-in
process class and using the srandom() method.
class packet;
rand bit [7:0] header;
initial begin
packet p=new;
p.new(33);
end
program Rand_seed_p_80;
Rand_seed rs;
initial
begin
rs = new(20);
repeat(5)
void'(rs.randomize());
rs = new(1);
repeat(5)
void'(rs.randomize());
rs = new(20);
repeat(5)
void'(rs.randomize());
end
endprogram
Posted by Roy Chan at 5:41 PM No comments:
Labels: ASIC SystemVerilog
Answer:
Modport restrict interface access within a module based on the direction declared. Directions of signals are
specified as seen from the module.
e.g.
interface intf (input clk);
logic read, enable,
logic [7:0] addr,data;
modport dut (input read,enable,addr,output data);
modport tb (output read,enable,addr,input data);
endinterface :intf
2) How parallel case and full cases problems are avoided in SV?
The full_case and parallel_case directives are dangerous because they tell the synthesis tool
something different about the design than what is told to the simulator.
To the Verilog simulator, full_case and parallel_case are buried inside of Verilog
comments and are completely ignored. To the synthesis tool, full_case and parallel_case
are command-directives that instruct the synthesis tools to potentially take certain actions or
perform certain optimizations that are unknown to the simulator.
A full case statement is a case statement in which all possible case-expression binary patterns
can be matched to a case item or to a case default.
module mux3c
(output reg y,
input [1:0] sel,
input a, b, c);
always @*
case (sel)
2'b00: y = a;
2'b01: y = b;
2'b10: y = c;
default: y = 1'bx;
endcase
endmodule
// Use synopsys full_case statement to create the full case , but it treated differently in simulation and
synthesis.
module mux3b (y, a, b, c, sel);
(output reg y,
input [1:0] sel,
input a, b, c);
always @*
case (sel) // synopsys full_case
2'b00: y = a;
2'b01: y = b;
2'b10: y = c;
endcase
endmodule
SystemVerilog use priority modified case statement to solve the full case problem.
The biggest difference between a full_case directive and a priority modified case statement
is that the priority keyword is part of the SystemVerilog syntax that will be interpreted the
same by simulators, synthesis tools and formal verification tools. In essence, the priority case
statement is a "safe" full_case case statement.
e.g.
priority case (...)
...
endcase
A parallel case statement is a case statement in which it is only possible to match any case
expression to one and only one case item.
module intctl1b
(output reg int2, int1, int0,
input [2:0] irq );
always @* begin
{int2, int1, int0} = 3'b0;
casez (irq) // synopsys parallel_case
3'b1??: int2 = 1'b1;
3'b?1?: int1 = 1'b1;
3'b??1: int0 = 1'b1;
endcase
end
endmodule
This is an example that demonstrates that adding the parallel_case directive makes the design
smaller and faster, but in the process it also adversely changes the functionality of the design.
Guideline: Code all intentional priority encoders using if-else-if statements. It is easier for
the typical design engineer to recognize a priority encoder when it is coded as an if-else-if
statement.
Posted by Roy Chan at 4:23 PM No comments:
Labels: ASIC SystemVerilog
Answer:
The super keyword is used from within a derived class to refer to members of the parent class. It is necessary to
use super to access members of a parent class when those members are overridden by the derived class.
EXAMPLE:
class parent;
task printf();
$display(" THIS IS PARENT CLASS ");
endtask
endclass
class subclass extends parent;
task printf();
super.printf();
endtask
endclass
program main;
initial
begin
subclass s;
s = new();
s.printf();
end
endprogram
RESULT
Answer:
rand are standard random variables. When there are no other control on distrubution, these variables are
uniformly distributed across valid values.
randc are random cyclic that randomly iterates over all the values in the range and no value is repeated with
in an iteration until every possible value has been assigned.
3) What is solve...before constraint ?
Answer:
constraint order { solve a before b ;}
This guides the solver to give highest priority to a than b while picking the solution from solution space.
Answer:
4) What is the difference between fork/joins, fork/join_none fork/join_any ?
Fork Join None: The parent process continues to execute concurrently with all the processes spawned by the
fork. The spawned processes do not start executing until the parent thread executes a blocking statement.
Fork Join Any: The parent process blocks until any one of the processes spawned by this fork completes.
For Join All: The parent process blocks until all the processes spawned by this fork complete.
Posted by Roy Chan at 3:32 PM 1 comment:
Labels: ASIC SystemVerilog
Answer:
int q[$] = { 2, 4, 8 };
int p[$];
int e, pos;
e = q[0]; // read the first (leftmost) item
e = q[$]; // read the last (rightmost) item
q[0] = e; // write the first item
p = q; // read and write entire queue (copy)
A mailbox is a communication mechanism that allows messages to be exchanged between processes. Data can
be sent to a mailbox by one process and retrieved by another.
Answer:
In SV, we use mailbox to get data from different modules and compare the result.
class Scoreboard;
mailbox drvr2sb;
mailbox rcvr2sb;
task start();
packet pkt_rcv,pkt_exp;
forever
begin
rcvr2sb.get(pkt_rcv);
$display(" %0d : Scorebooard : Scoreboard received a packet from receiver ",$time);
drvr2sb.get(pkt_exp);
if(pkt_rcv.compare(pkt_exp))
$display(" %0d : Scoreboardd :Packet Matched ",$time);
else
$root.error++;
end
endtask : start
endclass
In VMM, we use channels to connect all the modules and compare the result.
Packet_channel drvr2sb_chan;
Packet_channel rcvr2sb_chan;
super.new("sb",inst,stream_id);
if(drvr2sb_chan == null)
`vmm_fatal(this.log,"drvr2sb_channel is not constructed");
else
this.drvr2sb_chan = drvr2sb_chan;
if(rcvr2sb_chan == null)
`vmm_fatal(this.log,"rcvr2sb_channel is not constructed");
else
this.rcvr2sb_chan = rcvr2sb_chan;
`vmm_note(log,"Scoreboard created ");
endfunction:new
task main();
Packet pkt_rcv,pkt_exp;
string msg;
super.main();
forever
begin
rcvr2sb_chan.get(pkt_rcv);
$display(" %0d : Scoreboard : Scoreboard received a packet from receiver ",$time);
drvr2sb_chan.get(pkt_exp);
if(pkt_rcv.compare(pkt_exp,msg))
$display(" %0d : Scoreboard :Packet Matched ",$time);
else
`vmm_error(this.log,$psprintf(" Packet MissMatched \n %s ",msg));
end
endtask : main
endclass
Queue has a certain order. It's hard to insert the data within the queue. But Linkedlist can easily insert the
data in any location.
Using Casting one can assign values to variables that might not ordinarily be valid because of differing data
type. SystemVerilog adds 2 types of casting. Static casting and dynamic casting.
// Dynamic casting
function int $cast( singular dest_var, singular source_exp );
or
task $cast( singular dest_var, singular source_exp );
Q. What is an object?
Objects are instances of classes. Class is a collection of similar kind of objects. When a class is created it
doesn’t occupy any memory, but when instances of class is created i.e., when objects are created they occupy
memory space.
Q. What is encapsulation?
A1. Encapsulation is welding of code and data together into objects.
Q. What is inheritance?
A2. Inheritance is a mechanism through which a subclass inherits the properties and behavior of its superclass.
The derived
class inherits the properties and method implementations of the base class and extends it by overriding
methods and adding additional properties and methods.
Q. What is polymorphism?
A3. In Greek this means "many shapes."As a consequence of inheritance and virtual functions, a single task (for
example, drawing
a geometrical shape) can be implemented using the same name (like draw()) and implemented differently (via
virtual functions) as each type in object hierarchy requires(circle.draw() or rectangle.draw()). Later, when a
polymorphic object (whose type is not known at compile time) executes the draw() virtual function, the
correct implementation is chosen andexecuted at run time.
Q. What is the difference between function overloading and function overriding?
A. Overloading is a method that allows defining multiple member functions with the same name but different
signatures. The compiler will pick the correct function based on the signature. Overriding is a method that
allows the derived class to redefine the behavior of member functions which the derived class inherits from a
base class. The signatures of both base class member function and derived class member function are the same;
however, the implementation and, therefore, the behavior will differ
Q. What are the advantages of OOP?
Virtual tasks and functions are the ways to achieve the polymorphism in system verilog. Try to fun the following
example and see it will help you understand the concept.
class base ;
virtual function int print;
$display("INSIDE BASE \n");
endfunction : print
endclass : base
program test ;
derived d1;
initial
begin
d1 = new();
d1.print();
callPrint (d1);
end
endprogram
What is the use of the abstract class?
A virtual class is a temple or place holder for the child classes. A virtual class is also called as the abstract class.
A virtual class is declared with a virtual keyword like :
virtual class base;
virtual task1;
endtask;
virtual task2;
endtask;
endclass;
A virtual class instance or object can not be constucted but you can define the hadle to the virtual class.
virtual class baseframe;
...
virtual function void iam();
endfunction
...
endclass
baseframe two; // OK
initial begin
two = new(4); // ERROR
...
Virtual interfaces provide a mechanism for separating abstract models and test programs from the actual signals
that make up the design. A virtual interface allows the same subprogram to operate on different portions of a
design and to dynamically control the set of signals associated with the subprogram. Instead of referring to the
actual set of signals directly, users are able to manipulate a set of virtual signals. Changes to the underlying
design do not require the code using virtual interfaces to be rewritten. By abstracting the connectivity and
functionality of a set of blocks, virtual interfaces promote code reuse.
Virtual interfaces can be declared as class properties, which can be initialized procedurally or by an argument
to new(). This allows the same virtual interface to be used in different classes. The following example shows
how the same transactor class can be used to interact with various different devices:
endclass
Its an intuitive, easy to learn language that combines the familiarity and strengths of HDLs, C++ and Java with
additional constructs targeted at functional verification that makes it ideal for developing testbenches,
assertions and properties.
2) What is SVA?
3) What is Callback?
The term factory method is often used to refer to any method whose main purpose is creation of objects.
e.g.
program main;
// Create object type my_class
my_class obj1;
obj1 = new
endprogram
// Using Factory I should be able to do the following
program main;
base_class my_class_object;
base_class = factory.create_object("my_class"); // See here the type of the object to be created is passed
as a string so we dont know the exact type of the object
endprogram
5) What's the difference between data type logic, reg and wire?
e.g.
7) What are the ways to avoid race condition between testbench and RTL using SystemVerilog?
There are mainly following ways to avoid the race condition between testbench and RTL using system verilog
1. Program Block
2. Clocking Block
3. Using non blocking assignments.
According to the eRM and OVM monitors and drivers should always be completely separate. This approach was
adopted mainly in order to facilitate reuse of block level agents in a top level testbench: at block level both
driver and monitor are used, while at top level only the monitor is used.
A systemverilog event is now a handle to a synchronization object that can be passed around to routines. The
events can be shared across objects without having to make the events global.
Both Code Coverage and Functional Coverage are available in SV. You can use the following examples:
class eth_frame;
// Definitions as above
covergroup cov;
coverpoint dest {
bins bcast[1] = {48'hFFFFFFFFFFFF};
bins ucast[1] = default;
}
coverpoint type {
bins length[16] = { [0:1535] };
bins typed[16] = { [1536:32767] };
bins other[1] = default;
}
psize: coverpoint payload.size {
bins size[] = { 46, [47:63], 64, [65:511], [512:1023], [1024:1499], 1500 };
}