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

Subversion Repositories zet86

[/] [zet86/] [tags/] [INITIAL/] [rtl-model/] [alu.v] - Blame information for rev 49

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zeus
`timescale 1ns/10ps
2
 
3
module alu(x, y, out, t, func, iflags, oflags, word_op, seg, off);
4
  // IO ports
5
  input  [/* 31 */ 15:0] x;
6
  input  [15:0] y;
7
  input  [2:0]  t, func;
8
  input  [15:0] iflags;
9
  input         word_op;
10
  input  [15:0] seg, off;
11
  output [31:0] out;
12
  output  [8:0] oflags;
13
 
14
  // Net declarations
15
  wire [15:0] add /* adj, log, shi, rot */;
16
  wire  [8:0] othflags;
17
  wire [19:0] oth;
18
//  wire [31:0] cnv, mul;
19
//  wire af_add, af_adj;
20
//  wire cf_adj, cf_add, cf_mul, cf_log, cf_shi, cf_rot;
21
//  wire of_adj, of_add, of_mul, of_log, of_shi, of_rot;
22
  wire /* ofi, */ sfi, zfi, /* afi, */ pfi, cfi;
23
  wire /* ofo, */ sfo, zfo, /* afo, */ pfo /*, cfo */;
24
  wire flags_unchanged;
25
 
26
  // Module instances
27
  addsub ad0(x[15:0], y, add, func, word_op, cfi, /* cf_add */, /* af_add, */
28
            /* of_add */);
29
/*
30
  adj    adj0(x[15:0], y, {cf_adj, adj}, func, afi, cfi, af_adj, of_adj);
31
  conv   cnv0(x[15:0], cnv, func[0]);
32
  muldiv mul0(x, y, mul, func[1:0], word_op, cf_mul, of_mul);
33
  bitlog lo0(x[15:0], y, log, func, cf_log, of_log);
34
  shifts sh0(x[15:0], y, shi, func[1:0], word_op, cfi, ofi, cf_shi, of_shi);
35
  rotat  rot0(x[15:0], y, rot, func[1:0], word_op, cfi, cf_rot, of_rot);
36
*/
37
  othop  oth0(x[15:0], y, seg, off, iflags, func, word_op, oth, othflags);
38
 
39
  mux8_16 m0(t, 16'd0/* adj */, add, 16'd0/* cnv[15:0] */,
40
             16'd0 /* mul[15:0] */, 16'd0 /* log */, 16'd0 /* shi */,
41
             16'd0 /* rot */, oth[15:0], out[15:0]);
42
  mux8_16 m1(t, 16'd0, 16'd0, 16'd0 /* cnv[31:16] */, 16'd0 /* mul[31:16] */,
43
             16'd0, 16'd0, 16'd0, {12'b0,oth[19:16]}, out[31:16]);
44
//  mux8_1  a1(t, cf_adj, cf_add, cfi, cf_mul, cf_log, cf_shi, cf_rot, 1'b0, cfo);
45
//  mux8_1  a2(t, af_adj, af_add, afi, 1'b0, 1'b0, 1'b0, afi, 1'b0, afo);
46
//  mux8_1  a3(t, of_adj, of_add, ofi, of_mul, of_log, of_shi, of_rot, 1'b0, ofo);
47
 
48
  // Flags
49
  assign pfo = flags_unchanged ? pfi : ^~ out[7:0];
50
  assign zfo = flags_unchanged ? zfi : (word_op ? ~|out[15:0] : ~|out[7:0]);
51
  assign sfo = flags_unchanged ? sfi : (word_op ? out[15] : out[7]);
52
 
53
  assign oflags = (t == 3'd7) ? othflags
54
                 : { 1'b0 /* ofo */, iflags[10:8], sfo, zfo, 1'b0 /* afo */,
55
                   pfo, 1'b0 /* cfo */ };
56
 
57
//  assign ofi = iflags[11];
58
  assign sfi = iflags[7];
59
  assign zfi = iflags[6];
60
//  assign afi = iflags[4];
61
  assign pfi = iflags[2];
62
  assign cfi = iflags[0];
63
 
64
  assign flags_unchanged = (t == 4'd6 || t == 4'd2 || t == 4'd4 && func == 4'd1);
65
endmodule
66
 
67
module addsub(x, y, out, func, word_op, cfi, cfo, /* afo, */ ofo);
68
  // IO ports
69
  input  [15:0] x, y;
70
  input  [2:0]  func;
71
  input         cfi, word_op;
72
  output        cfo, /* afo, */ ofo;
73
  output [15:0] out;
74
 
75
  // Net declarations
76
  wire [16:0] adc, add, ad8, dec, neg, sbb, sub, cmp;
77
//  wire [4:0]  tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
78
  wire        resta, bneg, bincdec, cfo8, cfo16, ofo8, ofo16, cfoneg8, cfoneg16;
79
// wire        afo_adc, afo_add, afo_inc, afo_dec, afo_neg, afo_sbb, afo_sub, afo_cmp;
80
  wire [16:0] out17;
81
 
82
  // Module instances
83
  mux8_17 m0(func, adc, add, ad8, dec, neg, sbb, sub, cmp, out17);
84
/*  mux8_1  m1(func, afo_adc, afo_add, afo_inc, afo_dec,
85
                   afo_neg, afo_sbb, afo_sub, afo_cmp, afo); */
86
 
87
  // Assignments
88
  assign adc = x + y + cfi;
89
  assign add = x + y;
90
  assign ad8 = x + y[7:0];
91
  assign dec = x - 8'b1;
92
  assign neg = {x==16'd0 ? 1'b0 : 1'b1, -x};
93
  assign sbb = x - y - cfi;
94
  assign sub = x - y;
95
  assign cmp = x - y;
96
/*
97
  assign tmp0 = x[3:0] + y[3:0] + cfi;
98
  assign tmp1 = x[3:0] + y[3:0];
99
  assign tmp2 = x[3:0] + 4'b1;
100
  assign tmp3 = x[3:0] - 4'b1;
101
  assign tmp4 = -x[3:0];
102
  assign tmp5 = x[3:0] - y[3:0] -cfi;
103
  assign tmp6 = x[3:0] - y[3:0];
104
  assign tmp7 = x[3:0] - y[3:0];
105
 
106
  assign afo_adc = tmp0[4];
107
  assign afo_add = tmp1[4];
108
  assign afo_inc = tmp2[4];
109
  assign afo_dec = tmp3[4];
110
  assign afo_neg = tmp4[4];
111
  assign afo_sbb = tmp5[4];
112
  assign afo_sub = tmp6[4];
113
  assign afo_cmp = tmp7[4];
114
*/
115
  assign resta = (func > 3'd2);
116
  assign bneg  = (func == 3'd4);
117
  assign ofo16 = resta ? ( bneg ? x[15] & out[15] :
118
                               (~x[15] & y[15] & out[15] | x[15] & ~y[15] & ~out[15]))
119
                     : (~x[15] & ~y[15] & out[15] | x[15] & y[15] & ~out[15]);
120
 
121
  assign ofo8  = resta ? ( bneg ? x[7] & out[7] :
122
                               (~x[7] & y[7] & out[7] | x[7] & ~y[7] & ~out[7]))
123
                     : (~x[7] & ~y[7] & out[7] | x[7] & y[7] & ~out[7]);
124
 
125
  assign cfoneg8  = x[7:0]!=8'd0;
126
  assign cfoneg16 = x[15:0]!=16'd0;
127
  assign bincdec = (func == 3'd2 || func == 3'd3);
128
  assign cfo8  = bneg ? cfoneg8  : out17[8];
129
  assign cfo16 = bneg ? cfoneg16 : out17[16];
130
  assign out   = out17[15:0];
131
  assign cfo   = bincdec ? cfi : (word_op ? cfo16 : cfo8);
132
  assign ofo   = word_op ? ofo16 : ofo8;
133
endmodule
134
 
135
/*
136
module adj(x, y, out, func, afi, cfi, afo, cfo);
137
  // IO ports
138
  input  [15:0] x, y;
139
  input  [2:0]  func;
140
  input         afi, cfi;
141
  output        afo, cfo;
142
  output [16:0] out;
143
 
144
  // Net declarations
145
  wire [16:0] aaa, aad, aam, aas, daa, das, aad16;
146
  wire [7:0]  ala, als, alout;
147
  wire        alcnd;
148
 
149
  // Module instances
150
  mux8_17 m0(func, aaa, aad, aam, aas,
151
                   daa, das, {9'd0, y[7:0]}, {1'b0, y}, out);
152
 
153
  // Assignments
154
  assign aaa = afo ? { x[15:8] + 8'd1, (x[7:0] + 8'd6) & 8'h0f } : x;
155
  assign aad16 = x[15:8] * 8'd10 + x[7:0];
156
  assign aad = { 8'b0, aad16[7:0] };
157
  assign aam = 16'd0; // FIXME: { x[7:0] / 8'd10, x[7:0] % 8'd10 };
158
  assign aas = afo ? { x[15:8] - 8'd1, (x[7:0] - 8'd6) & 8'h0f } : x;
159
 
160
  assign ala = afo ? x[7:0] + 8'd6 : x[7:0];
161
  assign als = afo ? x[7:0] - 8'd6 : x[7:0];
162
  assign alout = (func == 3'd4) ? ala : als;
163
  assign alcnd = (alout > 8'h9f) | cfi;
164
  assign daa = alcnd ? { x[15:8], x[3:0] + 8'h60 } : { x[15:8], alout };
165
  assign das = alcnd ? { x[15:8], x[3:0] - 8'h60 } : { x[15:8], alout };
166
 
167
  assign afo = (x[3:0] > 4'd9) | afi;
168
  assign cfo = func[2] ? alcnd : afo;
169
endmodule
170
 
171
module conv(x, out, func);
172
  // IO ports
173
  input  [15:0] x;
174
  input         func;  // type = 010 and func = 111 is reserved for INTO
175
  output [31:0] out;
176
 
177
  // Net declarations
178
  wire [31:0] cbw, cwd;
179
  wire [23:0] x7_24;
180
  wire [15:0] x15_16;
181
 
182
  // Assignments
183
  assign x7_24  = { 24{x[7]} };
184
  assign x15_16 = { 16{x[15]} };
185
  assign cbw = { x7_24, x[7:0] };
186
  assign cwd = { x15_16, x[7:0] };
187
  assign out = func ? cwd : cbw;
188
endmodule
189
 
190
module muldiv(x, y, out, func, word_op, cfo, ofo);
191
  // IO ports
192
  input  [31:0] x;
193
  input  [15:0] y;
194
  input  [1:0] func;
195
  input        word_op;
196
  output [31:0] out;
197
  output        cfo, ofo;
198
 
199
  // Net declarations
200
  wire signed [31:0] x_s, imul, idiv32, mods32;
201
  wire signed [15:0] y_s, idivr16, modsr16, idiv16, mods16;
202
  wire signed [7:0]  idivr8, modsr8;
203
  wire [31:0] mul, div32, modu32, div, idiv;
204
  wire [15:0] divr16, modur16, div16, modu16;
205
  wire [7:0]  divr8, modur8;
206
  wire cfo8, cfo16;
207
 
208
  // Module instantiations
209
  mux4_32 m0(func, mul, imul, div, idiv, out);
210
 
211
  // Assignments
212
  assign x_s = x;
213
  assign y_s = y;
214
  assign mul  = x[15:0] * y;
215
  assign imul = x_s[15:0] * y_s;
216
 
217
  assign div32  = x / y;
218
  assign modu32 = x % y;
219
  assign idiv32 = x_s / y_s;
220
  assign mods32 = x_s % y_s;
221
  assign divr16  = div32[15:0];
222
  assign modur16 = modu32[15:0];
223
  assign idivr16 = idiv32[15:0];
224
  assign modsr16 = mods32[15:0];
225
 
226
  assign div16  = x[15:0] / y[7:0];
227
  assign modu16 = x[15:0] % y[7:0];
228
  assign idiv16 = x_s[15:0] / y_s[7:0];
229
  assign mods16 = x_s[15:0] % y_s[7:0];
230
  assign divr8  = div16[7:0];
231
  assign modur8 = modu16[7:0];
232
  assign idivr8 = idiv16[7:0];
233
  assign modsr8 = mods16[7:0];
234
 
235
  assign div   = word_op ? { modur16, divr16 } : { 16'd0, modur8, divr8 };
236
  assign idiv  = word_op ? { modsr16, idivr16 } : { 16'd0, modsr8, idivr8 };
237
 
238
  assign cfo16 = (out[31:16] != { 16{out[15]} });
239
  assign cfo8  = (out[15:8]  != {  8{out[7]} });
240
  assign cfo = word_op ? cfo16 : cfo8;
241
  assign ofo = cfo;
242
endmodule
243
 
244
module bitlog(x, y, out, func, cfo, ofo);
245
  // IO ports
246
  input  [15:0] x, y;
247
  input  [2:0]  func;
248
  output [15:0] out;
249
  output        cfo, ofo;
250
 
251
  // Net declarations
252
  wire [15:0] and_n, or_n, not_n, xor_n, test_n;
253
 
254
  // Module instantiations
255
  mux8_16 m0(func, and_n, or_n, not_n, xor_n, test_n, 16'd0, 16'd0, 16'd0, out);
256
 
257
  // Assignments
258
  assign and_n  = x & y;
259
  assign or_n   = x | y;
260
  assign not_n  = ~x;
261
  assign xor_n  = x ^ y;
262
  assign test_n = x & y;
263
 
264
  assign cfo = 1'b0;
265
  assign ofo = 1'b0;
266
endmodule
267
 
268
module shifts(x, y, out, func, word_op, cfi, ofi, cfo, ofo);
269
  // IO ports
270
  input  [15:0] x, y;
271
  input   [1:0] func;
272
  input         cfi, ofi;
273
  input         word_op;
274
  output [15:0] out;
275
  output        cfo, ofo;
276
 
277
  // Net declarations
278
  wire [15:0] sal_shl, sar, shr, sar16, shr16;
279
  wire [7:0]  sar8, shr8;
280
  wire signed [15:0] x_s;
281
  wire ofo_shl, ofo_sar, ofo_shr, ofo_o, cfo16, cfo8;
282
 
283
  // Module instantiations
284
  mux4_16 m0(func, sal_shl, sar, shr, 16'd0, out);
285
  mux4_1  m1(func, ofo_shl, ofo_sar, ofo_shr, 1'b0, ofo_o);
286
 
287
  // Assignments
288
  assign x_s     = x;
289
  assign sal_shl = x << y[7:0];
290
  assign sar16   = x_s >>> y[7:0];
291
  assign shr16   = x >> y[7:0];
292
  assign sar8    = x_s[7:0] >>> y[7:0];
293
  assign shr8    = x[7:0] >> y[7:0];
294
  assign shr     = word_op ? shr16 : {8'd0, shr8};
295
  assign sar     = word_op ? sar16 : {8'd0, sar8};
296
 
297
  assign cfo16 = (y == 16'd0) ? cfi :
298
                ( (func==2'd0) ? |(x & (16'h8000 >> (y-1))) : |(x & (16'h1 << (y-1))));
299
  assign cfo8  = (y[7:0] == 8'd0) ? cfi :
300
                ( (func==2'd0) ? |(x[7:0] & (8'h80 >> (y-1)))
301
                               : |(x[7:0] & (8'h1 << (y-1))));
302
  assign cfo = word_op ? cfo16 : cfo8;
303
  assign ofo = (y == 16'd0) ? ofi : ofo_o;
304
  assign ofo_shl = word_op ? (out[15] != cfo) : (out[7] != cfo);
305
  assign ofo_sar = 1'b0;
306
  assign ofo_shr = word_op ? x[15] : x[7];
307
endmodule
308
 
309
module rotat(x, y, out, func, word_op, cfi, cfo, ofo);
310
  // IO ports
311
  input  [15:0] x, y;
312
  input   [1:0] func;
313
  input         cfi, word_op;
314
  output [15:0] out;
315
  output        cfo;
316
  output        ofo;
317
 
318
  // Net declarations
319
  wire [15:0] rcl16, rcr16, rol16, ror16, rcl, rcr, rol, ror;
320
  wire [7:0]  yce16, ye16, yce8, ye8, rcl8, rcr8, rol8, ror8, yc16, yc8;
321
  wire        cfo_rcl, cfo_rcr, cfo_rol, cfo_ror;
322
 
323
  // Module instantiations
324
  mux4_16 m0(func, rcl, rcr, rol, ror, out);
325
  mux4_1  m1(func, cfo_rcl, cfo_rcr, cfo_rol, cfo_ror, cfo);
326
 
327
  // Assignments
328
  assign yce16 = ye16; // FIXME: y[7:0] % 8'd17;
329
  assign ye16  = y[7:0] % 8'd16;
330
  assign rcl16 = yce16 ? (x << yce16 | cfi << (yce16-8'd1)  | x >> (8'd17-yce16)) : x;
331
  assign rcr16 = yce16 ? (x >> yce16 | cfi << (8'd16-yce16) | x << (8'd17-yce16)) : x;
332
  assign rol16 = (x << ye16 | x >> (8'd16-ye16));
333
  assign ror16 = (x >> ye16 | x << (8'd16-ye16));
334
 
335
  assign yce8 = ye8; // FIXME: y[7:0] % 8'd9;
336
  assign ye8  = y[7:0] % 8'd8;
337
  assign rcl8 = yce8 ? (x[7:0] << yce8 | cfi << (yce8-8'd1) | x[7:0] >> (8'd9-yce8)) : x[7:0];
338
  assign rcr8 = yce8 ? (x[7:0] >> yce8 | cfi << (8'd8-yce8) | x[7:0] << (9'd9-yce8)) : x[7:0];
339
  assign rol8 = (x[7:0] << ye8 | x[7:0] >> (8'd8-ye8));
340
  assign ror8 = (x[7:0] >> ye8 | x[7:0] << (8'd8-ye8));
341
 
342
  assign rcl = word_op ? rcl16 : { 8'd0, rcl8 };
343
  assign rcr = word_op ? rcr16 : { 8'd0, rcr8 };
344
  assign rol = word_op ? rol16 : { 8'd0, rol8 };
345
  assign ror = word_op ? ror16 : { 8'd0, ror8 };
346
 
347
  // Carry
348
  assign yc16 = (y[7:0]-8'd1)%8'd16;
349
  assign yc8  = (y[7:0]-8'd1)%8'd8;
350
  assign cfo_rcl = word_op ? (yce16==8'd0 ? cfi : x[16-yce16])
351
                            : (yce8==8'd0 ? cfi : x[8-yce8]);
352
  assign cfo_rcr = word_op ? (yce16==8'd0 ? cfi : x[yce16-1])
353
                            : (yce8==8'd0 ? cfi : x[yce8-1]);
354
  assign cfo_rol = word_op ? (y[7:0]==8'd0 ? cfi : x[15-yc16])
355
                            : (y[7:0]==8'd0 ? cfi : x[7-yc8]);
356
  assign cfo_ror = word_op ? (y[7:0]==8'd0 ? cfi : x[yc16])
357
                            : (y[7:0]==8'd0 ? cfi : x[yc8]);
358
 
359
  // Overflow
360
  assign ofo = func[0] ? // right
361
                        (word_op ? out[15]^out[14] : out[7]^out[6])
362
                        : // left
363
                         (word_op ? cfo^out[15] : cfo^out[7]);
364
endmodule
365
*/
366
 
367
module othop (x, y, seg, off, iflags, func, word_op, out, oflags);
368
  // IO ports
369
  input [15:0] x, y, off, seg, iflags;
370
  input [2:0] func;
371
  input word_op;
372
  output [19:0] out;
373
  output [8:0] oflags;
374
 
375
  // Net declarations
376
  wire [15:0] deff, deff2, outf, clcm, setf, intf, strf;
377
  wire [19:0] dcmp, dcmp2;
378
  wire dfi;
379
 
380
  // Module instantiations
381
  mux8_16 m0(func, dcmp[15:0], dcmp2[15:0], deff, outf, clcm, setf,
382
                   intf, strf, out[15:0]);
383
  assign out[19:16] = func ? dcmp2[19:16] : dcmp[19:16];
384
 
385
  // Assignments
386
  assign dcmp  = (seg << 4) + deff;
387
  assign dcmp2 = (seg << 4) + deff2;
388
  assign deff  = x + y + off;
389
  assign deff2 = x + y + off + 16'd2;
390
  assign outf  = y;
391
  assign clcm  = y[2] ? (y[1] ? /* -1: clc */ {iflags[15:1], 1'b0}
392
                         : /* 4: cld */ {iflags[15:11], 1'b0, iflags[9:0]})
393
                     : (y[1] ? /* 2: cli */ {iflags[15:10], 1'b0, iflags[8:0]}
394
                       : /* 0: cmc */ {iflags[15:1], ~iflags[0]});
395
  assign setf  = y[2] ? (y[1] ? /* -1: stc */ {iflags[15:1], 1'b1}
396
                         : /* 4: std */ {iflags[15:11], 1'b1, iflags[9:0]})
397
                     : (y[1] ? /* 2: sti */ {iflags[15:10], 1'b1, iflags[8:0]}
398
                       : /* 0: outf */ iflags);
399
 
400
  assign intf = {iflags[15:10], 2'b0, iflags[7:0]};
401
  assign dfi  = iflags[10];
402
  assign strf = dfi ? (x - y) : (x + y);
403
 
404
  assign oflags = word_op ? { out[11:6], out[4], out[2], out[0] }
405
                           : { iflags[11:8], out[7:6], out[4], out[2], out[0] };
406
endmodule

powered by: WebSVN 2.1.0

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