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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [rtl/] [lxp32_shifter.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
---------------------------------------------------------------------
2
-- Barrel shifter
3
--
4
-- Part of the LXP32 CPU
5
--
6
-- Copyright (c) 2016 by Alex I. Kuznetsov
7
--
8
-- Performs logical (unsigned) and arithmetic (signed) shifts
9
-- in both directions. Pipeline latency: 1 cycle.
10
---------------------------------------------------------------------
11
 
12
library ieee;
13
use ieee.std_logic_1164.all;
14
 
15
entity lxp32_shifter is
16
        port(
17
                clk_i: in std_logic;
18
                rst_i: in std_logic;
19
                ce_i: in std_logic;
20
                d_i: in std_logic_vector(31 downto 0);
21
                s_i: in std_logic_vector(4 downto 0);
22
                right_i: in std_logic;
23
                sig_i: in std_logic;
24
                ce_o: out std_logic;
25
                d_o: out std_logic_vector(31 downto 0)
26
        );
27
end entity;
28
 
29
architecture rtl of lxp32_shifter is
30
 
31
signal data: std_logic_vector(d_i'range);
32
signal data_shifted: std_logic_vector(d_i'range);
33
 
34
signal fill: std_logic; -- 0 for unsigned shifts, sign bit for signed ones
35
signal fill_v: std_logic_vector(3 downto 0);
36
 
37
type cascades_type is array (4 downto 0) of std_logic_vector(d_i'range);
38
signal cascades: cascades_type;
39
 
40
signal stage2_data: std_logic_vector(d_i'range);
41
signal stage2_s: std_logic_vector(s_i'range);
42
signal stage2_fill: std_logic;
43
signal stage2_fill_v: std_logic_vector(15 downto 0);
44
signal stage2_right: std_logic;
45
 
46
signal ceo: std_logic:='0';
47
 
48
begin
49
 
50
-- Internally, data are shifted in left direction. For right shifts
51
-- we reverse the argument's bit order
52
 
53
data_gen: for i in data'range generate
54
        data(i)<=d_i(i) when right_i='0' else d_i(d_i'high-i);
55
end generate;
56
 
57
-- A set of cascaded shifters shifting by powers of two
58
 
59
fill<=sig_i and data(0);
60
fill_v<=(others=>fill);
61
 
62
cascades(0)<=data(30 downto 0)&fill_v(0) when s_i(0)='1' else data;
63
cascades(1)<=cascades(0)(29 downto 0)&fill_v(1 downto 0) when s_i(1)='1' else cascades(0);
64
cascades(2)<=cascades(1)(27 downto 0)&fill_v(3 downto 0) when s_i(2)='1' else cascades(1);
65
 
66
process (clk_i) is
67
begin
68
        if rising_edge(clk_i) then
69
                if rst_i='1' then
70
                        ceo<='0';
71
                        stage2_data<=(others=>'-');
72
                        stage2_s<=(others=>'-');
73
                        stage2_fill<='-';
74
                        stage2_right<='-';
75
                else
76
                        ceo<=ce_i;
77
                        stage2_data<=cascades(2);
78
                        stage2_s<=s_i;
79
                        stage2_fill<=fill;
80
                        stage2_right<=right_i;
81
                end if;
82
        end if;
83
end process;
84
 
85
stage2_fill_v<=(others=>stage2_fill);
86
 
87
cascades(3)<=stage2_data(23 downto 0)&stage2_fill_v(7 downto 0) when stage2_s(3)='1' else stage2_data;
88
cascades(4)<=cascades(3)(15 downto 0)&stage2_fill_v(15 downto 0) when stage2_s(4)='1' else cascades(3);
89
 
90
-- Reverse bit order back, if needed
91
 
92
data_shifted_gen: for i in data_shifted'range generate
93
        data_shifted(i)<=cascades(4)(i) when stage2_right='0' else cascades(4)(cascades(4)'high-i);
94
end generate;
95
 
96
d_o<=data_shifted;
97
ce_o<=ceo;
98
 
99
end architecture;

powered by: WebSVN 2.1.0

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