How to Get the Address of a varaible in SV?

I want to Write the address of a variable (bit/logic/reg) to some other hardware registers as pointers. How to know the address of that variable?

For example,
I have a variable
bit [31:0] A ;
with new() function it was initialized.

       I want to know the starting address of that array A. Is it possible in SV?  In "C" language, We have "&" operator. So Can we Use DPI with C? Can anyone please explain with some example?

Thanks & regards
Naveen

In reply to kalyan14310:

except for class, there are no type can use the pointer

In reply to haitao73:

So, you can encapsulate the variable in a class, use the class object handle!

In reply to haitao73:

Thanks for the reply sir. I had listed all variables inside class only. can you please explain with one example?

In reply to kalyan14310:

I think its better if you can give some info on what you wanted to do with this. As far as i know SV cannot give you the address of a variable.
Using class handle you can refer the same data with two or multiple handle.

class A;
 int i;
endclass

A a1,a2;
initial begin
a1 = new();
a2 = a1; // if you update one then that value will be reflected in other
a2.i = 10;
$display("Data value in a1: %d, a2: %d",a1.i,a2.i);
end

I think you are confusing many different concepts. SystemVerilog is a Hardware Description Language (HDL). When you declare an array of hardware registers:

bit [31:0] A ;

The hardware address of the first register is 0, the second is 1, etc. When you compile your HDL to run a simulation, you have no knowledge of how the simulator implemented those registers on the host system running the simulation and where in the actually memory they are located. Even for the testbench features of the language, SystemVerilog does not have any pointer like C/C++; it has handles and references which do not let you manipulate the “address” of a variable.

When you start talking about the DPI, that becomes a slightly different story. The C language requires pointers to address arrays. So the simulator either has to provide the actual address, or provide access routines to get to the actual register.

So with these clarifications, you need to provide more explanation of what you are looking to achieve.

In reply to Naven8:

Hi Naven8,

Thanks for the quick reply. I am currently working on HOST CONTROLLER INTERFACE for USB-3.0. In that Project I have a requirement like this:
I have to construct TRANSFER RINGS. Basically a Ring is a circular queue data structure. Ring Size is not fixed. So for that I am using variable like this:
bit [31:0] RING [$];
And the problem is, I should write the base address/ starting address of the RING variable in another Register DEQUEUE POINTER field. The Register was implemented using UVM Register Model. How can we address this problem?

Thanks & Regards
Naveen

In reply to dave_59:

Hello sir,
Thanks for the quick reply. I am currently working on HOST CONTROLLER INTERFACE for USB-3.0. In that Project I have a requirement like this:
I have to construct TRANSFER RING, whose size is not fixed. Basically a Ring is a circular queue data structure. So for that I am using variable like this:
bit [31:0] RING [$];
The problem is, I should write the base address/ starting address of the RING variable in another Register DEQUEUE POINTER field to tell the Hardware that Transfer Ring was allocated & initialized in that base address. And all Registers were implemented using UVM Register Model. How can we address this problem?

Thanks & Regards
Naveen

class base;

endclass

class trb extends base;
  trb this_trb_p;
  trb next_trb_p;
  bit[7:0] data_buffer_pointer[];
  int status;
  int control;

  function execute_trb();
    $display("execute trb");
  endfunction

endclass

class td extends trb;
  td  this_td_p;
  td  next_td_p;

  trb start_trb_p;
  trb end_trb_p;

  function execute_td();
    m_trb;
    m_trb = start_trb_p;

    do begin
      m_trb.execute_trb();
      m_trb = m_trb.next_trb_p;
    while(m_trb != null);  
  endfunction

  function add_trb(trb add_trb);
    if(start_trb_p == null) begin
      start_trb_p = add_trb;
      end_trb_p = add_trb;
    end  
    else begin
      end_trb_p.next_trb_p = add_trb;
      end_trb_p = add_trb;
    end    
  endfunction  

endclass

class transfer_ring extends td;
  transfer_ring this_tr;
  
  trb dequeue_pointer;
  trb enqueue_pointer;

  td start_td_p;
  td end_td_p;

  function execute_tr();
    td m_td;

    m_td = dequeue_pointer;
    do begin
      m_td.execute_td();
      if(m_td == enqueue_pointer)
        break;
      m_td = m_td.next_td_p;
    while(m_td != null)  

  endfunction

  function add_td(td add_td);
    if(start_td_p == null) begin
      start_td_p = add_td;
      end_td_p = add_td;
    end  
    else begin
      end_td_p.next_td_p = add_td;
      end_trb_p = add_td;
    end    

    dequeue_pointer = start_td_p.start_trb_p;
    enqueue_pointer = end_td_p.end_trb_p;
  endfunction  
endclass  

module test;
  base aa[bit[31;0]];
  trb0 = new();
  trb1 = new();
  td = new();
  transfer_ring = new();

  td.add_trb(trb0);
  td.add_trb(trb1);
  transfer_ring.add_td(td);

  aa[32'h0000_0001] = transfer_ring.dequeue_pointer;
  aa[32'h0000_0002] = trandfer_ring.enqueue_pointer;

  //so address 32'h01 and 32'h02 correspond to dequeue and enqueue
  //you can use register model to access the two addresses

endmodule  

In reply to haitao73:

hi,
This example is a little long, I hope it can help you!

In reply to kalyan14310:

As far as i know there is no way to get address of a variable in sv.

But if you really need this…you can create a variable in c file and return the address. In SV file with DPI_C and chandle daata type you can get the adress of that variable in sv.

In reply to 1117ashish:

Hi Ashish,

 Can you please provide a small working example. I tried using DPI, but it is not working. Please help me

In reply to kalyan14310:

kalyan,

How about showing us what you tried using the DPI, and explain what you expected it to do had it worked.

In reply to dave_59:

Hi Dave,

For me, looks like DPI-C is not better approach to solve this issue. Whether Rings can be implemented using UVM reg model?

In reply to kalyan14310:

Does the answer posted by haitao73 help?

In reply to dave_59:

I think haitao73 was worked on this project…he actually explained how to add trbs into rings…
My requirement is,

  1. Have to create an empty ring (allocating and initializing all fields as 0).
  2. Size of the ring should be randomized…it is not fixed to particular length.
  3. After creating ring, write the base address of the newly created ring to another register.