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

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [src/] [components/] [ALU/] [alu2.vhdl] - Blame information for rev 21

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 6 lcdsgmtr
-- Clocked ALU
25
-- To make the clock cycle shorter, the result between the operation output and
26
-- the selection multiplexer is clocked.
27
 
28 2 lcdsgmtr
ENTITY alu IS
29
  GENERIC(
30
    w_data : NATURAL RANGE 1 TO 32 := 16);
31
  PORT(
32
    clk : IN  STD_LOGIC;
33
    op  : IN  STD_LOGIC_VECTOR(3 DOWNTO 0);
34
    A   : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
35
    B   : IN  STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
36
    Y   : OUT STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0));
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;
42
 
43
  FUNCTION alu_add(
44
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
45
    SIGNAL B : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
46
    RETURN STD_LOGIC_VECTOR IS
47
  BEGIN  -- alu_add
48
    RETURN STD_LOGIC_VECTOR(UNSIGNED(A) + UNSIGNED(B));
49
  END alu_add;
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;
55
 
56
  FUNCTION alu_sub(
57
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
58
    SIGNAL B : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
59
    RETURN STD_LOGIC_VECTOR IS
60
  BEGIN  -- alu_sub
61
    RETURN STD_LOGIC_VECTOR(UNSIGNED(A) - UNSIGNED(B));
62
  END alu_sub;
63
 
64
  FUNCTION alu_inc (
65
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
66
    RETURN STD_LOGIC_VECTOR;
67
 
68
  FUNCTION alu_inc (
69
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
70
    RETURN STD_LOGIC_VECTOR IS
71
  BEGIN
72
    RETURN STD_LOGIC_VECTOR(UNSIGNED(A) + 1);
73
  END alu_inc;
74
 
75
  FUNCTION alu_dec (
76
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
77
    RETURN STD_LOGIC_VECTOR;
78
 
79
  FUNCTION alu_dec (
80
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
81
    RETURN STD_LOGIC_VECTOR IS
82
  BEGIN
83
    RETURN STD_LOGIC_VECTOR(UNSIGNED(A) - 1);
84
  END alu_dec;
85
 
86
  FUNCTION shift_left (
87
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
88
    RETURN STD_LOGIC_VECTOR;
89
 
90
  FUNCTION shift_left (
91
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
92
    RETURN STD_LOGIC_VECTOR IS
93
  BEGIN
94
    RETURN STD_LOGIC_VECTOR(shift_left(UNSIGNED(A), 1));
95
  END shift_left;
96
 
97
  FUNCTION shift_right (
98
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
99
    RETURN STD_LOGIC_VECTOR;
100
 
101
  FUNCTION shift_right (
102
    SIGNAL A : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0))
103
    RETURN STD_LOGIC_VECTOR IS
104
  BEGIN
105
    RETURN STD_LOGIC_VECTOR(shift_right(UNSIGNED(A), 1));
106
  END shift_right;
107
 
108
END ENTITY alu;
109
 
110
ARCHITECTURE Behavioral OF alu IS
111
 
112
  CONSTANT ZERO : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)
113
    := STD_LOGIC_VECTOR(TO_UNSIGNED(0, w_data));
114
  CONSTANT ONE : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0)
115
    := STD_LOGIC_VECTOR(TO_UNSIGNED(1, w_data));
116
 
117
  SIGNAL R_INC  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
118
  SIGNAL R_DEC  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
119
  SIGNAL R_ZERO : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
120
  SIGNAL R_ONE  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
121
  SIGNAL R_B    : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
122
  SIGNAL R_A    : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
123
  SIGNAL R_ADD  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
124
  SIGNAL R_SUB  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
125
  SIGNAL R_AND  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
126
  SIGNAL R_OR   : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
127
  SIGNAL R_XOR  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
128
  SIGNAL R_NOT  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
129
  SIGNAL R_SLL  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
130
  SIGNAL R_SRL  : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
131
 
132
 
133
BEGIN  -- ARCHITECTURE Behavioral
134
 
135
  PROCESS (CLK)
136
  BEGIN
137
    IF rising_edge(CLK) THEN
138
 
139
      R_INC  <= alu_inc(A);
140
      R_DEC  <= alu_dec(A);
141
      R_ZERO <= ZERO;
142
      R_ONE  <= ONE;
143
      R_B    <= B;
144
      R_A    <= A;
145
      R_ADD  <= alu_add(A, B);
146
      R_SUB  <= alu_sub(A, B);
147
      R_AND  <= A AND B;
148
      R_OR   <= A OR B;
149
      R_XOR  <= A XOR B;
150
      R_NOT  <= NOT A;
151
      R_SLL  <= shift_left(A);
152
      R_SRL  <= shift_right(A);
153
 
154
    END IF;
155
  END PROCESS;
156
 
157
  WITH op SELECT
158
    y <=
159
    R_INC  WHEN "0000",
160
    R_DEC  WHEN "0001",
161
    R_ZERO WHEN "0010",                 -- Place holder
162
    R_ONE  WHEN "0011",                 -- Place holder
163
    R_B    WHEN "0100",
164
    R_A    WHEN "0101",                 -- Place holder
165
    R_A    WHEN "0110",                 -- Place holder
166
    R_ADD  WHEN "0111",
167
    R_SUB  WHEN "1000",
168
    R_A    WHEN "1001",                 -- Place holder
169
    R_AND  WHEN "1010",
170
    R_OR   WHEN "1011",
171
    R_XOR  WHEN "1100",
172
    R_NOT  WHEN "1101",
173
    R_SLL  WHEN "1110",
174
    R_SRL  WHEN "1111",
175
    R_A    WHEN OTHERS;
176
 
177
END ARCHITECTURE Behavioral;

powered by: WebSVN 2.1.0

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