Boosted Add-Op
authorMarkus Hofstätter <markus.hofstaetter@gmx.net>
Sun, 19 Dec 2010 10:36:42 +0000 (11:36 +0100)
committerMarkus Hofstätter <markus.hofstaetter@gmx.net>
Sun, 19 Dec 2010 10:36:56 +0000 (11:36 +0100)
cpu/src/exec_op/add_op_b.vhd

index 77cd90116469e657b299534e20a5363af78f234d..331bb2968edf4bf5f52f20832d3d80a2c9de619a 100644 (file)
@@ -23,37 +23,46 @@ calc: process(left_operand, right_operand, alu_state, sub, addc)
        variable addcarry               : unsigned(carry_res'range);
 begin
                alu_result_v := alu_state;
-               
-               addcarry := (others =>'0');
-               addcarry(0) := alu_state.status.carry and addc;
-               
-               complement := inc(not(right_operand));
-               l_neg := left_operand(gp_register_t'high);
-               
-               carry_res := unsigned('0' & left_operand)+addcarry;
-               oflo1 := add_oflo(l_neg,'0',carry_res(gp_register_t'high));
-               
+               addcarry := (others => '0');
+               addcarry(0):= (alu_state.status.carry and addc) or sub;
                if sub = '1' then
-                       tmp_right_operand := unsigned('0' & complement);
+                       carry_res := unsigned('0' & left_operand)+unsigned('0' & not(right_operand))+addcarry;
                else
-                       tmp_right_operand := unsigned('0' & right_operand);
+                       carry_res := unsigned('0' & left_operand)+unsigned('0' & right_operand)+addcarry;
                end if;
+               alu_result_v.result := std_logic_vector(carry_res(gp_register_t'range));
+               alu_result_v.status.carry := carry_res(carry_res'high);
+               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));
+               -- addcarry := (others =>'0');
+               -- addcarry(0) := alu_state.status.carry and addc;
                
-               l_neg := carry_res(gp_register_t'high);
-               r_neg := tmp_right_operand(gp_register_t'high);
+               -- complement := inc(not(right_operand));
+               -- l_neg := left_operand(gp_register_t'high);
                
-               carry_res := carry_res + tmp_right_operand;
-               oflo2 := add_oflo(l_neg,r_neg,carry_res(gp_register_t'high));
+               -- carry_res := unsigned('0' & left_operand)+addcarry;
+               -- oflo1 := add_oflo(l_neg,'0',carry_res(gp_register_t'high));
+               
+               -- if sub = '1' then
+                       -- tmp_right_operand := unsigned('0' & complement);
+               -- else
+                       -- tmp_right_operand := unsigned('0' & right_operand);
+               -- end if;
+               
+               -- l_neg := carry_res(gp_register_t'high);
+               -- r_neg := tmp_right_operand(gp_register_t'high);
+               
+               -- carry_res := carry_res + tmp_right_operand;
+               -- oflo2 := add_oflo(l_neg,r_neg,carry_res(gp_register_t'high));
                
 
-               alu_result_v.result := std_logic_vector(carry_res(gp_register_t'range));
-               alu_result_v.status.carry := carry_res(carry_res'high);
-       --      alu_result_v.result := (0 => '1', others => '0');
+               -- alu_result_v.result := std_logic_vector(carry_res(gp_register_t'range));
+               -- alu_result_v.status.carry := carry_res(carry_res'high);
+       -- --   alu_result_v.result := (0 => '1', others => '0');
                
-               alu_result_v.status.oflo := oflo1 or oflo2;
+               -- alu_result_v.status.oflo := oflo1 or oflo2;
                
-               --sign will be set globally.
-               --zero will be set globally.
+               -- --sign will be set globally.
+               -- --zero will be set globally.
                
                alu_result <= alu_result_v;
 end process;