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

Subversion Repositories t400

[/] [t400/] [trunk/] [rtl/] [vhdl/] [t400_alu.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 arniml
-------------------------------------------------------------------------------
2
--
3
-- The Arithmetic Logic Unit (ALU).
4
-- It contains the accumulator and the C flag.
5
--
6
-- $Id: t400_alu.vhd,v 1.1.1.1 2006-05-06 01:56:44 arniml Exp $
7
--
8
-- Copyright (c) 2006 Arnim Laeuger (arniml@opencores.org)
9
--
10
-- All rights reserved
11
--
12
-- Redistribution and use in source and synthezised forms, with or without
13
-- modification, are permitted provided that the following conditions are met:
14
--
15
-- Redistributions of source code must retain the above copyright notice,
16
-- this list of conditions and the following disclaimer.
17
--
18
-- Redistributions in synthesized form must reproduce the above copyright
19
-- notice, this list of conditions and the following disclaimer in the
20
-- documentation and/or other materials provided with the distribution.
21
--
22
-- Neither the name of the author nor the names of other contributors may
23
-- be used to endorse or promote products derived from this software without
24
-- specific prior written permission.
25
--
26
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
30
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
-- POSSIBILITY OF SUCH DAMAGE.
37
--
38
-- Please report bugs to the author, but before you do so, please
39
-- make sure that this is not a derivative work and that
40
-- you have the latest version of this file.
41
--
42
-- The latest version of this file can be found at:
43
--      http://www.opencores.org/cvsweb.shtml/t400/
44
--
45
-------------------------------------------------------------------------------
46
 
47
library ieee;
48
use ieee.std_logic_1164.all;
49
 
50
use work.t400_pack.all;
51
 
52
entity t400_alu is
53
 
54
  port (
55
    -- System Interface -------------------------------------------------------
56
    ck_i       : in  std_logic;
57
    ck_en_i    : in  boolean;
58
    por_i      : in  boolean;
59
    res_i      : in  boolean;
60
    -- Control Interface ------------------------------------------------------
61
    op_i       : in  alu_op_t;
62
    -- Data Interface ---------------------------------------------------------
63
    m_i        : in  dw_t;
64
    dec_data_i : in  dec_data_t;
65
    q_low_i    : in  dw_t;
66
    b_i        : in  b_t;
67
    g_i        : in  dw_t;
68
    in_i       : in  dw_t;
69
    il_i       : in  dw_t;
70
    sio_i      : in  dw_t;
71
    a_o        : out dw_t;
72
    carry_o    : out std_logic;
73
    c_o        : out std_logic
74
  );
75
 
76
end t400_alu;
77
 
78
 
79
library ieee;
80
use ieee.numeric_std.all;
81
 
82
architecture rtl of t400_alu is
83
 
84
  subtype alu_dw_t     is unsigned(dw_t'high+1 downto 0);
85
  signal  alu_result_s : alu_dw_t;
86
 
87
  signal  a_q          : dw_t;
88
  signal  c_q          : std_logic;
89
 
90
begin
91
 
92
  -----------------------------------------------------------------------------
93
  -- Process regs
94
  --
95
  -- Purpose:
96
  --   Implements the sequential registers of the ALU:
97
  --     * A - accumulator
98
  --     * C - carry flag
99
  --
100
  regs: process (ck_i, por_i)
101
  begin
102
    if por_i then
103
      a_q <= (others => '0');
104
      c_q <= '0';
105
 
106
    elsif ck_i'event and ck_i = '1' then
107
      if res_i then
108
        -- synchronous reset upon external reset event
109
        a_q <= (others => '0');
110
        c_q <= '0';
111
 
112
      elsif ck_en_i then
113
        -- update accumulator
114
        case op_i is
115
          when ALU_CLRA    |
116
               ALU_ADD     |
117
               ALU_ADD_10  |
118
               ALU_ADD_C   |
119
               ALU_ADD_DEC |
120
               ALU_COMP    |
121
               ALU_XOR     =>
122
            a_q <= std_logic_vector(alu_result_s(dw_t'range));
123
          when ALU_LOAD_M =>
124
            a_q <= m_i;
125
          when ALU_LOAD_Q =>
126
            a_q <= q_low_i;
127
          when ALU_LOAD_G =>
128
            a_q <= g_i;
129
          when ALU_LOAD_IN =>
130
            a_q <= in_i;
131
          when ALU_LOAD_IL =>
132
            a_q <= il_i(3) & "10" & il_i(0);
133
          when ALU_LOAD_BR =>
134
            a_q(3 downto 2) <= (others => '0');
135
            a_q(1 downto 0) <= b_i(br_range_t);
136
          when ALU_LOAD_BD =>
137
            a_q <= b_i(bd_range_t);
138
          when ALU_LOAD_SIO =>
139
            a_q <= sio_i;
140
          when others =>
141
            null;
142
        end case;
143
 
144
        -- update C flag upon the following instructions
145
        case op_i is
146
          -- carry result of addition -----------------------------------------
147
          when ALU_ADD_C =>
148
            c_q <= alu_result_s(alu_dw_t'high);
149
 
150
          -- reset C flag -----------------------------------------------------
151
          when ALU_RC =>
152
            c_q <= '0';
153
 
154
          -- set C flag -------------------------------------------------------
155
          when ALU_SC =>
156
            c_q <= '1';
157
 
158
          when others =>
159
            null;
160
        end case;
161
      end if;
162
    end if;
163
  end process regs;
164
  --
165
  -----------------------------------------------------------------------------
166
 
167
 
168
  -----------------------------------------------------------------------------
169
  -- Process dp
170
  --
171
  -- Purpose:
172
  --   Implements the ALU's data path.
173
  --
174
  dp: process (op_i,
175
               a_q,
176
               m_i,
177
               dec_data_i,
178
               c_q)
179
    variable in1_v,
180
             in2_v,
181
             in3_v,
182
             add_v, xor_v : alu_dw_t;
183
  begin
184
    -- prepare adder
185
    in1_v      := '0' & unsigned(a_q);
186
    if    op_i = ALU_ADD_10 then
187
      in2_v    := to_unsigned(10, alu_dw_t'length);
188
    elsif op_i = ALU_ADD_DEC then
189
      in2_v    := '0' & unsigned(dec_data_i(dw_t'range));
190
    else
191
      in2_v    := '0' & unsigned(m_i);
192
    end if;
193
    if op_i = ALU_ADD_C then
194
      in3_v    := (others => '0');
195
      in3_v(0) := c_q;
196
    else
197
      in3_v    := (others => '0');
198
    end if;
199
    add_v := in1_v + in2_v + in3_v;
200
 
201
    -- prepare exclusive or
202
    xor_v := in1_v xor in2_v;
203
 
204
    case op_i is
205
      -- ALU operation: Clear accumulator -------------------------------------
206
      when ALU_CLRA =>
207
        alu_result_s <= (others => '0');
208
 
209
      -- ALU operation: Add to accumulator ------------------------------------
210
      when ALU_ADD     |
211
           ALU_ADD_10  |
212
           ALU_ADD_C   |
213
           ALU_ADD_DEC =>
214
        alu_result_s <= add_v;
215
 
216
      -- ALU operation: Complement accumulator --------------------------------
217
      when ALU_COMP =>
218
        alu_result_s <= '0' & not unsigned(a_q);
219
 
220
      -- ALU operation: XOR to accumulator ------------------------------------
221
      when ALU_XOR =>
222
        alu_result_s <= xor_v;
223
 
224
      when others =>
225
        alu_result_s <= (others => '-');
226
    end case;
227
  end process dp;
228
  --
229
  -----------------------------------------------------------------------------
230
 
231
 
232
  -----------------------------------------------------------------------------
233
  -- Output mapping
234
  -----------------------------------------------------------------------------
235
  a_o     <= a_q;
236
  carry_o <= alu_result_s(alu_dw_t'high);
237
  c_o     <= c_q;
238
 
239
end rtl;
240
 
241
 
242
-------------------------------------------------------------------------------
243
-- File History:
244
--
245
-- $Log: not supported by cvs2svn $
246
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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