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

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [src/] [components/] [ALU/] [alu.vhdl] - Blame information for rev 29

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

Line No. Rev Author Line
1 2 lcdsgmtr
-- Copyright 2015, Jürgen Defurne
2
--
3
-- This file is part of the Experimental Unstable CPU System.
4
--
5
-- The Experimental Unstable CPU System Is free software: you can redistribute
6
-- it and/or modify it under the terms of the GNU Lesser General Public License
7
-- as published by the Free Software Foundation, either version 3 of the
8
-- License, or (at your option) any later version.
9
--
10
-- The Experimental Unstable CPU System is distributed in the hope that it will
11
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
13
-- General Public License for more details.
14
--
15
-- You should have received a copy of the GNU Lesser General Public License
16
-- along with Experimental Unstable CPU System. If not, see
17
-- http://www.gnu.org/licenses/lgpl.txt.
18
 
19
 
20
LIBRARY ieee;
21
USE ieee.STD_LOGIC_1164.ALL;
22
USE ieee.NUMERIC_STD.ALL;
23
 
24
ENTITY alu IS
25
  GENERIC(
26
    w_data : NATURAL RANGE 1 TO 32 := 16);
27
  PORT(
28
    op : IN  STD_LOGIC_VECTOR(3 DOWNTO 0);
29
    A  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
30
    B  : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
31
    Y  : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));
32
 
33
  FUNCTION alu_add (
34
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
35
    SIGNAL B : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
36
    RETURN STD_LOGIC_VECTOR;
37
 
38
  FUNCTION alu_add(
39
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
40
    SIGNAL B : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
41
    RETURN STD_LOGIC_VECTOR IS
42
  BEGIN  -- alu_add
43
    RETURN STD_LOGIC_VECTOR(UNSIGNED(A) + UNSIGNED(B));
44
  END alu_add;
45
 
46
  FUNCTION alu_sub (
47
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
48
    SIGNAL B : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
49
    RETURN STD_LOGIC_VECTOR;
50
 
51
  FUNCTION alu_sub(
52
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
53
    SIGNAL B : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
54
    RETURN STD_LOGIC_VECTOR IS
55
  BEGIN  -- alu_sub
56
    RETURN STD_LOGIC_VECTOR(UNSIGNED(A) - UNSIGNED(B));
57
  END alu_sub;
58
 
59
  FUNCTION alu_inc (
60
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
61
    RETURN STD_LOGIC_VECTOR;
62
 
63
  FUNCTION alu_inc (
64
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
65
    RETURN STD_LOGIC_VECTOR IS
66
  BEGIN
67
    RETURN STD_LOGIC_VECTOR(UNSIGNED(A) + 1);
68
  END alu_inc;
69
 
70
  FUNCTION alu_dec (
71
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
72
    RETURN STD_LOGIC_VECTOR;
73
 
74
  FUNCTION alu_dec (
75
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
76
    RETURN STD_LOGIC_VECTOR IS
77
  BEGIN
78
    RETURN STD_LOGIC_VECTOR(UNSIGNED(A) - 1);
79
  END alu_dec;
80
 
81
  FUNCTION shift_left (
82
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
83
    RETURN STD_LOGIC_VECTOR;
84
 
85
  FUNCTION shift_left (
86
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
87
    RETURN STD_LOGIC_VECTOR IS
88
  BEGIN
89
    RETURN STD_LOGIC_VECTOR(shift_left(UNSIGNED(A), 1));
90
  END shift_left;
91
 
92
  FUNCTION shift_right (
93
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
94
    RETURN STD_LOGIC_VECTOR;
95
 
96
  FUNCTION shift_right (
97
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
98
    RETURN STD_LOGIC_VECTOR IS
99
  BEGIN
100
    RETURN STD_LOGIC_VECTOR(shift_right(UNSIGNED(A), 1));
101
  END shift_right;
102
 
103
END ENTITY alu;
104
 
105
ARCHITECTURE Behavioral OF alu IS
106
 
107
  CONSTANT ZERO : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)
108
    := STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data));
109
  CONSTANT ONE : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)
110
    := STD_LOGIC_VECTOR(TO_UNSIGNED(1, w_data));
111
 
112
BEGIN  -- ARCHITECTURE Behavioral
113
 
114
  WITH op SELECT
115
    y <=
116
    alu_inc(A)     WHEN "0000",
117
    alu_dec(A)     WHEN "0001",
118
    ZERO           WHEN "0010",         -- Place holder
119
    ONE            WHEN "0011",         -- Place holder
120
    B WHEN "0100",
121
    A WHEN "0101",                      -- Place holder
122
    A WHEN "0110",                      -- Place holder
123
    alu_add(A, B)  WHEN "0111",
124
    alu_sub(A, B)  WHEN "1000",
125
    A WHEN "1001",                      -- Place holder
126
    A AND B        WHEN "1010",
127
    A OR B         WHEN "1011",
128
    A XOR B        WHEN "1100",
129
    NOT A          WHEN "1101",
130
    shift_left(A)  WHEN "1110",
131
    shift_right(A) WHEN "1111",
132
    A WHEN OTHERS;
133
 
134
END ARCHITECTURE Behavioral;

powered by: WebSVN 2.1.0

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