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

Subversion Repositories k68

[/] [k68/] [trunk/] [rtl/] [verilog/] [k68_prims.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sybreon
//                              -*- Mode: Verilog -*-
2
// Filename        : k68_prims.v
3
// Description     : RISC ALU blocks
4
// Author          : Shawn Tan
5
// Created On      : Sun Feb  9 00:06:41 2003
6
// Last Modified By: .
7
// Last Modified On: .
8
// Update Count    : 0
9
// Status          : Unknown, Use with caution!
10
/////////////////////////////////////////////////////////////////////
11
////                                                             ////
12
//// Copyright (C) 2002 to Shawn Tan Ser Ngiap.                  ////
13
////                       shawn.tan@aeste.net                   ////
14
////                                                             ////
15
//// This source file may be used and distributed without        ////
16
//// restriction provided that this copyright statement is not   ////
17
//// removed from the file and that any derivative work contains ////
18
//// the original copyright notice and the associated disclaimer.////
19
////                                                             ////
20
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
21
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
22
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
23
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
24
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
25
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
26
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
27
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
28
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
29
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
30
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
31
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
32
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
33
////                                                             ////
34
/////////////////////////////////////////////////////////////////////
35
 
36
 
37
`include "k68_defines.v"
38
 
39
//
40
// 1 CLK 32bit ROX Shifter
41
//
42
module k68_rox (/*AUTOARG*/
43
   // Outputs
44
   res,
45
   // Inputs
46
   in, step
47
   ) ;
48
   parameter dw = `k68_DATA_W;
49
 
50
   output [dw-1:0] res;
51
   input [dw-1:0] in;
52
   input [5:0]     step;
53
   reg [dw-1:0]    res;
54
   reg [4:0]               move;
55
 
56
   always @ ( /*AUTOSENSE*/step) begin
57
      if (step[5])
58
        move <= 6'd32 - step[4:0];
59
      else
60
        move <= step[4:0];
61
   end
62
 
63
   always @ ( /*AUTOSENSE*/in or move) begin
64
      //
65
      // Barrel Shift
66
      //
67
      case (move)
68
        5'd01: res <= {in[30:0],in[31]};
69
        5'd02: res <= {in[29:0],in[31:30]};
70
        5'd03: res <= {in[28:0],in[31:29]};
71
        5'd04: res <= {in[27:0],in[31:28]};
72
        5'd05: res <= {in[26:0],in[31:27]};
73
        5'd06: res <= {in[25:0],in[31:26]};
74
        5'd07: res <= {in[24:0],in[31:25]};
75
        5'd08: res <= {in[23:0],in[31:24]};
76
        5'd09: res <= {in[22:0],in[31:23]};
77
        5'd10: res <= {in[21:0],in[31:22]};
78
        5'd11: res <= {in[20:0],in[31:21]};
79
        5'd12: res <= {in[19:0],in[31:20]};
80
        5'd13: res <= {in[18:0],in[31:19]};
81
        5'd14: res <= {in[17:0],in[31:18]};
82
        5'd15: res <= {in[16:0],in[31:17]};
83
        5'd16: res <= {in[15:0],in[31:16]};
84
        5'd17: res <= {in[14:0],in[31:15]};
85
        5'd18: res <= {in[13:0],in[31:14]};
86
        5'd19: res <= {in[12:0],in[31:13]};
87
        5'd20: res <= {in[11:0],in[31:12]};
88
        5'd21: res <= {in[10:0],in[31:11]};
89
        5'd22: res <= {in[9:0],in[31:10]};
90
        5'd23: res <= {in[8:0],in[31:9]};
91
        5'd24: res <= {in[7:0],in[31:8]};
92
        5'd25: res <= {in[6:0],in[31:7]};
93
        5'd26: res <= {in[5:0],in[31:6]};
94
        5'd27: res <= {in[4:0],in[31:5]};
95
        5'd28: res <= {in[3:0],in[31:4]};
96
        5'd29: res <= {in[2:0],in[31:3]};
97
        5'd30: res <= {in[1:0],in[31:2]};
98
        5'd31: res <= {in[0],in[31:1]};
99
        default: res <= {in[31:0]};
100
 
101
      endcase // case(step)
102
   end
103
 
104
endmodule // k68_barrel
105
 
106
//
107
// 1 CLK 32bit ROX Shifter
108
//
109
module k68_roxx (/*AUTOARG*/
110
   // Outputs
111
   res,
112
   // Inputs
113
   in, xin, step
114
   ) ;
115
   parameter dw = `k68_DATA_W;
116
 
117
   output [dw:0] res;
118
   input [dw-1:0] in;
119
   input        xin;
120
   input [6:0]   step;
121
   reg [dw:0] res;
122
   reg [5:0]     move;
123
 
124
   always @ ( /*AUTOSENSE*/step) begin
125
      if (step[6])
126
        move <= 6'd33 - step[5:0];
127
      else
128
        move <= step[5:0];
129
   end
130
 
131
   always @ ( /*AUTOSENSE*/in or move or xin) begin
132
      //
133
      // Barrel Shift
134
      //
135
      case (move)
136
        6'd01: res <= {in[30:0],xin,in[31]};
137
        6'd02: res <= {in[29:0],xin,in[31:30]};
138
        6'd03: res <= {in[28:0],xin,in[31:29]};
139
        6'd04: res <= {in[27:0],xin,in[31:28]};
140
        6'd05: res <= {in[26:0],xin,in[31:27]};
141
        6'd06: res <= {in[25:0],xin,in[31:26]};
142
        6'd07: res <= {in[24:0],xin,in[31:25]};
143
        6'd08: res <= {in[23:0],xin,in[31:24]};
144
        6'd09: res <= {in[22:0],xin,in[31:23]};
145
        6'd10: res <= {in[21:0],xin,in[31:22]};
146
        6'd11: res <= {in[20:0],xin,in[31:21]};
147
        6'd12: res <= {in[19:0],xin,in[31:20]};
148
        6'd13: res <= {in[18:0],xin,in[31:19]};
149
        6'd14: res <= {in[17:0],xin,in[31:18]};
150
        6'd15: res <= {in[16:0],xin,in[31:17]};
151
        6'd16: res <= {in[15:0],xin,in[31:16]};
152
        6'd17: res <= {in[14:0],xin,in[31:15]};
153
        6'd18: res <= {in[13:0],xin,in[31:14]};
154
        6'd19: res <= {in[12:0],xin,in[31:13]};
155
        6'd20: res <= {in[11:0],xin,in[31:12]};
156
        6'd21: res <= {in[10:0],xin,in[31:11]};
157
        6'd22: res <= {in[9:0],xin,in[31:10]};
158
        6'd23: res <= {in[8:0],xin,in[31:9]};
159
        6'd24: res <= {in[7:0],xin,in[31:8]};
160
        6'd25: res <= {in[6:0],xin,in[31:7]};
161
        6'd26: res <= {in[5:0],xin,in[31:6]};
162
        6'd27: res <= {in[4:0],xin,in[31:5]};
163
        6'd28: res <= {in[3:0],xin,in[31:4]};
164
        6'd29: res <= {in[2:0],xin,in[31:3]};
165
        6'd30: res <= {in[1:0],xin,in[31:2]};
166
        6'd31: res <= {in[0],xin,in[31:1]};
167
        6'd32: res <= {xin,in[31:0]};
168
        default: res <= {in[31:0],xin};
169
 
170
      endcase // case(step)
171
   end
172
 
173
endmodule // k68_barrel
174
 
175
//
176
// 1 CLK 32bit LSX Shifter
177
//
178
module k68_lsx (/*AUTOARG*/
179
   // Outputs
180
   res,
181
   // Inputs
182
   in, step
183
   ) ;
184
   parameter dw = `k68_DATA_W;
185
 
186
   output [dw-1:0] res;
187
   input [dw-1:0] in;
188
   input [5:0]     step;
189
   reg [dw-1:0]    res;
190
 
191
   always @ ( /*AUTOSENSE*/in or step) begin
192
      if (step[5])
193
        res <= in >> step[4:0];
194
      else
195
        res <= in << step[4:0];
196
   end
197
 
198
 
199
endmodule // k68_barrel
200
 
201
//
202
// 1 CLK 32bit ASX Shifter
203
//
204
module k68_asx (/*AUTOARG*/
205
   // Outputs
206
   res,
207
   // Inputs
208
   in, step
209
   ) ;
210
   parameter dw = `k68_DATA_W;
211
 
212
   output [dw-1:0] res;
213
   input [dw-1:0] in;
214
   input [5:0]     step;
215
   reg [dw-1:0]    res;
216
 
217
   always @ ( /*AUTOSENSE*/in or step) begin
218
      if (step[5])
219
        if (in[31])
220
          case (step[4:0])
221
            5'd01: res <= {1'b1,in[31:1]};
222
            5'd02: res <= {2'b11,in[31:2]};
223
            5'd03: res <= {3'b111,in[31:3]};
224
            5'd04: res <= {4'b1111,in[31:4]};
225
            5'd05: res <= {5'b11111,in[31:5]};
226
            5'd06: res <= {6'b111111,in[31:6]};
227
            5'd07: res <= {7'b1111111,in[31:7]};
228
            5'd08: res <= {8'b11111111,in[31:8]};
229
            5'd09: res <= {9'b111111111,in[31:9]};
230
            5'd10: res <= {10'b1111111111,in[31:10]};
231
            5'd11: res <= {11'b11111111111,in[31:11]};
232
            5'd12: res <= {12'b111111111111,in[31:12]};
233
            5'd13: res <= {13'b1111111111111,in[31:13]};
234
            5'd14: res <= {14'b11111111111111,in[31:14]};
235
            5'd15: res <= {15'b111111111111111,in[31:15]};
236
            5'd16: res <= {16'b1111111111111111,in[31:16]};
237
            5'd17: res <= {17'b11111111111111111,in[31:17]};
238
            5'd18: res <= {18'b111111111111111111,in[31:18]};
239
            5'd19: res <= {19'b1111111111111111111,in[31:19]};
240
            5'd20: res <= {20'b11111111111111111111,in[31:20]};
241
            5'd21: res <= {21'b111111111111111111111,in[31:21]};
242
            5'd22: res <= {22'b1111111111111111111111,in[31:22]};
243
            5'd23: res <= {23'b11111111111111111111111,in[31:23]};
244
            5'd24: res <= {24'b111111111111111111111111,in[31:24]};
245
            5'd25: res <= {25'b1111111111111111111111111,in[31:25]};
246
            5'd26: res <= {26'b11111111111111111111111111,in[31:26]};
247
            5'd27: res <= {27'b111111111111111111111111111,in[31:27]};
248
            5'd28: res <= {28'b1111111111111111111111111111,in[31:28]};
249
            5'd29: res <= {29'b11111111111111111111111111111,in[31:29]};
250
            5'd30: res <= {30'b111111111111111111111111111111,in[31:30]};
251
            5'd31: res <= {31'b1111111111111111111111111111111,in[31]};
252
            default: res <= in;
253
          endcase // case(step[4:0])
254
        else
255
          res <= in >> step[4:0];
256
      else
257
        res <= in << step[4:0];
258
   end
259
 
260
 
261
endmodule // k68_barrel
262
 
263
//
264
// 1 CLK 34bit Parallel Multiplier
265
//
266
module k68_par_mul (/*AUTOARG*/
267
   // Outputs
268
   res,
269
   // Inputs
270
   src, dst
271
   ) ;
272
   parameter dw = `k68_DATA_W;
273
 
274
   output [dw:0] res;
275
   input [dw/2-1:0] src,dst;
276
 
277
 
278
endmodule // k68_par_mul
279
 
280
//
281
// 1 CLK 32bit Adder
282
//
283
module k68_adder (/*AUTOARG*/
284
   // Outputs
285
   res,
286
   // Inputs
287
   src, dst
288
   ) ;
289
   parameter dw = `k68_DATA_W;
290
 
291
   output [dw:0] res;
292
   input [dw-1:0] src, dst;
293
   reg [dw:0]      res;
294
 
295
   always @(/*AUTOSENSE*/dst or src) begin
296
      res <= src + dst;
297
   end
298
 
299
endmodule // k68_adder
300
 
301
//
302
// CC Condition Calc
303
//
304
module k68_ccc(/*AUTOARG*/
305
   // Outputs
306
   flag,
307
   // Inputs
308
   cc, code
309
   );
310
 
311
   parameter XF = `k68_X_FLAG;
312
   parameter CF = `k68_C_FLAG;
313
   parameter NF = `k68_N_FLAG;
314
   parameter ZF = `k68_Z_FLAG;
315
   parameter VF = `k68_V_FLAG;
316
 
317
   input [7:0] cc;
318
   input [3:0] code;
319
   output      flag;
320
   reg         flag;
321
 
322
   always @(/*AUTOSENSE*/cc or code) begin
323
      case (code)
324
        4'h4: flag <= ~cc[CF];
325
        4'h5: flag <= cc[CF];
326
        4'h7: flag <= cc[ZF];
327
        4'hC: flag <= cc[NF] & cc[VF] | ~cc[NF] & ~cc[VF];
328
        4'hE: flag <= cc[NF] & cc[VF] & ~cc[ZF] | ~cc[NF] & ~cc[VF] & ~cc[ZF];
329
        4'h2: flag <= ~cc[CF] & ~cc[ZF];
330
        4'hF: flag <= cc[ZF] | cc[NF] & ~cc[VF] | ~cc[NF] & cc[VF];
331
        4'h3: flag <= cc[CF] | cc[ZF];
332
        4'hD: flag <= cc[NF] & ~cc[VF] | ~cc[NF] & cc[VF];
333
        4'hB: flag <= cc[NF];
334
        4'h6: flag <= ~cc[ZF];
335
        4'hA: flag <= ~cc[NF];
336
        4'h8: flag <= ~cc[VF];
337
        4'h9: flag <= cc[VF];
338
        4'h1: flag <= 1'b0;
339
        4'h0: flag <= 1'b1;
340
        //default: flag <= 1'b0;
341
      endcase // case(code)
342
   end
343
 
344
endmodule // k68_ccc
345
 
346
//
347
// BCD CONVERTER
348
//
349
module k68_d2b(/*AUTOARG*/
350
   // Outputs
351
   b,
352
   // Inputs
353
   d
354
   );
355
   parameter dw = `k68_DATA_W;
356
   input [7:0] d;
357
   output [7:0] b;
358
   reg [7:0]     b;
359
 
360
   always @ ( /*AUTOSENSE*/d) begin
361
 
362
      if (d[7:4] >= 4'd5)
363
        b[7:4] <= d[7:4] + 2'd3;
364
      else
365
        b[7:4] <= d[7:4];
366
 
367
      if (d[3:0] >= 4'd5)
368
        b[3:0] <= d[3:0] + 2'd3;
369
      else
370
        b[3:0] <= d[3:0];
371
 
372
   end
373
 
374
 
375
endmodule // k68_d2b
376
 
377
//
378
// BCD CONVERTER
379
//
380
module k68_b2d(/*AUTOARG*/
381
   // Outputs
382
   d,
383
   // Inputs
384
   b
385
   );
386
   parameter dw = `k68_DATA_W;
387
   input [7:0] b;
388
   output [7:0] d;
389
   reg [7:0]     d;
390
 
391
   always @ ( /*AUTOSENSE*/b) begin
392
 
393
      if (b[7:4] >= 4'd5)
394
        d[7:4] <= b[7:4] - 2'd3;
395
      else
396
        d[7:4] <= b[7:4];
397
 
398
      if (b[3:0] >= 4'd5)
399
        d[3:0] <= b[3:0] - 2'd3;
400
      else
401
        d[3:0] <= b[3:0];
402
 
403
   end
404
 
405
 
406
endmodule // k68_b2d
407
 

powered by: WebSVN 2.1.0

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