Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

systemverilog questions on how to write a class

Status
Not open for further replies.

bigrice911

Member level 3
Joined
Apr 27, 2004
Messages
65
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
500
system verilog questions

Hi, guys!
I want to write a class in systemverilog which can implement calculate generic array's sum, product.
eg.
class arth_oper;
.....;
endclass
module test_class();
....
//when I call it
int a [] = {1, 2, 3, 4};
int b = a.sum //b = 10;
int c = a.product; //c = 24

logic [7:0] array [2:0];
for(int i=0; i<8; i++)
array = i;

a_s = array.sum; //a_s = 0+1+2+...+8
...

endmodule

Do you got me? can anybody show me an example on how to write this class in sv?
I know sv may support this class(sum, product), but Questa61 dosen't support it, so I want to write one...

Many many Th@nks!
 

systemverilog questions

can anyone help?
 

systemverilog +polymorphism

I'M SRY......

I'M replying this not to help you instead to take help from you......

I'm a novice in SYSTEM VERILOG......

if possible can you upload any ebook(not System verilog 3.1a.PDF)relating to System verilog or atleast give me the links....

Writing Testbenches using System Verilog (or)

Sytem Verilog By Sutherland


Thanks....and A Very Prosperous HAppy New Year....
 

system verilog class

Hi, guy!
I don't think I got the two books. The best way to learn sv is to practise again and again, then ask questions where you can get help. Don't dwell in any book except sv LRM or IEEE1800 paper.

Anyway, thank you for your replay!
 

system verilog sum of elements of array

bigrice911 said:
Hi, guys!
I want to write a class in systemverilog which can implement calculate generic array's sum, product.

What is your exact definition of a "generic sum/product"? Say something that calculates the sum/product of an array input? Please be more clear about the input, output of your system.

I am not sure why you need a class, SV has a foreach construct that works on different array types that can fit your need. You can use it in module also.

Do you got me? can anybody show me an example on how to write this class in sv?

I'm afraid I didn't get your problem straight.

Regards
Ajeetha, CVC
www.noveldv.com
 

systemverilog commonly asked questions

Thanks Aji_vlsi! I am sorry for the ambiguous discription.
What I mean is I want a class which can calculate input array's sum(product) of all elements. The class should be so generic that it could fit all types of array(different dimensions).
example:
int a [] = {1, 2, 3, 4};
logic [7:0] s [3:0]; //assume: s = i;

int b = a.sum; //expected b = 10
int d = s.sum; //expected d = 0+1+2+3+....+15

int p = a.product; //expected p = 1*2*3*4 = 24
int q = s.product; //expected q = 0*1*2*3*...*15 = 0

Got me now?

Thanks again!
 

systemverilog array method sum()

bigrice911 said:
Thanks Aji_vlsi! I am sorry for the ambiguous discription.
What I mean is I want a class which can calculate input array's sum(product) of all elements. The class should be so generic that it could fit all types of array(different dimensions).
example:
int a [] = {1, 2, 3, 4};
logic [7:0] s [3:0]; //assume: s = i;

int b = a.sum; //expected b = 10
int d = s.sum; //expected d = 0+1+2+3+....+15

int p = a.product; //expected p = 1*2*3*4 = 24
int q = s.product; //expected q = 0*1*2*3*...*15 = 0

Got me now?

Thanks again!


IEEE 1800 LRM says sum() and product() are methods on any array, see: section 5.15.3 - are you saying since your tool doesn't support it, you want to write your own one? I don't believe it is that simple, but can be attempted via some argument to constructor of a class etc. But I would not waste time doing that, rather just write separate methods for each array type.

Just my 2 cents
Ajeetha, CVC
www.noveldv.com
 

system verilog question

Thanks to aji_vlsi, I've done it by using foreach...
actually what I want to know is how to write a class, I have been writting RTL for 3~4 years and I got no (maybe little) experience on OOP language(C/C++), now I want to learn that, I don't find many good examples of SV class, so I need someone to show me an example, hopefully, it would guide me to go further on sv learning.
 

classes system verilog

bigrice911 said:
Thanks to aji_vlsi, I've done it by using foreach...
actually what I want to know is how to write a class, I have been writting RTL for 3~4 years and I got no (maybe little) experience on OOP language(C/C++), now I want to learn that, I don't find many good examples of SV class, so I need someone to show me an example, hopefully, it would guide me to go further on sv learning.

Look in www.project-veripage.com, www.electrosofts.com, www.verificationguild.com have some examples. We show how to use SV class in a framework for efficient verification in our recent book on VMM adoption, see www.noveldv.com or www.systemverilog.us

HTH
Ajeetha, CVC
www.noveldv.com
 

writing a task in package of systemverilog

Hi,
look the following program, its compiled using cadence simulator.
there can be many other ways. may be it can be helful

package display_msg;
integer k=0;
endpackage:display_msg

import display_msg:: * ;
module my_module;
bit clk;

//class
class mannu;

task my_task(input logic[1:0] x,input logic [1:0] y );
logic[2:0] z;
z= x + y;
$write("the value of result is z = %0d\n",z);
endtask:my_task

function logic[3:0] my_func(input logic [2:0] a, input logic [2:0] b);
logic [3:0] c;
c= a - b;
return c;
endfunction:my_func

task print();
$write("i am in base class\n");
endtask:print

endclass:mannu

//inheritance
class mannu_one extends mannu;
task display();
$write("derived class of base class mannu\n");
endtask:display
endclass:mannu_one

// task
task display();
$write("My name is Hehaaaaaaaa\n");
endtask:display

//function
function void print();
$write("My name is Heeeeeeeeeeeeha\n");
endfunction:print

//########### concept of polymorphism ###############

virtual class transaction;
virtual task transact();
endtask:transact
endclass:transaction

class read_transaction extends transaction;
task transact;
$write("I am in read transaction\n");
endtask:transact
endclass:read_transaction

class write_transaction extends transaction;
task transact;
$write("I am in write transaction\n");
endtask:transact
endclass:write_transaction

transaction tr1,tr2;
read_transaction rd_tr;
write_transaction wr_tr;

initial
begin
rd_tr = new() ;
wr_tr = new() ;
tr1 = rd_tr ;
tr2 = wr_tr ;
tr1.transact();
tr2.transact();
end

//Main calls
logic [3:0] val;
mannu man;
mannu_one man1;
initial
begin
man = new;
man1 = new;
man.my_task(3,2);
val = man.my_func(5,7);
$write("the value of function is =%0d\n ",val);
display();
print();
man1.display();
man1.print();
$write("the value of global var is = %0d\n",k);
end
endmodule:my_module
 

Hi, Mssajwan! Thanks for your sharing of your knowledge. It takes time to digest your sv program. :)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top