OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [hf-riscv/] [core_rv32i/] [alu.vhd] - Blame information for rev 19

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

Line No. Rev Author Line
1 13 serginhofr
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_unsigned.all;
4
 
5
entity alu is
6
        port (  op1:            in std_logic_vector(31 downto 0);
7
                op2:            in std_logic_vector(31 downto 0);
8
                alu_op:         in std_logic_vector(3 downto 0);
9
                result:         out std_logic_vector(31 downto 0);
10
                zero:           out std_logic;
11
                less_than:      out std_logic
12
        );
13
end alu;
14
 
15
architecture arch_alu of alu is
16
        signal r, shift: std_logic_vector(31 downto 0);
17
        signal shift_op2: std_logic_vector(4 downto 0);
18
        signal addsub: std_logic_vector(32 downto 0);
19
        signal less, left, logical: std_logic;
20
begin
21
        process(op1, op2, alu_op, addsub, less, shift_op2, shift)
22
        begin
23
                case alu_op is
24
                        when "0000" => r <= op1 and op2;
25
                        when "0001" => r <= op1 or op2;
26
                        when "0010" => r <= op1 xor op2;
27
                        when "0100" | "0101" => r <= addsub(31 downto 0);
28
                        when "0110" => r <= op2;
29
                        when "0111" | "1000" => r <= x"0000000" & "000" & less;
30
                        when others => r <= shift;
31
                end case;
32
        end process;
33
 
34
        addsub <= ('0' & op1) - ('0' & op2) when alu_op > "0100" else ('0' & op1) + ('0' & op2);
35
        less <= addsub(32) when op1(31) = op2(31) or alu_op = "1000" else op1(31);
36
        less_than <= less;
37
        zero <= not (r(31) or r(30) or r(29) or r(28) or r(27) or r(26) or r(25) or r(24) or
38
                        r(23) or r(22) or r(21) or r(20) or r(19) or r(18) or r(17) or r(16) or
39
                        r(15) or r(14) or r(13) or r(12) or r(11) or r(10) or r(9) or r(8) or
40
                        r(7) or r(6) or r(5) or r(4) or r(3) or r(2) or r(1) or r(0));
41
 
42
        shift_op2 <= op2(4 downto 0);
43
 
44
        left <= '1' when alu_op(0) = '1' else '0';
45
        logical <= '1' when alu_op(2) = '0' else '0';
46
 
47
        barrel_shifter: entity work.bshift
48
        port map(       left => left,
49
                        logical => logical,
50
                        shift => shift_op2,
51
                        input => op1,
52
                        output => shift
53
        );
54
 
55
        result <= r;
56
 
57
end arch_alu;
58
 

powered by: WebSVN 2.1.0

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