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

Subversion Repositories rv01_riscv_core

[/] [rv01_riscv_core/] [trunk/] [VHDL/] [RV01_pstllog_2w_p6.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 madsilicon
-----------------------------------------------------------------
2
--                                                             --
3
-----------------------------------------------------------------
4
--                                                             --
5
-- Copyright (C) 2015 Stefano Tonello                          --
6
--                                                             --
7
-- This source file may be used and distributed without        --
8
-- restriction provided that this copyright statement is not   --
9
-- removed from the file and that any derivative work contains --
10
-- the original copyright notice and the associated disclaimer.--
11
--                                                             --
12
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY         --
13
-- EXPRESS OR IMPLIED WARRS1NTIES, INCLUDING, BUT NOT LIMITED   --
14
-- TO, THE IMPLIED WARRS1NTIES OF MERCHANTABILITY AND FITNESS   --
15
-- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      --
16
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         --
17
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    --
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   --
19
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        --
20
-- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  --
21
-- LIABILITY, WHETHER IN  CONTRS1CT, STRICT LIABILITY, OR TORT  --
22
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  --
23
-- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         --
24
-- POSSIBILITY OF SUCH DAMAGE.                                 --
25
--                                                             --
26
-----------------------------------------------------------------
27
 
28
---------------------------------------------------------
29
-- RV01 Pipeline stall logic 
30
---------------------------------------------------------
31
 
32
library IEEE;
33
use IEEE.std_logic_1164.all;
34
use IEEE.numeric_std.all;
35
 
36
library WORK;
37
use WORK.RV01_CONSTS_PKG.all;
38
use WORK.RV01_TYPES_PKG.all;
39
use WORK.RV01_FUNCS_PKG.all;
40
use work.RV01_IDEC_PKG.all;
41
 
42
entity RV01_PSTLLOG_2W_P6 is
43
  generic(
44
    DXE : std_logic := '1';
45
    SIMULATION_ONLY : std_logic := '0'
46
  );
47
  port(
48
    CLK_i : in std_logic;
49
    ID_INSTR_i : in DEC_INSTR_T;
50
    ID_V_i : in std_logic;
51
    IX1_INSTR0_i : in DEC_INSTR_T;
52
    IX1_INSTR1_i : in DEC_INSTR_T;
53
    IX1_V_i : in std_logic_vector(2-1 downto 0);
54
    IX1_FWDE_i : in std_logic_vector(2-1 downto 0);
55
    IX2_INSTR0_i : in DEC_INSTR_T;
56
    IX2_INSTR1_i : in DEC_INSTR_T;
57
    IX2_V_i : in std_logic_vector(2-1 downto 0);
58
    IX2_FWDE_i : in std_logic_vector(2-1 downto 0);
59
    IX3_INSTR0_i : in DEC_INSTR_T;
60
    IX3_INSTR1_i : in DEC_INSTR_T;
61
    IX3_V_i : in std_logic_vector(2-1 downto 0);
62
    IX3_FWDE_i : in std_logic_vector(2-1 downto 0);
63
 
64
    OPA_V_o : out std_logic;
65
    OPB_V_o : out std_logic;
66
    DSA_o : out std_logic;
67
    DSB_o : out std_logic;
68
    PSTALL_o : out std_logic
69
  );
70
end RV01_PSTLLOG_2W_P6;
71
 
72
architecture ARC of RV01_PSTLLOG_2W_P6 is
73
 
74
  function dep_a(RMTCH,IDV,IXV : std_logic;IDI,IXI : DEC_INSTR_T)
75
    return std_logic is
76
  begin
77
    if(RMTCH = '1') then
78
      return(IDV and IXV and IDI.RRS1 and IXI.WRD);
79
    else
80
      return('0');
81
    end if;
82
  end function;
83
 
84
  function dep_b(RMTCH,IDV,IXV : std_logic;IDI,IXI : DEC_INSTR_T)
85
    return std_logic is
86
  begin
87
    if(RMTCH = '1') then
88
      return(IDV and IXV and IDI.RRS2 and IXI.WRD);
89
    else
90
      return('0');
91
    end if;
92
  end function;
93
 
94
  function stall_a(DEP,FWDE,IX_2C : std_logic;IDI,IXI : DEC_INSTR_T)
95
    return std_logic is
96
  begin
97
    if(
98
      (DEP = '1') -- and ((FWDE = '0') or (IX_2C = '1'))
99
    ) then
100
      return(qmark((FWDE = '0') or (IX_2C = '1'),'1','0'));
101
    else
102
      return('0');
103
    end if;
104
  end function;
105
 
106
  function stall_b(DEP,FWDE,IX_2C : std_logic;IDI,IXI : DEC_INSTR_T)
107
    return std_logic is
108
  begin
109
    if(
110
      (DEP = '1') -- and ((FWDE = '0') or (IX_2C = '1'))
111
    ) then
112
      return(qmark((FWDE = '0') or (IX_2C = '1'),'1','0'));
113
    else
114
      return('0');
115
    end if;
116
  end function;
117
 
118
  signal IX_2C0,IX_2C1 : std_logic;
119
  signal DX : std_logic;
120
  signal SEQX : std_logic;
121
  signal OPA_V_N,OPB_V_N : std_logic;
122
  signal DATA_DEPA_IX1_0,DATA_DEPA_IX2_0,DATA_DEPA_IX3_0 : std_logic;
123
  signal DATA_DEPB_IX1_0,DATA_DEPB_IX2_0,DATA_DEPB_IX3_0 : std_logic;
124
  signal DATA_DEPA_IX1_1,DATA_DEPA_IX2_1,DATA_DEPA_IX3_1 : std_logic;
125
  signal DATA_DEPB_IX1_1,DATA_DEPB_IX2_1,DATA_DEPB_IX3_1 : std_logic;
126
  signal RMTCH_A_IX1_0,RMTCH_A_IX2_0,RMTCH_A_IX3_0 : std_logic;
127
  signal RMTCH_B_IX1_0,RMTCH_B_IX2_0,RMTCH_B_IX3_0 : std_logic;
128
  signal RMTCH_A_IX1_1,RMTCH_A_IX2_1,RMTCH_A_IX3_1 : std_logic;
129
  signal RMTCH_B_IX1_1,RMTCH_B_IX2_1,RMTCH_B_IX3_1 : std_logic;
130
  signal RS1P1,RS2P1 : RID_T;
131
  signal RD1P1_0,RD2P1_0,RD3P1_0 : RID_T;
132
  signal RD1P1_1,RD2P1_1,RD3P1_1 : RID_T;
133
  signal STALL_A_IX1_0,STALL_A_IX2_0,STALL_A_IX3_0 : std_logic;
134
  signal STALL_B_IX1_0,STALL_B_IX2_0,STALL_B_IX3_0 : std_logic;
135
  signal STALL_A_IX1_1,STALL_A_IX2_1,STALL_A_IX3_1 : std_logic;
136
  signal STALL_B_IX1_1,STALL_B_IX2_1,STALL_B_IX3_1 : std_logic;
137
 
138
  type NVEC is array (8-1 downto 0) of natural;
139
  signal STALL_STATS : NVEC := (0,0,0,0,0,0,0,0);
140
 
141
begin
142
 
143
  ----------------------------------------------------
144
  -- Notes:
145
  ----------------------------------------------------
146
  --
147
  -- This modules checks if an instruction in ID stage
148
  -- has a data dependency from an older instruction
149
  -- (in IX* stage) which prevents it from being
150
  -- issued.
151
 
152
  ----------------------------------------------------
153
  -- General rules:
154
  ----------------------------------------------------
155
  --
156
  -- Issuing must be stalled if ID stage instruction
157
  -- needs result generated by an instruction in IX*
158
  -- stage and this instruction is not enabled to
159
  -- result forwarding (only add/i, sub, slt/i, sltu/i
160
  -- and lw instructions are, and the last type is a
161
  -- 2-cycle instructions that allows forwarding only
162
  -- from stage IX2).
163
  --
164
  -- As a consequence, issuing must be stalled (because
165
  -- result forwarding is not possible) if:
166
  -- 1) instruction in ID stage needs a result generated by
167
  -- an instructions in IX* stage, AND [
168
  -- 2.a) the instruction in IX1, is not enabled to
169
  -- result forwarding or is a two-cycle instruction, OR
170
  -- 2.b) the instruction in IX2 stage is not enabled
171
  -- to result forwarding, OR
172
  -- 2.c) the instruction in IX3 stage is not enabled
173
  -- to result forwarding.
174
  -- ]
175
 
176
  -- NOTE: only IF* and ID stages get actually stalled,
177
  -- allowing IX* stages to proceed.
178
 
179
  -- This version supports delayed execution by avoiding
180
  -- stalling issue when the instruction in ID stage is
181
  -- of add/i, sub, slt/i and sltu/i type, and providing
182
  -- additional outputs to flag operands status.  
183
 
184
  ----------------------------------------------------
185
 
186
  -- two-cycle forward-enabled instruction flags
187
 
188
  IX_2C0 <= '1' when (
189
   (IX1_INSTR0_i.IMNMC = IM_LW)
190
  ) else '0';
191
 
192
  IX_2C1 <= '1' when (
193
   (IX1_INSTR1_i.IMNMC = IM_LW)
194
  ) else '0';
195
 
196
  ----------------------------------------------------
197
 
198
  -- Delayed eXecution flag (set to '1' for
199
  -- instructions which can be executed in delayed
200
  -- mode).
201
 
202
  GDXE_0 : if(DXE = '0') generate
203
 
204
  DX <= '0';
205
 
206
  end generate;
207
 
208
  GDXE_1 : if(DXE = '1') generate
209
 
210
  DX <= '1' when (
211
   (ID_INSTR_i.IMNMC = IM_ADD) or
212
   (ID_INSTR_i.IMNMC = IM_ADDI) or
213
   (ID_INSTR_i.IMNMC = IM_AND) or
214
   (ID_INSTR_i.IMNMC = IM_ANDI) or
215
   (ID_INSTR_i.IMNMC = IM_OR) or
216
   (ID_INSTR_i.IMNMC = IM_ORI) or
217
   (ID_INSTR_i.IMNMC = IM_XOR) or
218
   (ID_INSTR_i.IMNMC = IM_XORI)
219
  ) else '0';
220
 
221
  end generate;
222
 
223
  ----------------------------------------------------
224
 
225
  -- Sequential eXecution flag.
226
 
227
  -- Sequential execution flag is asserted when:
228
  -- 1) ID instruction has SEQX flag set and there's,
229
  -- at least, a valid instruction under execution, OR
230
  -- 2) there's , at least, a valid instruction under
231
  -- execution having SEQX flag set.
232
 
233
  SEQX <=
234
    (
235
      ID_INSTR_i.SEQX and (
236
        IX1_V_i(0) or
237
        IX1_V_i(1) or
238
        IX2_V_i(0) or
239
        IX2_V_i(1) or
240
        IX3_V_i(0) or
241
        IX3_V_i(1)
242
      )
243
    )
244
    or
245
    (
246
      (IX1_INSTR0_i.SEQX and IX1_V_i(0)) or
247
      (IX1_INSTR1_i.SEQX and IX1_V_i(1)) or
248
      (IX2_INSTR0_i.SEQX and IX2_V_i(0)) or
249
      (IX2_INSTR1_i.SEQX and IX2_V_i(1)) or
250
      (IX3_INSTR0_i.SEQX and IX3_V_i(0)) or
251
      (IX3_INSTR1_i.SEQX and IX3_V_i(1))
252
    );
253
 
254
  ----------------------------------------------------
255
 
256
  -- ID instr. vs. IX1/2/3 instr. register match flags 
257
  -- (when a flag is asserted, there's a mtach between a
258
  -- register read by ID instruction and the register
259
  -- written by IX1/2/3 instruction).
260
 
261
  -- RMTCH_x_IXy_z = '1' when there's a match between ID instruction
262
  -- operand register id. x and IXy instruction #z destination
263
  -- register id..
264
 
265
  RMTCH_A_IX1_0 <= '1' when (ID_INSTR_i.RS1 = IX1_INSTR0_i.RD) else '0';
266
  RMTCH_A_IX2_0 <= '1' when (ID_INSTR_i.RS1 = IX2_INSTR0_i.RD) else '0';
267
  RMTCH_A_IX3_0 <= '1' when (ID_INSTR_i.RS1 = IX3_INSTR0_i.RD) else '0';
268
  RMTCH_B_IX1_0 <= '1' when (ID_INSTR_i.RS2 = IX1_INSTR0_i.RD) else '0';
269
  RMTCH_B_IX2_0 <= '1' when (ID_INSTR_i.RS2 = IX2_INSTR0_i.RD) else '0';
270
  RMTCH_B_IX3_0 <= '1' when (ID_INSTR_i.RS2 = IX3_INSTR0_i.RD) else '0';
271
  RMTCH_A_IX1_1 <= '1' when (ID_INSTR_i.RS1 = IX1_INSTR1_i.RD) else '0';
272
  RMTCH_A_IX2_1 <= '1' when (ID_INSTR_i.RS1 = IX2_INSTR1_i.RD) else '0';
273
  RMTCH_A_IX3_1 <= '1' when (ID_INSTR_i.RS1 = IX3_INSTR1_i.RD) else '0';
274
  RMTCH_B_IX1_1 <= '1' when (ID_INSTR_i.RS2 = IX1_INSTR1_i.RD) else '0';
275
  RMTCH_B_IX2_1 <= '1' when (ID_INSTR_i.RS2 = IX2_INSTR1_i.RD) else '0';
276
  RMTCH_B_IX3_1 <= '1' when (ID_INSTR_i.RS2 = IX3_INSTR1_i.RD) else '0';
277
 
278
  ----------------------------------------------------
279
 
280
  -- DATA_DEPx_IXy_z = '1' when there's a data dependency between
281
  -- ID instruction operand x and IXy instruction #z result 
282
 
283
  DATA_DEPA_IX1_0 <=
284
    dep_a(RMTCH_A_IX1_0,ID_V_i,IX1_V_i(0),ID_INSTR_i,IX1_INSTR0_i);
285
 
286
  DATA_DEPA_IX2_0 <=
287
    dep_a(RMTCH_A_IX2_0,ID_V_i,IX2_V_i(0),ID_INSTR_i,IX2_INSTR0_i);
288
 
289
  DATA_DEPA_IX3_0 <=
290
    dep_a(RMTCH_A_IX3_0,ID_V_i,IX3_V_i(0),ID_INSTR_i,IX3_INSTR0_i);
291
 
292
  DATA_DEPB_IX1_0 <=
293
    dep_b(RMTCH_B_IX1_0,ID_V_i,IX1_V_i(0),ID_INSTR_i,IX1_INSTR0_i);
294
 
295
  DATA_DEPB_IX2_0 <=
296
    dep_b(RMTCH_B_IX2_0,ID_V_i,IX2_V_i(0),ID_INSTR_i,IX2_INSTR0_i);
297
 
298
  DATA_DEPB_IX3_0 <=
299
    dep_b(RMTCH_B_IX3_0,ID_V_i,IX3_V_i(0),ID_INSTR_i,IX3_INSTR0_i);
300
 
301
  DATA_DEPA_IX1_1 <=
302
    dep_a(RMTCH_A_IX1_1,ID_V_i,IX1_V_i(1),ID_INSTR_i,IX1_INSTR1_i);
303
 
304
  DATA_DEPA_IX2_1 <=
305
    dep_a(RMTCH_A_IX2_1,ID_V_i,IX2_V_i(1),ID_INSTR_i,IX2_INSTR1_i);
306
 
307
  DATA_DEPA_IX3_1 <=
308
    dep_a(RMTCH_A_IX3_1,ID_V_i,IX3_V_i(1),ID_INSTR_i,IX3_INSTR1_i);
309
 
310
  DATA_DEPB_IX1_1 <=
311
    dep_b(RMTCH_B_IX1_1,ID_V_i,IX1_V_i(1),ID_INSTR_i,IX1_INSTR1_i);
312
 
313
  DATA_DEPB_IX2_1 <=
314
    dep_b(RMTCH_B_IX2_1,ID_V_i,IX2_V_i(1),ID_INSTR_i,IX2_INSTR1_i);
315
 
316
  DATA_DEPB_IX3_1 <=
317
    dep_b(RMTCH_B_IX3_1,ID_V_i,IX3_V_i(1),ID_INSTR_i,IX3_INSTR1_i);
318
 
319
  ----------------------------------------------------
320
 
321
  -- STALL_x_IXy_z = '1' when there's a stall condition caused by
322
  -- ID instruction operand x and IXy instruction #z result
323
 
324
  STALL_A_IX1_0 <=
325
    stall_a(DATA_DEPA_IX1_0,IX1_FWDE_i(0),IX_2C0,ID_INSTR_i,IX1_INSTR0_i);
326
 
327
  STALL_A_IX2_0 <=
328
    stall_a(DATA_DEPA_IX2_0,IX2_FWDE_i(0),'0',ID_INSTR_i,IX2_INSTR0_i);
329
 
330
  STALL_A_IX3_0 <=
331
    stall_a(DATA_DEPA_IX3_0,IX3_FWDE_i(0),'0',ID_INSTR_i,IX3_INSTR0_i);
332
 
333
  STALL_B_IX1_0 <=
334
    stall_b(DATA_DEPB_IX1_0,IX1_FWDE_i(0),IX_2C0,ID_INSTR_i,IX1_INSTR0_i);
335
 
336
  STALL_B_IX2_0 <=
337
    stall_b(DATA_DEPB_IX2_0,IX2_FWDE_i(0),'0',ID_INSTR_i,IX2_INSTR0_i);
338
 
339
  STALL_B_IX3_0 <=
340
    stall_b(DATA_DEPB_IX3_0,IX3_FWDE_i(0),'0',ID_INSTR_i,IX3_INSTR0_i);
341
 
342
  STALL_A_IX1_1 <=
343
    stall_a(DATA_DEPA_IX1_1,IX1_FWDE_i(1),IX_2C1,ID_INSTR_i,IX1_INSTR1_i);
344
 
345
  STALL_A_IX2_1 <=
346
    stall_a(DATA_DEPA_IX2_1,IX2_FWDE_i(1),'0',ID_INSTR_i,IX2_INSTR1_i);
347
 
348
  STALL_A_IX3_1 <=
349
    stall_a(DATA_DEPA_IX3_1,IX3_FWDE_i(1),'0',ID_INSTR_i,IX3_INSTR1_i);
350
 
351
  STALL_B_IX1_1 <=
352
    stall_b(DATA_DEPB_IX1_1,IX1_FWDE_i(1),IX_2C1,ID_INSTR_i,IX1_INSTR1_i);
353
 
354
  STALL_B_IX2_1 <=
355
    stall_b(DATA_DEPB_IX2_1,IX2_FWDE_i(1),'0',ID_INSTR_i,IX2_INSTR1_i);
356
 
357
  STALL_B_IX3_1 <=
358
    stall_b(DATA_DEPB_IX3_1,IX3_FWDE_i(1),'0',ID_INSTR_i,IX3_INSTR1_i);
359
  ----------------------------------------------------
360
 
361
  -- operand valid flags
362
 
363
  OPA_V_o <= not(OPA_V_N);
364
 
365
  OPA_V_N <=
366
    STALL_A_IX1_0 or
367
    STALL_A_IX2_0 or
368
    STALL_A_IX3_0 or
369
    STALL_A_IX1_1 or
370
    STALL_A_IX2_1 or
371
    STALL_A_IX3_1;
372
 
373
  OPB_V_o <= not(OPB_V_N);
374
 
375
  OPB_V_N <=
376
    STALL_B_IX1_0 or
377
    STALL_B_IX2_0 or
378
    STALL_B_IX3_0 or
379
    STALL_B_IX1_1 or
380
    STALL_B_IX2_1 or
381
    STALL_B_IX3_1;
382
 
383
  -- Double Stall flags (set to '1' when operand A/B is
384
  -- subject to a double (dependency) condition, this
385
  -- information must be piped to stage X1 to prevent
386
  -- instructions from reading the incorrect result).
387
 
388
  -- Double Stall can be '1' only for instructions
389
  -- which can be executed in delayed mode.
390
 
391
  DSA_o <= DX when (
392
    (DATA_DEPA_IX1_0= '1' or DATA_DEPA_IX1_1 = '1') and
393
    (DATA_DEPA_IX2_0 = '1' or DATA_DEPA_IX2_1 = '1')
394
  ) else '0';
395
 
396
  DSB_o <= DX when (
397
    (DATA_DEPB_IX1_0 = '1' or DATA_DEPB_IX1_1 = '1') and
398
    (DATA_DEPB_IX2_0 = '1' or DATA_DEPB_IX2_1 = '1')
399
  ) else '0';
400
 
401
  -- pipeline (instr. issue) stall flag
402
 
403
  PSTALL_o <= ((
404
    STALL_A_IX1_0 or
405
    STALL_A_IX2_0 or
406
    STALL_A_IX3_0 or
407
    STALL_B_IX1_0 or
408
    STALL_B_IX2_0 or
409
    STALL_B_IX3_0 or
410
    STALL_A_IX1_1 or
411
    STALL_A_IX2_1 or
412
    STALL_A_IX3_1 or
413
    STALL_B_IX1_1 or
414
    STALL_B_IX2_1 or
415
    STALL_B_IX3_1
416
  ) and not(DX)) or SEQX;
417
 
418
  ----------------------------------------------------
419
  -- Generate stall statistics (debug only)
420
  ----------------------------------------------------
421
 
422
  GSTAT: if(SIMULATION_ONLY = '1') generate
423
 
424
    process(CLK_i)
425
    begin
426
      if(CLK_i = '1' and CLK_i'event) then
427
 
428
        --if(ID_V_i = '1') then
429
 
430
          if(STALL_A_IX1_0 = '1') then
431
            STALL_STATS(0) <= STALL_STATS(0) + 1;
432
          end if;
433
 
434
          if(STALL_A_IX2_0 = '1') then
435
            STALL_STATS(1) <= STALL_STATS(1) + 1;
436
          end if;
437
 
438
          if(STALL_B_IX1_0 = '1') then
439
            STALL_STATS(2) <= STALL_STATS(2) + 1;
440
          end if;
441
 
442
          if(STALL_B_IX2_0 = '1') then
443
            STALL_STATS(3) <= STALL_STATS(3) + 1;
444
          end if;
445
 
446
          if(STALL_A_IX1_1 = '1') then
447
            STALL_STATS(4) <= STALL_STATS(4) + 1;
448
          end if;
449
 
450
          if(STALL_A_IX2_1 = '1') then
451
            STALL_STATS(5) <= STALL_STATS(5) + 1;
452
          end if;
453
 
454
          if(STALL_B_IX1_1 = '1') then
455
            STALL_STATS(6) <= STALL_STATS(6) + 1;
456
          end if;
457
 
458
          if(STALL_B_IX2_1 = '1') then
459
            STALL_STATS(7) <= STALL_STATS(7) + 1;
460
          end if;
461
 
462
        --end if;
463
 
464
      end if;
465
 
466
    end process;
467
 
468
  end generate;
469
 
470
end;
471
 

powered by: WebSVN 2.1.0

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