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

Subversion Repositories g729a_codec

[/] [g729a_codec/] [trunk/] [VHDL/] [G729A_asip_cpu_2w_p6.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 madsilicon
-----------------------------------------------------------------
2
--                                                             --
3
-----------------------------------------------------------------
4
--                                                             --
5
-- Copyright (C) 2013 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 WARRANTIES, INCLUDING, BUT NOT LIMITED   --
14
-- TO, THE IMPLIED WARRANTIES 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  CONTRACT, 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
-- G.729a ASIP CPU module
30
---------------------------------------------------------------
31
 
32
library IEEE;
33
use IEEE.std_logic_1164.all;
34
use IEEE.numeric_std.all;
35
use STD.textio.all;
36
 
37
library work;
38
use work.G729A_ASIP_PKG.all;
39
use work.G729A_ASIP_IDEC_2W_PKG.all;
40
use WORK.G729A_ASIP_BASIC_PKG.all;
41
use WORK.G729A_ASIP_ARITH_PKG.all;
42
use WORK.G729A_ASIP_OP_PKG.all;
43
 
44
entity G729A_ASIP_CPU_2W is
45
  generic(
46
    -- synthesis translate_off
47
    ST_FILENAME : string := "NONE";
48
    WB_FILENAME : string := "NONE";
49
    -- synthesis translate_on
50
    SIMULATION_ONLY : std_logic := '1'
51
  );
52
  port(
53
    CLK_i : in std_logic;
54
    RST_i : in std_logic;
55
    STRT_i : in std_logic;
56
    SADR_i : in unsigned(ALEN-1 downto 0);
57
    -- instruction memory interface
58
    INSTR_i : in std_logic_vector(ILEN*2-1 downto 0); -- two instructions!
59
    -- data memory interface
60
    DDAT0_i : in std_logic_vector(SDLEN-1 downto 0);
61
    DDAT1_i : in std_logic_vector(SDLEN-1 downto 0);
62
    -- check interface
63
    CHK_ENB_i : in std_logic;
64
 
65
    BSY_o : out std_logic;
66
    -- instruction memory interface
67
    IADR_o : out unsigned(ALEN-2 downto 0);
68
    -- data memory interface
69
    DRE_o : out std_logic_vector(2-1 downto 0);
70
    DWE0_o : out std_logic;
71
    DADR0_o : out unsigned(ALEN-1 downto 0);
72
    DADR1_o : out unsigned(ALEN-1 downto 0);
73
    DDAT0_o : out std_logic_vector(SDLEN-1 downto 0)
74
  );
75
end G729A_ASIP_CPU_2W;
76
 
77
architecture ARC of G729A_ASIP_CPU_2W is
78
 
79
  constant LCSTK_DEPTH : natural := 4;
80
  constant SZERO : SDWORD_T := (others => '0');
81
  constant LZERO : LDWORD_T := (others => '0');
82
 
83
  constant NW : natural := 2;
84
  constant NWX2M1 : natural := NW*2-1;
85
 
86
  component G729A_ASIP_LCSTKLOG_2W is
87
    generic(
88
      DEPTH : natural
89
    );
90
    port(
91
      CLK_i : in std_logic;
92
      RST_i : in std_logic;
93
      SRST_i : in std_logic;
94
      LLBRX_i : in std_logic; -- llbri eXecute flag
95
      LLERX_i : in std_logic; -- lleri eXecute flag
96
      LLCRX_i : in std_logic; -- llcnt/llcnti eXecute flag
97
      IMM_i : in unsigned(16-1 downto 0); -- loop count
98
      PCF0_i : in unsigned(ALEN-1 downto 0); -- IF program counter
99
      PCF1_i : in unsigned(ALEN-1 downto 0); -- IF program counter
100
      PCX0_i : in unsigned(ALEN-1 downto 0); -- IX1 program counter
101
      PCX1_i : in unsigned(ALEN-1 downto 0); -- IX1 program counter
102
      IXV_i : in std_logic_vector(2-1 downto 0);
103
 
104
      KLL1_o : out std_logic;
105
      LEND_o : out std_logic;
106
      LEIS_o : out std_logic;
107
      LBX_o : out std_logic; -- loop-back jump eXecute flag
108
      LBTA_o : out unsigned(16-1 downto 0) -- loop-back target address
109
    );
110
  end component;
111
 
112
  component G729A_ASIP_FTCHLOG_2W is
113
    port(
114
      CLK_i : in std_logic;
115
      RST_i : in std_logic;
116
      STRT_i : in std_logic;
117
      HALT_i : in std_logic;
118
      SADR_i : in unsigned(ALEN-1 downto 0);
119
      BJX_i : in std_logic;
120
      BJTA_i : in unsigned(ALEN-1 downto 0);
121
      LBX_i : in std_logic;
122
      LBTA_i : in unsigned(ALEN-1 downto 0);
123
      PSTALL_i : in std_logic;
124
 
125
      IFV_o : out std_logic_vector(2-1 downto 0);
126
      IADR0_o : out unsigned(ALEN-1 downto 0);
127
      IADR1_o : out unsigned(ALEN-1 downto 0);
128
      BSY_o : out std_logic
129
    );
130
  end component;
131
 
132
  component G729A_ASIP_IFQ is
133
    port(
134
      CLK_i : in std_logic;
135
      RST_i : in std_logic;
136
      ID_HALT_i : in std_logic;
137
      IX_BJX_i : in std_logic;
138
      ID_ISSUE_i : in std_logic_vector(2-1 downto 0);
139
      IF_V_i : in std_logic_vector(2-1 downto 0);
140
      IF_PC0_i : in unsigned(ALEN-1 downto 0);
141
      IF_PC1_i : in unsigned(ALEN-1 downto 0);
142
      IF_INSTR0_i : in std_logic_vector(ILEN-1 downto 0);
143
      IF_INSTR1_i : in std_logic_vector(ILEN-1 downto 0);
144
      IF_DEC_INSTR0_i : in DEC_INSTR_T;
145
      IF_DEC_INSTR1_i : in DEC_INSTR_T;
146
      IF_IMM0_i : in std_logic;
147
      IF_IMM1_i : in std_logic;
148
      IF_OPB0_i : in LDWORD_T;
149
      IF_OPB1_i : in LDWORD_T;
150
 
151
      PSTALL_o : out std_logic;
152
      ID_V_o : out std_logic_vector(2-1 downto 0);
153
      ID_PC0_o : out unsigned(ALEN-1 downto 0);
154
      ID_PC1_o : out unsigned(ALEN-1 downto 0);
155
      ID_INSTR0_o : out std_logic_vector(ILEN-1 downto 0);
156
      ID_INSTR1_o : out std_logic_vector(ILEN-1 downto 0);
157
      ID_DEC_INSTR0_o : out DEC_INSTR_T;
158
      ID_DEC_INSTR1_o : out DEC_INSTR_T;
159
      ID_IMM0_o : out std_logic;
160
      ID_IMM1_o : out std_logic;
161
      ID_OPB0_o : out LDWORD_T;
162
      ID_OPB1_o : out LDWORD_T
163
    );
164
  end component;
165
 
166
  component G729A_ASIP_IDEC1_2W is
167
    port(
168
      INSTR_i : in std_logic_vector(ILEN-1 downto 0);
169
 
170
      OPB_IMM_o : out std_logic;
171
      OPB_o : out LDWORD_T;
172
      DEC_INSTR_o : out DEC_INSTR_T
173
    );
174
  end component;
175
 
176
  component G729A_ASIP_IDEC2 is
177
    port(
178
      INSTR_i : in std_logic_vector(ILEN-1 downto 0);
179
      DRA_i : in std_logic_vector(LDLEN-1 downto 0);
180
      DRB_i : in std_logic_vector(LDLEN-1 downto 0);
181
      PCP1_i : in std_logic_vector(ALEN-1 downto 0);
182
      OPB_IMM_i : in std_logic;
183
      OPB_i : in LDWORD_T;
184
      ID_V_i : in std_logic;
185
 
186
      OPA_o : out LDWORD_T;
187
      OPB_o : out LDWORD_T;
188
      OPC_o : out SDWORD_T;
189
      IMM_o : out SDWORD_T;
190
      JL_o : out std_logic;
191
      HALT_o : out std_logic
192
    );
193
  end component;
194
 
195
  component G729A_ASIP_PSTLLOG_2W is
196
    generic(
197
      SIMULATION_ONLY : std_logic := '0'
198
    );
199
    port(
200
      CLK_i : in std_logic;
201
      ID_INSTR_i : in DEC_INSTR_T;
202
      ID_V_i : in std_logic;
203
      IX1_INSTR0_i : in DEC_INSTR_T;
204
      IX1_INSTR1_i : in DEC_INSTR_T;
205
      IX1_V_i : in std_logic_vector(2-1 downto 0);
206
      IX1_FWDE_i : in std_logic_vector(2-1 downto 0);
207
      IX2_INSTR0_i : in DEC_INSTR_T;
208
      IX2_INSTR1_i : in DEC_INSTR_T;
209
      IX2_V_i : in std_logic_vector(2-1 downto 0);
210
      IX2_FWDE_i : in std_logic_vector(2-1 downto 0);
211
 
212
      PSTALL_o : out std_logic
213
    );
214
  end component;
215
 
216
  component G729A_ASIP_PSTLLOG_2W_P6 is
217
    generic(
218
      SIMULATION_ONLY : std_logic := '0'
219
    );
220
    port(
221
      CLK_i : in std_logic;
222
      ID_INSTR_i : in DEC_INSTR_T;
223
      ID_V_i : in std_logic;
224
      IX1_INSTR0_i : in DEC_INSTR_T;
225
      IX1_INSTR1_i : in DEC_INSTR_T;
226
      IX1_V_i : in std_logic_vector(2-1 downto 0);
227
      IX1_FWDE_i : in std_logic_vector(2-1 downto 0);
228
      IX2_INSTR0_i : in DEC_INSTR_T;
229
      IX2_INSTR1_i : in DEC_INSTR_T;
230
      IX2_V_i : in std_logic_vector(2-1 downto 0);
231
      IX2_FWDE_i : in std_logic_vector(2-1 downto 0);
232
      IX3_INSTR0_i : in DEC_INSTR_T;
233
      IX3_INSTR1_i : in DEC_INSTR_T;
234
      IX3_V_i : in std_logic_vector(2-1 downto 0);
235
      IX3_FWDE_i : in std_logic_vector(2-1 downto 0);
236
 
237
      PSTALL_o : out std_logic
238
    );
239
  end component;
240
 
241
  component G729A_ASIP_PXLOG is
242
    port(
243
      ID_INSTR0_i : in DEC_INSTR_T;
244
      ID_INSTR1_i : in DEC_INSTR_T;
245
      ID_V_i : in std_logic_vector(2-1 downto 0);
246
      ID_FWDE_i : in std_logic_vector(2-1 downto 0);
247
 
248
      PXE1_o : out std_logic
249
    );
250
  end component;
251
 
252
 
253
  component G729A_ASIP_PIPE_A_DEC_2W is
254
    port(
255
      INSTR_i : in DEC_INSTR_T;
256
 
257
      FWDE_o : out std_logic;
258
      SEL_o :  out std_logic_vector(7-1 downto 0)
259
    );
260
  end component;
261
 
262
  component G729A_ASIP_FWDLOG_2W is
263
    port(
264
      ID_RX_i : in RID_T;
265
      ID_RRX_i : in std_logic;
266
      IX1_INSTR0_i : in DEC_INSTR_T;
267
      IX2_INSTR0_i : in DEC_INSTR_T;
268
      IX1_INSTR1_i : in DEC_INSTR_T;
269
      IX2_INSTR1_i : in DEC_INSTR_T;
270
      IX1_PA_RES0_i : in SDWORD_T;
271
      IX1_PA_RES1_i : in SDWORD_T;
272
      IX2_PA_RES0_i : in LDWORD_T;
273
      IX2_PA_RES1_i : in LDWORD_T;
274
      ID_OPX_NOFWD_i : in LDWORD_T;
275
      IX1_V_i : in std_logic_vector(2-1 downto 0);
276
      IX2_V_i : in std_logic_vector(2-1 downto 0);
277
      IX1_FWDE_i : in std_logic_vector(2-1 downto 0);
278
      IX2_FWDE_i : in std_logic_vector(2-1 downto 0);
279
 
280
      ID_OPX_o : out LDWORD_T
281
    );
282
  end component;
283
 
284
  component G729A_ASIP_FWDLOG_2W_P6 is
285
    port(
286
      ID_RX_i : in RID_T;
287
      ID_RRX_i : in std_logic;
288
      IX1_INSTR0_i : in DEC_INSTR_T;
289
      IX2_INSTR0_i : in DEC_INSTR_T;
290
      IX3_INSTR0_i : in DEC_INSTR_T;
291
      IX1_INSTR1_i : in DEC_INSTR_T;
292
      IX2_INSTR1_i : in DEC_INSTR_T;
293
      IX3_INSTR1_i : in DEC_INSTR_T;
294
      IX1_PA_RES0_i : in SDWORD_T;
295
      IX1_PA_RES1_i : in SDWORD_T;
296
      IX2_PA_RES0_i : in LDWORD_T;
297
      IX2_PA_RES1_i : in LDWORD_T;
298
      IX3_PA_RES0_i : in LDWORD_T;
299
      IX3_PA_RES1_i : in LDWORD_T;
300
      ID_OPX_NOFWD_i : in LDWORD_T;
301
      IX1_V_i : in std_logic_vector(2-1 downto 0);
302
      IX2_V_i : in std_logic_vector(2-1 downto 0);
303
      IX3_V_i : in std_logic_vector(2-1 downto 0);
304
      IX1_FWDE_i : in std_logic_vector(2-1 downto 0);
305
      IX2_FWDE_i : in std_logic_vector(2-1 downto 0);
306
      IX3_FWDE_i : in std_logic_vector(2-1 downto 0);
307
      NOREGS_i : in std_logic;
308
      NOREGD_i : in LDWORD_T;
309
 
310
      ID_OPX_o : out LDWORD_T
311
    );
312
  end component;
313
 
314
  component G729A_ASIP_PIPE_A_2W is
315
    port(
316
      CLK_i : in std_logic;
317
      SEL_i :  in std_logic_vector(7-1 downto 0);
318
      OPA_i : in SDWORD_T;
319
      OPB_i : in SDWORD_T;
320
      ACC_i : in LDWORD_T;
321
      LDAT_i : in std_logic_vector(SDLEN-1 downto 0);
322
 
323
      RES_1C_o : out SDWORD_T; --  port #0 1-cycle result
324
      RES_o : out LDWORD_T; -- port #0 result
325
      ACC_o : out LDWORD_T; -- updated accumulator
326
      OVF_o : out std_logic -- port #0 overflow flag
327
    );
328
  end component;
329
 
330
  component G729A_ASIP_PIPE_B is
331
    port(
332
      CLK_i : in std_logic;
333
      OP_i :  in ALU_OP_T;
334
      OPA_i : in LDWORD_T;
335
      OPB_i : in LDWORD_T;
336
      OVF_i : in std_logic;
337
      ACC_i : in LDWORD_T;
338
 
339
      RES_o : out LDWORD_T;
340
      OVF_o : out std_logic
341
    );
342
  end component;
343
 
344
  component G729A_ASIP_BJXLOG is
345
    port(
346
      CLK_i : in std_logic;
347
      RST_i : in std_logic;
348
      BJ_OP : in BJ_OP_T;
349
      PC0P1_i : in unsigned(ALEN-1 downto 0);
350
      PC1P1_i : in unsigned(ALEN-1 downto 0);
351
      PC0_i : in unsigned(ALEN-1 downto 0);
352
      PCSEL_i : in std_logic;
353
      OPA_i : in LDWORD_T;
354
      OPB_i : in LDWORD_T;
355
      OPC_i : in SDWORD_T;
356
      IV_i : in std_logic;
357
      LLCRX_i : in std_logic;
358
      FSTLL_i : in std_logic;
359
 
360
      BJX_o : out std_logic;
361
      BJTA_o : out unsigned(ALEN-1 downto 0)
362
    );
363
  end component;
364
 
365
  component G729A_ASIP_LSU is
366
    port(
367
      IV_i : in std_logic;
368
      LS_OP_i : in LS_OP_T;
369
      OPA_i : in LDWORD_T;
370
      OPB_i : in LDWORD_T;
371
      OPC_i : in SDWORD_T;
372
 
373
      DRE_o : out std_logic;
374
      DWE_o : out std_logic;
375
      DADR_o : out unsigned(ALEN-1 downto 0);
376
      DDAT_o : out std_logic_vector(SDLEN-1 downto 0)
377
    );
378
  end component;
379
 
380
  component G729A_ASIP_LU is
381
    port(
382
      IV_i : in std_logic;
383
      LS_OP_i : in LS_OP_T;
384
      OPA_i : in LDWORD_T;
385
      OPB_i : in LDWORD_T;
386
 
387
      DRE_o : out std_logic;
388
      DADR_o : out unsigned(ALEN-1 downto 0)
389
    );
390
  end component;
391
 
392
  component G729A_ASIP_LCSTKLOG_IX is
393
    port(
394
      IX_V_i : in std_logic;
395
      IX_INSTR_i : in DEC_INSTR_T;
396
      IX_OPA_i : in LDWORD_T;
397
 
398
      SRST_o : out std_logic;
399
      LLBRX_o : out std_logic; -- llbri eXecute flag
400
      LLERX_o : out std_logic; -- lleri eXecute flag
401
      LLCRX_o : out std_logic; -- llcnt/llcnti eXecute flag
402
      IMM_o : out unsigned(ALEN-1 downto 0) -- loop count
403
    );
404
  end component;
405
 
406
  component G729A_ASIP_REGFILE_16X16_2W is
407
    port(
408
      CLK_i : in std_logic;
409
      RA0_i : in RID_T;
410
      RA1_i : in RID_T;
411
      RA2_i : in RID_T;
412
      RA3_i : in RID_T;
413
      WA0_i : in RID_T;
414
      WA1_i : in RID_T;
415
      LR0_i : in std_logic;
416
      LR1_i : in std_logic;
417
      LR2_i : in std_logic;
418
      LR3_i : in std_logic;
419
      LW0_i : in std_logic;
420
      LW1_i : in std_logic;
421
      WE0_i : in std_logic;
422
      WE1_i : in std_logic;
423
      D0_i : in std_logic_vector(LDLEN-1 downto 0);
424
      D1_i : in std_logic_vector(LDLEN-1 downto 0);
425
 
426
      Q0_o : out std_logic_vector(LDLEN-1 downto 0);
427
      Q1_o : out std_logic_vector(LDLEN-1 downto 0);
428
      Q2_o : out std_logic_vector(LDLEN-1 downto 0);
429
      Q3_o : out std_logic_vector(LDLEN-1 downto 0)
430
    );
431
  end component;
432
 
433
  component G729A_ASIP_STATS is
434
    port(
435
      CLK_i : in std_logic;
436
      RST_i : in std_logic;
437
      ID_V_i : in std_logic_vector(2-1 downto 0);
438
      ID_PS_i : in std_logic_vector(2-1 downto 0);
439
      ID_PXE1_i : std_logic;
440
      IX2_V_i : in std_logic_vector(2-1 downto 0);
441
      STRT_i : in std_logic;
442
      HALT_i : in std_logic
443
    );
444
  end component;
445
 
446
  function to_unsigned(S : signed) return unsigned is
447
    variable U : unsigned(S'high downto S'low);
448
  begin
449
    for i in S'low to S'high loop
450
      U(i) := S(i);
451
    end loop;
452
    return(U);
453
  end function;
454
 
455
  function to_signed(U : unsigned) return signed is
456
    variable S : signed(U'high downto U'low);
457
  begin
458
    for i in U'low to U'high loop
459
      S(i) := U(i);
460
    end loop;
461
    return(S);
462
  end function;
463
 
464
  function EXTS16(V : std_logic_vector) return signed is
465
    variable S : signed(SDLEN-1 downto 0);
466
  begin
467
    S(V'HIGH downto 0) := to_signed(V);
468
    S(SDLEN-1 downto V'HIGH+1) := (others => V(V'HIGH));
469
    return(S);
470
  end function;
471
 
472
  function EXTS32(S : signed) return signed is
473
    variable XS : signed(LDLEN-1 downto 0);
474
  begin
475
    XS(S'HIGH downto 0) := S;
476
    XS(LDLEN-1 downto S'HIGH+1) := (others => S(S'HIGH));
477
    return(XS);
478
  end function;
479
 
480
  type DEC_INSTR_VEC_T is array (natural range<>) of DEC_INSTR_T;
481
  type LDWORD_VEC_T is array (natural range<>) of LDWORD_T;
482
  subtype ADR_T is unsigned(ALEN-1 downto 0);
483
  type ADR_VEC_T is array (natural range<>) of ADR_T;
484
 
485
  signal ZERO : std_logic := '0';
486
  signal ONE : std_logic := '1';
487
 
488
  signal IF_INSTR0,IF_INSTR1 : std_logic_vector(ILEN-1 downto 0);
489
  signal IF_INSTR_q : std_logic_vector(ILEN*NW-1 downto 0);
490
  signal IF_V,IF_V_q : std_logic_vector(NW-1 downto 0);
491
  signal IF_V_KLL1 : std_logic_vector(NW-1 downto 0);
492
  signal IF_V_q2 : std_logic_vector(NW-1 downto 0);
493
  signal IF_PC0,IF_PC1 : ADR_T;
494
  signal IF_PC_q : ADR_VEC_T(NW-1 downto 0);
495
  signal IF_PC_q2 : ADR_VEC_T(NW-1 downto 0);
496
  signal IF_KLL1 : std_logic;
497
  signal IF_LBX : std_logic;
498
  signal IF_LBTA : unsigned(ALEN-1 downto 0);
499
  signal IF_DEC_INSTR0,IF_DEC_INSTR1 : DEC_INSTR_T;
500
  signal IF_DEC_INSTR_q : DEC_INSTR_VEC_T(NW-1 downto 0);
501
  signal IF_OPB_IMM0,IF_OPB_IMM1 : std_logic;
502
  signal IF_OPB_IMM_q : std_logic_vector(NW-1 downto 0);
503
  signal IF_OPB0,IF_OPB1 : LDWORD_T;
504
  signal IF_OPB_q : LDWORD_VEC_T(NW-1 downto 0);
505
 
506
  signal ID_INSTR0,ID_INSTR1 : DEC_INSTR_T;
507
  signal ID_INSTR_q : DEC_INSTR_VEC_T(NW-1 downto 0);
508
  signal ID_IMM0,ID_IMM1 : signed(SDLEN-1 downto 0);
509
  signal ID_V,ID_V_q : std_logic_vector(NW-1 downto 0);
510
  signal ID_ISSUE : std_logic_vector(NW-1 downto 0);
511
  signal ID_PC_q : ADR_VEC_T(NW-1 downto 0);
512
  signal ID_PCP1_q : ADR_VEC_T(NW-1 downto 0);
513
  signal ID_OPA0,ID_OPA0_q : LDWORD_T;
514
  signal ID_OPB0,ID_OPB0_q : LDWORD_T;
515
  signal ID_OPA1,ID_OPA1_q : LDWORD_T;
516
  signal ID_OPB1,ID_OPB1_q : LDWORD_T;
517
  signal ID_OPC0,ID_OPC0_q : SDWORD_T;
518
  signal ID_HALT0,ID_HALT1,ID_HALT : std_logic;
519
  signal ID_PSTALL : std_logic;
520
  signal ID_PS0,ID_PS1 : std_logic;
521
  signal ID_PXE1 : std_logic;
522
  signal ID_JLRA0,ID_JLRA1 : unsigned(ALEN-1 downto 0);
523
  signal ID_JLRA0_S,ID_JLRA1_S : LDWORD_T;
524
  signal ID_FWDE : std_logic_vector(NW-1 downto 0);
525
  signal ID_FWDE_q : std_logic_vector(NW-1 downto 0);
526
  signal ID_PASEL0,ID_PASEL1 :  std_logic_vector(7-1 downto 0);
527
  signal ID_PASEL0_q,ID_PASEL1_q :  std_logic_vector(7-1 downto 0);
528
  signal ID_JL0,ID_JL1 : std_logic;
529
 
530
  signal IX1_INSTR0_q,IX1_INSTR1_q : DEC_INSTR_T;
531
  signal IX1_SRST : std_logic;
532
  signal IX1_LLBR,IX1_LLER,IX1_LLCR : std_logic;
533
  signal IX1_BJX : std_logic;
534
  signal IX1_BJTA : unsigned(ALEN-1 downto 0);
535
  signal IX1_IMM : unsigned(ALEN-1 downto 0);
536
  signal IX1_ALUV : std_logic;
537
  signal IX1_ALUOVF : std_logic;
538
  signal IX1_LDV : std_logic;
539
  signal IX1_DWE : std_logic;
540
  signal IX1_DDATO : std_logic_vector(SDLEN-1 downto 0);
541
  signal IX1_DADR : unsigned(ALEN-1 downto 0);
542
  signal UNUSED1 : std_logic := '0';
543
  signal IX1_MC : MUL_CTRL;
544
  signal IX1_V,IX1_V_q : std_logic_vector(NW-1 downto 0);
545
  signal IX1_FWDE_q : std_logic_vector(NW-1 downto 0);
546
  signal IX1_PA0_RES : SDWORD_T;
547
  signal IX1_PA1_RES : SDWORD_T;
548
  signal IX1_LEND : std_logic;
549
  signal IX1_LEIS : std_logic;
550
  signal IX1_PCLN : std_logic;
551
  signal IX1_PCLN_PC : unsigned(ALEN-1 downto 0);
552
 
553
  signal IX2_OVF0 : std_logic;
554
  signal IX2_OVF1 : std_logic;
555
  signal IX2_DRD0,IX2_DRD1 : signed(LDLEN-1 downto 0);
556
  signal IX2_PA0_RES : LDWORD_T;
557
  signal IX2_PA1_RES : LDWORD_T;
558
  signal IX2_PA0_OVF : std_logic;
559
  signal IX2_PA1_OVF : std_logic;
560
  signal IX2_PB0_RES : LDWORD_T;
561
  signal IX2_PB0_OVF : std_logic;
562
 
563
  signal IX2_INSTR0_q,IX2_INSTR1_q : DEC_INSTR_T;
564
  signal IX2_DRD0_q,IX2_DRD1_q : signed(LDLEN-1 downto 0);
565
  signal IX3_DRD0,IX3_DRD1 : signed(LDLEN-1 downto 0);
566
  signal IX2_OVF0_q,IX2_OVF1_q : std_logic;
567
  signal IX3_OVF0,IX3_OVF1 : std_logic;
568
  signal IX2_V_q : std_logic_vector(NW-1 downto 0);
569
  signal IX2_FWDE : std_logic_vector(NW-1 downto 0);
570
  signal IX2_FWDE_q : std_logic_vector(NW-1 downto 0);
571
 
572
  signal WB_WE0,WB_WE1 : std_logic;
573
  signal WB_WA1 : RID_T;
574
  signal WB_RDA0,WB_RDB0 : std_logic_vector(LDLEN-1 downto 0);
575
  signal WB_RDA1,WB_RDB1 : std_logic_vector(LDLEN-1 downto 0);
576
  signal WB_OVF,WB_OVF_q : std_logic;
577
  signal WB_ACC_q : signed(LDLEN-1 downto 0);
578
  signal WB_PXE_q : std_logic;
579
 
580
  -- debug-only signals
581
 
582
  component G729A_ASIP_ST_CHECKER is
583
    generic(
584
      ST_FILENAME : string := "NONE"
585
    );
586
    port(
587
      CLK_i : in std_logic;
588
    ENB_i : in std_logic;
589
      DWE_i : in std_logic;
590
      DADR_i : in unsigned(ALEN-1 downto 0);
591
      DDATO_i : in std_logic_vector(SDLEN-1 downto 0)
592
    );
593
  end component;
594
 
595
  component G729A_ASIP_WB_CHECKER is
596
    generic(
597
      WB_FILENAME : string := "NONE"
598
    );
599
    port(
600
      CLK_i : in std_logic;
601
      ENB_i : in std_logic;
602
      WE0_i : in std_logic;
603
      WE1_i : in std_logic;
604
      IX_INSTR0_i : in DEC_INSTR_T;
605
      IX_INSTR1_i : in DEC_INSTR_T;
606
      IX_DRD0_i : in LDWORD_T;
607
      IX_DRD1_i : in LDWORD_T
608
    );
609
  end component;
610
 
611
begin
612
 
613
  ----------------------------------------------------
614
  -- Notes:
615
  ----------------------------------------------------
616
 
617
  -- *** Pipeline ***
618
  -- ASIP employs the following 7-stage pipeline:
619
  -- 1) Instruction Fetch (IF1)
620
  -- 2) Instruction Fetch (IF2)
621
  -- 3) Instruction Decode (ID)
622
  -- 4) Instruction Execute (IX1)
623
  -- 5) Instruction Execute (IX2)
624
  -- 6) Instruction Execute (IX3)
625
  -- 7) Write Back (WB)
626
 
627
  -- *** Branch processing ***
628
  -- There's no branch prediction: branches are processed
629
  -- in IX1 stage, like other instructions, as a consequence
630
  -- there's a fixed branch penalty of 2 cycles.
631
 
632
  -- *** Loop Control Stack management ***
633
  -- 1) Loop control stack is pushed when a llcnt/llcnti
634
  -- instruction enters IX1 stage. 
635
  -- 2) Loop count is decremented
636
  -- every time the first loop instruction enters IX1 stage.
637
  -- 3) loop-back implicit jump is performed when last
638
  -- loop instruction is fetched, in order to avoid the
639
  -- 2-cycle penalty imposed by the pipeline. First/last
640
  -- loop instruction CAN'T be a conditionally executed
641
  -- instruction!
642
 
643
  ----------------------------------------------------
644
  -- IF1 Stage:
645
  ----------------------------------------------------
646
 
647
  -- Loop Control Stack Logic
648
 
649
  U_LCSTK : G729A_ASIP_LCSTKLOG_2W
650
    generic map(
651
      DEPTH => LCSTK_DEPTH
652
    )
653
    port map(
654
      CLK_i => CLK_i,
655
      RST_i => RST_i,
656
      SRST_i => IX1_SRST,
657
      LLBRX_i => IX1_LLBR,
658
      LLERX_i => IX1_LLER,
659
      LLCRX_i => IX1_LLCR,
660
      IMM_i => IX1_IMM,
661
      PCF0_i => IF_PC_q(0),
662
      PCF1_i => IF_PC_q(1),
663
      PCX0_i => ID_PC_q(0),
664
      PCX1_i => ID_PC_q(1),
665
      IXV_i => ID_V_q,
666
 
667
      KLL1_o => IF_KLL1,
668
      LEND_o => IX1_LEND,
669
      LEIS_o => IX1_LEIS,
670
      LBX_o => IF_LBX,
671
      LBTA_o => IF_LBTA
672
    );
673
 
674
  -- Instruction Fetch Logic 
675
 
676
  -- This logic fetches instruction pairs, so that
677
  -- fetch address LSb is always zero
678
 
679
  U_FTCH : G729A_ASIP_FTCHLOG_2W
680
    port map(
681
      CLK_i => CLK_i,
682
      RST_i => RST_i,
683
      STRT_i => STRT_i,
684
      HALT_i => ID_HALT,
685
      SADR_i => SADR_i,
686
      BJX_i => IX1_BJX,
687
      BJTA_i => IX1_BJTA,
688
      LBX_i => IF_LBX,
689
      LBTA_i => IF_LBTA,
690
      PSTALL_i => ID_PSTALL,
691
 
692
      IFV_o => IF_V,
693
      IADR0_o => IF_PC0,
694
      IADR1_o => IF_PC1,
695
      BSY_o => BSY_o
696
    );
697
 
698
  -- Instruction memory address is a two-word address and
699
  -- therefore is one bit-shorter than individual instruction
700
  -- addresses.
701
 
702
  IADR_o <= IF_PC0(ALEN-1 downto 1);
703
 
704
  -- Pipeline Registers
705
 
706
  process(CLK_i)
707
  begin
708
    if(CLK_i = '1' and CLK_i'event) then
709
 
710
      if(RST_i = '1') then
711
        IF_V_q <= "00";
712
      elsif(ID_HALT = '1') then
713
        IF_V_q <= "00";
714
      elsif(ID_PSTALL = '0') then
715
        IF_V_q <= IF_V;
716
      end if;
717
 
718
      IF_PC_q(0) <= IF_PC0;
719
      IF_PC_q(1) <= IF_PC1;
720
 
721
    end if;
722
  end process;
723
 
724
  ----------------------------------------------------
725
  -- IF2 Stage
726
  ----------------------------------------------------
727
 
728
  -- Split instruction memory output into two individual instructions
729
 
730
  IF_INSTR0 <= INSTR_i(ILEN*1-1 downto ILEN*0);
731
  IF_INSTR1 <= INSTR_i(ILEN*2-1 downto ILEN*1);
732
 
733
  -- Pre-decode individual instructions
734
 
735
  U_IDEC10 : G729A_ASIP_IDEC1_2W
736
    port map(
737
      INSTR_i => IF_INSTR0,
738
 
739
      OPB_IMM_o => IF_OPB_IMM0,
740
      OPB_o => IF_OPB0,
741
      DEC_INSTR_o => IF_DEC_INSTR0
742
    );
743
 
744
  U_IDEC11 : G729A_ASIP_IDEC1_2W
745
    port map(
746
      INSTR_i => IF_INSTR1,
747
 
748
      OPB_IMM_o => IF_OPB_IMM1,
749
      OPB_o => IF_OPB1,
750
      DEC_INSTR_o => IF_DEC_INSTR1
751
    );
752
 
753
  -- IF2 stage instruction valid flags (accounting for KILL flag).
754
  -- Instruction slot #1 gets "killed" (invalidated) if slot #0
755
  -- instruction is a B/J one.
756
 
757
  IF_V_KLL1 <= ((IF_V_q(1) and not (IF_KLL1 and IF_LBX)) & IF_V_q(0));
758
 
759
  -- Instruction queue
760
 
761
  -- Note: IFQ includes pipeline registers between IF2 and ID stages.
762
 
763
  U_IFQ : G729A_ASIP_IFQ
764
    port map(
765
      CLK_i => CLK_i,
766
      RST_i => RST_i,
767
      ID_HALT_i => ID_HALT,
768
      IX_BJX_i => IX1_BJX,
769
      ID_ISSUE_i => ID_ISSUE,
770
      IF_V_i => IF_V_KLL1, --IF_V_q,
771
      IF_PC0_i => IF_PC_q(0),
772
      IF_PC1_i => IF_PC_q(1),
773
      IF_INSTR0_i => IF_INSTR0,
774
      IF_INSTR1_i => IF_INSTR1,
775
      IF_DEC_INSTR0_i => IF_DEC_INSTR0,
776
      IF_DEC_INSTR1_i => IF_DEC_INSTR1,
777
      IF_IMM0_i => IF_OPB_IMM0,
778
      IF_IMM1_i => IF_OPB_IMM1,
779
      IF_OPB0_i => IF_OPB0,
780
      IF_OPB1_i => IF_OPB1,
781
 
782
      PSTALL_o => ID_PSTALL,
783
      ID_V_o => IF_V_q2,
784
      ID_PC0_o => IF_PC_q2(0),
785
      ID_PC1_o => IF_PC_q2(1),
786
      ID_INSTR0_o => IF_INSTR_q(ILEN*1-1 downto ILEN*0),
787
      ID_INSTR1_o => IF_INSTR_q(ILEN*2-1 downto ILEN*1),
788
      ID_DEC_INSTR0_o => IF_DEC_INSTR_q(0),
789
      ID_DEC_INSTR1_o => IF_DEC_INSTR_q(1),
790
      ID_IMM0_o => IF_OPB_IMM_q(0),
791
      ID_IMM1_o => IF_OPB_IMM_q(1),
792
      ID_OPB0_o => IF_OPB_q(0),
793
      ID_OPB1_o => IF_OPB_q(1)
794
    );
795
 
796
  ----------------------------------------------------
797
  -- ID Stage
798
  ----------------------------------------------------
799
 
800
  -- jump & link instructions return address
801
 
802
  ID_JLRA0 <= IF_PC_q2(1);
803
  ID_JLRA1 <= (IF_PC_q2(1) + 1);
804
 
805
  -- If there's a taken branch, or a jump, in IX1,
806
  -- instructions in ID are nullified.
807
 
808
  ID_V(0) <= IF_V_q2(0) and not(IX1_BJX) and ID_ISSUE(0);
809
  ID_V(1) <= IF_V_q2(1) and not(IX1_BJX) and ID_ISSUE(1);
810
 
811
  -- Instruction Decoder
812
 
813
  U_IDEC20 : G729A_ASIP_IDEC2
814
    port map(
815
      INSTR_i => IF_INSTR_q(ILEN*1-1 downto ILEN*0),
816
      DRA_i => WB_RDA0,
817
      DRB_i => WB_RDB0,
818
      PCP1_i => to_std_logic_vector(ID_JLRA0),
819
      OPB_IMM_i => IF_OPB_IMM_q(0),
820
      OPB_i => IF_OPB_q(0),
821
      ID_V_i => ID_V(0),
822
 
823
      OPA_o => open, --ID_OPA0_NOFWD,
824
      OPB_o => open, --ID_OPB0_NOFWD,
825
      OPC_o => ID_OPC0,
826
      IMM_o => ID_IMM0,
827
      JL_o => ID_JL0,
828
      HALT_o => ID_HALT0
829
    );
830
 
831
  U_IDEC21 : G729A_ASIP_IDEC2
832
    port map(
833
      INSTR_i => IF_INSTR_q(ILEN*2-1 downto ILEN*1),
834
      DRA_i => WB_RDA1,
835
      DRB_i => WB_RDB1,
836
      PCP1_i => to_std_logic_vector(ID_JLRA1),
837
      OPB_IMM_i => IF_OPB_IMM_q(1),
838
      OPB_i => IF_OPB_q(1),
839
      ID_V_i => ID_V(1),
840
 
841
      OPA_o => open, --ID_OPA1_NOFWD,
842
      OPB_o => open, --ID_OPB1_NOFWD,
843
      OPC_o => open, --ID_OPC1,
844
      IMM_o => ID_IMM1,
845
      JL_o => ID_JL1,
846
      HALT_o => ID_HALT1
847
    );
848
 
849
  -- execution must be halted if either instr. #0 or instr. #1 is a halt
850
  ID_HALT <= (ID_HALT0 or ID_HALT1);
851
 
852
  -- update decoded instr. immediate field
853
 
854
  process(IF_DEC_INSTR_q,ID_IMM0,ID_IMM1)
855
    variable TMP : DEC_INSTR_T;
856
  begin
857
 
858
    TMP := IF_DEC_INSTR_q(0);
859
    TMP.IMM := ID_IMM0;
860
    ID_INSTR0 <= TMP;
861
 
862
    TMP := IF_DEC_INSTR_q(1);
863
    TMP.IMM := ID_IMM1;
864
    ID_INSTR1 <= TMP;
865
 
866
  end process;
867
 
868
  -- Pipeline stall logic
869
 
870
  U_PSTL0 : G729A_ASIP_PSTLLOG_2W_P6
871
    generic map(
872 3 madsilicon
      SIMULATION_ONLY => SIMULATION_ONLY
873 2 madsilicon
    )
874
    port map(
875
      CLK_i => CLK_i,
876
      ID_INSTR_i => ID_INSTR0,
877
      ID_V_i => IF_V_q2(0),
878
      IX1_INSTR0_i => ID_INSTR_q(0),
879
      IX1_INSTR1_i => ID_INSTR_q(1),
880
      IX1_V_i => ID_V_q,
881
      IX1_FWDE_i => ID_FWDE_q,
882
      IX2_INSTR0_i => IX1_INSTR0_q,
883
      IX2_INSTR1_i => IX1_INSTR1_q,
884
      IX2_V_i => IX1_V_q,
885
      IX2_FWDE_i => IX1_FWDE_q,
886
      IX3_INSTR0_i => IX2_INSTR0_q,
887
      IX3_INSTR1_i => IX2_INSTR1_q,
888
      IX3_V_i => IX2_V_q,
889
      IX3_FWDE_i => IX2_FWDE_q,
890
 
891
      PSTALL_o => ID_PS0
892
    );
893
 
894
  U_PSTL1 : G729A_ASIP_PSTLLOG_2W_P6
895
    generic map(
896 3 madsilicon
      SIMULATION_ONLY => SIMULATION_ONLY
897 2 madsilicon
    )
898
    port map(
899
      CLK_i => CLK_i,
900
      ID_INSTR_i => ID_INSTR1,
901
      ID_V_i => IF_V_q2(1),
902
      IX1_INSTR0_i => ID_INSTR_q(0),
903
      IX1_INSTR1_i => ID_INSTR_q(1),
904
      IX1_V_i => ID_V_q,
905
      IX1_FWDE_i => ID_FWDE_q,
906
      IX2_INSTR0_i => IX1_INSTR0_q,
907
      IX2_INSTR1_i => IX1_INSTR1_q,
908
      IX2_V_i => IX1_V_q,
909
      IX2_FWDE_i => IX1_FWDE_q,
910
      IX3_INSTR0_i => IX2_INSTR0_q,
911
      IX3_INSTR1_i => IX2_INSTR1_q,
912
      IX3_V_i => IX2_V_q,
913
      IX3_FWDE_i => IX2_FWDE_q,
914
 
915
      PSTALL_o => ID_PS1
916
    );
917
 
918
  -- Parallel eXecution logic
919
 
920
  U_PXLOG : G729A_ASIP_PXLOG
921
    port map(
922
      ID_INSTR0_i => IF_DEC_INSTR_q(0),
923
      ID_INSTR1_i => IF_DEC_INSTR_q(1),
924
      ID_V_i => IF_V_q2(2-1 downto 0),
925
      ID_FWDE_i => ID_FWDE,
926
 
927
      PXE1_o => ID_PXE1
928
    );
929
 
930
  -- Instruction issue flags
931
 
932
  -- instr. #0 is issued if there's no stall due to a data dependency.
933
 
934
  ID_ISSUE(0) <=
935
     not(ID_PS0); -- instr. #0 can be issued
936
 
937
  -- instr. #1 is issued if:
938
  -- 1) there's no stall due to data dependency AND
939
  -- 2) isntr. #0 is isseud too (in-order issue rule)
940
  -- AND instr #1 can execute in parallel with instr. #1.
941
 
942
  --ID_ISSUE(1) <= 
943
  --   not(ID_PS1) and -- instr. #1 can be issued
944
  --   not(ID_PS0) and -- instr. #0 is issued too (in-order issue)
945
  --   ID_PXE1 and  -- instr. #1 can execute in parallel with #0
946
  --   WB_PXE_q; -- parallel execution is enabled
947
 
948
  -- ...same code of above, but restructured to improve timing.
949
  ID_ISSUE(1) <= (ID_PXE1 and WB_PXE_q) when
950
    (ID_PS1 = '0' and ID_PS0 = '0') else '0';
951
 
952
  -- Extend Jump & Link instruction return address to 32 bits.
953
  ID_JLRA0_S <= EXTS32(to_signed(ID_JLRA0));
954
  ID_JLRA1_S <= EXTS32(to_signed(ID_JLRA1));
955
 
956
  -- Instruction #0 Operand A forward logic
957
 
958
  U_FWDLOGA0 : G729A_ASIP_FWDLOG_2W_P6
959
    port map(
960
      ID_RX_i => ID_INSTR0.RA,
961
      ID_RRX_i => ID_INSTR0.RRA,
962
      IX1_INSTR0_i => ID_INSTR_q(0),
963
      IX2_INSTR0_i => IX1_INSTR0_q,
964
      IX3_INSTR0_i => IX2_INSTR0_q,
965
      IX1_INSTR1_i => ID_INSTR_q(1),
966
      IX2_INSTR1_i => IX1_INSTR1_q,
967
      IX3_INSTR1_i => IX2_INSTR1_q,
968
      IX1_PA_RES0_i => IX1_PA0_RES,
969
      IX1_PA_RES1_i => IX1_PA1_RES,
970
      IX2_PA_RES0_i => IX2_PA0_RES,
971
      IX2_PA_RES1_i => IX2_PA1_RES,
972
      IX3_PA_RES0_i => IX3_DRD0,
973
      IX3_PA_RES1_i => IX3_DRD1,
974
      ID_OPX_NOFWD_i => to_signed(WB_RDA0), --ID_OPA0_NOFWD,
975
      IX1_V_i => ID_V_q,
976
      IX2_V_i => IX1_V_q,
977
      IX3_V_i => IX2_V_q,
978
      IX1_FWDE_i => ID_FWDE_q,
979
      IX2_FWDE_i => IX1_FWDE_q,
980
      IX3_FWDE_i => IX2_FWDE_q,
981
      NOREGS_i => ID_JL0,
982
      NOREGD_i => ID_JLRA0_S,
983
 
984
      ID_OPX_o => ID_OPA0
985
    );
986
 
987
  -- Instruction #1 Operand A forward logic
988
 
989
  U_FWDLOGA1 : G729A_ASIP_FWDLOG_2W_P6
990
    port map(
991
      ID_RX_i => ID_INSTR1.RA,
992
      ID_RRX_i => ID_INSTR1.RRA,
993
      IX1_INSTR0_i => ID_INSTR_q(0),
994
      IX2_INSTR0_i => IX1_INSTR0_q,
995
      IX3_INSTR0_i => IX2_INSTR0_q,
996
      IX1_INSTR1_i => ID_INSTR_q(1),
997
      IX2_INSTR1_i => IX1_INSTR1_q,
998
      IX3_INSTR1_i => IX2_INSTR1_q,
999
      IX1_PA_RES0_i => IX1_PA0_RES,
1000
      IX1_PA_RES1_i => IX1_PA1_RES,
1001
      IX2_PA_RES0_i => IX2_PA0_RES,
1002
      IX2_PA_RES1_i => IX2_PA1_RES,
1003
      IX3_PA_RES0_i => IX3_DRD0,
1004
      IX3_PA_RES1_i => IX3_DRD1,
1005
      ID_OPX_NOFWD_i => to_signed(WB_RDA1), --ID_OPA1_NOFWD,
1006
      IX1_V_i => ID_V_q,
1007
      IX2_V_i => IX1_V_q,
1008
      IX3_V_i => IX2_V_q,
1009
      IX1_FWDE_i => ID_FWDE_q,
1010
      IX2_FWDE_i => IX1_FWDE_q,
1011
      IX3_FWDE_i => IX2_FWDE_q,
1012
      NOREGS_i => ID_JL1,
1013
      NOREGD_i => ID_JLRA1_S,
1014
 
1015
      ID_OPX_o => ID_OPA1
1016
    );
1017
 
1018
  -- Instruction #0 Operand B forward logic
1019
 
1020
  U_FWDLOGB0 : G729A_ASIP_FWDLOG_2W_P6
1021
    port map(
1022
      ID_RX_i => ID_INSTR0.RB,
1023
      ID_RRX_i => ID_INSTR0.RRB,
1024
      IX1_INSTR0_i => ID_INSTR_q(0),
1025
      IX2_INSTR0_i => IX1_INSTR0_q,
1026
      IX3_INSTR0_i => IX2_INSTR0_q,
1027
      IX1_INSTR1_i => ID_INSTR_q(1),
1028
      IX2_INSTR1_i => IX1_INSTR1_q,
1029
      IX3_INSTR1_i => IX2_INSTR1_q,
1030
      IX1_PA_RES0_i => IX1_PA0_RES,
1031
      IX1_PA_RES1_i => IX1_PA1_RES,
1032
      IX2_PA_RES0_i => IX2_PA0_RES,
1033
      IX2_PA_RES1_i => IX2_PA1_RES,
1034
      IX3_PA_RES0_i => IX3_DRD0,
1035
      IX3_PA_RES1_i => IX3_DRD1,
1036
      ID_OPX_NOFWD_i => to_signed(WB_RDB0), --ID_OPB0_NOFWD,
1037
      IX1_V_i => ID_V_q,
1038
      IX2_V_i => IX1_V_q,
1039
      IX3_V_i => IX2_V_q,
1040
      IX1_FWDE_i => ID_FWDE_q,
1041
      IX2_FWDE_i => IX1_FWDE_q,
1042
      IX3_FWDE_i => IX2_FWDE_q,
1043
      NOREGS_i => IF_OPB_IMM_q(0),
1044
      NOREGD_i => IF_OPB_q(0),
1045
 
1046
      ID_OPX_o => ID_OPB0
1047
    );
1048
 
1049
  -- Instruction #1 Operand B forward logic
1050
 
1051
  U_FWDLOGB1 : G729A_ASIP_FWDLOG_2W_P6
1052
    port map(
1053
      ID_RX_i => ID_INSTR1.RB,
1054
      ID_RRX_i => ID_INSTR1.RRB,
1055
      IX1_INSTR0_i => ID_INSTR_q(0),
1056
      IX2_INSTR0_i => IX1_INSTR0_q,
1057
      IX3_INSTR0_i => IX2_INSTR0_q,
1058
      IX1_INSTR1_i => ID_INSTR_q(1),
1059
      IX2_INSTR1_i => IX1_INSTR1_q,
1060
      IX3_INSTR1_i => IX2_INSTR1_q,
1061
      IX1_PA_RES0_i => IX1_PA0_RES,
1062
      IX1_PA_RES1_i => IX1_PA1_RES,
1063
      IX2_PA_RES0_i => IX2_PA0_RES,
1064
      IX2_PA_RES1_i => IX2_PA1_RES,
1065
      IX3_PA_RES0_i => IX3_DRD0,
1066
      IX3_PA_RES1_i => IX3_DRD1,
1067
      ID_OPX_NOFWD_i => to_signed(WB_RDB1), --ID_OPB1_NOFWD,
1068
      IX1_V_i => ID_V_q,
1069
      IX2_V_i => IX1_V_q,
1070
      IX3_V_i => IX2_V_q,
1071
      IX1_FWDE_i => ID_FWDE_q,
1072
      IX2_FWDE_i => IX1_FWDE_q,
1073
      IX3_FWDE_i => IX2_FWDE_q,
1074
      NOREGS_i => IF_OPB_IMM_q(1),
1075
      NOREGD_i => IF_OPB_q(1),
1076
 
1077
      ID_OPX_o => ID_OPB1
1078
    );
1079
  -- Pipeline-A (dedicated) pre-decoder
1080
 
1081
  U_PADEC0 : G729A_ASIP_PIPE_A_DEC_2W
1082
    port map(
1083
      INSTR_i => ID_INSTR0,
1084
 
1085
      FWDE_o => ID_FWDE(0),
1086
      SEL_o => ID_PASEL0
1087
    );
1088
 
1089
  U_PADEC1 : G729A_ASIP_PIPE_A_DEC_2W
1090
    port map(
1091
      INSTR_i => ID_INSTR1,
1092
 
1093
      FWDE_o => ID_FWDE(1),
1094
      SEL_o => ID_PASEL1
1095
    );
1096
 
1097
  -- Pipeline Registers
1098
 
1099
  process(CLK_i)
1100
  begin
1101
    if(CLK_i = '1' and CLK_i'event) then
1102
      if(RST_i = '1') then
1103
        ID_V_q <= "00";
1104
      else
1105
        ID_V_q(0) <= ID_V(0) and not(ID_HALT0);
1106
        ID_V_q(1) <= ID_V(1) and not(ID_HALT);
1107
      end if;
1108
      ID_PC_q <= IF_PC_q2(2-1 downto 0);
1109
      ID_INSTR_q(0) <= ID_INSTR0;
1110
      ID_INSTR_q(1) <= ID_INSTR1;
1111
      ID_OPA0_q <= ID_OPA0;
1112
      ID_OPB0_q <= ID_OPB0;
1113
      ID_OPA1_q <= ID_OPA1;
1114
      ID_OPB1_q <= ID_OPB1;
1115
      ID_OPC0_q <= ID_OPC0;
1116
      --ID_OPC1_q <= ID_OPC1;
1117
      ID_FWDE_q <= ID_FWDE;
1118
      ID_PASEL0_q <= ID_PASEL0;
1119
      ID_PASEL1_q <= ID_PASEL1;
1120
 
1121
      ID_PCP1_q <= (IF_PC_q2(1) + 1,IF_PC_q2(0) + 1);
1122
 
1123
    end if;
1124
  end process;
1125
 
1126
  ----------------------------------------------------
1127
  -- IX1 Stage
1128
  ----------------------------------------------------
1129
 
1130
  -- Pipeline-A
1131
 
1132
  U_PIPEA0 : G729A_ASIP_PIPE_A_2W
1133
    port map(
1134
      CLK_i => CLK_i,
1135
      SEL_i => ID_PASEL0_q,
1136
      OPA_i => ID_OPA0_q(SDLEN-1 downto 0),
1137
      OPB_i => ID_OPB0_q(SDLEN-1 downto 0),
1138
      ACC_i => WB_ACC_q,
1139
      LDAT_i => DDAT0_i,
1140
 
1141
      RES_1C_o => IX1_PA0_RES,
1142
      RES_o => IX2_PA0_RES,
1143
      ACC_o => open, --IX2_PA0_ACC,
1144
      OVF_o => IX2_PA0_OVF
1145
    );
1146
 
1147
  U_PIPEA1 : G729A_ASIP_PIPE_A_2W
1148
    port map(
1149
      CLK_i => CLK_i,
1150
      SEL_i => ID_PASEL1_q,
1151
      OPA_i => ID_OPA1_q(SDLEN-1 downto 0),
1152
      OPB_i => ID_OPB1_q(SDLEN-1 downto 0),
1153
      ACC_i => WB_ACC_q,
1154
      LDAT_i => DDAT1_i,
1155
 
1156
      RES_1C_o => IX1_PA1_RES,
1157
      RES_o => IX2_PA1_RES,
1158
      ACC_o => open, --IX2_PA1_ACC,
1159
      OVF_o => IX2_PA1_OVF
1160
    );
1161
 
1162
  U_PIPEB : G729A_ASIP_PIPE_B
1163
    port map(
1164
      CLK_i => CLK_i,
1165
      OP_i => ID_INSTR_q(0).ALU_OP,
1166
      OPA_i => ID_OPA0_q,
1167
      OPB_i => ID_OPB0_q,
1168
      OVF_i => WB_OVF_q,
1169
      ACC_i => WB_ACC_q,
1170
 
1171
      RES_o => IX2_PB0_RES,
1172
      OVF_o => IX2_PB0_OVF
1173
    );
1174
 
1175
  -- Pipe-A/B result selection
1176
 
1177
  IX2_DRD0 <= IX2_PA0_RES when IX1_FWDE_q(0) = '1' else IX2_PB0_RES;
1178
  IX2_OVF0 <= IX2_PA0_OVF when IX1_FWDE_q(0) = '1' else IX2_PB0_OVF;
1179
 
1180
  IX2_DRD1 <= IX2_PA1_RES;
1181
  IX2_OVF1 <= IX2_PA1_OVF;
1182
 
1183
  -- Branch/Jump processing logic (pipe #0)
1184
 
1185
  -- Note: loop count setting instructions (LLCR*) are handled
1186
  -- like un-conditional jumps to the following instruction.
1187
  -- This is needed because LLCR* are processed in IX1 stage
1188
  -- when some instruction affecting loop count may have been
1189
  -- already fetched and improperly processed by loop stack
1190
  -- logic.
1191
  -- Loop last instruction is treated in the following way,
1192
  -- to nullify any loop instruction which may be have been
1193
  -- fetched incorrectly.
1194
 
1195
  IX1_PCLN <= IX1_LLCR or IX1_LEND;
1196
 
1197
  U_BJXLOG : G729A_ASIP_BJXLOG
1198
    port map(
1199
      CLK_i => CLK_i,
1200
      RST_i => RST_i,
1201
      BJ_OP => ID_INSTR_q(0).BJ_OP,
1202
      PC0P1_i => ID_PCP1_q(0),
1203
      PC1P1_i => ID_PCP1_q(1),
1204
      PC0_i => ID_PC_q(0),
1205
      PCSEL_i => IX1_LEIS,
1206
      OPA_i => ID_OPA0_q,
1207
      OPB_i => ID_OPB0_q,
1208
      OPC_i => ID_OPC0_q,
1209
      IV_i => ID_V_q(0),
1210
      LLCRX_i => IX1_PCLN,
1211
      FSTLL_i => ID_PSTALL,
1212
 
1213
      BJX_o => IX1_BJX,
1214
      BJTA_o => IX1_BJTA
1215
    );
1216
 
1217
  IX1_V(0) <= ID_V_q(0);
1218
 
1219
  -- Instr. #1 must be invalidated when:
1220
  -- 1) instr. #0 is a regular branch/jump, OR
1221
  -- 2) instr. #0 is a loop closing instruction.
1222
  --
1223
  -- Both cases trigger IV1_BJX and therefore are distinguished
1224
  -- by checking loop-end instruction selector IX1_LEIS).
1225
 
1226
  IX1_V(1) <= '0' when (
1227
    (IX1_BJX = '1') and not(IX1_LEIS = '1')
1228
  ) else ID_V_q(1);
1229
 
1230
  -- Load/Store logic
1231
 
1232
  U_LSU0 : G729A_ASIP_LSU
1233
    port map(
1234
      IV_i => ID_V_q(0),
1235
      LS_OP_i => ID_INSTR_q(0).LS_OP,
1236
      OPA_i => ID_OPA0_q,
1237
      OPB_i => ID_OPB0_q,
1238
      OPC_i => ID_OPC0_q,
1239
 
1240
      DRE_o => DRE_o(0),
1241
      DWE_o => IX1_DWE,
1242
      DADR_o => IX1_DADR,
1243
      DDAT_o => IX1_DDATO
1244
    );
1245
 
1246
  DWE0_o <= IX1_DWE;
1247
  DADR0_o <= IX1_DADR;
1248
  DDAT0_o <= IX1_DDATO;
1249
 
1250
  U_LU1 : G729A_ASIP_LU
1251
    port map(
1252
      IV_i => ID_V_q(1),
1253
      LS_OP_i => ID_INSTR_q(1).LS_OP,
1254
      OPA_i => ID_OPA1_q,
1255
      OPB_i => ID_OPB1_q,
1256
 
1257
      DRE_o => DRE_o(1),
1258
      DADR_o => DADR1_o
1259
    );
1260
 
1261
  ----------------------------------------------------
1262
  -- Store Checker
1263
  ----------------------------------------------------
1264
 
1265
  -- synthesis translate_off
1266
 
1267
  G_ST : if(SIMULATION_ONLY = '1') generate
1268
 
1269
  U_STCHK : G729A_ASIP_ST_CHECKER
1270
    generic map(
1271
      ST_FILENAME => ST_FILENAME
1272
    )
1273
    port map(
1274
      CLK_i => CLK_i,
1275
      ENB_i => CHK_ENB_i,
1276
      DWE_i => IX1_DWE,
1277
      DADR_i => IX1_DADR,
1278
      DDATO_i => IX1_DDATO
1279
    );
1280
 
1281
  end generate;
1282
 
1283
  -- synthesis translate_on
1284
 
1285
  -- Loop Stack control logic
1286
 
1287
  U_LCSTK_IX : G729A_ASIP_LCSTKLOG_IX
1288
    port map(
1289
      IX_V_i => ID_V_q(0),
1290
      IX_INSTR_i => ID_INSTR_q(0),
1291
      IX_OPA_i => ID_OPA0_q,
1292
 
1293
      SRST_o => IX1_SRST,
1294
      LLBRX_o => IX1_LLBR,
1295
      LLERX_o => IX1_LLER,
1296
      LLCRX_o => IX1_LLCR,
1297
      IMM_o => IX1_IMM
1298
    );
1299
 
1300
  -- Overflow result selection
1301
  -- 1) OVF_q or (instruction #0 OVF) or (instruction #1 OVF)
1302
  -- 2) OVF_q or (instruction #0 OVF)
1303
  -- 3) OVF_q or (instruction #1 OVF)
1304
  -- 4) (instruction #1 OVF)
1305
  -- 5) OVF_q
1306
 
1307
  -- Pipeline Registers
1308
 
1309
  process(CLK_i)
1310
  begin
1311
    if(CLK_i = '1' and CLK_i'event) then
1312
      if(RST_i = '1') then
1313
        IX1_V_q <= "00";
1314
      else
1315
        IX1_V_q <= IX1_V;
1316
      end if;
1317
      IX1_INSTR0_q <= ID_INSTR_q(0);
1318
      IX1_INSTR1_q <= ID_INSTR_q(1);
1319
      IX1_FWDE_q <= ID_FWDE_q;
1320
    end if;
1321
  end process;
1322
 
1323
  ----------------------------------------------------
1324
  -- IX3 Stage
1325
  ----------------------------------------------------
1326
 
1327
  IX2_FWDE(0) <= '1';
1328
  IX2_FWDE(1) <= IX1_FWDE_q(1);
1329
 
1330
  -- Pipeline Registers
1331
 
1332
  process(CLK_i)
1333
  begin
1334
    if(CLK_i = '1' and CLK_i'event) then
1335
      if(RST_i = '1') then
1336
        IX2_V_q <= "00";
1337
      else
1338
        IX2_V_q <= IX1_V_q;
1339
      end if;
1340
      IX2_INSTR0_q <= IX1_INSTR0_q;
1341
      IX2_INSTR1_q <= IX1_INSTR1_q;
1342
      IX2_FWDE_q <= IX2_FWDE;
1343
      IX2_DRD0_q <= IX2_DRD0;
1344
      IX2_DRD1_q <= IX2_DRD1;
1345
      IX2_OVF0_q <= IX2_OVF0;
1346
      IX2_OVF1_q <= IX2_OVF1;
1347
    end if;
1348
  end process;
1349
 
1350
  IX3_DRD0 <= IX2_DRD0_q;
1351
  IX3_DRD1 <= IX2_DRD1_q;
1352
  IX3_OVF0 <= IX2_OVF0_q;
1353
  IX3_OVF1 <= IX2_OVF1_q;
1354
 
1355
  ----------------------------------------------------
1356
  -- WB Stage
1357
  ----------------------------------------------------
1358
 
1359
  -- Register File
1360
 
1361
  WB_WE0 <= IX2_V_q(0) and IX2_INSTR0_q.WRD;
1362
  WB_WE1 <= IX2_V_q(1) and IX2_INSTR1_q.WRD;
1363
 
1364
  U_REGF : G729A_ASIP_REGFILE_16X16_2W
1365
    port map(
1366
      CLK_i => CLK_i,
1367
      RA0_i => ID_INSTR0.RA,
1368
      RA1_i => ID_INSTR0.RB,
1369
      RA2_i => ID_INSTR1.RA,
1370
      RA3_i => ID_INSTR1.RB,
1371
      WA0_i => IX2_INSTR0_q.RD,
1372
      WA1_i => IX2_INSTR1_q.RD,
1373
      LR0_i => ID_INSTR0.LA,
1374
      LR1_i => ID_INSTR0.LB,
1375
      LR2_i => ID_INSTR1.LA,
1376
      LR3_i => ID_INSTR1.LB,
1377
      LW0_i => IX2_INSTR0_q.LD,
1378
      LW1_i => IX2_INSTR1_q.LD,
1379
      WE0_i => WB_WE0,
1380
      WE1_i => WB_WE1,
1381
      D0_i => to_std_logic_vector(IX3_DRD0),
1382
      D1_i => to_std_logic_vector(IX3_DRD1),
1383
 
1384
      Q0_o => WB_RDA0,
1385
      Q1_o => WB_RDB0,
1386
      Q2_o => WB_RDA1,
1387
      Q3_o => WB_RDB1
1388
    );
1389
 
1390
  -- Overflow register
1391
 
1392
  -- It's allowed to execute in parallel two instructions
1393
  -- writing overflow register.
1394
 
1395
  process(CLK_i)
1396
  begin
1397
    if(CLK_i = '1' and CLK_i'event) then
1398
      if(RST_i = '1') then
1399
        WB_OVF_q <= '0';
1400
      elsif(IX2_INSTR0_q.WOVF = '1' and IX2_INSTR0_q.WOVF = '1') then
1401
        -- both instr. #0 and #1 write OVF flag
1402
        if(IX2_INSTR0_q.IMNMC = IM_COVF) then
1403
          -- instr. #0 is covf
1404
          WB_OVF_q <= IX3_OVF1;
1405
        else
1406
          WB_OVF_q <= WB_OVF_q or IX3_OVF0 or IX3_OVF1;
1407
        end if;
1408
      elsif(IX2_INSTR0_q.WOVF = '1') then
1409
        -- only instr. #0 write OVF flag
1410
        if(IX2_INSTR0_q.IMNMC = IM_COVF) then
1411
          -- instr. #0 is covf
1412
          WB_OVF_q <= '0';
1413
        else
1414
          WB_OVF_q <= WB_OVF_q or IX3_OVF0;
1415
        end if;
1416
      elsif(IX2_INSTR1_q.WOVF = '1') then
1417
        -- only instr. #1 write OVF flag
1418
        WB_OVF_q <= WB_OVF_q or IX3_OVF1;
1419
      end if;
1420
    end if;
1421
  end process;
1422
 
1423
  -- Accumulator register
1424
 
1425
  -- WARNING: it's not possible to execute in parallel two
1426
  -- instructions writing accumulator register!
1427
 
1428
  process(CLK_i)
1429
  begin
1430
    if(CLK_i = '1' and CLK_i'event) then
1431
      if(RST_i = '1') then
1432
        WB_ACC_q <= to_signed(0,LDLEN);
1433
      elsif(IX1_V_q(0) = '1' and IX1_INSTR0_q.WACC = '1') then
1434
        WB_ACC_q <= IX2_DRD0;
1435
      elsif(IX1_V_q(1) = '1' and IX1_INSTR1_q.WACC = '1') then
1436
        WB_ACC_q <= IX2_DRD1;
1437
      end if;
1438
    end if;
1439
  end process;
1440
 
1441
  -- Parallel eXecution Enable register
1442
 
1443
  process(CLK_i)
1444
  begin
1445
    if(CLK_i = '1' and CLK_i'event) then
1446
      if(RST_i = '1') then
1447
        WB_PXE_q <= '1'; -- PXE is on at reset
1448
      elsif(IX2_V_q(0) = '1' and IX2_INSTR0_q.IMNMC = IM_PXON) then
1449
        WB_PXE_q <= '1';
1450
      elsif(
1451
        (IX2_V_q(0) = '1' and IX2_INSTR0_q.IMNMC = IM_PXOFF) or
1452
        (IX2_V_q(1) = '1' and IX2_INSTR1_q.IMNMC = IM_PXOFF)
1453
      ) then
1454
        WB_PXE_q <= '0';
1455
      end if;
1456
    end if;
1457
  end process;
1458
 
1459
  ----------------------------------------------------
1460
  -- Write-Back Checker
1461
  ----------------------------------------------------
1462
 
1463
  -- synthesis translate_off
1464
 
1465
  G_WB : if(SIMULATION_ONLY = '1') generate
1466
 
1467
  U_WBCHK : G729A_ASIP_WB_CHECKER
1468
    generic map(
1469
      WB_FILENAME => WB_FILENAME
1470
    )
1471
    port map(
1472
      CLK_i => CLK_i,
1473
      ENB_i => CHK_ENB_i,
1474
      WE0_i => WB_WE0,
1475
      WE1_i => WB_WE1,
1476
      IX_INSTR0_i => IX2_INSTR0_q,
1477
      IX_INSTR1_i => IX2_INSTR1_q,
1478
      IX_DRD0_i => IX3_DRD0,
1479
      IX_DRD1_i => IX3_DRD1
1480
    );
1481
 
1482
  end generate;
1483
 
1484
  -- synthesis translate_on
1485
 
1486
  ----------------------------------------------------
1487
  -- Statistics
1488
  ----------------------------------------------------
1489
 
1490
  G_STAT : if(SIMULATION_ONLY = '1') generate
1491
 
1492
  U_STAT : G729A_ASIP_STATS
1493
    port map(
1494
      CLK_i => CLK_i,
1495
      RST_i => RST_i,
1496
      ID_V_i => IF_V_q2,
1497
      ID_PS_i(0) => ID_PS0,
1498
      ID_PS_i(1) => ID_PS1,
1499
      ID_PXE1_i => ID_PXE1,
1500
      IX2_V_i => IX2_V_q,
1501
      STRT_i => STRT_i,
1502
      HALT_i => ID_HALT
1503
    );
1504
 
1505
  end generate;
1506
 
1507
end ARC;

powered by: WebSVN 2.1.0

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