1 -- `Deep Thought', a softcore CPU implemented on a FPGA
3 -- Copyright (C) 2010 Markus Hofstaetter <markus.manrow@gmx.at>
4 -- Copyright (C) 2010 Martin Perner <e0725782@student.tuwien.ac.at>
5 -- Copyright (C) 2010 Stefan Rebernig <stefan.rebernig@gmail.com>
6 -- Copyright (C) 2010 Manfred Schwarz <e0725898@student.tuwien.ac.at>
7 -- Copyright (C) 2010 Bernhard Urban <lewurm@gmail.com>
9 -- This program is free software: you can redistribute it and/or modify
10 -- it under the terms of the GNU General Public License as published by
11 -- the Free Software Foundation, either version 3 of the License, or
12 -- (at your option) any later version.
14 -- This program is distributed in the hope that it will be useful,
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 -- GNU General Public License for more details.
19 -- You should have received a copy of the GNU General Public License
20 -- along with this program. If not, see <http://www.gnu.org/licenses/>.
23 use IEEE.std_logic_1164.all;
24 use IEEE.numeric_std.all;
26 use work.common_pkg.all;
29 architecture add_op of exec_op is
31 signal sub, addc : std_logic;
35 sub <= op_detail(SUB_OPT);
36 addc <= op_detail(CARRY_OPT);
38 calc: process(left_operand, right_operand, alu_state, sub, addc)
39 variable alu_result_v : alu_result_rec;
40 variable complement : gp_register_t;
41 variable carry_res : unsigned(gp_register_t'length downto 0);
42 variable tmp_right_operand : unsigned(gp_register_t'length downto 0);
43 variable oflo1, oflo2, l_neg, r_neg : std_logic;
44 variable addcarry : unsigned(carry_res'range);
46 alu_result_v := alu_state;
47 addcarry := (others => '0');
48 addcarry(0):= (alu_state.status.carry and addc) or (sub and not(addc));
50 carry_res := unsigned('0' & left_operand)+unsigned('0' & not(right_operand))+addcarry;
52 carry_res := unsigned('0' & left_operand)+unsigned('0' & right_operand)+addcarry;
54 alu_result_v.result := std_logic_vector(carry_res(gp_register_t'range));
55 alu_result_v.status.carry := carry_res(carry_res'high);
56 alu_result_v.status.oflo := add_oflo(left_operand(gp_register_t'high),right_operand(gp_register_t'high) xor sub, carry_res(gp_register_t'high));
57 -- addcarry := (others =>'0');
58 -- addcarry(0) := alu_state.status.carry and addc;
60 -- complement := inc(not(right_operand));
61 -- l_neg := left_operand(gp_register_t'high);
63 -- carry_res := unsigned('0' & left_operand)+addcarry;
64 -- oflo1 := add_oflo(l_neg,'0',carry_res(gp_register_t'high));
67 -- tmp_right_operand := unsigned('0' & complement);
69 -- tmp_right_operand := unsigned('0' & right_operand);
72 -- l_neg := carry_res(gp_register_t'high);
73 -- r_neg := tmp_right_operand(gp_register_t'high);
75 -- carry_res := carry_res + tmp_right_operand;
76 -- oflo2 := add_oflo(l_neg,r_neg,carry_res(gp_register_t'high));
79 -- alu_result_v.result := std_logic_vector(carry_res(gp_register_t'range));
80 -- alu_result_v.status.carry := carry_res(carry_res'high);
81 -- -- alu_result_v.result := (0 => '1', others => '0');
83 -- alu_result_v.status.oflo := oflo1 or oflo2;
85 -- --sign will be set globally.
86 -- --zero will be set globally.
88 alu_result <= alu_result_v;
91 end architecture add_op;