Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] shift left(or right) with arithmetic operation for data type SIGNED in VHDL

Status
Not open for further replies.

rafimiet

Member level 5
Joined
May 21, 2015
Messages
94
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,364
I have to use shift operation for signed data type. sll and srl are synthesizable, however sla and sra are not. How can I perform them?
 

sla is the same as srl.
sra exists in the 2008 version of numeric_std (and in the '93 compatability package).

Otherwise, you can just use the resize function and slice it - or write your own


Code VHDL - [expand]
1
2
3
4
5
function "sra" (l : signed; r : natural) return signed is
  alias l_a : signed(l'length-1 downto 0) is l;
begin
  return resize(l_a, l_a'length + r)(l_a'length+r-1 downto r);
end function "sra";

 

I have selected VHDL-200X and the code is as follows:

Code VHDL - [expand]
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
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
 
entity shift is
    Port ( din : in  STD_LOGIC_VECTOR(7 downto 0);
           clk : in  STD_LOGIC;
           dout : out  STD_LOGIC_VECTOR(7 downto 0));
end shift;
 
architecture Behavioral of shift is
SIGNAL s1,s2 : SIGNED(7 downto 0);
begin
    Process(clk)
        VARIABLE v1 : SIGNED(7 downto 0);
    BEGIN
        IF clk'event and clk = '1' then
            s1 <= signed(din);
            s2 <= s1 sla 2;
            dout <= std_logic_vector(s2);
        END IF;
    END PROCESS;
 
 
end Behavioral;



It shows the following error
ERROR:HDLParsers:808 - Line 19. sla can not have such operands in this context.
Am I making any mistake while using sla or it is still not supported in VHDL-2008?
 

I assume this is Vivado? it does not support the 2008 versions of the IEEE packages. It only has selective support for some parts of VHDL 2008. Hence why they call it 200X (to cover both 2002/2008).
Afaik, Intel Quartus Pro 17 and synplify are the only two tools to have proper 2008 support

- - - Updated - - -

But like I said, you're using sla - this is identical in functionality to sll for signed. So use SLL instead.
 

I assume this is Vivado?
I am actually working on Xilinx ISE 14.2.
you're using sla - this is identical in functionality to sll for signed. So use SLL instead.
when I try this,
x = 11001010;
y = x sll 2;
y =00101000;
which is a positive number!!
 

What do you expect? you're shifting it by 2 (multiplying by 4) and limiting the bit width to 8 bits, and clearly its overflowing. Shifting left always appends 0 to the right (sra and srl both do this). sra appends the sign bit.

see https://en.wikipedia.org/wiki/Arithmetic_shift
 

I needed to use both sla and sra. Then I can use the function you provided above for sra and sll for sla.
 

I needed to use both sla and sra. Then I can use the function you provided above for sra and sll for sla.

As with most code from the internet - use at your own peril.
Completely Untested.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top