1) How do you swap two integers? Without another variable?
Answer:
example main.cpp
void main()
{
int a=2, b=3;
swap (a, b);
}
swap ( int &a, int &b) // pass by reference
{
int tmp = a;
a = b;
b = tmp;
}
Without a third variable
swap ( int &a, int &b)
{
a = a +b; // a = 2 +3 =5
b = a-b; // b = 5-3 =2
a = a -b; // a = 5 - 2 = 3, a and b swap
}
template < class T>
void swap ( T &a, T &b)
{
T tmp =a;
a = b;
b = tmp;
}
use swap (a, b ) to call the swap. It can swap any data type.
Sunday, May 30, 2010
C++ Interview algorithms questions
1) Reverse a single linked list
Answer code:
Node* ReverseList(Node ** List) // Provide a link list
{
// Declare 3 pointer variable
Node *head = *List;
Node *temp2 = NULL;
Node *temp3 =NULL;
while(head)
{
*List = head; // set the head to last node
temp2 = head->pNext; // save the next ptr in the temp2
head->pNext = temp3; // change next to previous
temp3 = head;
head = temp2;
}
}
Diagram detail:
List linked list [ 1 ] ->; [ 2 ] ->; [ 3 ] ->;
1) *List= head; // Set head point to the last node
2) temp2 = head->pNext; // saved as temp2 ( temp2 point to ptr2 )
3) head ->pNext = temp3; // at the first round, it point to the null
4) temp3 = head; // set temp3 as head ( temp3 point to ptr1)
5) head = temp2; // get back the temp2 location ( head point to ptr2 )
second round
6) *List= head; // Set head point to the last node ( head to ptr2 )
7) temp2 = head->pNext; // saved as temp2 ( temp2 point to ptr3 )
8) head ->pNext = temp3; // at the second round, it point ptr 1
9) temp3 = head; // set temp3 as head ( temp3 point to ptr2 )
10) head = temp2; // get back the temp2 location ( head point to ptr3 )
2) Delete a node in double linked list
Answer:
Doubly linked lists are like singly linked lists, except each node has two pointers -- one to the next node, and one to the previous node. This makes life nice in many ways:
void deleteNode( Node *n)
{
node *np = n->prev; // set np pointer to the n->prev
node *nn = n->next; // set nn pointer to the n->next
np->next = n->next; // skip n node
nn->prev = n->prev; // skip n node
delete n;
}
Diagram:
[ np ] ->; [ n ] ->; [ nn ] ->;
3) Sort a linked list
// Sorting in descending order
struct node
{
int value;
node* NEXT;
}
// start the sorting
sort (node *head) // pass the linklist head to the function
{
node* first, second, temp; // define 3 nodes variable
first = head; // set first as head
while(first!=null) // check first is not empty link list
{
second = first->NEXT;
while(second !=null ) // check the end of linked list
{
if(first->value > second->value)
{
temp = new node(); // allocate memory
temp->value = first->value;
first->value = second->value;
second->value = temp->value;
delete temp; // release the memory
}
second= second->NEXT;
}
first=first->NEXT;
}
}
4) Reverse a string
Answer:
void ReverseString ( char *String)
{
char *Begin = String; // set up 2 pointer, one for the beginning of the spring address
char *End = String + strlen(String) -1; // point to the end of the spring address
char tempChar ='\0'; // end of line
while (Begin < End)
{
TempChar = *Begin;
*Begin = *End;
*End = *TempChar;
Begin++;
End--;
}
}
Answer code:
Node* ReverseList(Node ** List) // Provide a link list
{
// Declare 3 pointer variable
Node *head = *List;
Node *temp2 = NULL;
Node *temp3 =NULL;
while(head)
{
*List = head; // set the head to last node
temp2 = head->pNext; // save the next ptr in the temp2
head->pNext = temp3; // change next to previous
temp3 = head;
head = temp2;
}
}
Diagram detail:
List linked list [ 1 ] ->; [ 2 ] ->; [ 3 ] ->;
1) *List= head; // Set head point to the last node
2) temp2 = head->pNext; // saved as temp2 ( temp2 point to ptr2 )
3) head ->pNext = temp3; // at the first round, it point to the null
4) temp3 = head; // set temp3 as head ( temp3 point to ptr1)
5) head = temp2; // get back the temp2 location ( head point to ptr2 )
second round
6) *List= head; // Set head point to the last node ( head to ptr2 )
7) temp2 = head->pNext; // saved as temp2 ( temp2 point to ptr3 )
8) head ->pNext = temp3; // at the second round, it point ptr 1
9) temp3 = head; // set temp3 as head ( temp3 point to ptr2 )
10) head = temp2; // get back the temp2 location ( head point to ptr3 )
2) Delete a node in double linked list
Answer:
Doubly linked lists are like singly linked lists, except each node has two pointers -- one to the next node, and one to the previous node. This makes life nice in many ways:
- You can traverse lists forward and backward.
- You can insert anywhere in a list easily. This includes inserting before a node, after a node, at the front of the list, and at the end of the list.
- You can delete nodes very easily.
void deleteNode( Node *n)
{
node *np = n->prev; // set np pointer to the n->prev
node *nn = n->next; // set nn pointer to the n->next
np->next = n->next; // skip n node
nn->prev = n->prev; // skip n node
delete n;
}
Diagram:
[ np ] ->; [ n ] ->; [ nn ] ->;
3) Sort a linked list
// Sorting in descending order
struct node
{
int value;
node* NEXT;
}
// start the sorting
sort (node *head) // pass the linklist head to the function
{
node* first, second, temp; // define 3 nodes variable
first = head; // set first as head
while(first!=null) // check first is not empty link list
{
second = first->NEXT;
while(second !=null ) // check the end of linked list
{
if(first->value > second->value)
{
temp = new node(); // allocate memory
temp->value = first->value;
first->value = second->value;
second->value = temp->value;
delete temp; // release the memory
}
second= second->NEXT;
}
first=first->NEXT;
}
}
4) Reverse a string
Answer:
void ReverseString ( char *String)
{
char *Begin = String; // set up 2 pointer, one for the beginning of the spring address
char *End = String + strlen(String) -1; // point to the end of the spring address
char tempChar ='\0'; // end of line
while (Begin < End)
{
TempChar = *Begin;
*Begin = *End;
*End = *TempChar;
Begin++;
End--;
}
}
Wednesday, April 21, 2010
SystemVerilog Interview Question 9
1) How to kill a process in fork/join?
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.
2) What is cross coverage ?
Cross allows keeping track of information which is received simultaneous on more than one cover point. Cross coverage is specified using the cross construct.
program main;
bit [0:1] y;
bit [0:1] y_values[$]= '{1,3};
bit [0:1] z;
bit [0:1] z_values[$]= '{1,2};
covergroup cg;
cover_point_y : coverpoint y ;
cover_point_z : coverpoint z ;
cross_yz : cross cover_point_y,cover_point_z ;
endgroup
cg cg_inst = new();
initial
foreach(y_values[i])
begin
y = y_values[i];
z = z_values[i];
cg_inst.sample();
end
endprogram
3) Why always block is not allowed in program block?
The program block does not allow always block. Only initial and methods are allowed, which are more controllable.
4) What is final block ?
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:
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.
2) What is cross coverage ?
Cross allows keeping track of information which is received simultaneous on more than one cover point. Cross coverage is specified using the cross construct.
program main;
bit [0:1] y;
bit [0:1] y_values[$]= '{1,3};
bit [0:1] z;
bit [0:1] z_values[$]= '{1,2};
covergroup cg;
cover_point_y : coverpoint y ;
cover_point_z : coverpoint z ;
cross_yz : cross cover_point_y,cover_point_z ;
endgroup
cg cg_inst = new();
initial
foreach(y_values[i])
begin
y = y_values[i];
z = z_values[i];
cg_inst.sample();
end
endprogram
3) Why always block is not allowed in program block?
The program block does not allow always block. Only initial and methods are allowed, which are more controllable.
4) What is final block ?
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:
SystemVerilog Interview Questions 7
1) Difference between Associative array and Dynamic array ?
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];
2) What are the advantages of SystemVerilog DPI?
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.
3) What is bin?
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
4) What are void functions ?
The function does not have return value
5) What is coverage driven verification?
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.
6) Explain about pass by ref and pass by value?
Pass by value is the default method through which arguments are passed into functions and tasks. Each subroutine retains a local copy of the argument. If the arguments are changed within the subroutine declaration, the changes do not affect the caller.
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) );
}
7) What is the difference between program block and module ?
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:
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];
2) What are the advantages of SystemVerilog DPI?
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.
3) What is bin?
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
4) What are void functions ?
The function does not have return value
5) What is coverage driven verification?
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.
6) Explain about pass by ref and pass by value?
Pass by value is the default method through which arguments are passed into functions and tasks. Each subroutine retains a local copy of the argument. If the arguments are changed within the subroutine declaration, the changes do not affect the caller.
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) );
}
7) What is the difference between program block and module ?
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.
SystemVerilog Interview Questions 6
1) What is the difference between $random and $urandom?
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;
function new(int seed);
this.srandom(seed);
endfunction
endclass
initial begin
packet p=new;
p.new(33);
end
2) How do we get seed or use single seed in the VMM ?
Method 1: Let it random by itself
In VMM , VCS usually prints it to log file. Recently it added a system task to get the seed, something like: $get_initial_random_seed()
Use the following command to put seed back to get the same result "+nbt_random_seed=".
Method: Fix the seed.
The better approach is to use srandom task/function to fix the seed. We can increase the seed by 1 or use other script to generate the seed. The start seed is only start the regression. It has enough randomize with the test environment.
EXAMPLE:
class Rand_seed;
rand integer Var;
function new (int seed);
srandom(seed);
$display(" SEED is initised to %0d ",seed);
endfunction
function void post_randomize();
$display(": %0d :",Var);
endfunction
endclass
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
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;
function new(int seed);
this.srandom(seed);
endfunction
endclass
initial begin
packet p=new;
p.new(33);
end
2) How do we get seed or use single seed in the VMM ?
Method 1: Let it random by itself
In VMM , VCS usually prints it to log file. Recently it added a system task to get the seed, something like: $get_initial_random_seed()
Use the following command to put seed back to get the same result "+nbt_random_seed=
Method: Fix the seed.
The better approach is to use srandom task/function to fix the seed. We can increase the seed by 1 or use other script to generate the seed. The start seed is only start the regression. It has enough randomize with the test environment.
EXAMPLE:
class Rand_seed;
rand integer Var;
function new (int seed);
srandom(seed);
$display(" SEED is initised to %0d ",seed);
endfunction
function void post_randomize();
$display(": %0d :",Var);
endfunction
endclass
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
SystemVerilog Interview Question 5
1) What is the use of modports ?
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.
e.g. Full case, sel=2'b11 will be covered by default statement.
The x-assignment will also be treated as a don'tcare for synthesis, which may allow the synthesis tool to further optimize the synthesized design. It's the potentially causing a mismatch to occur between simulation and synthesis. To insure that the pre-synthesis and post-synthesis simulations match, the case default could assign the y-output to either a
predetermined constant value, or to one of the other multiplexer input values
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.
e.g. A parallel case statement
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.
SystemVerilog adds the new case statement modifier called "unique."
The unique keyword shall cause the simulator to report a run-time error if a case expression is
ever found to match more than one of the case items. In essence, the unique
case statement is a "safe" parallel_case case statement.
unique case (...)
...
default: ...
endcase
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.
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.
e.g. Full case, sel=2'b11 will be covered by default statement.
The x-assignment will also be treated as a don'tcare for synthesis, which may allow the synthesis tool to further optimize the synthesized design. It's the potentially causing a mismatch to occur between simulation and synthesis. To insure that the pre-synthesis and post-synthesis simulations match, the case default could assign the y-output to either a
predetermined constant value, or to one of the other multiplexer input values
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.
e.g. A parallel case statement
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.
SystemVerilog adds the new case statement modifier called "unique."
The unique keyword shall cause the simulator to report a run-time error if a case expression is
ever found to match more than one of the case items. In essence, the unique
case statement is a "safe" parallel_case case statement.
unique case (...)
...
default: ...
endcase
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.
SystemVerilog interview Questions 4
1) How to call the task which is defined in parent object into derived class ?
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
THIS IS PARENT CLASS
2) What is the difference between rand and randc?
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.
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
THIS IS PARENT CLASS
2) What is the difference between rand and randc?
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.
Subscribe to:
Posts (Atom)