OpenCores
URL https://opencores.org/ocsvn/minimips_superscalar/minimips_superscalar/trunk

Subversion Repositories minimips_superscalar

[/] [minimips_superscalar/] [trunk/] [sources/] [renvoi.vhd] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mcafruni
--------------------------------------------------------------------------
2
--                                                                      --
3
--                                                                      --
4
-- miniMIPS Superscalar Processor : Bypass unit                         --
5
-- based on miniMIPS Processor                                          --
6
--                                                                      --
7
--                                                                      --
8
-- Author : Miguel Cafruni                                              --
9
-- miguel_cafruni@hotmail.com                                           --
10
--                                                      December 2018   --
11
--------------------------------------------------------------------------
12
 
13
library IEEE;
14
use IEEE.std_logic_1164.all;
15
use IEEE.numeric_std.all;
16
 
17
library work;
18
use work.pack_mips.all;
19
 
20
entity renvoi is
21
port (
22
    -- Register access signals
23
    adr1 : in adr_reg_type;    -- Operand 1 address (end. a ser lido asssincronamente pelo DI)
24
    adr2 : in adr_reg_type;    -- Operand 2 address (end. a ser lido asssincronamente pelo DI)
25
    use1 : in std_logic;       -- Operand 1 utilisation
26
    use2 : in std_logic;       -- Operand 2 utilisation    
27
    data1 : out bus32;         -- First register value (para DI OP1)
28
    data2 : out bus32;         -- Second register value (para DI OP2)
29
    alea : out std_logic;      -- Unresolved hazards detected
30
 
31
    -- Bypass signals of the intermediary datas (Sinais de retorno dos dados intermediários)
32
    DI_level : in level_type;  -- Availability level of the data (Nível de disponibilidade dos dados)
33
    DI_adr : in adr_reg_type;  -- Register destination of the result
34
    DI_ecr : in std_logic;     -- Writing register request
35
    DI_data : in bus32;        -- Data to used (op2 do DI)
36
 
37
    EX_level : in level_type;  -- Availability level of the data
38
    EX_adr : in adr_reg_type;  -- Register destination of the result
39
    EX_ecr : in std_logic;     -- Writing register request
40
    EX_data : in bus32;        -- Data to used
41
 
42
    MEM_level : in level_type; -- Availability level of the data
43
    MEM_adr : in adr_reg_type; -- Register destination of the result
44
    MEM_ecr : in std_logic;    -- Writing register request
45
    MEM_data : in bus32;       -- Data to used
46
 
47
    interrupt : in std_logic;  -- Exceptions or interruptions
48
 
49
    -- Connexion to the differents bank of register
50
 
51
      -- Writing commands for writing in the registers
52
    write_data : out bus32;    -- Data to write
53
    write_adr : out bus5;      -- Address of the register to write
54
    write_GPR : out std_logic; -- Selection in the internal registers
55
    write_SCP : out std_logic; -- Selection in the coprocessor system registers
56
 
57
      -- Reading commands for Reading in the registers
58
    read_adr1 : out bus5;      -- Address of the first register to read
59
    read_adr2 : out bus5;      -- Address of the second register to read
60
    read_data1_GPR : in bus32; -- Value of operand 1 from the internal registers
61
    read_data2_GPR : in bus32; -- Value of operand 2 from the internal registers
62
    read_data1_SCP : in bus32; -- Value of operand 1 from the coprocessor system registers
63
    read_data2_SCP : in bus32;  -- Value of operand 2 from the coprocessor system registers
64
 
65
        --modificacao duplicacao
66
    -- Register access signals
67
    adr3 : in adr_reg_type;    -- Operand 3 address (end. a ser lido asssincronamente pelo DI2)
68
    adr4 : in adr_reg_type;    -- Operand 4 address (end. a ser lido asssincronamente pelo DI2)
69
    use12 : in std_logic;       -- Operand 3 utilisation
70
    use22 : in std_logic;       -- Operand 4 utilisation
71
 
72
    data3 : out bus32;         -- First register value
73
    data4 : out bus32;         -- Second register value
74
    alea2 : out std_logic;      -- Unresolved hazards detected
75
 
76
    -- Bypass signals of the intermediary datas
77
    DI_level2 : in level_type;  -- Availability level of the data
78
    DI_adr2 : in adr_reg_type;  -- Register destination of the result
79
    DI_ecr2 : in std_logic;     -- Writing register request
80
    DI_data2 : in bus32;        -- Data to used (op2 do DI2)
81
 
82
    EX_level2 : in level_type;  -- Availability level of the data
83
    EX_adr2 : in adr_reg_type;  -- Register destination of the result
84
    EX_ecr2 : in std_logic;     -- Writing register request
85
    EX_data2 : in bus32;        -- Data to used
86
 
87
    MEM_level2 : in level_type; -- Availability level of the data
88
    MEM_adr2 : in adr_reg_type; -- Register destination of the result
89
    MEM_ecr2 : in std_logic;    -- Writing register request
90
    MEM_data2 : in bus32;       -- Data to used
91
 
92
 
93
    -- Connexion to the differents bank of register
94
 
95
      -- Writing commands for writing in the registers
96
    write_data2 : out bus32;    -- Data to write
97
    write_adr2 : out bus5;      -- Address of the register to write
98
    write_GPR2 : out std_logic; -- Selection in the internal registers
99
    --sem necessidade--write_SCP : out std_logic; -- Selection in the coprocessor system registers
100
 
101
      -- Reading commands for Reading in the registers
102
    read_adr3 : out bus5;      -- Address of the first register to read
103
    read_adr4 : out bus5;      -- Address of the second register to read
104
    read_data3_GPR : in bus32; -- Value of operand 1 from the internal registers
105
    read_data4_GPR : in bus32; -- Value of operand 2 from the internal registers
106
    read_data3_SCP : in bus32; -- Value of operand 1 from the coprocessor system registers
107
    read_data4_SCP : in bus32  -- Value of operand 2 from the coprocessor system registers
108
);
109
end renvoi;
110
 
111
architecture rtl of renvoi is
112
    signal dep_r1 : level_type; -- Dependency level for operand 1
113
    signal dep_r2 : level_type; -- Dependency level for operand 2
114
    signal read_data1 : bus32;  -- Data contained in the register asked by operand 1
115
    signal read_data2 : bus32;  -- Data contained in the register asked by operand 2
116
    signal res_reg, res_mem, res_ex, res_di, res_mem2, res_ex2, res_di2 : std_logic;
117
    signal resolution : bus7;   -- Verification of the resolved hazards
118
    signal idx1, idx2, idx3, idx4 : integer range 0 to 6;
119
        --duplicação dos sinais para o segundo pipe
120
    signal dep_r3 : level_type; -- Dependency level for operand 1
121
    signal dep_r4 : level_type; -- Dependency level for operand 2
122
    signal read_data3 : bus32;  -- Data contained in the register asked by operand 1
123
    signal read_data4 : bus32;  -- Data contained in the register asked by operand 2
124
 
125
begin
126
    -- Connexion of the writing command signals
127
    write_data <= MEM_data;
128
    write_adr <= MEM_adr(4 downto 0);
129
    write_GPR <= not MEM_adr(5) and MEM_ecr when interrupt = '0' else  -- The high bit to 0 selects the internal registers
130
                 '0';
131
    write_SCP <= MEM_adr(5) and MEM_ecr;      -- The high bit to 1 selects the coprocessor system registers
132
    -- Connexion of the writing command signals
133
    read_adr1 <= adr1(4 downto 0);            -- Connexion of the significative address bits (end. source 1 a ser lido no banco assincronamente pelo DI)
134
    read_adr2 <= adr2(4 downto 0);            -- Connexion of the significative address bits (end. source 2 a ser lido no banco assincronamente PELO DI)
135
    -- Evaluation of the level of dependencies
136
    dep_r1 <= LVL_REG  when adr1(4 downto 0)="00000" or use1='0' else -- No dependency with register 0, se use1 for igual a '0' aqui, significa que op1 = imm ou shamt
137
              LVL_DI   when adr1=DI_adr  and DI_ecr ='1' else         -- Dependency with DI stage (reg. fonte = reg.destino no momento da escrita, (DI_ecr ='1'))
138
              LVL_EX   when adr1=EX_adr  and EX_ecr ='1' else         -- Dependency with EX stage
139
              LVL_MEM  when adr1=MEM_adr and MEM_ecr='1' else         -- Dependency with MEM stage
140
              LVL_DI2  when adr1=DI_adr2  and DI_ecr2 = '1' else  -- Dependency with DI stage (reg. fonte = reg.destino no momento da escrita, (DI_ecr ='1'))
141
              LVL_EX2  when adr1=EX_adr2  and EX_ecr2 = '1' else  -- Dependency with EX stage
142
              LVL_MEM2 when adr1=MEM_adr2 and MEM_ecr2 ='1' else  -- Dependency with MEM stage
143
              LVL_REG;                                               -- No dependency detected
144
    dep_r2 <= LVL_REG  when adr2(4 downto 0)="00000" or use2='0' else -- No dependency with register 0
145
              LVL_DI   when adr2=DI_adr  and DI_ecr ='1' else         -- Dependency with DI stage
146
              LVL_EX   when adr2=EX_adr  and EX_ecr ='1' else         -- Dependency with EX stage
147
              LVL_MEM  when adr2=MEM_adr and MEM_ecr='1' else         -- Dependency with MEM stage
148
              LVL_DI2  when adr2=DI_adr2  and DI_ecr2 = '1' else  -- Dependency with DI2 stage (reg. fonte = reg.destino no momento da escrita, (DI_ecr ='1'))
149
              LVL_EX2  when adr2=EX_adr2  and EX_ecr2 = '1' else  -- Dependency with EX2 stage
150
              LVL_MEM2 when adr2=MEM_adr2 and MEM_ecr2 ='1' else  -- Dependency with MEM stage
151
              LVL_REG;                                               -- No dependency detected
152
 
153
    -- Elaboration of the signals with the datas form the bank registers
154
    read_data1 <= read_data1_GPR when adr1(5)='0' else       -- Selection of the internal registers
155
                  read_data1_SCP when adr1(5)='1' else       -- Selection of the coprocessor registers
156
                  (others => '0');
157
    read_data2 <= read_data2_GPR when adr2(5)='0' else       -- Selection of the internal registers   
158
                  read_data2_SCP when adr2(5)='1' else       -- Selection of the coprocessor registers
159
                  (others => '0');
160
    -- Bypass the datas (the validity is tested later when detecting the hazards)
161
    data1 <= read_data1 when dep_r1=LVL_REG  else -- DI recebe dado direto dos registradores
162
             MEM_data   when dep_r1=LVL_MEM  else -- DI recebe dado direto do MEM2 (MEM no original )
163
             MEM_data2  when dep_r1=LVL_MEM2 else -- DI recebe dado direto do MEM2 (MEM no original )
164
             EX_data    when dep_r1=LVL_EX   else -- DI recebe dado direto do EX2  (EX no original )
165
             EX_data2   when dep_r1=LVL_EX2  else -- DI recebe dado direto do EX2  (EX no original )
166
             DI_data    when dep_r1=LVL_DI   else
167
             DI_data2;                            -- DI recebe dado direto do DI2  (DI no original )
168
    data2 <= read_data2 when dep_r2=LVL_REG  else
169
             MEM_data   when dep_r2=LVL_MEM  else
170
             MEM_data2  when dep_r2=LVL_MEM2 else
171
             EX_data    when dep_r2=LVL_EX   else
172
             EX_data2   when dep_r2=LVL_EX2  else
173
             DI_data    when dep_r2=LVL_DI   else
174
             DI_data2;
175
 
176
    -- duplicação para o segundo pipe
177
 
178
    -- Connexion of the writing command signals
179
    write_data2 <= MEM_data2;
180
    write_adr2 <= MEM_adr2(4 downto 0);
181
    write_GPR2 <= not MEM_adr2(5) and MEM_ecr2 when interrupt = '0' else  -- The high bit to 0 selects the internal registers
182
                 '0';
183
    --write_SCP <= MEM_adr(5) and MEM_ecr;      -- The high bit to 1 selects the coprocessor system registers
184
 
185
    -- Connexion of the writing command signals
186
    read_adr3 <= adr3(4 downto 0);            -- Connexion of the significative address bits (lido assincronamente pelo DI2)
187
    read_adr4 <= adr4(4 downto 0);            -- Connexion of the significative address bits (lido assincronamente pelo DI2)
188
 
189
    -- Evaluation of the level of dependencies
190
    dep_r3 <= LVL_REG  when adr3(4 downto 0)="00000" or use12='0' else -- No dependency with register 0, se use1 for igual a '0' aqui, significa que op1 = imm ou shamt
191
              LVL_DI   when adr3=DI_adr  and DI_ecr ='1' else         -- Dependency with DI stage (reg. fonte = reg.destino no momento da escrita, (DI_ecr ='1'))
192
              LVL_EX   when adr3=EX_adr  and EX_ecr ='1' else         -- Dependency with EX stage
193
              LVL_MEM  when adr3=MEM_adr and MEM_ecr='1' else         -- Dependency with MEM stage
194
              LVL_DI2  when adr3=DI_adr2  and DI_ecr2 = '1' else  -- Dependency with DI stage (reg. fonte = reg.destino no momento da escrita, (DI_ecr ='1'))
195
              LVL_EX2  when adr3=EX_adr2  and EX_ecr2 = '1' else  -- Dependency with EX stage
196
              LVL_MEM2 when adr3=MEM_adr2 and MEM_ecr2 ='1' else  -- Dependency with MEM stage
197
              LVL_REG;                                               -- No dependency detected
198
    dep_r4 <= LVL_REG  when adr4(4 downto 0)="00000" or use22='0' else -- No dependency with register 0
199
              LVL_DI   when adr4=DI_adr  and DI_ecr ='1' else         -- Dependency with DI stage
200
              LVL_EX   when adr4=EX_adr  and EX_ecr ='1' else         -- Dependency with EX stage
201
              LVL_MEM  when adr4=MEM_adr and MEM_ecr='1' else         -- Dependency with MEM stage
202
              LVL_DI2  when adr4=DI_adr2  and DI_ecr2 = '1' else  -- Dependency with DI2 stage (reg. fonte = reg.destino no momento da escrita, (DI_ecr ='1'))
203
              LVL_EX2  when adr4=EX_adr2  and EX_ecr2 = '1' else  -- Dependency with EX2 stage
204
              LVL_MEM2 when adr4=MEM_adr2 and MEM_ecr2 ='1' else  -- Dependency with MEM stage
205
              LVL_REG;                                               -- No dependency detected
206
    -- Elaboration of the signals with the datas form the bank registers
207
    read_data3 <= read_data3_GPR when adr3(5)='0' else       -- Selection of the internal registers
208
                  read_data3_SCP when adr3(5)='1' else       -- Selection of the coprocessor registers
209
                  (others => '0');
210
 
211
    read_data4 <= read_data4_GPR when adr4(5)='0' else       -- Selection of the internal registers   
212
                  read_data4_SCP when adr4(5)='1' else       -- Selection of the coprocessor registers
213
                  (others => '0');
214
 
215
    -- Bypass the datas (the validity is tested later when detecting the hazards) Dar a volta dos dados(a validade é testada posteriormente ao detectar os hazards)
216
    data3 <= read_data3 when dep_r3=LVL_REG  else -- DI recebe dado direto dos registradores
217
             MEM_data   when dep_r3=LVL_MEM  else -- DI recebe dado direto do MEM2 (MEM no original )
218
             MEM_data2  when dep_r3=LVL_MEM2 else -- DI recebe dado direto do MEM2 (MEM no original )
219
             EX_data    when dep_r3=LVL_EX   else -- DI recebe dado direto do EX2  (EX no original )
220
             EX_data2   when dep_r3=LVL_EX2  else -- DI recebe dado direto do EX2  (EX no original )
221
             DI_data    when dep_r3=LVL_DI   else
222
             DI_data2;                            -- DI recebe dado direto do DI2  (DI no original )
223
    data4 <= read_data4 when dep_r4=LVL_REG  else
224
             MEM_data   when dep_r4=LVL_MEM  else
225
             MEM_data2  when dep_r4=LVL_MEM2 else
226
             EX_data    when dep_r4=LVL_EX   else
227
             EX_data2   when dep_r4=LVL_EX2  else
228
             DI_data    when dep_r4=LVL_DI   else
229
             DI_data2;
230
 
231
    -- Detection of a potential unresolved hazard
232
    -- '1' significa que os dados estao atualizados,
233
    -- '0' nao, os dados ainda serao escritos                          <<< dep neste sentido nao eh hazard <<< dados repassado por forwarding ou bypassing para o DI/DI2
234
    res_reg <= '1'; --This hazard is always resolved LVL_REG=0           ________ _______ _______ _______
235
    res_mem <= '1' when MEM_level>=LVL_MEM else '0'; -- >= 1             | 3      | 2     | 1     | 0     |
236
    res_ex  <= '1' when EX_level >=LVL_EX  else '0'; -- >= 2             |   DI   |   EX  |  MEM  |  REG  |
237
    res_di  <= '1' when DI_level >=LVL_DI  else '0'; -- >= 3             |________|_______|_______|_______|___
238
    res_mem2 <= '1' when MEM_level2>=LVL_MEM2 else '0'; -- >= 4            | 6      | 5     | 4     | 0     |
239
    res_ex2  <= '1' when EX_level2 >=LVL_EX2  else '0'; -- >= 5            |   DI2  |  EX2  |  MEM2 |  REG  |
240
    res_di2  <= '1' when DI_level2 >=LVL_DI2  else '0'; -- >= 6            |________|_______|_______|_______|
241
--                                                   --                                 >>> dep neste sentido eh hazard  >>> espera o proximo ciclo para entrar novamente no DI/DI2
242
    -- Table defining the resolved hazard for each stage
243
    resolution <= res_di2 & res_ex2 & res_mem2 & res_di & res_ex & res_mem & res_reg; -- '1111111', se nao ocorrer hazard
244
    -- Verification of the validity of the transmitted datas (test the good resolution of the hazards)
245
    idx1 <= to_integer(unsigned(dep_r1(2 downto 0)));
246
    idx2 <= to_integer(unsigned(dep_r2(2 downto 0)));
247
    idx3 <= to_integer(unsigned(dep_r3(2 downto 0)));
248
    idx4 <= to_integer(unsigned(dep_r4(2 downto 0)));
249
 
250
    alea  <= (not resolution(idx1) or not resolution(idx2));
251
    alea2 <= (not resolution(idx3) or not resolution(idx4));
252
 
253
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.