2 use IEEE.std_logic_1164.all;
\r
3 use IEEE.numeric_std.all;
\r
5 use work.alu_pkg.all;
\r
8 architecture behaviour of alu is
\r
14 reset : in std_logic;
\r
16 left_operand : in gp_register_t;
\r
17 right_operand : in gp_register_t;
\r
18 op_detail : in op_opt_t;
\r
19 alu_state : in alu_result_rec;
\r
20 alu_result : out alu_result_rec
\r
22 end component exec_op;
\r
24 signal add_result, and_result, or_result, xor_result, shift_result : alu_result_rec;
\r
29 port map(clk,reset,left_operand, right_operand, op_detail, alu_state, add_result);
\r
32 port map(clk,reset,left_operand, right_operand, op_detail, alu_state, and_result);
\r
34 port map(clk,reset,left_operand, right_operand, op_detail, alu_state, or_result);
\r
36 port map(clk,reset,left_operand, right_operand, op_detail, alu_state, xor_result);
\r
38 shift_inst : exec_op
\r
39 port map(clk,reset,left_operand, right_operand, op_detail, alu_state, shift_result);
\r
41 calc: process(condition, op_group, op_detail ,alu_state,and_result,add_result,or_result,xor_result,shift_result)
\r
42 variable result_v : alu_result_rec;
\r
43 variable res_prod : std_logic;
\r
44 variable cond_met : std_logic;
\r
45 variable mem_en : std_logic;
\r
47 result_v := alu_state;
\r
49 result_v.result := add_result.result;
\r
55 cond_met := not(alu_state.status.zero);
\r
57 cond_met := alu_state.status.zero;
\r
59 cond_met := not(alu_state.status.oflo);
\r
61 cond_met := alu_state.status.oflo;
\r
63 cond_met := not(alu_state.status.carry);
\r
65 cond_met := alu_state.status.carry;
\r
67 cond_met := not(alu_state.status.sign);
\r
69 cond_met := alu_state.status.sign;
\r
71 cond_met := not(alu_state.status.carry) and not(alu_state.status.zero);
\r
73 cond_met := alu_state.status.carry or alu_state.status.zero;
\r
75 cond_met := not(alu_state.status.sign xor alu_state.status.oflo);
\r
77 cond_met := alu_state.status.sign xor alu_state.status.oflo;
\r
79 cond_met := not(alu_state.status.zero) and not(alu_state.status.sign xor alu_state.status.oflo);
\r
81 cond_met := alu_state.status.zero or (alu_state.status.sign xor alu_state.status.oflo);
\r
90 result_v := add_result;
\r
92 result_v := and_result;
\r
94 result_v := or_result;
\r
96 result_v := xor_result;
\r
98 result_v := shift_result;
\r
101 if result_v.result = REG_ZERO then
\r
102 result_v.status.zero := '1';
\r
105 result_v.status.sign := result_v.result(gp_register_t'high);
\r
107 if (op_detail(NO_PSW_OPT) = '1') or (cond_met = '0') then
\r
108 result_v.status := alu_state.status;
\r
111 result_v.new_val := not(op_detail(NO_DST_OPT)) and res_prod and cond_met;
\r
112 result_v.mem_en := mem_en and cond_met;
\r
114 alu_result <= result_v;
\r
118 end architecture behaviour;
\r
120 configuration alu_cfg of alu is
\r
123 for add_inst : exec_op
\r
124 use entity work.exec_op(add_op);
\r
126 for and_inst : exec_op
\r
127 use entity work.exec_op(and_op);
\r
129 for or_inst : exec_op
\r
130 use entity work.exec_op(or_op);
\r
132 for xor_inst : exec_op
\r
133 use entity work.exec_op(xor_op);
\r
135 for shift_inst : exec_op
\r
136 use entity work.exec_op(shift_op);
\r
140 end configuration alu_cfg;
\r