copyleft: gplv3 added and set repo to public
[calu.git] / cpu / src / exec_op / add_op_b.vhd
1 --   `Deep Thought', a softcore CPU implemented on a FPGA
2 --
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>
8 --
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.
13 --
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.
18 --
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/>.
21
22 library IEEE;
23 use IEEE.std_logic_1164.all;
24 use IEEE.numeric_std.all;
25
26 use work.common_pkg.all;
27 use work.alu_pkg.all;
28
29 architecture add_op of exec_op is
30
31 signal sub, addc : std_logic;
32
33 begin
34
35 sub <= op_detail(SUB_OPT);
36 addc <= op_detail(CARRY_OPT);
37
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);
45 begin
46                 alu_result_v := alu_state;
47                 addcarry := (others => '0');
48                 addcarry(0):= (alu_state.status.carry and addc) or (sub and not(addc));
49                 if sub = '1' then
50                         carry_res := unsigned('0' & left_operand)+unsigned('0' & not(right_operand))+addcarry;
51                 else
52                         carry_res := unsigned('0' & left_operand)+unsigned('0' & right_operand)+addcarry;
53                 end if;
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;
59                 
60                 -- complement := inc(not(right_operand));
61                 -- l_neg := left_operand(gp_register_t'high);
62                 
63                 -- carry_res := unsigned('0' & left_operand)+addcarry;
64                 -- oflo1 := add_oflo(l_neg,'0',carry_res(gp_register_t'high));
65                 
66                 -- if sub = '1' then
67                         -- tmp_right_operand := unsigned('0' & complement);
68                 -- else
69                         -- tmp_right_operand := unsigned('0' & right_operand);
70                 -- end if;
71                 
72                 -- l_neg := carry_res(gp_register_t'high);
73                 -- r_neg := tmp_right_operand(gp_register_t'high);
74                 
75                 -- carry_res := carry_res + tmp_right_operand;
76                 -- oflo2 := add_oflo(l_neg,r_neg,carry_res(gp_register_t'high));
77                 
78
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');
82                 
83                 -- alu_result_v.status.oflo := oflo1 or oflo2;
84                 
85                 -- --sign will be set globally.
86                 -- --zero will be set globally.
87                 
88                 alu_result <= alu_result_v;
89 end process; 
90
91 end architecture add_op;