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

Subversion Repositories m32632

[/] [m32632/] [trunk/] [rtl/] [I_PFAD.v] - Blame information for rev 23

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

Line No. Rev Author Line
1 9 ns32kum
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
//
3
// This file is part of the M32632 project
4
// http://opencores.org/project,m32632
5
//
6 23 ns32kum
//      Filename:       I_PFAD.v
7
//      Version:        2.0
8
//      History:        1.1 bug fix of 7 November 2015
9
//                              1.0 first release of 30 Mai 2015
10
//      Date:           14 August 2016
11 9 ns32kum
//
12 15 ns32kum
// Copyright (C) 2016 Udo Moeller
13 9 ns32kum
// 
14
// This source file may be used and distributed without 
15
// restriction provided that this copyright statement is not 
16
// removed from the file and that any derivative work contains 
17
// the original copyright notice and the associated disclaimer.
18
// 
19
// This source file is free software; you can redistribute it 
20
// and/or modify it under the terms of the GNU Lesser General 
21
// Public License as published by the Free Software Foundation;
22
// either version 2.1 of the License, or (at your option) any 
23
// later version. 
24
// 
25
// This source is distributed in the hope that it will be 
26
// useful, but WITHOUT ANY WARRANTY; without even the implied 
27
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
28
// PURPOSE. See the GNU Lesser General Public License for more 
29
// details. 
30
// 
31
// You should have received a copy of the GNU Lesser General 
32
// Public License along with this source; if not, download it 
33
// from http://www.opencores.org/lgpl.shtml 
34
// 
35
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
36
//
37
//      Modules contained in this file:
38
//      1. BITMASK      Mask Generator , was a ROM on falling edge in early days
39
//      2. MULFILTER    Filter for Multiplier Input Data
40
//      3. SIGNMUL              Signed Multiplier for Integer Multiplication
41
//      4. SHIFTER              Barrel Shifter for all Shift Opcodes
42
//      5. FFS_LOGIK    Logic for FFS opcode 
43
//      6. SCHALE               Enclosure for Adder/Subtractor
44
//      7. I_PFAD               The Integer Datapath
45
//
46 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
47 9 ns32kum
 
48 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
49 9 ns32kum
//
50
//      1. BITMASK      Mask Generator , was a ROM on falling edge in early days
51
//
52 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53 9 ns32kum
module BITMASK (AA, DOUT);
54
 
55
//      0    :   FFFFFFFF;      Masktype 1 , Zero from right
56
//      1    :   FFFFFFFE;
57
//      2    :   FFFFFFFC;
58
//      3    :   FFFFFFF8;
59
//      .    :   ...
60
//      32   :   00000001;      Masktype 2 , Decoder
61
//      33   :   00000002;
62
//      34   :   00000004;
63
//      35   :   00000008;
64
//      ..   :   ...
65
//      64   :   00000001;      Masktyte 3 , One from right
66
//      65   :   00000003;
67
//      66   :   00000007;
68
//      67   :   0000000F;
69
//      ..   :   ...
70
//      96   :   FFFFFFFF;      Masktype 4 , like Masktype 3 but AA-1
71
//      97   :   00000001;
72
//      98   :   00000003;
73
//      99   :   00000007;
74
//      ..   :   ...
75
 
76
        input           [6:0]    AA;
77
 
78
        output  reg     [31:0]   DOUT;
79
 
80
        reg             [7:0]    dec_bit;
81
 
82
        wire     [4:0]   code;
83
        wire                    high,low;
84
 
85
 
86
        assign code = AA[4:0] - {4'd0,&AA[6:5]};
87
 
88
        assign high = (AA[6:5] == 2'd0);
89
        assign low  =  AA[6];
90
 
91
        always @(code or high or low)
92
                case (code[2:0])
93
                  3'b000 : dec_bit = {{7{high}},1'b1         };
94
                  3'b001 : dec_bit = {{6{high}},1'b1,   low  };
95
                  3'b010 : dec_bit = {{5{high}},1'b1,{2{low}}};
96
                  3'b011 : dec_bit = {{4{high}},1'b1,{3{low}}};
97
                  3'b100 : dec_bit = {{3{high}},1'b1,{4{low}}};
98
                  3'b101 : dec_bit = {{2{high}},1'b1,{5{low}}};
99
                  3'b110 : dec_bit = {   high  ,1'b1,{6{low}}};
100
                  3'b111 : dec_bit = {          1'b1,{7{low}}};
101
                endcase
102
 
103
        always @(code or high or low or dec_bit)
104
                case (code[4:3])
105
                  2'b00 : DOUT = {{24{high}},dec_bit              };
106
                  2'b01 : DOUT = {{16{high}},dec_bit,{ 8{low}}};
107
                  2'b10 : DOUT = {{ 8{high}},dec_bit,{16{low}}};
108
                  2'b11 : DOUT = {           dec_bit,{24{low}}};
109
                endcase
110
 
111
endmodule
112
 
113 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
114 9 ns32kum
//
115
//      2. MULFILTER    Filter for Multiplier Input Data
116
//
117 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118 9 ns32kum
module MULFILTER (BWD, FLOAT, SRC1, SRC2, DEST1, DEST2);
119
 
120
        input    [1:0]   BWD;
121
        input                   FLOAT;
122
        input   [31:0]   SRC1,SRC2;
123
        output  [31:0]   DEST1,DEST2;
124
 
125
        reg             [31:0]   DEST1,DEST2;
126
 
127 23 ns32kum
        always @(FLOAT or BWD or SRC1)
128
                casex ({FLOAT,BWD})
129
                  3'b0_00 : DEST1 = {{24{SRC1[7]}}, SRC1[7:0]};
130
                  3'b0_01 : DEST1 = {{16{SRC1[15]}},SRC1[15:0]};
131
                  3'b1_xx : DEST1 = {        9'h001,SRC1[22:0]};
132
                  default : DEST1 = SRC1;
133 9 ns32kum
                endcase
134
 
135 23 ns32kum
        always @(FLOAT or BWD or SRC2)
136
                casex ({FLOAT,BWD})
137
                  3'b0_00 : DEST2 = {{24{SRC2[7]}}, SRC2[7:0]};
138
                  3'b0_01 : DEST2 = {{16{SRC2[15]}},SRC2[15:0]};
139
                  3'b1_xx : DEST2 = {            9'h001,SRC2[22:0]};
140
                  default : DEST2 = SRC2;
141 9 ns32kum
                endcase
142
 
143
endmodule
144
 
145 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
146 9 ns32kum
//
147
//      3. SIGNMUL              Signed Multiplier for Integer Multiplication
148
//
149 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
150 9 ns32kum
module SIGNMUL (dataa, datab, result);
151
 
152
        input   signed  [31:0]   dataa,datab;
153
        output  signed  [63:0]   result;
154
 
155
        assign result = dataa * datab;
156
 
157
endmodule
158
 
159 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
160 9 ns32kum
//
161
//      4. SHIFTER              Barrel Shifter for all Shift Opcodes
162
//
163 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
164 9 ns32kum
module SHIFTER ( MASKE,ROT,LSH,ASH,SIZE,SH_VAL,SH_DAT,SH_OUT,MASK_SEL);
165
 
166
        input  [31:0] MASKE;
167
        input         ROT,LSH,ASH;
168
        input   [1:0] SIZE;
169
        input   [7:0] SH_VAL;
170
        input  [31:0] SH_DAT;
171
        output [31:0] SH_OUT;
172
        output  [4:0] MASK_SEL;
173
 
174
        reg  [31:0] sh_dat_in;
175
        wire [31:0] sh_dat_0,sh_dat_1,sh_dat_2,sh_dat_3,sh_dat_4;
176
        wire  [4:0] shift;
177
        reg                 msb;
178
        wire  [1:0] mask_code;
179
        reg  [31:0] SH_OUT;
180
        reg   [4:0] MASK_SEL;
181
 
182
        // Inputstage : prepare for ROT opcode :
183
 
184
        always @(ROT or SIZE or SH_DAT)
185
          casex ({ROT,SIZE})
186
                3'b100  : sh_dat_in = {SH_DAT[31:16],SH_DAT[7:0],SH_DAT[7:0]};    // Byte copy to left
187
                3'b101  : sh_dat_in = {SH_DAT[15:0],SH_DAT[15:0]};        // Word copy to left
188
                default : sh_dat_in = SH_DAT;
189
          endcase
190
 
191
        // Special case for ROT and BYTE : this way less logic
192
 
193
        assign shift = (ROT & (SIZE == 2'b00)) ? {2'b11,SH_VAL[2:0]} : SH_VAL[4:0];
194
 
195
        // Rotation logic
196
 
197 11 ns32kum
        assign sh_dat_0 = shift[0] ? {sh_dat_in[30:0],sh_dat_in[31]} : sh_dat_in; // Rotation of 1 bit position
198 9 ns32kum
        assign sh_dat_1 = shift[1] ? {sh_dat_0[29:0],sh_dat_0[31:30]} : sh_dat_0;        // 2
199
        assign sh_dat_2 = shift[2] ? {sh_dat_1[27:0],sh_dat_1[31:28]} : sh_dat_1;        // 4
200
        assign sh_dat_3 = shift[3] ? {sh_dat_2[23:0],sh_dat_2[31:24]} : sh_dat_2;        // 8
201
        assign sh_dat_4 = shift[4] ? {sh_dat_3[15:0],sh_dat_3[31:16]} : sh_dat_3;        // 16
202
 
203
        // Detection of negativ data    
204
 
205
        always @(SIZE or SH_DAT)
206
          casex (SIZE)
207
                2'b00   : msb = SH_DAT[7];      // Byte
208
                2'b01   : msb = SH_DAT[15];     // Word
209
                default : msb = SH_DAT[31];     // Double = 11
210
          endcase
211
 
212
        // needs mask for output data : SH_VAL[7] says negativ number and "right" shift
213
 
214
        assign mask_code[1] = ROT | (SH_VAL[7] &   ASH &  msb);
215
        assign mask_code[0] = ROT | (SH_VAL[7] & ((ASH & ~msb) | LSH));
216
 
217
        always @(SH_VAL or SIZE)
218
          casex ({SH_VAL[7],SIZE})
219
                3'b100  : MASK_SEL = {2'b00,SH_VAL[2:0]};        // special mask for Byte at right-shift
220
                3'b101  : MASK_SEL = {1'b0,SH_VAL[3:0]}; // special mask for Word at right-shift
221
                default : MASK_SEL = SH_VAL[4:0];
222
          endcase
223
 
224
        always @(mask_code or sh_dat_4 or MASKE)        // top bits of MASKE are "1", lower bits are "0"
225
          casex (mask_code)
226
                  2'b00 : SH_OUT = sh_dat_4 &  MASKE;   // LSH and ASH with positiv shift count
227
                  2'b01 : SH_OUT = sh_dat_4 & ~MASKE;   // Negativ shift count : LSH or ASH with positiv data
228
                  2'b10 : SH_OUT = sh_dat_4 |  MASKE;   // ASH with negativ shift count and negativ input data
229
                default : SH_OUT = sh_dat_4;                    // ROT
230
          endcase
231
 
232
endmodule
233
 
234 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
235 9 ns32kum
//
236
//      5. FFS_LOGIK    Logic for FFS opcode 
237
//
238 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
239 9 ns32kum
module FFS_LOGIK  (SRC1, SRC2, BWD, FLAG, DOUT);
240
 
241
        input   [31:0]   SRC1;
242
        input    [4:0]   SRC2;
243
        input    [1:0]   BWD;
244
        output  reg             FLAG;
245
        output   [4:0]   DOUT;
246
 
247
        reg              [6:0]   maske;
248
        reg              [7:0]   byte_1,byte_2;
249
 
250
        wire     [7:0]   byte_0,byte_3;
251
        wire    [15:0]   mdat_0;
252
        wire     [7:0]   mdat_1;
253
        wire     [3:0]   mdat_2;
254
        wire     [4:0]   obits;
255
 
256
        always @(*)
257
                case (SRC2[2:0])
258
                  3'd0 : maske = 7'h7F;
259
                  3'd1 : maske = 7'h7E;
260
                  3'd2 : maske = 7'h7C;
261
                  3'd3 : maske = 7'h78;
262
                  3'd4 : maske = 7'h70;
263
                  3'd5 : maske = 7'h60;
264
                  3'd6 : maske = 7'h40;
265
                  3'd7 : maske = 7'h00;
266
                endcase
267
 
268
        assign byte_0 = (SRC2[4:3] == 2'b00) ? {SRC1[7],(SRC1[6:0] & maske)} : 8'h00;
269
 
270
        always @(*)
271
                casex (SRC2[4:3])
272
                  2'b00 : byte_1 = SRC1[15:8];
273
                  2'b01 : byte_1 = {SRC1[15],(SRC1[14:8] & maske)};
274
                  2'b1x : byte_1 = 8'h00;
275
                endcase
276
 
277
        always @(*)
278
                casex (SRC2[4:3])
279
                  2'b0x : byte_2 = SRC1[23:16];
280
                  2'b10 : byte_2 = {SRC1[23],(SRC1[22:16] & maske)};
281
                  2'b11 : byte_2 = 8'h00;
282
                endcase
283
 
284
        assign byte_3 = (SRC2[4:3] == 2'b11) ? {SRC1[31],(SRC1[30:24] & maske)} : SRC1[31:24];
285
 
286
        assign obits[4] = ({byte_1,byte_0} == 16'h0);
287
        assign mdat_0   = obits[4] ? {byte_3,byte_2} : {byte_1,byte_0}; // 16 Bit
288
 
289
        assign obits[3] = (mdat_0[7:0] == 8'h0);
290
        assign mdat_1   = obits[3] ? mdat_0[15:8] : mdat_0[7:0];
291
 
292
        assign obits[2] = (mdat_1[3:0] == 4'h0);
293
        assign mdat_2   = obits[2] ? mdat_1[7:4] : mdat_1[3:0];
294
 
295 23 ns32kum
        assign obits[1] =   (mdat_2[1:0] == 2'b00);
296
        assign obits[0] = ~((mdat_2[2:1] == 2'b10) | mdat_2[0]);
297 9 ns32kum
 
298 23 ns32kum
        always @(BWD or obits or mdat_2)
299 9 ns32kum
                casex ({BWD,obits[4:3]})
300
                  4'b00_x1 : FLAG = 1;  // Byte Overflow => nothing found
301
                  4'b00_10 : FLAG = 1;  // Byte Overflow => nothing found
302
                  4'b01_1x : FLAG = 1;  // Word Overflow => nothing found
303 23 ns32kum
                  default  : FLAG = (mdat_2 == 4'b0000);
304 9 ns32kum
                endcase
305
 
306
        assign DOUT = FLAG ? 5'h0 : obits;
307
 
308
endmodule
309
 
310 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
311 9 ns32kum
//
312
//      6. SCHALE               Enclosure for Adder/Subtractor
313
//
314 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
315 9 ns32kum
module SCHALE (dataa, datab, cin, add_sub, bwd, result, cout, overflow);
316
 
317
        input   [31:0]   dataa,datab;
318
        input                   cin;
319
        input                   add_sub;        // 1 = Addition , 0 = Subtraction
320
        input    [1:0]   bwd;
321
 
322
        output  [31:0]   result;
323
        output                  cout,overflow;
324
 
325
        reg              [2:0]   seldat;
326
        reg                             overflow;
327
 
328
        wire    [32:0]   summe;
329
 
330
        assign summe = {1'b0,dataa} + {1'b0,(add_sub ? datab : ~datab)} + {32'd0,cin};
331
 
332
        always @(bwd or dataa or datab or summe)
333
                case (bwd)
334
                  2'b00   : seldat = {summe[7], dataa[7], datab[7]};
335
                  2'b01   : seldat = {summe[15],dataa[15],datab[15]};
336
                  default : seldat = {summe[31],dataa[31],datab[31]};
337
                endcase
338
 
339
        always @(seldat or add_sub)
340
                case (seldat[1:0])
341
                  2'b00 : overflow = add_sub ?  seldat[2] : 1'b0;
342
                  2'b01 : overflow = add_sub ? 1'b0 :  seldat[2];
343
                  2'b10 : overflow = add_sub ? 1'b0 : ~seldat[2];
344
                  2'b11 : overflow = add_sub ? ~seldat[2] : 1'b0;
345
                endcase
346
 
347
        assign cout = add_sub ? summe[32] : ~summe[32];
348
        assign result = summe[31:0];
349
 
350
endmodule
351
 
352 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
353 9 ns32kum
//
354
//      7. I_PFAD               The Integer Datapath
355
//
356 11 ns32kum
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
357
module I_PFAD ( BCLK, BRESET, SFP_DAT, FSR, DP_OUT, SRC1, SRC2, BMASKE, ADDR, MRESULT, OPCODE, BWD, FL, SP_CMP, DP_CMP, LD_OUT,
358
                                WREN, WRADR, RDAA, DETOIP, BITSEL, OVF_BCD, DISP, RWVFLAG, DSR, I_OUT, PSR, BMCODE, OV_FLAG, ACB_ZERO, STRING);
359 9 ns32kum
 
360
        input                   BCLK,BRESET;
361
        input   [31:0]   SFP_DAT,FSR,DP_OUT;
362
        input   [31:0]   SRC1,SRC2;
363
        input   [31:0]   BMASKE;
364
        input   [31:0]   ADDR;
365
        input   [63:0]   MRESULT;
366
        input    [7:0]   OPCODE;
367
        input    [1:0]   BWD;
368
        input                   FL;
369
        input    [2:0]   SP_CMP;
370
        input    [2:0]   DP_CMP;
371
        input                   LD_OUT;
372
        input                   WREN;
373
        input    [5:0]   WRADR;
374
        input    [7:0]   RDAA;
375
        input   [11:0]   DETOIP;
376
        input    [2:0]   BITSEL;
377
        input    [3:0]   OVF_BCD;
378
        input    [4:0]   DISP;
379
        input                   RWVFLAG;
380
        input    [3:0]   DSR;
381
 
382
        output  [31:0]   I_OUT;
383
        output  [11:0]   PSR;
384
        output   [6:0]   BMCODE; // ROM Address for BITMASK
385
        output  reg             OV_FLAG;
386
        output                  ACB_ZERO;
387
        output   [4:0]   STRING;
388
 
389
        reg             [31:0]   I_OUT;
390
        reg             [31:0]   pfad_7,pfad_6,pfad_8,pfad_4a;
391
        wire    [31:0]   pfad_4,pfad_5,pfad_11;
392
 
393
        reg             [31:0]   bwd_daten1,bwd_daten2;
394
        wire    [31:0]   addsub_q;
395
 
396
        // +++++++++++++  Global Output Multiplexer  ++++++++++++++++++++++++++++
397
 
398 11 ns32kum
        always @(OPCODE or pfad_4 or pfad_5 or pfad_6 or pfad_7 or pfad_8 or DP_OUT or FL or SFP_DAT or FSR or pfad_11)
399 9 ns32kum
                casex (OPCODE[7:3])
400
                  5'b0100_x : I_OUT = pfad_4;
401
                  5'b0101_x : I_OUT = pfad_5;   // String opcodes
402
                  5'b0110_x : I_OUT = pfad_6;
403
                  5'b0111_x : I_OUT = pfad_7;
404
                  5'b1000_x : I_OUT = pfad_8;
405
                  5'b1001_0 : I_OUT = DP_OUT;   // SP_FPU has higher priority ! LFSR has no output
406
                  // SFSR : ROUND,TRUNC,FLOOR Integer Data : SP or DP Block
407
                  5'b1001_1 : I_OUT = (OPCODE[2:1] == 2'b10) ? FSR : (FL ? SFP_DAT : DP_OUT);
408
                  5'b1011_x : I_OUT = pfad_11;
409
                  5'b1101_x : I_OUT = DP_OUT;   // Coprocessor
410
                  default       : I_OUT = 32'hxxxx_xxxx;        // don't care
411
                endcase
412
 
413
        // ++++++++++++++ PSR Register :         I  P S U / N Z F V - L T C
414
        //                                                                      11 10 9 8   7 6 5 4 3 2 1 0
415
 
416
        reg              [3:0]   psr_high;
417
        reg              [7:0]   psr_low,psr_new;
418
        reg             [11:0]   push_psr;       // true Register
419
        reg             [11:0]   calc_psr;       // only verilog case
420
        reg              [1:0]   nl_int;
421
 
422
        wire                    ld_psr_l,ld_psr_h,up_psr;
423
        wire                    cmp_op,bit_op,ari_op,neg_op,ffs_op,str_op,chk_op,abs_op,rwv_op;
424
        wire     [1:0]   fp_nz;
425
        wire                    f_flag,z_flag;
426
        wire     [1:0]   nl_flags;
427
        wire                    over_flow,cy_out;
428
        wire                    ffs_flag;       // FLAG result of FFS
429
        wire                    chk_flag;       // FLAG result of CHECK
430
        wire                    save_psr,pop_psr;
431
        wire     [4:0]   selbits;
432
        // Bits from DETOIP;
433 11 ns32kum
        wire                    cmps_op,ph_match,until,kill_opt,inss_op,exin_cmd,extract,bit_reg,kurz_st,dw_info,acb_reg,t2p;
434 9 ns32kum
        wire                    bcd_op,bcd_carry;
435
 
436
        assign cmps_op  = DETOIP[11];   // for CMPS
437
        assign ph_match = DETOIP[10];   // MATCH phase
438
        assign until    = DETOIP[9];    // UNITL Flag for String
439
        assign kill_opt = DETOIP[8];    // optimized execution of MOVS/MOVM
440
        assign inss_op  = DETOIP[7];    // 1=INSS
441
        assign exin_cmd = DETOIP[6];    // for EXT/INS
442
        assign extract  = DETOIP[5] & exin_cmd; // 1=EXT
443
        assign bit_reg  = DETOIP[4];    // for Bit opcodes
444
        assign kurz_st  = DETOIP[3];    // for MOVM/CMPM
445
        assign dw_info  = DETOIP[2];    // at ADJSPi is SP=SRC2 always 32 Bit
446
        assign acb_reg  = DETOIP[1];    // suppresses Carry-Set at ACB
447
        assign t2p          = DETOIP[0]; // Pulse to Load Trace-Bit to Pending-Trace-Bit
448
 
449
        assign bcd_op    = OVF_BCD[1];  // ADDPi,SUBPi - from DP_FPU
450
        assign bcd_carry = OVF_BCD[0];
451
 
452
        assign ld_psr_l = ((WRADR == 6'h1D) | (WRADR == 6'h10)) & WREN; // Register PSR & UPSR
453
        assign ld_psr_h =  (WRADR == 6'h1D) & (BWD != 2'b00) & WREN;    // Register PSR
454
        // LD_OUT[1] is coming out of DECODER for this purpose
455
        assign up_psr = bcd_op | ((cmp_op | bit_op | ari_op | neg_op | ffs_op | chk_op) & LD_OUT);
456
 
457 11 ns32kum
        assign cmp_op = (OPCODE == 8'h41) | ((OPCODE == 8'hB2) & (FL ? ~SP_CMP[2] : ~DP_CMP[2]));       // CMPi or (CMPf & ~NAN)
458
        assign bit_op =   ((OPCODE[7:4] == 4'h6) & ((~OPCODE[3] & OPCODE[1]) | OPCODE[3:0] == 4'hE))     // the last term is for IBIT
459 9 ns32kum
                                        | (OPCODE == 8'h4D) | str_op | rwv_op;  // TBIT or CMPS or RDVAL/WRVAL
460 11 ns32kum
        assign ari_op = (OPCODE[7:4] == 4'h4) & (OPCODE[1:0] == 2'b0) & ~dw_info;        // ADDi,ADDCi,SUBi,SUBCi - special case ADJSPi no flags
461 9 ns32kum
        assign neg_op = (OPCODE[7:4] == 4'h6) & (OPCODE[3] & (OPCODE[1:0] == 2'b0));     // ABSi,NEGi  
462
        assign ffs_op = (OPCODE          == 8'h85);     // FFS
463
        assign chk_op = (OPCODE          == 8'h83);     // CHECK
464 11 ns32kum
        assign str_op = (OPCODE[7:4] == 4'h5) & (OPCODE[3:2] == 2'b0) & ~kurz_st;       // String-"S" opcodes : F-Flag to 0, at start always
465 9 ns32kum
        assign abs_op = (OPCODE          == 8'h6C);     // ABSi : Carry is not affected !
466
        assign rwv_op = (OPCODE[7:4] == 4'hE) & (OPCODE[3:1] == 3'b0);  // RDVAL + WRVAL
467
 
468
        always @(bwd_daten1 or bwd_daten2 or addsub_q)  // SRC1 > SRC2 ?
469
                case ({bwd_daten2[31],bwd_daten1[31]})
470
                  2'b00 : nl_int = {addsub_q[31],addsub_q[31]}; // MSB = N , LSB = L
471
                  2'b01 : nl_int = {   1'b0     ,    1'b1    };
472
                  2'b10 : nl_int = {   1'b1     ,    1'b0    };
473
                  2'b11 : nl_int = {addsub_q[31],addsub_q[31]};
474
                endcase
475
 
476
        assign ACB_ZERO = (addsub_q == 32'h0);  // is used for ACBi opcode too
477 11 ns32kum
        assign f_flag = str_op ? 1'b0 : (rwv_op ? RWVFLAG : (bit_op ? SRC2[selbits] : (acb_reg ? PSR[5] : over_flow)));
478 9 ns32kum
        assign fp_nz  = FL ? SP_CMP[1:0] : DP_CMP[1:0];
479
        assign z_flag =   OPCODE[1] ?  fp_nz[0] : ACB_ZERO;
480
        assign nl_flags = OPCODE[1] ? {fp_nz[1],1'b0} : nl_int;
481
 
482
        always @(*)     // Bits : N Z F V - L T C
483
                casex ({cmp_op,bcd_op,bit_op,(ffs_op | chk_op)})
484 11 ns32kum
                  4'b0000 : psr_new = {PSR[7:6],          f_flag,PSR[4:1],((acb_reg | abs_op) ? PSR[0] : cy_out)};       // arithmetic Op : CY and F
485 9 ns32kum
                  4'b0001 : psr_new = {PSR[7:6],(ffs_op ? ffs_flag : chk_flag),PSR[4:0]};                // FFS or CHECK
486
                  4'b001x : psr_new = (cmps_op & str_op) ?
487
                                                          {2'b01,             f_flag,PSR[4:3],1'b0,PSR[1:0]}             // Init CMPS
488
                                                        : {PSR[7:6],          f_flag,PSR[4:0]};                                          // Bit opcode
489
                  4'b01xx : psr_new = {PSR[7:6],          1'b0,  PSR[4:1],bcd_carry};                   // BCD opcode
490
                  4'b1xxx : psr_new = ph_match ?
491
                                                          {PSR[7:6], ~(ACB_ZERO ^ until), PSR[4:0]}                                      // Until/While Option at String-"S" opcodes
492
                                                        : {nl_flags[1],z_flag,PSR[5:3],   nl_flags[0],PSR[1:0]};  // CMP f or i
493
                endcase
494
 
495
        always @(save_psr or pop_psr or OPCODE or PSR or SRC1)
496
                casex ({save_psr,pop_psr,OPCODE[6],OPCODE[2]})
497 11 ns32kum
                  4'b10xx : calc_psr = PSR & {~OPCODE[0],11'h0ED};       // clear P S U V T and the I-Bit at Interrupt & ABORT
498 9 ns32kum
                  4'b11xx : calc_psr = SRC1[27:16];
499
                  4'b0x00 : calc_psr = PSR & ~SRC1[11:0];        // BICPSR : Opcode = h32
500
                  4'b0x01 : calc_psr = PSR |  SRC1[11:0];        // BISPSR                        h36
501
                  default : calc_psr = SRC1[11:0];                       // LPR PSR                       h76
502
                endcase
503
 
504
        // Special case Exception Handling : Code x'89-x'8F
505
        assign save_psr = (OPCODE[7:3] == 5'b1000_1);
506
        assign pop_psr  = (OPCODE[2:0] == 3'b000);
507
 
508
        always @(posedge BCLK or negedge BRESET)        // central memory for PSR low
509
                if (!BRESET) psr_low <= 8'h0;
510
                  else
511
                  begin
512
                        if (ld_psr_l || save_psr) psr_low <= calc_psr[7:0];
513
                          else
514
                                if (up_psr) psr_low <= psr_new; // the Status result of a normal opcode
515
                  end
516
 
517
        always @(posedge BCLK or negedge BRESET)        // central memory for PSR high
518
                if (!BRESET) psr_high <= 4'h0;
519
                  else
520
                  begin
521
                        if (ld_psr_h || save_psr)  psr_high <= calc_psr[11:8];  // only at WORD access
522
                          else  // t2p : copy T-Bit into P-Bit at the beginning of opcode
523
                                if (t2p) psr_high <= {psr_high[3],psr_low[1],psr_high[1:0]};
524
                  end
525
 
526
        // Register for storage of PSR at Entry of Exception
527 11 ns32kum
        always @(posedge BCLK) if (save_psr) push_psr <= {PSR[11],(~OPCODE[1] & PSR[10]),PSR[9:0]};      // P-Flag modified
528 9 ns32kum
 
529
        assign PSR = {psr_high,psr_low};
530
 
531
        // ++++++++++++++  Overflow Detection  ++++++++++++++++++++++++++++++++++++++
532
 
533
        reg                             ovf_mul,ovf_ash;
534
        wire    [31:0]   shdat;
535
 
536
        always @(posedge BCLK or negedge BRESET)
537
                if (!BRESET) OV_FLAG <= 1'b0;
538
                  else
539
                        if (OVF_BCD[3]) OV_FLAG <= OVF_BCD[2];  // DEI,QUO,DIV
540
                          else
541
                                if (LD_OUT)
542
                                  case (OPCODE)
543
                                         8'h78 : OV_FLAG <= ovf_mul;
544
                                         8'h61 : OV_FLAG <= ovf_ash;
545
                                         8'h40 : OV_FLAG <= over_flow & acb_reg;        // ADD Opcode at ACB
546
                                   default : OV_FLAG <= 1'b0;
547
                                  endcase
548
 
549
        always @(BWD or MRESULT)
550
                casex (BWD)
551
                        2'b00 : ovf_mul = ~((MRESULT[15:7]  ==  9'd0) | (MRESULT[15:7]  ==  9'h1FF));
552
                        2'b01 : ovf_mul = ~((MRESULT[31:15] == 17'd0) | (MRESULT[31:15] == 17'h1FFFF));
553
                  default : ovf_mul = ~((MRESULT[63:31] == 33'd0) | (MRESULT[63:31] == 33'h1FFFFFFFF));
554
                endcase
555
 
556
        always @(BWD or SRC2 or shdat)
557
                casex (BWD)
558
                        2'b00 : ovf_ash = (SRC2[7]  != shdat[7]);
559
                        2'b01 : ovf_ash = (SRC2[15] != shdat[15]);
560
                  default : ovf_ash = (SRC2[31] != shdat[31]);
561
                endcase
562
 
563
        // ++++++++++++++ Format 4 Opcodes : Basic Integer Opcodes, MOVi is special case  +++++++++++++
564
 
565
        reg                             cy_in;
566 15 ns32kum
        reg                             get_psr,rd_psr,rd_dsr,get_mod;
567 9 ns32kum
        wire                    add_flag;
568
 
569
        always @(BWD or SRC1)
570
                casex (BWD)
571
                        2'b00 : bwd_daten1 = {{24{SRC1[7]}}, SRC1[7:0]}; // Sign Extension
572
                        2'b01 : bwd_daten1 = {{16{SRC1[15]}},SRC1[15:0]};
573
                  default : bwd_daten1 = SRC1;
574
                endcase
575
 
576 11 ns32kum
        assign add_flag = ~OPCODE[3] & ~OPCODE[1] & ~OPCODE[0];  // Only ADDi and ADDCi otherwise subtract in SCHALE
577 9 ns32kum
 
578
        always @(PSR or OPCODE) // more effort due to ABSi und NEGi : Format 6
579
                casex ({OPCODE[5],OPCODE[3:2]})
580
                   3'b000 : cy_in = OPCODE[0];   // ADD + CMP
581
                   3'b001 : cy_in =  PSR[0];     // ADDC
582
                   3'b011 : cy_in = ~PSR[0];     // SUBC
583
                  default : cy_in = 1'b1;               // SUB + ABS + NEG : BORROW must be 1 for normal Adder 
584
                endcase
585
 
586 11 ns32kum
        SCHALE     addsub_ipfad  (.dataa(bwd_daten2), .datab(bwd_daten1), .cin(cy_in), .add_sub(add_flag), .bwd(BWD),
587 9 ns32kum
                                                          .result(addsub_q), .cout(cy_out), .overflow(over_flow) );
588
 
589 11 ns32kum
        always @(posedge BCLK) get_psr <= (RDAA == 8'h9D) | (RDAA == 8'h90) | (RDAA == 8'h93);  // PSR or US or DSR is read
590 9 ns32kum
        always @(posedge BCLK) rd_psr  <= (RDAA[1:0] == 2'b01);
591
        always @(posedge BCLK) rd_dsr  <= (RDAA[1:0] == 2'b11);
592 15 ns32kum
        always @(posedge BCLK) get_mod <= (RDAA == 8'h9F);
593 9 ns32kum
 
594 15 ns32kum
        always @(OPCODE or SRC1 or SRC2 or get_psr or rd_psr or rd_dsr or get_mod or DSR or PSR or ADDR)
595 9 ns32kum
                casex (OPCODE[3:1])
596
                   3'b001 : pfad_4a = SRC2 & ~SRC1;     // BIC
597 15 ns32kum
                   3'bx10 : pfad_4a = get_psr ? {({4{rd_dsr}} & DSR),16'd0,({4{rd_psr}} & PSR[11:8]),({8{~rd_dsr}} & PSR[7:0])}  // MOV
598
                                                                          : (get_mod ? {16'd0,SRC1[15:0]} : SRC1);
599 9 ns32kum
                   3'b011 : pfad_4a = SRC2 |  SRC1;     // OR
600
                   3'b101 : pfad_4a = SRC2 &  SRC1;     // AND
601
                   3'b111 : pfad_4a = SRC2 ^  SRC1;     // XOR
602
                  default : pfad_4a = ADDR;                     // ADDR, comes from ADDR_UNIT
603
                endcase
604
 
605
        assign pfad_4 = (OPCODE[1:0] == 2'b00) ? addsub_q : pfad_4a;     // ADD,ADDC,SUB,SUBC have extra path
606
 
607
        // ++++++++++++++ Format 5 Opcodes : Strings MOVS , CMPS und SKPS  +++++++++++++++++++++++++++++++
608
 
609
        reg             [11:0]   spointer,dpointer;
610
        reg              [9:0]   todo;
611
        reg              [9:4]  todo_reg;
612 13 ns32kum
        reg                             dis_opt;
613
        wire    [31:0]   diff_poi;
614 9 ns32kum
        wire                    mehr,weiter,op_str,no_opt;
615
 
616
        assign op_str = (OPCODE[7:3] == 5'b0101_0);
617
 
618 13 ns32kum
        assign diff_poi = SRC2 - SRC1;  // Special Case
619
 
620
        always @(posedge BCLK) if (op_str && OPCODE[2]) dis_opt <= (diff_poi[31:3] == 29'd0);
621
 
622 11 ns32kum
        // This logic is for detection if an accelerated MOVS/MOVM inside a page is possible - Backward is not possible
623 9 ns32kum
        always @(posedge BCLK)
624
                if (op_str)
625
                        begin
626
                                spointer <= OPCODE[2] ? SRC1[11:0] : (spointer + {8'h00,todo[3:0]});      // Source
627
                                dpointer <= OPCODE[2] ? SRC2[11:0] : (dpointer + {8'h00,todo[3:0]});      // Destination
628
                        end
629
 
630
        assign no_opt = OPCODE[1] | ((spointer[11:3] == 9'h1FF) & (spointer[2:0] != 3'b000))
631 13 ns32kum
                                   | kill_opt | ((dpointer[11:3] == 9'h1FF) & (dpointer[2:0] != 3'b000))
632
                                   | dis_opt;
633 9 ns32kum
 
634 13 ns32kum
        assign pfad_5 = SRC1 - {28'h0,todo_reg[7:4]};
635 9 ns32kum
 
636
        assign mehr = (pfad_5[31:4] != 28'h0);
637
 
638
        always @(no_opt or BWD or mehr or pfad_5)
639
                casex ({no_opt,BWD,mehr,pfad_5[3:0]})
640
                  8'b000_1xxxx : todo = 10'h388; // Byte
641
                  8'b000_01xxx : todo = 10'h388;
642
                  8'b000_001xx : todo = 10'h244;
643
                  8'b000_0001x : todo = 10'h122;
644
                  8'b000_00001 : todo = 10'h011;
645
                //
646
                  8'b001_1xxxx : todo = 10'h348; // Word
647
                  8'b001_01xxx : todo = 10'h348;
648
                  8'b001_001xx : todo = 10'h348;
649
                  8'b001_0001x : todo = 10'h224;
650
                  8'b001_00001 : todo = 10'h112;
651
                //
652
                  8'b01x_1xxxx : todo = 10'h328; // DWord
653
                  8'b01x_01xxx : todo = 10'h328;
654
                  8'b01x_001xx : todo = 10'h328;
655
                  8'b01x_0001x : todo = 10'h328;
656
                  8'b01x_00001 : todo = 10'h214;
657
                //
658
                  8'b100_xxxxx : todo = 10'h011; // the opcodes CMPS and SKPS work on a single element
659
                  8'b101_xxxxx : todo = 10'h112;
660
                  8'b11x_xxxxx : todo = 10'h214;
661
                  default          : todo = 10'hxxx;
662
                endcase
663
 
664 13 ns32kum
        always @(posedge BCLK) if (op_str) todo_reg <= {todo[9:8],(OPCODE[2] ? 4'd0 : todo[7:4])};      // store for next phase 51
665 9 ns32kum
 
666
        assign weiter = mehr | (pfad_5[3:0] != 4'h0);
667
 
668 11 ns32kum
        assign STRING = {1'b0,ACB_ZERO,weiter,( op_str ? todo[9:8] : todo_reg[9:8] )};  // ACB_ZERO is delayed 1 cycle extern
669 9 ns32kum
 
670
        // +++++++++++++  Format 6 opcodes : ADDP + SUBP are done in DP_FPU  ++++++++++++++++++++
671
 
672
        wire                    rot,ash,lsh,eis_op;
673
        wire     [7:0]   sh_count;
674
        wire     [4:0]   shcode;         // comes from SHIFTER
675
 
676
        reg              [4:0]   disp_reg;       // for EXT/INS
677
        reg              [2:0]   offs_reg;       // for INSS
678
        wire                    exin_op,exin_op2;
679
        wire     [4:0]   shval_ei;
680
        wire     [7:0]   sh_exin;
681
 
682
        assign rot = (OPCODE[3:0] == 4'h0);
683
        assign ash = (OPCODE[3:0] == 4'h1);
684 11 ns32kum
        assign lsh = (OPCODE[3:1] == 3'b010);   // 5 is LSH , but 4 is Trap(UND) and is used for right-shift of Offset !
685 9 ns32kum
 
686 11 ns32kum
        assign eis_op = (OPCODE == 8'h73) | (OPCODE[7] & ~OPCODE[1] & inss_op); // EXTSi | INSSi at OPCODE=80h
687 9 ns32kum
        assign exin_op  = exin_cmd & (OPCODE[7:4] == 4'h8);                             // identifies EXT/INS
688
        assign exin_op2 = (exin_cmd | inss_op) & (OPCODE[7:4] == 4'h6); // identifies LSH
689
 
690
        always @(posedge BCLK) disp_reg <= DISP;        // at EXT the path via ADDR is already used for DEST !!!
691
        always @(posedge BCLK) if (OPCODE[7]) offs_reg <= SRC1[7:5];    // for INSS , OPCODE=80h
692
 
693
        // Byte for external Bit source, Double for Register
694
        assign selbits = (bit_reg | eis_op | exin_op) ? (exin_op ? disp_reg : SRC1[4:0]) : {2'b00,BITSEL};
695
 
696
        assign shval_ei = inss_op ? {2'b00,offs_reg} : (bit_reg ? SRC1[4:0] : {2'b00,SRC1[2:0]});
697 23 ns32kum
        assign sh_exin[4:0] = ({5{extract}} ^ shval_ei) + {4'd0,extract};        // EXT : right shift, INS : left shift
698 11 ns32kum
        assign sh_exin[7:5] = (shval_ei == 5'd0) ? 3'b000 : {3{extract}};       // Special case : 0 has no negativ sign !
699 9 ns32kum
 
700
        // LSH shift by 16 bit to right
701
        assign sh_count = (OPCODE[3:0] == 4'h4) ? 8'hF0 : (exin_op2 ? sh_exin : SRC1[7:0]);
702
 
703 11 ns32kum
        assign BMCODE = (bit_op | eis_op | exin_op) ? {(eis_op | exin_op),(bit_op | exin_op),selbits} : {2'b00,shcode};
704 9 ns32kum
 
705 11 ns32kum
        SHIFTER  shift_inst (.MASKE(BMASKE), .ROT(rot), .ASH(ash), .LSH(lsh), .SH_DAT(SRC2), .SH_VAL(sh_count),
706 9 ns32kum
                                                 .MASK_SEL(shcode), .SIZE(BWD), .SH_OUT(shdat) );
707
 
708
        always @(BWD or SRC2 or neg_op or dw_info)
709
                casex ({neg_op,(dw_info | BWD[1]),BWD[0]})                               // special case ADJSPi
710
                   3'b000 : bwd_daten2 = {{24{SRC2[7]}}, SRC2[7:0]};     // Sign Extension
711
                   3'b001 : bwd_daten2 = {{16{SRC2[15]}},SRC2[15:0]};
712
                   3'b1xx : bwd_daten2 = 32'h0;                                                 // is used for ABSi and NEGi
713
                  default : bwd_daten2 = SRC2;
714
                endcase
715
 
716
        always @(OPCODE or SRC2 or BMASKE or addsub_q or bwd_daten1 or SRC1 or shdat or DP_OUT)
717
                casex (OPCODE[3:0])
718
                  4'b001x : pfad_6 = SRC2 & ~BMASKE;            // CBIT & CBITI
719
                  4'b011x : pfad_6 = SRC2 |  BMASKE;            // SBIT & SBITI
720
                  4'b1000 : pfad_6 = addsub_q;                          // NEG
721
                  4'b1001 : pfad_6 = {SRC1[31:1],~SRC1[0]};      // NOT
722
                  4'b1010 : pfad_6 = SRC1;                                      // Special case 6A : not used normal -> op_lmr !
723
                  4'b1100 : pfad_6 = bwd_daten1[31] ? addsub_q : SRC1;  // ABS
724
                  4'b1101 : pfad_6 = ~SRC1;                                     // COM
725 23 ns32kum
                  4'b111x : pfad_6 = SRC2 ^  BMASKE;            // IBIT
726 9 ns32kum
                  default : pfad_6 = shdat;                                     // Result of Barrelshifter
727
                endcase
728
 
729
        // ++++++++++++++  Format 7 : MUL  +++++++++++++++++++++++
730
 
731
        // This Condition-Code Decoder is written twice ... see DECODER
732
 
733
        reg                             sc_bit;
734
        wire                    sc_negativ,sc_zero,sc_flag,sc_larger,sc_carry_psr;
735
 
736
        assign sc_negativ       = PSR[7];
737
        assign sc_zero      = PSR[6];
738
        assign sc_flag          = PSR[5];
739
        assign sc_larger        = PSR[2];
740
        assign sc_carry_psr = PSR[0];
741
 
742
        always @(SRC1 or sc_zero or sc_carry_psr or sc_larger or sc_negativ or sc_flag)
743
                case (SRC1[3:0])
744
                  4'h0 : sc_bit =  sc_zero;                     // EQual
745
                  4'h1 : sc_bit = ~sc_zero;                     // Not Equal
746
                  4'h2 : sc_bit =  sc_carry_psr;        // Carry Set
747
                  4'h3 : sc_bit = ~sc_carry_psr;        // Carry Clear
748
                  4'h4 : sc_bit =  sc_larger;           // Higher
749
                  4'h5 : sc_bit = ~sc_larger;           // Lower or Same
750
                  4'h6 : sc_bit =  sc_negativ;          // Greater Than
751
                  4'h7 : sc_bit = ~sc_negativ;          // Less or Equal
752
                  4'h8 : sc_bit =  sc_flag;                     // Flag Set
753
                  4'h9 : sc_bit = ~sc_flag;                     // Flag Clear
754
                  4'hA : sc_bit = ~sc_larger  & ~sc_zero;       // LOwer
755
                  4'hB : sc_bit =  sc_larger  |  sc_zero;       // Higher or Same
756
                  4'hC : sc_bit = ~sc_negativ & ~sc_zero;       // Less Than
757
                  4'hD : sc_bit =  sc_negativ |  sc_zero;       // Greater or Equal
758
                  4'hE : sc_bit = 1'b1;                         // True
759
                  4'hF : sc_bit = 1'b0;                         // False
760
                endcase
761
 
762
        reg              [3:0]  bytes2anz;
763
        wire    [23:0]   and_src1;
764
        wire    [31:0]   movxz_dat;
765
        wire     [4:0]   kurz_anz;
766
        wire    [31:0]   ext_sh4,ext_sh2;
767
 
768
        assign and_src1  = {{16{BWD[1]}},{8{BWD[0]}}} & SRC1[31:8];      // for MOVZ
769
 
770
        assign movxz_dat = (OPCODE[1] ^ OPCODE[0]) ? {and_src1,SRC1[7:0]} : bwd_daten1;   // MOVZ.. ?
771
 
772
        always @(ADDR or BWD)
773
                casex (BWD[1:0])
774
                  2'b00 : bytes2anz = ADDR[3:0];
775
                  2'b01 : bytes2anz = {1'b0,ADDR[3:1]};
776
                  2'b1x : bytes2anz = {2'b0,ADDR[3:2]};
777
                endcase
778
 
779
        assign kurz_anz = {1'b0,bytes2anz} + 5'h01;     // count for MOVM/CMPM
780
 
781
        assign ext_sh4 = SRC1[7] ? {4'h0,SRC2[31:4]}    : SRC2;         // EXTSi
782
        assign ext_sh2 = SRC1[6] ? {2'b0,ext_sh4[31:2]} : ext_sh4;
783
 
784
        always @(*)
785
                casex (OPCODE[3:0])
786
                  4'b0011 : pfad_7 = (SRC1[5] ? {1'b0,ext_sh2[31:1]} : ext_sh2) & BMASKE;       // EXTSi
787
                  4'b01xx : pfad_7 = movxz_dat;                 // MOVXBW, MOVZBW, MOVZiD, MOVXiD
788
                  4'b1000 : pfad_7 = MRESULT[31:0];              // MULi
789
                  4'b1010 : pfad_7 = {27'h0,(kurz_st ? kurz_anz : {4'h0,sc_bit})};      // SCond or start of MOVM/CMPM
790
                  default : pfad_7 = DP_OUT;                    // DIV etc.
791
                endcase
792
 
793
        // ++++++++++++++  Format 8 : multiple opcodes  +++++++++++++++++++++++
794
 
795
        reg                             chk_p1;
796
        reg             [31:0]   ins_maske;
797
 
798
        wire     [4:0]   ffs_out;
799
        wire    [15:0]   low_bou,upp_bou,zeiger,chk_upp,chk_low;
800
        wire                    flag_up,flag_lo;
801
 
802
        FFS_LOGIK ffs_unit (.SRC1(SRC1), .SRC2(SRC2[4:0]), .BWD(BWD), .FLAG(ffs_flag), .DOUT(ffs_out) );
803
 
804
        // CHECK : SRC1 are the Bounds
805
        assign low_bou = BWD[0] ? SRC1[31:16] : {{8{SRC1[15]}},SRC1[15:8]};
806
        assign upp_bou = BWD[0] ? SRC1[15:0]  : {{8{SRC1[7]}}, SRC1[7:0]};
807
        assign zeiger  = BWD[0] ? SRC2[15:0]  : {{8{SRC2[7]}}, SRC2[7:0]};
808
 
809
        assign chk_upp = upp_bou - zeiger;      // F=1 if upp_bou < zeiger
810
        assign chk_low = zeiger - low_bou;      // F=1 if zeiger < low_bou
811
 
812
        assign flag_up = (upp_bou[15] == zeiger[15]) ? chk_upp[15] : upp_bou[15];       // See NL Definition
813
        assign flag_lo = (low_bou[15] == zeiger[15]) ? chk_low[15] : zeiger[15];
814
 
815
        always @(posedge BCLK) chk_p1 <= chk_op & BWD[1];       // CHECKD needs 2 cycles to execute
816
 
817
        assign chk_flag = BWD[1] ? (chk_p1 ? (nl_int[1] | psr_low[5]) : nl_int[1]) : (flag_up | flag_lo);
818
 
819
        always @(posedge BCLK) ins_maske <= shdat;      // expensive solution in terms of LEs ! 
820
 
821
        always @(*)
822
                casex (OPCODE[3:0])              // CVTP (81) has no OPCODE !
823 11 ns32kum
                  4'b000x : pfad_8 = (extract ? SRC2 : 32'hFFFF_FFFF) & BMASKE; // EXT, the other form is for INS to get the mask
824
                  4'b0010 : pfad_8 = (SRC1 & ins_maske) | (SRC2 & ~ins_maske);  // INS ins_maske[] ? SRC1[] : SRC2[]
825 9 ns32kum
                  4'b0011 : pfad_8 = BWD[1] ? addsub_q : {16'h0,chk_low};
826
                  4'b0101 : pfad_8 = {24'hxx_xxxx,3'b000,ffs_out};
827 11 ns32kum
                  default : pfad_8 = {4'hx,push_psr,SRC1[15:0]}; // Opcode x'87-x'8F is used at CXP and therefore in Exception-Processing
828 9 ns32kum
                endcase
829
 
830
        // ++++++++++++++ Format 11 : Floating-Point Datapath  +++++++++++++++++++++++++++++++
831
 
832
        assign pfad_11 = (OPCODE[1:0] == 2'b01) ?
833
                                                {((OPCODE[3:2] == 2'b11) ? 1'b0 : (SRC1[31] ^ OPCODE[2])),SRC1[30:0]}    // ABSf , NEGf + MOVf
834
                                                                                        : DP_OUT;
835
 
836
endmodule

powered by: WebSVN 2.1.0

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