| 1 | -- test bench for CLA |
|---|
| 2 | |
|---|
| 3 | library ieee; |
|---|
| 4 | use ieee.std_logic_1164.all; |
|---|
| 5 | use ieee.numeric_std.all; |
|---|
| 6 | |
|---|
| 7 | entity test_CLA is |
|---|
| 8 | end entity test_CLA; |
|---|
| 9 | |
|---|
| 10 | architecture test_CLA_tb of test_CLA is |
|---|
| 11 | |
|---|
| 12 | component carry_lookahead_adder is |
|---|
| 13 | generic ( numBits : integer := 4 |
|---|
| 14 | ); |
|---|
| 15 | port ( a : in std_logic_vector(numBits-1 downto 0); |
|---|
| 16 | b : in std_logic_vector(numBits-1 downto 0); |
|---|
| 17 | cIn : in std_logic; |
|---|
| 18 | s : out std_logic_vector(numBits-1 downto 0); |
|---|
| 19 | cOut : out std_logic |
|---|
| 20 | ); |
|---|
| 21 | end component carry_lookahead_adder; |
|---|
| 22 | |
|---|
| 23 | signal A, B : std_logic_vector(3 downto 0) := (others => '0'); |
|---|
| 24 | signal S : std_logic_vector(3 downto 0); |
|---|
| 25 | signal CIN, COUT : std_logic; |
|---|
| 26 | |
|---|
| 27 | signal result : std_logic_vector(4 downto 0); |
|---|
| 28 | signal check : std_logic_vector(4 downto 0); |
|---|
| 29 | |
|---|
| 30 | begin |
|---|
| 31 | |
|---|
| 32 | CLA_inst : carry_lookahead_adder |
|---|
| 33 | generic map ( numBits => 4 |
|---|
| 34 | ) |
|---|
| 35 | port map ( a => A, |
|---|
| 36 | b => B, |
|---|
| 37 | cIn => CIN, |
|---|
| 38 | s => S, |
|---|
| 39 | cOut => COUT |
|---|
| 40 | ); |
|---|
| 41 | |
|---|
| 42 | -- calculate 5 bit result from circuit |
|---|
| 43 | result <= COUT & S; |
|---|
| 44 | -- calculate 5 bit result independently |
|---|
| 45 | check <= std_logic_vector(unsigned("0" & A) + unsigned("0" & B) + ("000" & CIN)); |
|---|
| 46 | |
|---|
| 47 | enter_inputs : process |
|---|
| 48 | begin |
|---|
| 49 | |
|---|
| 50 | -- loop for CIN |
|---|
| 51 | for i in 0 to 1 loop |
|---|
| 52 | |
|---|
| 53 | -- set CIN test values |
|---|
| 54 | if (i = 0) then |
|---|
| 55 | CIN <= '0'; |
|---|
| 56 | else |
|---|
| 57 | CIN <= '1'; |
|---|
| 58 | end if; |
|---|
| 59 | |
|---|
| 60 | -- loop for A |
|---|
| 61 | for iA in 0 to 15 loop |
|---|
| 62 | |
|---|
| 63 | if (iA = 0) then |
|---|
| 64 | A <= (others => '0'); |
|---|
| 65 | elsif (iA > 0) then |
|---|
| 66 | A <= std_logic_vector(unsigned(A) + 1); |
|---|
| 67 | end if; |
|---|
| 68 | |
|---|
| 69 | -- loop for B |
|---|
| 70 | for iB in 0 to 15 loop |
|---|
| 71 | |
|---|
| 72 | if (iB = 0) then |
|---|
| 73 | B <= (others => '0'); |
|---|
| 74 | elsif (iB > 0) then |
|---|
| 75 | B <= std_logic_vector(unsigned(B) + 1); |
|---|
| 76 | end if; |
|---|
| 77 | |
|---|
| 78 | wait for 1 ns; |
|---|
| 79 | |
|---|
| 80 | if (check /= result) then |
|---|
| 81 | report "The summation has been calculated incorrectly!"; |
|---|
| 82 | end if; |
|---|
| 83 | |
|---|
| 84 | end loop; |
|---|
| 85 | |
|---|
| 86 | end loop; |
|---|
| 87 | |
|---|
| 88 | end loop; |
|---|
| 89 | |
|---|
| 90 | end process enter_inputs; |
|---|
| 91 | |
|---|
| 92 | end architecture test_CLA_tb; |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|