-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBranch_Unit.vhd
76 lines (68 loc) · 2.33 KB
/
Branch_Unit.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 20:19:09 04/20/2016
-- Design Name:
-- Module Name: Branch_Unit - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity Branch_Unit is
PORT( CLK, CLK_MAIN: IN STD_LOGIC; --CLK IS CLK_EX, CLK_MAIN IS CLK IN TOP LEVEL. IT IS CONFUSING, WE WILL CHANGE THIS LATER. LABELS ARE OUR FRIEND, ONCE WE MESS UP THE ORDER, THEY WILL BE OUR ENEMY :)
MASK : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
FLAG_IN : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
CURRENT_INS_NUMBER: IN STD_LOGIC_VECTOR(7 DOWNTO 0);
LOCATION : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
RESULT_JUMP_OR_NOT : OUT STD_LOGIC_VECTOR ( 7 DOWNTO 0)
);
end Branch_Unit;
architecture Behavioral of Branch_Unit is
SIGNAL FLAG_SIGNAL,MASK1,MASK2,MASK3 : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL CURRENT_INS_NUMBER_1,CURRENT_INS_NUMBER_2,CURRENT_INS_NUMBER_3,LOCATION_1,LOCATION_2,LOCATION_3: STD_LOGIC_VECTOR(7 DOWNTO 0);
begin
PROCESS(CLK_MAIN)
BEGIN
IF FALLING_EDGE(CLK_MAIN) THEN
MASK1<=MASK;
MASK2<=MASK1;
MASK3<=MASK2;
CURRENT_INS_NUMBER_1<=CURRENT_INS_NUMBER;
CURRENT_INS_NUMBER_2<=CURRENT_INS_NUMBER_1;
CURRENT_INS_NUMBER_3<=CURRENT_INS_NUMBER_2;
LOCATION_1<=LOCATION;
LOCATION_2<=LOCATION_1;
LOCATION_3<=LOCATION_2;
END IF;
END PROCESS;
PROCESS(CLK)
BEGIN
IF FALLING_EDGE(CLK) THEN
IF(MASK3=FLAG_IN) THEN
RESULT_JUMP_OR_NOT<=LOCATION_3-"00000001"; --TO SUPPORT JUMP AFTER BRANCH, WE CHECK BRANCHED ADDRS - 1 . WE LOSE ADDTIONAL ONE MORE CYCLE ON TOP OF 3 CYCLE LOSS.
ELSE
RESULT_JUMP_OR_NOT<=CURRENT_INS_NUMBER_3;--TO SUPPORT JUMP AFTER BRANCH PLUS CONTUNIE
END IF;
END IF;
END PROCESS;
end Behavioral;