OpenCores
URL https://opencores.org/ocsvn/ion/ion/trunk

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [mips_shifter.vhdl] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ja_rd
---------------------------------------------------------------------
2
 
3
---------------------------------------------------------------------
4
library ieee;
5
use ieee.std_logic_1164.all;
6
use ieee.std_logic_arith.all;
7
use ieee.std_logic_signed.all;
8
 
9
entity mips_shifter is
10
    port(
11
        -- data input
12
        d               : in  std_logic_vector(31 downto 0);
13
        -- shift amount
14
        a               : in  std_logic_vector(4 downto 0);
15
        -- shift function: {0=sll,1=sla(unused),2=srl,3=sra}
16
        fn              : in  std_logic_vector(1 downto 0);
17
        -- shift result
18
        r               : out std_logic_vector(31 downto 0)
19
    );
20
end;
21
 
22
architecture small of mips_shifter is
23
 
24
signal i_rev, o_rev :       std_logic_vector(31 downto 0);
25
 
26
signal ext :                std_logic_vector(31 downto 0);
27
type t_s is array(0 to 5) of std_logic_vector(31 downto 0);
28
signal s :                  t_s;
29
 
30
begin
31
    -- The barrel shifter needs to shift left and right. This would usually 
32
    -- require two parallel barrel shifters (left and right) and an output mux
33
    -- stage. Instead, we're gonna use a single left shifter, with two 
34
    -- conditional bit-reversal stages at input and output. 
35
    -- This will increase the LUT depth (and thus the delay) by 1 LUT row but 
36
    -- we'll cut the area by 4/11 more or less (depends on how many dedicated 
37
    -- muxes vs. LUTs the synth will use).
38
    -- The barrel shifter can account for as much as 1/4 of the CPU area 
39
    -- (excluding mult/div unit) so it makes sense to be cheap here if what we 
40
    -- want is a small core.
41
 
42
    -- Reverse input when shifting right
43
    input_reversed:
44
    for i in 0 to 31 generate
45
    begin
46
        i_rev(i) <= d(31-i);
47
    end generate input_reversed;
48
    s(5) <= i_rev when fn(1)='1' else d;
49
 
50
    -- Sign extension / zero extension
51
    ext <= (others => d(31)) when fn(0)='1' else (others => '0');
52
 
53
    -- Build left barrel shifter in 5 binary stages as usual
54
    shifter_stages:
55
    for i in 0 to 4 generate
56
    begin
57
        with a(i) select s(i) <=
58
            s(i+1)(31-2**i downto 0) & ext(2**i-1 downto 0) when '1',
59
            s(i+1)                                          when others;
60
    end generate shifter_stages;
61
 
62
    -- Reverse output when shifting right
63
    output_reversal:
64
    for i in 0 to 31 generate
65
    begin
66
        o_rev(i) <= s(0)(31-i);
67
    end generate output_reversal;
68
    r <= o_rev when fn(1)='1' else s(0);
69
 
70
end architecture small;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.