Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > how to write VHDL for shifting?

Reply
Thread Tools

how to write VHDL for shifting?

 
 
walala
Guest
Posts: n/a
 
      11-20-2003
For example,

T2:=CONV_INTEGER(X)*(2**5)-CONV_INTEGER(X)*(2**3)+CONV_INTEGER(X)

how to use shifting to represent it?

thanks a lot,

-Walala


 
Reply With Quote
 
 
 
 
Egbert Molenkamp
Guest
Posts: n/a
 
      11-20-2003

"walala" <> schreef in bericht
news:bphc5c$om4$...
> For example,
>
> T2:=CONV_INTEGER(X)*(2**5)-CONV_INTEGER(X)*(2**3)+CONV_INTEGER(X)
>
> how to use shifting to represent it?
>
> thanks a lot,
>
> -Walala


Maybe your synthesis tool can handle this! You want to multiply X with the
constant 41.
Try this

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY mul IS
PORT (x : IN unsigned(7 downto 0);
y : OUT unsigned(15 downto 0));
END mul;

ARCHITECTURE behaviour OF mul IS
SIGNAL qi : std_logic;
BEGIN
y <= 41 * x;
END behaviour;

Egbert Molenkamp


 
Reply With Quote
 
 
 
 
MM
Guest
Posts: n/a
 
      11-20-2003
"walala" <> wrote in message
news:bphc5c$om4$...
> For example,
>
> T2:=CONV_INTEGER(X)*(2**5)-CONV_INTEGER(X)*(2**3)+CONV_INTEGER(X)
>
> how to use shifting to represent it?


signal foo: std_logic_vector(7 downto 0);
signal shifted_by_2bits: std_logic_vector(7 downto 0);

shifted_by_2bits <= "00" & foo(7 downto 2);

Remember about the sign extension if you do signed arithmetic.

There are standard shift functions as well...


/Mikhail





 
Reply With Quote
 
Brent Hayhoe
Guest
Posts: n/a
 
      11-21-2003
MM wrote:
> "walala" <> wrote in message
> news:bphc5c$om4$...
>
>>For example,
>>
>>T2:=CONV_INTEGER(X)*(2**5)-CONV_INTEGER(X)*(2**3)+CONV_INTEGER(X)
>>
>>how to use shifting to represent it?

>
> signal foo: std_logic_vector(7 downto 0);
> signal shifted_by_2bits: std_logic_vector(7 downto 0);
>
> shifted_by_2bits <= "00" & foo(7 downto 2);
>
> Remember about the sign extension if you do signed arithmetic.
>
> There are standard shift functions as well...
>
> /Mikhail


Consider using the IEEE Numeric_Std package and defining your signals as either
Signed or Unsigned types dependant on the arithmetic that you are performing.
All the operator overloading is then predefined for you and you don't need to
concern yourself with sign extension when using Signed... it's handled by the
package functions.

N.B. integer conversion then becomes the 'To_Integer' function.

In general this should lead to more comprehensible code, and by inference, more
maintainable code.

Believe me, I have suffered the nightmare of converting a huge DSP design to
Numeric_Std from the Synopsys Std_Logic_Arith and it's associated packages.
Trying to work out when the designer switches from Unsigned to Signed numbers,
when all the signals/variables are defined as Std_Logic_Vectors is not as easy
as you might think!

I hope these packages are not standardized into the IEEE library!

--

Regards,

Brent Hayhoe.

Aftonroy Limited
Email: <A
HREF="mailto:Brent.Hayhoe@Aftonroy.com">

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL-2002 vs VHDL-93 vs VHDL-87? afd VHDL 1 03-23-2007 09:33 AM
BPSK on VHDL (warning - VHDL newbie) pygmalion VHDL 6 06-23-2006 07:30 PM
VHDL 2002 vs VHDL 1993 dude VHDL 1 03-23-2006 01:18 PM
multiD-vhdl: Multi Dimensional Arrays (allowing generics on each dimension) for VHDL (including ports) albert.neu@gmail.com VHDL 2 03-21-2006 04:05 PM
what's the difference between VHDL 93 CONCATENATION and VHDL 87 CONCATENATION? walala VHDL 3 09-18-2003 04:17 AM



Advertisments
 



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 47 48 49 50 51 52 53 54 55 56 57