FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-02-2010, 09:15 PM
fpgaasicdesigner
Guest
 
Posts: n/a
Default concatenation with a for loop

Hi all,

How can I write more with more elegance this:

header={register[0],register[1],register[2]}.

Meaning having a for loop to concatenate these bus ?

Thanks
Reply With Quote
  #2 (permalink)  
Old 02-02-2010, 10:09 PM
Cary R.
Guest
 
Posts: n/a
Default Re: concatenation with a for loop

fpgaasicdesigner wrote:
> Hi all,
>
> How can I write more with more elegance this:
>
> header={register[0],register[1],register[2]}.
>
> Meaning having a for loop to concatenate these bus ?
>
> Thanks


localparam max = 2;
for (idx=0; idx<=max; idx=idx+1)
header[(max-idx)*<width> +: <width>] = register[idx];

<width> is the width of the register words.

Cary
Reply With Quote
  #3 (permalink)  
Old 02-02-2010, 10:15 PM
John_H
Guest
 
Posts: n/a
Default Re: concatenation with a for loop

On Feb 2, 4:15*pm, fpgaasicdesigner <fpgaasicdesig...@gmail.com>
wrote:
> Hi all,
>
> How can I write more with more elegance this:
>
> *header={register[0],register[1],register[2]}.
>
> Meaning having a for loop to concatenate these bus ?
>
> Thanks


A generate statement is the way to go for a wide bus. There really is
no clean way to reverse the order of a bus so the "generate for" will
take care of it in a somewhat better fashion. But if you have few
elements, just write it out. Even 16 elements can come out clean with
4 rows of 4 elements each all lined up under each other in a visible
grid.

header <= { register[ 0], register[ 1], register[ 2], register[ 3]
, register[ 4], register[ 5], register[ 6], register[ 7]
, register[ 8], register[ 9], register[10], register[11]
, register[12], register[13], register[14], register
[15] };

It's possible to use bit manipulation or perhaps the width syntax

header[n] <= register[ n-1 :+ 1 ];

to use a normal for loop but things really start to look unclear to
the reader.
Reply With Quote
  #4 (permalink)  
Old 02-02-2010, 10:16 PM
John_H
Guest
 
Posts: n/a
Default Re: concatenation with a for loop

On Feb 2, 5:15*pm, John_H <newsgr...@johnhandwork.com> wrote:
>
> * header[n] <= register[ n-1 :+ 1 ];


Oops...
Make that register[ 15-n :+ 1 ]
Reply With Quote
  #5 (permalink)  
Old 02-02-2010, 10:17 PM
John_H
Guest
 
Posts: n/a
Default Re: concatenation with a for loop

On Feb 2, 5:16*pm, John_H <newsgr...@johnhandwork.com> wrote:
> On Feb 2, 5:15*pm, John_H <newsgr...@johnhandwork.com> wrote:
>
>
>
> > * header[n] <= register[ n-1 :+ 1 ];

>
> Oops...
> Make that register[ 15-n :+ 1 ]


Ans as Cary pointed out, it's +: not :+

I guess the day's gotten the better of me.
Reply With Quote
  #6 (permalink)  
Old 02-03-2010, 12:16 AM
fpgaasicdesigner
Guest
 
Posts: n/a
Default Re: concatenation with a for loop

On Feb 2, 5:17*pm, John_H <newsgr...@johnhandwork.com> wrote:
> On Feb 2, 5:16*pm, John_H <newsgr...@johnhandwork.com> wrote:
>
> > On Feb 2, 5:15*pm, John_H <newsgr...@johnhandwork.com> wrote:

>
> > > * header[n] <= register[ n-1 :+ 1 ];

>
> > Oops...
> > Make that register[ 15-n :+ 1 ]

>
> Ans as Cary pointed out, it's +: not :+
>
> I guess the day's gotten the better of me.


thanks guys, that works with
header[idx*WIDTH +: WIDTH] <= register[idx]
Reply With Quote
  #7 (permalink)  
Old 02-03-2010, 12:34 AM
Cary R.
Guest
 
Posts: n/a
Default Re: concatenation with a for loop

fpgaasicdesigner wrote:

> thanks guys, that works with
> header[idx*WIDTH +: WIDTH] <= register[idx]


except this gives you:

header = {register[2], register[1], register[0]};

not

header = {register[0], register[1], register[2]};

like you originally asked for. I'm just noting a discrepancy. What
matters is that it is working like you expect.

Cary
Reply With Quote
  #8 (permalink)  
Old 02-03-2010, 02:09 AM
fpgaasicdesigner
Guest
 
Posts: n/a
Default Re: concatenation with a for loop

On Feb 2, 7:34*pm, "Cary R." <no-s...@host.spam> wrote:
> fpgaasicdesigner wrote:
> > thanks guys, that works with
> > header[idx*WIDTH +: WIDTH] <= register[idx]

>
> except this gives you:
>
> header = {register[2], register[1], register[0]};
>
> not
>
> header = {register[0], register[1], register[2]};
>
> like you originally asked for. I'm just noting a discrepancy. What
> matters is that it is working like you expect.
>
> Cary


correct... you know it's never in the sense/direction you wanted 2,1,0
or 0,1,2 whatever or 1'b1 instead of been 1'b0 whatever lol
binary digital is funny if you don't have a 1 you will have a 0, so it
never can been wrong ?

thanks guys for the fast answers
and I didn't know this syntax +:, very interesting syntax...
Reply With Quote
  #9 (permalink)  
Old 02-03-2010, 02:12 AM
fpgaasicdesigner
Guest
 
Posts: n/a
Default Re: concatenation with a for loop

On Feb 2, 5:15*pm, John_H <newsgr...@johnhandwork.com> wrote:
> On Feb 2, 4:15*pm, fpgaasicdesigner <fpgaasicdesig...@gmail.com>
> wrote:
>
> > Hi all,

>
> > How can I write more with more elegance this:

>
> > *header={register[0],register[1],register[2]}.

>
> > Meaning having a for loop to concatenate these bus ?

>
> > Thanks

>
> A generate statement is the way to go for a wide bus. *There really is
> no clean way to reverse the order of a bus so the "generate for" will
> take care of it in a somewhat better fashion. *But if you have few
> elements, just write it out. *Even 16 elements can come out clean with
> 4 rows of 4 elements each all lined up under each other in a visible
> grid.
>
> * header <= { register[ 0], register[ 1], register[ 2], register[ 3]
> * * * * * * , register[ 4], register[ 5], register[ 6], register[ 7]
> * * * * * * , register[ 8], register[ 9], register[10], register[11]
> * * * * * * , register[12], register[13], register[14], register
> [15] };
>
> It's possible to use bit manipulation or perhaps the width syntax
>
> * header[n] <= register[ n-1 :+ 1 ];
>
> to use a normal for loop but things really start to look unclear to
> the reader.


and I didn't used an array structure cause it goes to an output I/O of
a module. That cannot be done in Verilog, that's annoying sometimes
and there's no difference in the synthesized result for an array or a
vector, cause an vector is a just a one dimension array... I was able
to do it in VHDL. Perhaps System Verilog is able to do that ?
Reply With Quote
  #10 (permalink)  
Old 02-03-2010, 10:11 AM
Jonathan Bromley
Guest
 
Posts: n/a
Default Re: concatenation with a for loop

On Tue, 2 Feb 2010 18:12:59 -0800 (PST), fpgaasicdesigner wrote:

>and I didn't used an array structure cause it goes to an output I/O of
>a module. That cannot be done in Verilog, that's annoying sometimes
>and there's no difference in the synthesized result for an array or a
>vector, cause an vector is a just a one dimension array... I was able
>to do it in VHDL.


Yes, VHDL has always been a much more expressive language
for synthesisable designs. Only now is SystemVerilog
beginning to catch up.

> Perhaps System Verilog is able to do that ?


Yes, it is. Ports can be of any array type, and all the
new user-definable data types (struct, union, enum) can
also go on ports. At last!

And the great majority of mainstream tools now fully
support that part of SystemVerilog for both simulation
and synthesis.
--
Jonathan Bromley
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird concatenation Franck Y VHDL 1 11-14-2007 02:36 PM
Re: How to desaturate integrator of a fast loop with a slow loop? bruce varley DSP 3 11-12-2005 10:19 PM
How to desaturate integrator of a fast loop with a slow loop? Bas DSP 4 11-08-2005 12:48 AM
vector concatenation pandora VHDL 5 04-05-2004 07:57 AM
what's the difference between VHDL 93 CONCATENATION and VHDL 87 CONCATENATION? walala VHDL 3 09-18-2003 05:17 AM


All times are GMT +1. The time now is 06:50 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved