Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Rotate by variable

 
Thread Tools Search this Thread
Old 02-16-2004, 07:12 PM   #1
Default Rotate by variable



Hi all,

sorry to drop in like this but I'm having a problem and thought I may be
able to gain some information from you all...

I'm trying to achieve a variable rotate as below. i.e. it takes in two
numbers, one 32 bits long, the other 5 bits long, and outputs the 32 bit
number, rotated left by 5 bits.

Now, this will compile fine (i.e. it's syntactically correct) but can't be
synthesised in Synplify Pro.

Does anyone have any suggestions, or code snippets that would be able to
make this synthesisable for a Virtex II (Pro).

tia,

patrick.



entity ro_lft is
port(
quantity : in STD_LOGIC_VECTOR(31 downto 0);
amount : in STD_LOGIC_VECTOR(4 downto 0);
clk : in STD_LOGIC;
output : out STD_LOGIC_VECTOR(31 downto 0)
);
end ro_lft;

--}} End of automatically maintained section

architecture ro_lft of ro_lft is

signal rotated : STD_LOGIC_VECTOR(31 downto 0);
--signal result: integer;
--signal a_std_vec : std_logic_vector (31 downto 0);
signal rotate_by : std_logic_vector(4 downto 0);

begin

-- enter your statements here --

rotate_by <= amount;

process (clk)
begin
if clk = '1' and clk'event then

rotated <= std_logic_vector(unsigned(quantity) rol
to_integer(signed(rotate_by)));

end if;
end process;

output <= rotated;

end ro_lft;


Patrick Moore
  Reply With Quote
Old 02-16-2004, 09:53 PM   #2
Egbert Molenkamp
 
Posts: n/a
Default Re: Rotate by variable
In your case the shift operator (ROL) can shift data to the left and to the
right (depends on sign of 'rotate_by').
As an alternative you could try the functions that are part of the
numeric_package:
shift_right en shift_left

I changed your code a little bit (only shift to the right). If your tool
supports this you can extend it to make a shift to the left and right.



library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity ro_lft is
port(
quantity : in unsigned(31 downto 0);
amount : in unsigned(4 downto 0);
clk : in STD_LOGIC;
output : out STD_LOGIC_VECTOR(31 downto 0)
);
end ro_lft;

--}} End of automatically maintained section

architecture ro_lft of ro_lft is

signal rotated : STD_LOGIC_VECTOR(31 downto 0);
signal rotate_by : unsigned(4 downto 0);

begin

-- enter your statements here --

rotate_by <= amount;

process (clk)
begin
if clk = '1' and clk'event then
rotated <=
std_logic_vector(shift_right(quantity,to_integer(u nsigned(rotate_by))));
end if;
end process;

output <= rotated;

end ro_lft;


Egbert Molenkamp

"Patrick Moore" <paddy-> schreef in bericht
news...
>
> Hi all,
>
> sorry to drop in like this but I'm having a problem and thought I may be
> able to gain some information from you all...
>
> I'm trying to achieve a variable rotate as below. i.e. it takes in two
> numbers, one 32 bits long, the other 5 bits long, and outputs the 32 bit
> number, rotated left by 5 bits.
>
> Now, this will compile fine (i.e. it's syntactically correct) but can't be
> synthesised in Synplify Pro.
>
> Does anyone have any suggestions, or code snippets that would be able to
> make this synthesisable for a Virtex II (Pro).
>
> tia,
>
> patrick.
>
>
>
> entity ro_lft is
> port(
> quantity : in STD_LOGIC_VECTOR(31 downto 0);
> amount : in STD_LOGIC_VECTOR(4 downto 0);
> clk : in STD_LOGIC;
> output : out STD_LOGIC_VECTOR(31 downto 0)
> );
> end ro_lft;
>
> --}} End of automatically maintained section
>
> architecture ro_lft of ro_lft is
>
> signal rotated : STD_LOGIC_VECTOR(31 downto 0);
> --signal result: integer;
> --signal a_std_vec : std_logic_vector (31 downto 0);
> signal rotate_by : std_logic_vector(4 downto 0);
>
> begin
>
> -- enter your statements here --
>
> rotate_by <= amount;
>
> process (clk)
> begin
> if clk = '1' and clk'event then
>
> rotated <= std_logic_vector(unsigned(quantity) rol
> to_integer(signed(rotate_by)));
>
> end if;
> end process;
>
> output <= rotated;
>
> end ro_lft;





Egbert Molenkamp
  Reply With Quote
Old 02-17-2004, 09:57 AM   #3
Jonathan Bromley
 
Posts: n/a
Default Re: Rotate by variable
"Patrick Moore" <paddy-> wrote in message
news...

> I'm trying to achieve a variable rotate as below. i.e. it takes in two
> numbers, one 32 bits long, the other 5 bits long, and outputs the 32 bit
> number, rotated left by 5 bits.
>
> Now, this will compile fine (i.e. it's syntactically correct) but can't be
> synthesised in Synplify Pro.


Can we ALL please bang VERY LOUDLY on Synplicity's door until they
finally support variable-length shifts?

> Does anyone have any suggestions, or code snippets that would be able to
> make this synthesisable for a Virtex II (Pro).


Two suggestions. Both work, but you need to try them out in your
synthesis tool - we've found that this barrel shift construct is
one which shows up some very big differences among tools.
You may need to tweak the details to suit your precise definition
of a barrel shift - mine rotates to the right.

For the sake of argument, let's suppose we have the following
entity:

entity barrel_shift is
port (
A : in std_logic_vector(31 downto 0); -- input word
S : in std_logic_vector(4 downto 0); -- rotate count
F : out std_logic_vector(31 downto 0) -- rotated output
);
end;

(1) Consider a funnel shifter. Stick two copies of the original
word together, then pick bits off it.

architecture funnel of barrel_shift is
begin
process (A, S)
variable double: std_logic_vector(63 downto 0);
begin
double := A & A; -- two copies of the input word
for i in 0 to 31 loop
F(i) <= double(to_integer(unsigned(S)) + i);
end loop;
end process;
end;


This depends on the tool correctly optimising the subscript
calculation by unrolling the loop.

(2) Use variable-length slices:

architecture slice of barrel_shift is
begin
F <= A(to_integer(unsigned(S)) - 1 downto 0) &
A(31 downto to_integer(unsigned(S)));
end;

I have seen this work correctly in some tools.

HTH
--
Jonathan Bromley, Consultant

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

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.






Jonathan Bromley
  Reply With Quote
Old 02-17-2004, 03:57 PM   #4
Patrick Moore
 
Posts: n/a
Default Re: Rotate by variable
On Tue, 17 Feb 2004 09:57:38 -0000, Jonathan Bromley
<> wrote:



>
> architecture funnel of barrel_shift is
> begin
> process (A, S)
> variable double: std_logic_vector(63 downto 0);
> begin
> double := A & A; -- two copies of the input word
> for i in 0 to 31 loop
> F(i) <= double(to_integer(unsigned(S)) + i);
> end loop;
> end process;
> end;


This one works, and even Synplify likes it, which is saying something.

What's the best way to reverse the rotate on this? (make it rotate left)

I guess doing a

temp := 32-S

and

F(i)<= double(to_integer(unsigned(temp)) + i);

Would do it, but I'm unsure of the fine tuning? :S (or if there's a
better way around it...)

As you can tell, I'm not very experienced in this whole thing, but
hopefully over time ...

> This depends on the tool correctly optimising the subscript
> calculation by unrolling the loop.
>
> (2) Use variable-length slices:
>
> architecture slice of barrel_shift is
> begin
> F <= A(to_integer(unsigned(S)) - 1 downto 0) &
> A(31 downto to_integer(unsigned(S)));
> end;
>
> I have seen this work correctly in some tools.


Unfortunately, Synplify Pro 7.2 doesn't like that one.. ;/

> HTH


It did, thanks.

atb,

Patrick


Patrick Moore
  Reply With Quote
Old 02-17-2004, 04:26 PM   #5
Jonathan Bromley
 
Posts: n/a
Default Re: Rotate by variable
"Patrick Moore" <paddy-> wrote in message
news...

> > architecture funnel of barrel_shift is
> > begin
> > process (A, S)
> > variable double: std_logic_vector(63 downto 0);
> > begin
> > double := A & A; -- two copies of the input word
> > for i in 0 to 31 loop
> > F(i) <= double(to_integer(unsigned(S)) + i);
> > end loop;
> > end process;
> > end;

>
> This one works, and even Synplify likes it


It's the version that I have found to be most portable
across synthesis tools. You may possibly get a harmless
warning about one of the bits of "double" being unused.

> What's the best way to reverse the rotate on this?
> (make it rotate left)


Reverse the order of bit numbering in all the vector
declarations - ports and internal signals A, F, double:
std_logic_vector(0 to 31) etc. Other code unchanged.
Unconventional but effective.

> I guess doing a
>
> temp := 32-S
>
> and
>
> F(i)<= double(to_integer(unsigned(temp)) + i);
>
> Would do it, but I'm unsure of the fine tuning


That, or something very close, sounds OK. But I would get
a bit jumpy about doing any unnecessary arithmetic on the
shift value; it would be OK in simulation but you really,
really don't want any adders in the select path. Hence
my preference for getting the left shift by re-numbering bits.
It's probably fine either way in most tools, but I've been
bitten with such things before now.

> As you can tell, I'm not very experienced in this whole thing, but
> hopefully over time ...


It's the usual engineering thing: there's no substitute for
lots of experience and plenty of paranoia.

> > (2) Use variable-length slices:

[...]
> Unfortunately, Synplify Pro 7.2 doesn't like that one.. ;/


Don't say I didn't warn you In fairness, that one is a
bit hard on synthesis tools; it implies data paths whose
widths vary as a function of one of the input values, which
doesn't sound very sensible. Only when you stick the two
variable-width pieces together can the tool discover that
the result is of constant width.

--

Jonathan Bromley, Consultant

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

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.





Jonathan Bromley
  Reply With Quote
Old 02-18-2004, 10:09 AM   #6
Egbert Molenkamp
 
Posts: n/a
Default Re: Rotate by variable

"Jonathan Bromley" <> wrote in message
news:c0sola$qf9$1$...
> Can we ALL please bang VERY LOUDLY on Synplicity's door until they
> finally support variable-length shifts?


I did .. and just received the answer that the issue is solved in 7.5 and
that the version is available for download.

Egbert Molenkamp







Egbert Molenkamp
  Reply With Quote
Old 02-18-2004, 10:38 AM   #7
Jonathan Bromley
 
Posts: n/a
Default Re: Rotate by variable
"Egbert Molenkamp" <> wrote
in message news:c0vdlc$5ig$...
>
> "Jonathan Bromley" <> wrote in message
> news:c0sola$qf9$1$...
> > Can we ALL please bang VERY LOUDLY on Synplicity's door until they
> > finally support variable-length shifts?

>
> I did .. and just received the answer that the issue is solved in 7.5

and
> that the version is available for download.


Yippee! Thanks Egbert.

--

Jonathan Bromley, Consultant

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

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.





Jonathan Bromley
  Reply With Quote
Old 02-18-2004, 02:51 PM   #8
ALuPin
 
Posts: n/a
Default Re: Rotate by variable
Hi,

I tried to compile your code with
Altera QuartusII v3.0 SP2

and got the following warning:

Warning: VHDL Subtype or Type Declaration warning at numeric_std.vhd(87:
subtype or type has null range Switching left and right bound of range.

Was does that mean?

Rgds
A.Vazquez

"Egbert Molenkamp" <> wrote in message news:<c0re3t$3bd$>...
> In your case the shift operator (ROL) can shift data to the left and to the
> right (depends on sign of 'rotate_by').
> As an alternative you could try the functions that are part of the
> numeric_package:
> shift_right en shift_left
>
> I changed your code a little bit (only shift to the right). If your tool
> supports this you can extend it to make a shift to the left and right.
>
>
>
> library ieee;
> use ieee.std_logic_1164.all;
> use ieee.numeric_std.all;
> entity ro_lft is
> port(
> quantity : in unsigned(31 downto 0);
> amount : in unsigned(4 downto 0);
> clk : in STD_LOGIC;
> output : out STD_LOGIC_VECTOR(31 downto 0)
> );
> end ro_lft;
>
> --}} End of automatically maintained section
>
> architecture ro_lft of ro_lft is
>
> signal rotated : STD_LOGIC_VECTOR(31 downto 0);
> signal rotate_by : unsigned(4 downto 0);
>
> begin
>
> -- enter your statements here --
>
> rotate_by <= amount;
>
> process (clk)
> begin
> if clk = '1' and clk'event then
> rotated <=
> std_logic_vector(shift_right(quantity,to_integer(u nsigned(rotate_by))));
> end if;
> end process;
>
> output <= rotated;
>
> end ro_lft;
>
>
> Egbert Molenkamp
>
> "Patrick Moore" <paddy-> schreef in bericht
> news...
> >
> > Hi all,
> >
> > sorry to drop in like this but I'm having a problem and thought I may be
> > able to gain some information from you all...
> >
> > I'm trying to achieve a variable rotate as below. i.e. it takes in two
> > numbers, one 32 bits long, the other 5 bits long, and outputs the 32 bit
> > number, rotated left by 5 bits.
> >
> > Now, this will compile fine (i.e. it's syntactically correct) but can't be
> > synthesised in Synplify Pro.
> >
> > Does anyone have any suggestions, or code snippets that would be able to
> > make this synthesisable for a Virtex II (Pro).
> >
> > tia,
> >
> > patrick.
> >
> >
> >
> > entity ro_lft is
> > port(
> > quantity : in STD_LOGIC_VECTOR(31 downto 0);
> > amount : in STD_LOGIC_VECTOR(4 downto 0);
> > clk : in STD_LOGIC;
> > output : out STD_LOGIC_VECTOR(31 downto 0)
> > );
> > end ro_lft;
> >
> > --}} End of automatically maintained section
> >
> > architecture ro_lft of ro_lft is
> >
> > signal rotated : STD_LOGIC_VECTOR(31 downto 0);
> > --signal result: integer;
> > --signal a_std_vec : std_logic_vector (31 downto 0);
> > signal rotate_by : std_logic_vector(4 downto 0);
> >
> > begin
> >
> > -- enter your statements here --
> >
> > rotate_by <= amount;
> >
> > process (clk)
> > begin
> > if clk = '1' and clk'event then
> >
> > rotated <= std_logic_vector(unsigned(quantity) rol
> > to_integer(signed(rotate_by)));
> >
> > end if;
> > end process;
> >
> > output <= rotated;
> >
> > end ro_lft;



ALuPin
  Reply With Quote
Old 02-18-2004, 03:06 PM   #9
Jonathan Bromley
 
Posts: n/a
Default Re: Rotate by variable
"ALuPin" <> wrote in message
news: om...
> Hi,
>
> I tried to compile your code with
> Altera QuartusII v3.0 SP2
>
> and got the following warning:
>
> Warning: VHDL Subtype or Type Declaration warning at
> numeric_std.vhd(87: subtype or type has null range


That's a completely reasonable warning, but VHDL is
supposed to allow null ranges. Many tools issue a warning,
but then go on to process the null range correctly. However,
Quartus says....

> Switching left and right bound of range.


AARGH!!!! This is absurd. Given

signal s: std_logic_vector (7 downto 0);

* the range (0 downto 0) is just a single bit s(0)
* the range (0 downto 1) is a null range - no bits at all
* the range (1 downto 0) is two bits wide

Therefore, switching the left and right bound is
completely unacceptable - it changes the meaning of
the code in a disastrous way.

> Was does that mean?


It means Quartus is doing something that it has no right to do.

See my other replies in this thread for a different solution
that does not require null ranges.




Jonathan Bromley
  Reply With Quote
Old 02-18-2004, 03:11 PM   #10
ALuPin
 
Posts: n/a
Default Re: Rotate by variable
Apart from that I get the Info
"No valid register-to-register paths exist for clock Clk"

What does go wrong with timing calculation?

Rgds

"Egbert Molenkamp" <> wrote in message news:<c0re3t$3bd$>...
> In your case the shift operator (ROL) can shift data to the left and to the
> right (depends on sign of 'rotate_by').
> As an alternative you could try the functions that are part of the
> numeric_package:
> shift_right en shift_left
>
> I changed your code a little bit (only shift to the right). If your tool
> supports this you can extend it to make a shift to the left and right.
>
>
>
> library ieee;
> use ieee.std_logic_1164.all;
> use ieee.numeric_std.all;
> entity ro_lft is
> port(
> quantity : in unsigned(31 downto 0);
> amount : in unsigned(4 downto 0);
> clk : in STD_LOGIC;
> output : out STD_LOGIC_VECTOR(31 downto 0)
> );
> end ro_lft;
>
> --}} End of automatically maintained section
>
> architecture ro_lft of ro_lft is
>
> signal rotated : STD_LOGIC_VECTOR(31 downto 0);
> signal rotate_by : unsigned(4 downto 0);
>
> begin
>
> -- enter your statements here --
>
> rotate_by <= amount;
>
> process (clk)
> begin
> if clk = '1' and clk'event then
> rotated <=
> std_logic_vector(shift_right(quantity,to_integer(u nsigned(rotate_by))));
> end if;
> end process;
>
> output <= rotated;
>
> end ro_lft;
>
>
> Egbert Molenkamp
>
> "Patrick Moore" <paddy-> schreef in bericht
> news...
> >
> > Hi all,
> >
> > sorry to drop in like this but I'm having a problem and thought I may be
> > able to gain some information from you all...
> >
> > I'm trying to achieve a variable rotate as below. i.e. it takes in two
> > numbers, one 32 bits long, the other 5 bits long, and outputs the 32 bit
> > number, rotated left by 5 bits.
> >
> > Now, this will compile fine (i.e. it's syntactically correct) but can't be
> > synthesised in Synplify Pro.
> >
> > Does anyone have any suggestions, or code snippets that would be able to
> > make this synthesisable for a Virtex II (Pro).
> >
> > tia,
> >
> > patrick.
> >
> >
> >
> > entity ro_lft is
> > port(
> > quantity : in STD_LOGIC_VECTOR(31 downto 0);
> > amount : in STD_LOGIC_VECTOR(4 downto 0);
> > clk : in STD_LOGIC;
> > output : out STD_LOGIC_VECTOR(31 downto 0)
> > );
> > end ro_lft;
> >
> > --}} End of automatically maintained section
> >
> > architecture ro_lft of ro_lft is
> >
> > signal rotated : STD_LOGIC_VECTOR(31 downto 0);
> > --signal result: integer;
> > --signal a_std_vec : std_logic_vector (31 downto 0);
> > signal rotate_by : std_logic_vector(4 downto 0);
> >
> > begin
> >
> > -- enter your statements here --
> >
> > rotate_by <= amount;
> >
> > process (clk)
> > begin
> > if clk = '1' and clk'event then
> >
> > rotated <= std_logic_vector(unsigned(quantity) rol
> > to_integer(signed(rotate_by)));
> >
> > end if;
> > end process;
> >
> > output <= rotated;
> >
> > end ro_lft;



ALuPin
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing value with out using variable in query string in PHP! Ali_ggl General Help Related Topics 0 11-29-2008 12:22 PM
How to set another machine's environment variable? vinay.babu Software 0 10-16-2008 12:54 PM
How to know if a variable is null peace2007 Software 1 09-30-2007 06:22 AM
Variable Scope in asp.Net jansi_rk Software 1 09-18-2006 06:05 PM
What's available in variable speed VCR's ? E. Matthews DVD Video 3 10-20-2005 11:44 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46