Move function for a memory model based class

Hi,

Can someone provide me an example for move function in memory model based class? How do we implement move function for memory model class, if someone has asked to do?

Thanks,
Bala

In reply to Madineni:

Somebody just asked a similar question yesterday. I showed them how to do this for a general class. I don’t know what you mean by a “memory model class” that would be any different.

In reply to dave_59:

Hi Dave,

Thanks for your reply.

The memory model class is something like below and need to implement the move function so that it will give output as described below.

Source code:

class memory_model # (int DEPTH = 1024);
  localparam ADDR_W = $clog2(DEPTH);
  bit [7:0] mem[DEPTH];
  
  extern virtual function void move ( bit [ADDR_W-1:0] source_address, 
                                      bit [ADDR_W-1:0] dest_address,
                                      bit [ADDR_W-1:0] size
                                    ); 

endclass: memory_model

Expected output:
move(0, 10, 5)
0 - > 10
1 - > 11
2 - > 12
3 - > 13
4 - > 14

implement the move function to get the expected output?

Thanks and Regards,
Madineni

In reply to Madineni:

I’d start like this:

for( int i = 0; i < size; i++ )
  mem[ dest_address + i ] = mem[ source_address + i ];

Regards,

Mark

In reply to Mark Curry:

This is simplest way. But be careful when memory wrap around.

Should change:


for( int i = 0; i < size; i++ )
  mem[ (dest_address + i) % DEPTH ] = mem[ (source_address + i) % DEPTH];

In reply to cuonghle:

why are addresses % DEPTH in this case. src and dst address will anyways be less than depth right? or maybe have a check before doing the move in the function
?