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 04-21-2006, 03:22 AM
Mr. Ken
Guest
 
Posts: n/a
Default What's the easiest way to bit-wisely reverse a vector?

I need to reverse the vector, and prefer simplest codes. One liner is
probably the best.

For example,
reg [31:0] mydata;
wire [31:0] mydata_r;

assign mydata_r = mydata[0:31] // Syntax error here.

TIA



Reply With Quote
  #2 (permalink)  
Old 04-21-2006, 07:57 AM
John_H
Guest
 
Posts: n/a
Default Re: What's the easiest way to bit-wisely reverse a vector?

Mr. Ken wrote:
> I need to reverse the vector, and prefer simplest codes. One liner is
> probably the best.
>
> For example,
> reg [31:0] mydata;
> wire [31:0] mydata_r;
>
> assign mydata_r = mydata[0:31] // Syntax error here.
>
> TIA


Use a Verilog2001 generate for loop to assign each bit of mydata to
mydata_r one at a time. The generate stays pretty compact.
Reply With Quote
  #3 (permalink)  
Old 04-21-2006, 08:07 AM
Mr. Ken
Guest
 
Posts: n/a
Default Re: What's the easiest way to bit-wisely reverse a vector?


"John_H" <[email protected]> wrote in message
news:[email protected]
> Mr. Ken wrote:
> > I need to reverse the vector, and prefer simplest codes. One liner is
> > probably the best.
> >
> > For example,
> > reg [31:0] mydata;
> > wire [31:0] mydata_r;
> >
> > assign mydata_r = mydata[0:31] // Syntax error here.
> >
> > TIA

>
> Use a Verilog2001 generate for loop to assign each bit of mydata to
> mydata_r one at a time. The generate stays pretty compact.


for loop is nice, but anything more compact? maybe I am expecting too much.



Reply With Quote
  #4 (permalink)  
Old 04-21-2006, 08:10 AM
Mr. Ken
Guest
 
Posts: n/a
Default Re: What's the easiest way to bit-wisely reverse a vector?


"Mr. Ken" <Mr. [email protected]> wrote in message
news:[email protected]
>
> "John_H" <[email protected]> wrote in message
> news:[email protected]
> > Mr. Ken wrote:
> > > I need to reverse the vector, and prefer simplest codes. One liner is
> > > probably the best.
> > >
> > > For example,
> > > reg [31:0] mydata;
> > > wire [31:0] mydata_r;
> > >
> > > assign mydata_r = mydata[0:31] // Syntax error here.
> > >
> > > TIA

> >
> > Use a Verilog2001 generate for loop to assign each bit of mydata to
> > mydata_r one at a time. The generate stays pretty compact.

>
> for loop is nice, but anything more compact? maybe I am expecting too

much.
basically a for loop doesn't do well with "assign".



Reply With Quote
  #5 (permalink)  
Old 04-21-2006, 08:50 AM
Guest
 
Posts: n/a
Default Re: What's the easiest way to bit-wisely reverse a vector?

A "generate for" loop is different from a "for" loop, whereby the
former is not seen during run-time, much like a compiler directive,
hence wouldn't be causing much problems with assign here ...

Joe
LogicSim - Your Personal Verilog Simulator
http://www.logicsim.com

Mr. Ken wrote:
> "Mr. Ken" <Mr. [email protected]> wrote in message
> news:[email protected]
> >
> > "John_H" <[email protected]> wrote in message
> > news:[email protected]
> > > Mr. Ken wrote:
> > > > I need to reverse the vector, and prefer simplest codes. One liner is
> > > > probably the best.
> > > >
> > > > For example,
> > > > reg [31:0] mydata;
> > > > wire [31:0] mydata_r;
> > > >
> > > > assign mydata_r = mydata[0:31] // Syntax error here.
> > > >
> > > > TIA
> > >
> > > Use a Verilog2001 generate for loop to assign each bit of mydata to
> > > mydata_r one at a time. The generate stays pretty compact.

> >
> > for loop is nice, but anything more compact? maybe I am expecting too

> much.
> basically a for loop doesn't do well with "assign".


Reply With Quote
  #6 (permalink)  
Old 04-21-2006, 03:27 PM
John_H
Guest
 
Posts: n/a
Default Re: What's the easiest way to bit-wisely reverse a vector?

Mr. Ken wrote:

> "Mr. Ken" <Mr. [email protected]> wrote in message
> news:[email protected]
>
>>"John_H" <[email protected]> wrote in message
>>news:[email protected]
>>
>>>Mr. Ken wrote:
>>>
>>>>I need to reverse the vector, and prefer simplest codes. One liner is
>>>>probably the best.
>>>>
>>>>For example,
>>>>reg [31:0] mydata;
>>>>wire [31:0] mydata_r;
>>>>
>>>>assign mydata_r = mydata[0:31] // Syntax error here.
>>>>
>>>>TIA
>>>
>>>Use a Verilog2001 generate for loop to assign each bit of mydata to
>>>mydata_r one at a time. The generate stays pretty compact.

>>
>>for loop is nice, but anything more compact? maybe I am expecting too

>
> much.
> basically a for loop doesn't do well with "assign".


That's why one uses the Verilog 2001 "generate" for statement. It's not
your grandfather's for statement.

Bottom line: the Verilog language has strict vector bit order. If you
declare the elements as increasing (e.g., my[0:35]) then the references
all need to be increasing. I'd *love* to be able to swap back & forth,
reversing the bit order to take care of my too-frequent bit-swizzle
needs but a short generate for statement or a fully expanded vector
assignment is the only way I've found to go.

I'll post the syntax of the generate block when I get in to work.
Reply With Quote
  #7 (permalink)  
Old 04-21-2006, 05:41 PM
Stephen Williams
Guest
 
Posts: n/a
Default Re: What's the easiest way to bit-wisely reverse a vector?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John_H wrote:
> Mr. Ken wrote:
>> I need to reverse the vector, and prefer simplest codes. One liner is
>> probably the best.
>>
>> For example,
>> reg [31:0] mydata;
>> wire [31:0] mydata_r;
>>
>> assign mydata_r = mydata[0:31] // Syntax error here.
>>
>> TIA

>
> Use a Verilog2001 generate for loop to assign each bit of mydata to
> mydata_r one at a time. The generate stays pretty compact.


Something like this:

genvar i;
for (i=0; i<32; i=i+1) assign mydata_r[i] = mydata[31-i];

(The generate/endgenerate is optional because it is obvious to the
parser that this is a generate loop.)

So it's 2 lines instead of 1. Sorry:-)

- --
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFESP0drPt1Sc2b3ikRAiWPAKDsrOOTfBaNlg5sRuEje9 VnwgVS8wCgzM1P
p6NVXpUtxD9qbtniF5sca94=
=yTRn
-----END PGP SIGNATURE-----
Reply With Quote
  #8 (permalink)  
Old 04-21-2006, 05:51 PM
John_H
Guest
 
Posts: n/a
Default Re: What's the easiest way to bit-wisely reverse a vector?

"John_H" <[email protected]> wrote in message
news:[email protected]

> Bottom line: the Verilog language has strict vector bit order. If you
> declare the elements as increasing (e.g., my[0:35]) then the references
> all need to be increasing. I'd *love* to be able to swap back & forth,
> reversing the bit order to take care of my too-frequent bit-swizzle needs
> but a short generate for statement or a fully expanded vector assignment
> is the only way I've found to go.
>
> I'll post the syntax of the generate block when I get in to work.


genvar i;
generate
for( i=0; i<8; i=i+1 )
begin : swiz
assign Y[i] = A[7-i];
end
endgenerate


Reply With Quote
  #9 (permalink)  
Old 04-21-2006, 06:24 PM
John_H
Guest
 
Posts: n/a
Default Re: What's the easiest way to bit-wisely reverse a vector?

I didn't know the Verilog2001 LRM allowed the generate to be optional.
SynplifyPro certainly doesn't like the "obvious" generate block without an
explicit generate/endgenerate. Even the for block needed a name.


"Stephen Williams" <[email protected]> wrote in message
news:[email protected]
> Something like this:
>
> genvar i;
> for (i=0; i<32; i=i+1) assign mydata_r[i] = mydata[31-i];
>
> (The generate/endgenerate is optional because it is obvious to the
> parser that this is a generate loop.)
>
> So it's 2 lines instead of 1. Sorry:-)
>
> - --
> Steve Williams "The woods are lovely, dark and deep.
> steve at icarus.com But I have promises to keep,
> http://www.icarus.com and lines to code before I sleep,
> http://www.picturel.com And lines to code before I sleep."



Reply With Quote
  #10 (permalink)  
Old 04-21-2006, 08:02 PM
Stephen Williams
Guest
 
Posts: n/a
Default Generate for-loop syntax (was Re: What's the easiest way to bit-wiselyreverse a vector?)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John_H wrote:
> I didn't know the Verilog2001 LRM allowed the generate to be optional.
> SynplifyPro certainly doesn't like the "obvious" generate block without an
> explicit generate/endgenerate. Even the for block needed a name.


The for-loop statement most definitely does *not* need a name. There
is a whole elaborate rule for assigning scope names to generate
blocks that are anonymous is the source code.

As for the generate/endgenerate being optional, I may have gotten
ahead of myself on that one. In fact, I somehow got it in my head
that it is optional (I think I read it in an errata draft) but I
cannot find any definitive reference.

The generate/endgenerate keywords are in fact silly because any
module items (not just generate schemes) are allowed withing them,
so they convey almost no information. Steve Sharp may speak more
authoritatively on this matter (as he often does).

In any case, Icarus Verilog doesn't require generate/endgenerate,
other then to require that generate has a matching endgenerate;-)

> "Stephen Williams" <[email protected]> wrote in message
> news:[email protected]
>> Something like this:
>>
>> genvar i;
>> for (i=0; i<32; i=i+1) assign mydata_r[i] = mydata[31-i];
>>
>> (The generate/endgenerate is optional because it is obvious to the
>> parser that this is a generate loop.)
>>
>> So it's 2 lines instead of 1. Sorry:-)
>>
>> - --
>> Steve Williams "The woods are lovely, dark and deep.
>> steve at icarus.com But I have promises to keep,
>> http://www.icarus.com and lines to code before I sleep,
>> http://www.picturel.com And lines to code before I sleep."

>
>



- --
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFESR4mrPt1Sc2b3ikRAqfzAKCDycxsoLWnaZb9bwN42q GTCHpddACfQ/tJ
gAeCZQnuGK2NiKCsnlzSVMQ=
=QfAp
-----END PGP SIGNATURE-----
Reply With Quote
  #11 (permalink)  
Old 04-21-2006, 11:44 PM
Jonathan Bromley
Guest
 
Posts: n/a
Default Re: Generate for-loop syntax (was Re: What's the easiest way to bit-wisely reverse a vector?)

On Fri, 21 Apr 2006 11:02:14 -0700, Stephen Williams
<[email protected]> wrote:

>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>John_H wrote:
>> I didn't know the Verilog2001 LRM allowed the generate to be optional.


It doesn't. I think you'll find "generate" became optional
in 1364-2005.

>The for-loop statement most definitely does *not* need a name.


Really? Again, I think this is a 1364-2005 relaxation. I'm sure
1364-2001 requires generate-for loop body to be a
labelled begin..end

>The generate/endgenerate keywords are in fact silly because any
>module items (not just generate schemes) are allowed withing them,
>so they convey almost no information. Steve Sharp may speak more
>authoritatively on this matter (as he often does).


Interestingly, though, the relaxation makes it much harder for a
compiler to issue clear diagnostics for certain simple errors,
since a for-loop might now be a generate-loop or simply a
procedural loop written by someone who innocently
forgot the preceding "initial" keyword.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 Email: [email protected]
Fax: +44 (0)1425 471573 Web: http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
Reply With Quote
  #12 (permalink)  
Old 04-22-2006, 12:04 AM
Stephen Williams
Guest
 
Posts: n/a
Default Re: Generate for-loop syntax (was Re: What's the easiest way to bit-wiselyreverse a vector?)

Jonathan Bromley wrote:
> On Fri, 21 Apr 2006 11:02:14 -0700, Stephen Williams
> <[email protected]> wrote:


>> John_H wrote:
>>> I didn't know the Verilog2001 LRM allowed the generate to be optional.

>
> It doesn't. I think you'll find "generate" became optional
> in 1364-2005.
>
>> The for-loop statement most definitely does *not* need a name.

>
> Really? Again, I think this is a 1364-2005 relaxation. I'm sure
> 1364-2001 requires generate-for loop body to be a
> labelled begin..end


*sigh* I can't refute you. In Icarus Verilog I implemented it
the "-2005" way because I've been working from some drafts of the
newer generate syntax. So it seems that I'm farther ahead of myself
then I originally thought:-O

I think I need to buy myself a copy of the 1364-2005 standard.


--
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
Reply With Quote
  #13 (permalink)  
Old 04-22-2006, 02:13 AM
Guest
 
Posts: n/a
Default Re: Generate for-loop syntax (was Re: What's the easiest way to bit-wisely reverse a vector?)

Some of the changes to generates were intended as corrections to
Verilog-2001, because of significant problems with what was specified
there. After approving the changes, the BTF recommended that
implementations of Verilog-2001 use the revised version. So they could
be considered to be part of a revised Verilog-2001, though there was no
official corrigendum.

Making generate/endgenerate optional was not a necessary correction, so
that could be considered a Verilog-2005 enhancement instead. But there
is not a clear dividing line.

Specifying that conditional generates created scopes was necessary for
practical implementation. Allowing implicit names for those scopes was
necessary to avoid annoyance to users (and to give backward
compatibility with any attempted implementations of the original
specification). But once the implicit naming scheme was added for
conditional generates, there was no reason to continue to require
explicit names for the for-generated scopes. So that change could be
viewed as part of the corrections or as a separate enhancement.

Reply With Quote
  #14 (permalink)  
Old 04-22-2006, 02:49 AM
Stephen Williams
Guest
 
Posts: n/a
Default Re: Generate for-loop syntax (was Re: What's the easiest way to bit-wiselyreverse a vector?)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[email protected] wrote:
> Some of the changes to generates were intended as corrections to
> Verilog-2001, because of significant problems with what was specified
> there. After approving the changes, the BTF recommended that
> implementations of Verilog-2001 use the revised version. So they could
> be considered to be part of a revised Verilog-2001, though there was no
> official corrigendum.


So with all that said, I might as well leave Icarus Verilog with
the 2005 behavior because it is almost 2001+ behavior anyhow. And
besides, it's a superset so strictly-2001 programs will care.

And my two-line solution that started this whole thread remains
as valid code if you have a newer compiler.
- --
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFESX21rPt1Sc2b3ikRAlHqAJ4l0ohU671A145We2Sqir zCuvM++wCcDABl
h4w5nWOBIfU2rL19EzbMENo=
=gDUg
-----END PGP SIGNATURE-----
Reply With Quote
  #15 (permalink)  
Old 04-22-2006, 08:51 AM
Guest
 
Posts: n/a
Default Re: What's the easiest way to bit-wisely reverse a vector?

If you want to reverse at the chip's top interface, this works:
module m(
input [31:0] a,
output [31:0] b);
assign b=a;
endmodule
// To this
module m(
input [0:31] a,
output [31:0] b);
assign b=a;
endmodule

T

Mr. Ken wrote:
> I need to reverse the vector, and prefer simplest codes. One liner is
> probably the best.
>
> For example,
> reg [31:0] mydata;
> wire [31:0] mydata_r;
>
> assign mydata_r = mydata[0:31] // Syntax error here.
>
> TIA


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
Traversing a vector counting zeros Uwe Stange Verilog 1 02-07-2004 08:19 PM
PLI 1.0 - access to value of a variable in a vector Ozzyboom Verilog 2 01-23-2004 09:35 PM
Indexing a vector using variables? Brendan Lynskey Verilog 3 12-19-2003 02:33 AM
Question on if (vector) ... David Rogoff Verilog 1 09-10-2003 11:00 PM
How to assign an array to a vector? Peng Yu Verilog 2 08-06-2003 08:50 PM


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


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