| 1 |
2 |
atypic |
library ieee;
|
| 2 |
|
|
use ieee.std_logic_1164.all;
|
| 3 |
|
|
use ieee.std_logic_unsigned.all;
|
| 4 |
|
|
use ieee.numeric_std.all;
|
| 5 |
|
|
use work.leval_package.all;
|
| 6 |
|
|
|
| 7 |
|
|
entity alu is
|
| 8 |
|
|
port (
|
| 9 |
|
|
in_a : in std_logic_vector(OBJECT_SIZE-1 downto 0);
|
| 10 |
|
|
in_b : in std_logic_vector(OBJECT_SIZE-1 downto 0);
|
| 11 |
|
|
funct : in std_logic_vector(FUNCT_SIZE-1 downto 0);
|
| 12 |
|
|
status : out std_logic_vector(STATUS_REG_SIZE-1 downto 0);
|
| 13 |
|
|
output : out std_logic_vector(OBJECT_SIZE-1 downto 0));
|
| 14 |
|
|
end entity alu;
|
| 15 |
|
|
|
| 16 |
|
|
architecture rtl of alu is
|
| 17 |
|
|
-- DIVIDER IS TOO SLOW, DISABLED
|
| 18 |
|
|
-- component divider is
|
| 19 |
|
|
-- GENERIC(WIDTH_DIVID : Integer := 32; -- Width Dividend
|
| 20 |
|
|
-- WIDTH_DIVIS : Integer := 16); -- Width Divisor
|
| 21 |
|
|
-- port(dividend : in std_logic_vector (WIDTH_DIVID-1 downto 0);
|
| 22 |
|
|
-- divisor : in std_logic_vector (WIDTH_DIVIS-1 downto 0);
|
| 23 |
|
|
-- quotient : out std_logic_vector (WIDTH_DIVID-1 downto 0);
|
| 24 |
|
|
-- remainder : out std_logic_vector (WIDTH_DIVIS-1 downto 0));
|
| 25 |
|
|
-- end component divider;
|
| 26 |
|
|
|
| 27 |
|
|
signal mul_res : std_logic_vector(DATUM_SIZE*2-3 downto 0);
|
| 28 |
|
|
|
| 29 |
|
|
signal type_a : std_logic_vector(TYPE_SIZE-1 downto 0);
|
| 30 |
|
|
signal gc_flag_a : std_logic;
|
| 31 |
|
|
signal datum_a : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 32 |
|
|
signal type_b : std_logic_vector(TYPE_SIZE-1 downto 0);
|
| 33 |
|
|
signal gc_flag_b : std_logic;
|
| 34 |
|
|
signal datum_b : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 35 |
|
|
signal type_r : std_logic_vector(TYPE_SIZE-1 downto 0);
|
| 36 |
|
|
signal gc_flag_r : std_logic;
|
| 37 |
|
|
signal datum_r : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 38 |
|
|
|
| 39 |
|
|
-- signal div_r : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 40 |
|
|
-- signal mod_r : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 41 |
|
|
-- signal fti_r : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 42 |
|
|
-- signal itf_r : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 43 |
|
|
-- signal fad_r : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 44 |
|
|
-- signal fml_r : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 45 |
|
|
-- signal fdv_r : std_logic_vector(DATUM_SIZE-1 downto 0);
|
| 46 |
|
|
|
| 47 |
|
|
-- signal fti_v, fti_a : std_logic;
|
| 48 |
|
|
-- signal fad_v, fad_u, fad_a : std_logic;
|
| 49 |
|
|
-- signal fml_v, fml_u, fml_a : std_logic;
|
| 50 |
|
|
-- signal fdv_v, fdv_u, fdv_a, fdv_zero : std_logic;
|
| 51 |
|
|
|
| 52 |
|
|
begin
|
| 53 |
|
|
|
| 54 |
|
|
-- divider_inst : divider
|
| 55 |
|
|
-- generic map (26,26)
|
| 56 |
|
|
-- port map (
|
| 57 |
|
|
-- dividend => datum_a,
|
| 58 |
|
|
-- divisor => datum_b,
|
| 59 |
|
|
-- quotient => div_r,
|
| 60 |
|
|
-- remainder => mod_r);
|
| 61 |
|
|
--
|
| 62 |
|
|
|
| 63 |
|
|
-- Decode inputs
|
| 64 |
|
|
type_a <= in_a(OBJECT_SIZE-1 downto 27);
|
| 65 |
|
|
gc_flag_a <= in_a(26);
|
| 66 |
|
|
datum_a <= in_a(25 downto 0);
|
| 67 |
|
|
type_b <= in_b(OBJECT_SIZE-1 downto 27);
|
| 68 |
|
|
gc_flag_b <= in_b(26);
|
| 69 |
|
|
datum_b <= in_b(25 downto 0);
|
| 70 |
|
|
|
| 71 |
|
|
-- SET STATUS FLAGS
|
| 72 |
|
|
-- Overflow
|
| 73 |
|
|
status(OVERFLOW) <= '0' when (mul_res(49 downto 25) = (mul_res(49 downto 25) xor mul_res(49 downto 25))) else '1';
|
| 74 |
|
|
-- negative
|
| 75 |
|
|
status(NEG) <= datum_r(25);
|
| 76 |
|
|
-- zero
|
| 77 |
|
|
status(ZERO) <= '1' when datum_r = (datum_r xor datum_r) else '0';
|
| 78 |
|
|
-- type error
|
| 79 |
|
|
status(TYP) <= '0' when type_a = type_b else '1';
|
| 80 |
|
|
-- io-error
|
| 81 |
|
|
status(IO) <= '0';
|
| 82 |
|
|
--unused
|
| 83 |
|
|
status(1) <= '0';
|
| 84 |
|
|
status(6) <= '0';
|
| 85 |
|
|
status(7) <= '0';
|
| 86 |
|
|
|
| 87 |
|
|
mul_res <= (datum_a(24 downto 0) * datum_b(24 downto 0));
|
| 88 |
|
|
|
| 89 |
|
|
-- set output to result
|
| 90 |
|
|
output <= type_r & gc_flag_r & datum_r;
|
| 91 |
|
|
|
| 92 |
|
|
process(funct, type_a, type_b, gc_flag_a, gc_flag_b, datum_a, datum_b, mul_res)
|
| 93 |
|
|
begin
|
| 94 |
|
|
type_r <= (others => '0');
|
| 95 |
|
|
gc_flag_r <= '0';
|
| 96 |
|
|
datum_r <= (others => '0');
|
| 97 |
|
|
case funct is
|
| 98 |
|
|
when ALU_ADD =>
|
| 99 |
|
|
type_r <= type_a;
|
| 100 |
|
|
gc_flag_r <= gc_flag_a;
|
| 101 |
|
|
datum_r <= datum_a + datum_b;
|
| 102 |
|
|
|
| 103 |
|
|
when ALU_SUB =>
|
| 104 |
|
|
type_r <= type_a;
|
| 105 |
|
|
gc_flag_r <= gc_flag_a;
|
| 106 |
|
|
datum_r <= datum_a - datum_b;
|
| 107 |
|
|
|
| 108 |
|
|
when ALU_MUL =>
|
| 109 |
|
|
type_r <= type_a;
|
| 110 |
|
|
gc_flag_r <= gc_flag_a;
|
| 111 |
|
|
datum_r(24 downto 0) <= mul_res(24 downto 0);
|
| 112 |
|
|
datum_r(25) <= datum_a(25) xor datum_b(25);
|
| 113 |
|
|
|
| 114 |
|
|
-- when ALU_DIV =>
|
| 115 |
|
|
-- type_r <= type_a;
|
| 116 |
|
|
-- gc_flag_r <= gc_flag_a;
|
| 117 |
|
|
-- datum_r <= div_r;
|
| 118 |
|
|
--
|
| 119 |
|
|
-- when ALU_MOD =>
|
| 120 |
|
|
-- type_r <= type_a;
|
| 121 |
|
|
-- gc_flag_r <= gc_flag_a;
|
| 122 |
|
|
-- datum_r <= mod_r;
|
| 123 |
|
|
|
| 124 |
|
|
when ALU_AND =>
|
| 125 |
|
|
type_r <= type_a;
|
| 126 |
|
|
gc_flag_r <= gc_flag_a;
|
| 127 |
|
|
datum_r <= datum_a and datum_b;
|
| 128 |
|
|
|
| 129 |
|
|
when ALU_OR =>
|
| 130 |
|
|
type_r <= type_a;
|
| 131 |
|
|
gc_flag_r <= gc_flag_a;
|
| 132 |
|
|
datum_r <= datum_a or datum_b;
|
| 133 |
|
|
|
| 134 |
|
|
when ALU_XOR =>
|
| 135 |
|
|
type_r <= type_a;
|
| 136 |
|
|
gc_flag_r <= gc_flag_a;
|
| 137 |
|
|
datum_r <= datum_a xor datum_b;
|
| 138 |
|
|
|
| 139 |
|
|
when ALU_GET_TYPE =>
|
| 140 |
|
|
type_r <= DT_INT;
|
| 141 |
|
|
gc_flag_r <= '0';
|
| 142 |
|
|
datum_r(TYPE_SIZE - 1 downto 0) <= type_b;
|
| 143 |
|
|
datum_r(DATUM_SIZE - 1 downto TYPE_SIZE) <= (others => '0');
|
| 144 |
|
|
|
| 145 |
|
|
when ALU_SET_TYPE =>
|
| 146 |
|
|
type_r <= datum_b(TYPE_SIZE-1 downto 0);
|
| 147 |
|
|
gc_flag_r <= '0';
|
| 148 |
|
|
datum_r <= datum_a;
|
| 149 |
|
|
|
| 150 |
|
|
when ALU_SET_DATUM =>
|
| 151 |
|
|
type_r <= type_a;
|
| 152 |
|
|
gc_flag_r <= gc_flag_a;
|
| 153 |
|
|
datum_r <= datum_b;
|
| 154 |
|
|
|
| 155 |
|
|
when ALU_SET_GC =>
|
| 156 |
|
|
type_r <= type_a;
|
| 157 |
|
|
gc_flag_r <= datum_b(0);
|
| 158 |
|
|
datum_r <= datum_a;
|
| 159 |
|
|
|
| 160 |
|
|
when ALU_GET_GC =>
|
| 161 |
|
|
type_r <= DT_INT;
|
| 162 |
|
|
gc_flag_r <= '0';
|
| 163 |
|
|
datum_r(0) <= gc_flag_b;
|
| 164 |
|
|
datum_r(DATUM_SIZE - 1 downto 1) <= (others => '0');
|
| 165 |
|
|
|
| 166 |
|
|
when ALU_CPY =>
|
| 167 |
|
|
type_r <= type_b;
|
| 168 |
|
|
gc_flag_r <= gc_flag_b;
|
| 169 |
|
|
datum_r <= datum_b;
|
| 170 |
|
|
|
| 171 |
|
|
-- shift right
|
| 172 |
|
|
when ALU_SR =>
|
| 173 |
|
|
type_r <= type_a;
|
| 174 |
|
|
gc_flag_r <= gc_flag_a;
|
| 175 |
|
|
datum_r <= std_logic_vector(shift_right(unsigned(datum_a),
|
| 176 |
|
|
to_integer(unsigned(datum_b))));
|
| 177 |
|
|
|
| 178 |
|
|
-- shift left
|
| 179 |
|
|
when ALU_SL =>
|
| 180 |
|
|
type_r <= type_a;
|
| 181 |
|
|
gc_flag_r <= gc_flag_a;
|
| 182 |
|
|
datum_r <= std_logic_vector(shift_left(unsigned(datum_a),
|
| 183 |
|
|
to_integer(unsigned(datum_b))));
|
| 184 |
|
|
|
| 185 |
|
|
when ALU_CMP_DATUM =>
|
| 186 |
|
|
type_r <= type_a;
|
| 187 |
|
|
gc_flag_r <= gc_flag_a;
|
| 188 |
|
|
datum_r <= datum_a - datum_b;
|
| 189 |
|
|
|
| 190 |
|
|
when ALU_CMP_TYPE =>
|
| 191 |
|
|
type_r <= type_a;
|
| 192 |
|
|
gc_flag_r <= gc_flag_a;
|
| 193 |
|
|
datum_r <= "000000000000000000000" & (type_a - type_b);
|
| 194 |
|
|
|
| 195 |
|
|
when ALU_CMP_TYPE_IMM =>
|
| 196 |
|
|
type_r <= type_a;
|
| 197 |
|
|
gc_flag_r <= gc_flag_a;
|
| 198 |
|
|
datum_r <= "000000000000000000000" & (type_a - datum_b(TYPE_SIZE - 1 downto 0));
|
| 199 |
|
|
|
| 200 |
|
|
when ALU_CMP_GC =>
|
| 201 |
|
|
type_r <= type_a;
|
| 202 |
|
|
gc_flag_r <= gc_flag_a;
|
| 203 |
|
|
datum_r <= "0000000000000000000000000"&(gc_flag_a xor gc_flag_b);
|
| 204 |
|
|
|
| 205 |
|
|
when ALU_CMP_GC_IMM =>
|
| 206 |
|
|
type_r <= type_a;
|
| 207 |
|
|
gc_flag_r <= gc_flag_a;
|
| 208 |
|
|
datum_r <= "0000000000000000000000000"&(gc_flag_a xor datum_b(0));
|
| 209 |
|
|
|
| 210 |
|
|
when ALU_CMP =>
|
| 211 |
|
|
if type_a = type_b and
|
| 212 |
|
|
datum_a = datum_b then -- we have equivalent objects
|
| 213 |
|
|
datum_r <= (others => '0');
|
| 214 |
|
|
else
|
| 215 |
|
|
datum_r(DATUM_SIZE-1 downto DATUM_SIZE-4) <= "1111";
|
| 216 |
|
|
datum_r(DATUM_SIZE-5 downto 0) <= (others => '0'); -- not same
|
| 217 |
|
|
end if;
|
| 218 |
|
|
|
| 219 |
|
|
when others =>
|
| 220 |
|
|
type_r <= (others => '0');
|
| 221 |
|
|
gc_flag_r <= '0';
|
| 222 |
|
|
datum_r <= (others => '0');
|
| 223 |
|
|
|
| 224 |
|
|
end case;
|
| 225 |
|
|
end process;
|
| 226 |
|
|
end rtl;
|