SystemVerilog: How to copy section of a buffer into smaller

On Mar 3, 3:33 pm, sh...@cadence.com wrote:
On Mar 3, 1:46 pm, mrfirmware <mrfirmw...@gmail.com> wrote:

I must be missing something but I've yet to find it in the SV LRM. How
does one "fragment" copy a large buffer (array)?
frag_buf = big_buf[offset:MPS_STEP-1];

I believe that you can do this, but the syntax needs to match the
"indexed part-select" syntax from Verilog-2001. Rather than a ":",
you need to use "+:", and rather than using the amount to be added to
the offset, you need to use the width. So this would be

frag_buf = big_buf[offset +: MPS_STEP];

Whether your tools will support this is another matter.
Ah! That's just what I needed. Thanks. Of course now knowing that I
found it right there in the LRM, p. 35.

Regards,

- Mark
 
On Mar 3, 1:46 pm, mrfirmware <mrfirmw...@gmail.com> wrote:
I must be missing something but I've yet to find it in the SV LRM. How
does one "fragment" copy a large buffer (array)?

    frag_buf = big_buf[offset:MPS_STEP-1];
I believe that you can do this, but the syntax needs to match the
"indexed part-select" syntax from Verilog-2001. Rather than a ":",
you need to use "+:", and rather than using the amount to be added to
the offset, you need to use the width. So this would be

frag_buf = big_buf[offset +: MPS_STEP];

Whether your tools will support this is another matter.
 
M

mrfirmware

Guest
I must be missing something but I've yet to find it in the SV LRM. How
does one "fragment" copy a large buffer (array)? For example, I have a
128kB buffer in a dynamic array of PCIe "dwords" which are 32-bits
wide. I have to send said buffer over a PCIe link with a Max. Payload
Size of 128B so I need to fragment. I'd like to code something like
this:

typedef int unsigned uint32;

parameter uint32 BIG_SIZE = 128 * 1024;
parameter uint32 MPS = 128;
parameter uint32 MPS_STEP = 128 / 4;

uint32 frag_buf[MPS];
uint32 big_buf[] = new[128 * 1024]; // Fill w/ data

for (uint32 offset = 0; offset < big_buf.size; offset += MPS_STEP)
begin : fragment
frag_buf = big_buf[offset:MPS_STEP-1];
mem64_wr(<some addr>, frag_buf);
end

Thanks,
- Mark
 

Welcome to EDABoard.com

Sponsor

Back
Top