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

Subversion Repositories xucpu

[/] [xucpu/] [trunk/] [src/] [components/] [ALU/] [summation.vhdl] - Blame information for rev 25

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

Line No. Rev Author Line
1 8 lcdsgmtr
LIBRARY IEEE;
2
USE IEEE.STD_LOGIC_1164.ALL;
3
USE ieee.NUMERIC_STD.ALL;
4
 
5
ENTITY adder IS
6
  GENERIC (
7
    w_data : NATURAL RANGE 1 TO 32 := 16);
8
  PORT (
9
    OP : IN  STD_LOGIC_VECTOR(1 DOWNTO 0);
10
    A  : IN  STD_LOGIC_VECTOR (w_data - 1 DOWNTO 0);
11
    B  : IN  STD_LOGIC_VECTOR (w_data - 1 DOWNTO 0);
12
    Ci : IN  STD_LOGIC;
13
    Y  : OUT STD_LOGIC_VECTOR (w_data - 1 DOWNTO 0);
14
    Co : OUT STD_LOGIC);
15
END adder;
16
 
17
ARCHITECTURE Behavioral OF adder IS
18
 
19
  SIGNAL An : NATURAL RANGE 0 TO 2**w_data - 1;
20
  SIGNAL Bn : NATURAL RANGE 0 TO 2**w_data - 1;
21
  SIGNAL Yn : NATURAL RANGE 0 TO 2**(w_data + 1) - 1;
22
 
23
  SIGNAL Cv : STD_LOGIC_VECTOR(0 TO 0);
24
  SIGNAL Cn : NATURAL RANGE 0 TO 1;
25
 
26
  SIGNAL sum : STD_LOGIC_VECTOR(w_data DOWNTO 0);
27
 
28
BEGIN
29
 
30
  SUM1 : PROCESS (A, B, OP, Ci) IS
31
  BEGIN  -- PROCESS SUM1
32
    An <= 0;
33
    Bn <= 0;
34
 
35
    Cv(0) <= '0';
36
    Cn    <= 0;
37
 
38
    Yn <= 0;
39
 
40
    sum <= (OTHERS => '0');
41
    Co  <= '0';
42
    Y   <= (OTHERS => '0');
43
 
44
    CASE OP IS
45
      WHEN "00" =>
46
        An <= to_integer(UNSIGNED(A));
47
        Bn <= to_integer(UNSIGNED(B));
48
 
49
        Cv(0) <= Ci;
50
        Cn    <= to_integer(UNSIGNED(Cv));
51
 
52
        Yn <= An + Bn + Cn;
53
 
54
        sum <= STD_LOGIC_VECTOR(to_unsigned(Yn, w_data + 1));
55
        Co  <= sum(w_data);
56
        Y   <= sum(w_data - 1 DOWNTO 0);
57
 
58
      WHEN "01" =>
59
        Y <= '0' & A(15 DOWNTO 1);
60
 
61
      WHEN "10" =>
62
        Y <= A(14 DOWNTO 0) & '0';
63
 
64
      WHEN "11" =>
65
        Y <= (OTHERS => '0');
66
 
67
      WHEN OTHERS =>
68
        NULL;
69
 
70
    END CASE;
71
  END PROCESS SUM1;
72
 
73
END Behavioral;
74
 
75
LIBRARY IEEE;
76
USE IEEE.STD_LOGIC_1164.ALL;
77
USE IEEE.NUMERIC_STD.ALL;
78
 
79
ENTITY summation IS
80
  GENERIC (
81
    w_data : NATURAL RANGE 1 TO 32 := 16);
82
  PORT (A  : IN  STD_LOGIC_VECTOR (w_data - 1 DOWNTO 0);
83
        B  : IN  STD_LOGIC_VECTOR (w_data - 1 DOWNTO 0);
84
        OP : IN  STD_LOGIC_VECTOR(2 DOWNTO 0);
85
        Y  : OUT STD_LOGIC_VECTOR (w_data - 1 DOWNTO 0));
86
END summation;
87
 
88
-- Operations:
89
-- "000" A + B
90
-- "001" A - B
91
-- "010" A + 1
92
-- "011" A - 1
93
-- "100" SHIFT LEFT
94
-- "101" SHIFT RIGHT
95
-- "110" ZERO
96
-- "111" ONE
97
 
98
ARCHITECTURE Behavioral OF summation IS
99
 
100
  COMPONENT adder IS
101
    GENERIC (
102
      w_data : NATURAL RANGE 1 TO 32 := w_data);
103
    PORT (
104
      OP : IN  STD_LOGIC_VECTOR(1 DOWNTO 0);
105
      A  : IN  STD_LOGIC_VECTOR (w_data - 1 DOWNTO 0);
106
      B  : IN  STD_LOGIC_VECTOR (w_data - 1 DOWNTO 0);
107
      Ci : IN  STD_LOGIC;
108
      Y  : OUT STD_LOGIC_VECTOR (w_data - 1 DOWNTO 0);
109
      Co : OUT STD_LOGIC);
110
  END COMPONENT adder;
111
 
112
  SIGNAL Ci : STD_LOGIC := '0';
113
  SIGNAL Bo : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
114
  SIGNAL Yr : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0);
115
 
116
  SIGNAL add_op : STD_LOGIC_VECTOR(1 DOWNTO 0);
117
 
118
  CONSTANT ZERO : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0) := (OTHERS => '0');
119
  CONSTANT ONE : STD_LOGIC_VECTOR(w_data - 1 DOWNTO 0) := STD_LOGIC_VECTOR(to_unsigned(1, w_data));
120
 
121
BEGIN
122
 
123
  ADD1 : adder PORT MAP (
124
    OP => add_op,
125
    A  => A,
126
    B  => Bo,
127
    Y  => Yr,
128
    Ci => Ci);
129
 
130
  WITH OP SELECT
131
    Ci <=
132
    '0' WHEN "000",                     -- Addition
133
    '1' WHEN "001",                     -- Subtraction
134
    '0' WHEN "010",                     -- Increment 1
135
    '1' WHEN "011",                     -- Decrement 1
136
    '0' WHEN OTHERS;
137
 
138
  WITH OP SELECT
139
    Bo <=
140
    B WHEN "000",
141
    NOT B                                    WHEN "001",
142
    STD_LOGIC_VECTOR(to_unsigned(1, w_data)) WHEN "010",
143
    STD_LOGIC_VECTOR(to_signed(-1, w_data))  WHEN "011",
144
    B WHEN OTHERS;
145
 
146
  WITH OP SELECT
147
    add_op <=
148
    "00" WHEN "000",
149
    "00" WHEN "001",
150
    "00" WHEN "010",
151
    "00" WHEN "011",
152
    "10" WHEN "100",
153
    "01" WHEN "101",
154
    "11" WHEN OTHERS;
155
 
156
  WITH OP SELECT
157
    Y <=
158
    ZERO WHEN "110",
159
    ONE  WHEN "111",
160
    Yr   WHEN OTHERS;
161
 
162
END Behavioral;
163
 

powered by: WebSVN 2.1.0

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