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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [rtl/] [core/] [fm_geo_matrix.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   fm_geo_matrix.v
7
//
8
// Abstract:
9
//   Matrix calculation module. 22-bit floating point number.
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 2 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2015, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42
`include "fm_3d_define.v"
43
module fm_geo_matrix (
44
  clk_core,
45
  rst_x,
46
  o_state,
47
  // vertex input
48
  i_en,
49
  o_ack,
50
  i_vx,
51
  i_vy,
52
  i_vz,
53
  i_vw,
54
  // matrix elements
55
`ifdef D3D_USE_MATRIX_PALETTE
56
  i_num_mats,
57
`endif
58
  i_m00,
59
  i_m01,
60
  i_m02,
61
  i_m03,
62
  i_m10,
63
  i_m11,
64
  i_m12,
65
  i_m13,
66
  i_m20,
67
  i_m21,
68
  i_m22,
69
  i_m23,
70
  i_m30,
71
  i_m31,
72
  i_m32,
73
  i_m33,
74
  // vertex output
75
  o_en,
76
  i_ack,
77
  o_vx,
78
  o_vy,
79
  o_vz,
80
  o_vw
81
);
82
localparam P_IDLE = 'd0;  // ROW0_IN
83
localparam P_ROW1_IN = 'd1;
84
localparam P_ROW2_IN = 'd2;
85
localparam P_ROW3_IN = 'd3;
86
localparam P_WAIT    = 'd4;
87
localparam P_DONE    = 'd5;
88
localparam P_FMUL_LAT = 'd3;
89
localparam P_FADD_LAT = 'd3;
90
localparam P_ROW_LAT = P_FMUL_LAT + P_FADD_LAT + P_FADD_LAT - 'd1;
91
`ifdef D3D_USE_MATRIX_PALETTE
92
localparam P_NEW_MAT = 'd6;
93
 
94
localparam P_ADD_IDLE = 'd0;
95
localparam P_ADD_Y = 'd1;
96
localparam P_ADD_Z = 'd2;
97
localparam P_ADD_W = 'd3;
98
localparam P_ADD_WAIT = 'd4;
99
 
100
`endif
101
//////////////////////////////////
102
// I/O port definition
103
//////////////////////////////////
104
input          clk_core;
105
input          rst_x;
106
output         o_state;
107
 
108
// vertex input
109
input          i_en;
110
output         o_ack;
111
input  [21:0]  i_vx;
112
input  [21:0]  i_vy;
113
input  [21:0]  i_vz;
114
input  [21:0]  i_vw;
115
// matrix elements
116
`ifdef D3D_USE_MATRIX_PALETTE
117
input [1:0] i_num_mats;
118
input  [22*`D3D_NUM_OF_MATS-1:0] i_m00;
119
input  [22*`D3D_NUM_OF_MATS-1:0] i_m01;
120
input  [22*`D3D_NUM_OF_MATS-1:0] i_m02;
121
input  [22*`D3D_NUM_OF_MATS-1:0] i_m03;
122
input  [22*`D3D_NUM_OF_MATS-1:0] i_m10;
123
input  [22*`D3D_NUM_OF_MATS-1:0] i_m11;
124
input  [22*`D3D_NUM_OF_MATS-1:0] i_m12;
125
input  [22*`D3D_NUM_OF_MATS-1:0] i_m13;
126
input  [22*`D3D_NUM_OF_MATS-1:0] i_m20;
127
input  [22*`D3D_NUM_OF_MATS-1:0] i_m21;
128
input  [22*`D3D_NUM_OF_MATS-1:0] i_m22;
129
input  [22*`D3D_NUM_OF_MATS-1:0] i_m23;
130
input  [22*`D3D_NUM_OF_MATS-1:0] i_m30;
131
input  [22*`D3D_NUM_OF_MATS-1:0] i_m31;
132
input  [22*`D3D_NUM_OF_MATS-1:0] i_m32;
133
input  [22*`D3D_NUM_OF_MATS-1:0] i_m33;
134
`else
135
input  [21:0]  i_m00;
136
input  [21:0]  i_m01;
137
input  [21:0]  i_m02;
138
input  [21:0]  i_m03;
139
input  [21:0]  i_m10;
140
input  [21:0]  i_m11;
141
input  [21:0]  i_m12;
142
input  [21:0]  i_m13;
143
input  [21:0]  i_m20;
144
input  [21:0]  i_m21;
145
input  [21:0]  i_m22;
146
input  [21:0]  i_m23;
147
input  [21:0]  i_m30;
148
input  [21:0]  i_m31;
149
input  [21:0]  i_m32;
150
input  [21:0]  i_m33;
151
`endif
152
// vertex output
153
output         o_en;
154
input          i_ack;
155
output [21:0]  o_vx;
156
output [21:0]  o_vy;
157
output [21:0]  o_vz;
158
output [21:0]  o_vw;
159
 
160
//////////////////////////////////
161
// regs 
162
//////////////////////////////////
163
reg [2:0]      r_state;
164
reg [11:0]     r_lat_cnt;
165
reg [21:0]     r_vx;
166
reg [21:0]     r_vy;
167
reg [21:0]     r_vz;
168
reg [21:0]     r_vw;
169
 
170
reg [21:0]     r_vx_in;
171
reg [21:0]     r_vy_in;
172
reg [21:0]     r_vz_in;
173
reg [21:0]     r_vw_in;
174
reg            r_wait_end_1z;
175
reg            r_wait_end_2z;
176
reg            r_wait_end_3z;
177
`ifdef D3D_USE_MATRIX_PALETTE
178
reg [3:0]     r_add_state;
179
reg [1:0]      r_cur_mats;
180
reg [1:0]      r_cur_mats_add;
181
reg [2:0]      r_lat_cnt_pal;
182
reg            r_wait_end_pal_1z;
183
reg            r_wait_end_pal_2z;
184
reg            r_wait_end_pal_3z;
185
`endif
186
//////////////////////////////////
187
// wire
188
//////////////////////////////////
189
wire [21:0] w_vx_in;
190
wire [21:0] w_vy_in;
191
wire [21:0] w_vz_in;
192
wire [21:0] w_vw_in;
193
 
194
wire [21:0] w_m0_b;
195
wire [21:0] w_m1_b;
196
wire [21:0] w_m2_b;
197
wire [21:0] w_m3_b;
198
 
199
wire [21:0] w_m0_out;
200
wire [21:0] w_m1_out;
201
wire [21:0] w_m2_out;
202
wire [21:0] w_m3_out;
203
 
204
wire [21:0] w_add01_out;
205
wire [21:0] w_add23_out;
206
wire [21:0] w_add0123_out;
207
 
208
wire        w_set_vx;
209
wire        w_set_vy;
210
wire        w_set_vz;
211
wire        w_set_vw;
212
 
213
wire        w_cnt_clear;
214
wire        w_cnt_inc;
215
wire        w_wait_end;
216
wire        w_set_input;
217
wire        w_wait_calc_end;
218
`ifdef D3D_USE_MATRIX_PALETTE
219
 wire  [21:0] w_m00[`D3D_NUM_OF_MATS-1:0];
220
 wire  [21:0] w_m01[`D3D_NUM_OF_MATS-1:0];
221
 wire  [21:0] w_m02[`D3D_NUM_OF_MATS-1:0];
222
 wire  [21:0] w_m03[`D3D_NUM_OF_MATS-1:0];
223
 wire  [21:0] w_m10[`D3D_NUM_OF_MATS-1:0];
224
 wire  [21:0] w_m11[`D3D_NUM_OF_MATS-1:0];
225
 wire  [21:0] w_m12[`D3D_NUM_OF_MATS-1:0];
226
 wire  [21:0] w_m13[`D3D_NUM_OF_MATS-1:0];
227
 wire  [21:0] w_m20[`D3D_NUM_OF_MATS-1:0];
228
 wire  [21:0] w_m21[`D3D_NUM_OF_MATS-1:0];
229
 wire  [21:0] w_m22[`D3D_NUM_OF_MATS-1:0];
230
 wire  [21:0] w_m23[`D3D_NUM_OF_MATS-1:0];
231
 wire  [21:0] w_m30[`D3D_NUM_OF_MATS-1:0];
232
 wire  [21:0] w_m31[`D3D_NUM_OF_MATS-1:0];
233
 wire  [21:0] w_m32[`D3D_NUM_OF_MATS-1:0];
234
 wire  [21:0] w_m33[`D3D_NUM_OF_MATS-1:0];
235
 wire [21:0] w_addp_in0;
236
 wire [21:0] w_addp_in1;
237
 wire [21:0] w_addp_out;
238
 wire        w_pal_valid;
239
 wire [1:0]  w_mode;
240
`endif
241
//////////////////////////////////
242
// assign
243
//////////////////////////////////
244
assign o_state = (r_state == P_IDLE);
245
`ifdef D3D_USE_MATRIX_PALETTE
246
genvar gi;
247
generate for (gi=0;gi<`D3D_NUM_OF_MATS;gi=gi+1) begin : gen_mat
248
  assign w_m00[gi] = i_m00[22*(gi+1)-1:22*gi];
249
  assign w_m01[gi] = i_m01[22*(gi+1)-1:22*gi];
250
  assign w_m02[gi] = i_m02[22*(gi+1)-1:22*gi];
251
  assign w_m03[gi] = i_m03[22*(gi+1)-1:22*gi];
252
  assign w_m10[gi] = i_m10[22*(gi+1)-1:22*gi];
253
  assign w_m11[gi] = i_m11[22*(gi+1)-1:22*gi];
254
  assign w_m12[gi] = i_m12[22*(gi+1)-1:22*gi];
255
  assign w_m13[gi] = i_m13[22*(gi+1)-1:22*gi];
256
  assign w_m20[gi] = i_m20[22*(gi+1)-1:22*gi];
257
  assign w_m21[gi] = i_m21[22*(gi+1)-1:22*gi];
258
  assign w_m22[gi] = i_m22[22*(gi+1)-1:22*gi];
259
  assign w_m23[gi] = i_m23[22*(gi+1)-1:22*gi];
260
  assign w_m30[gi] = i_m30[22*(gi+1)-1:22*gi];
261
  assign w_m31[gi] = i_m31[22*(gi+1)-1:22*gi];
262
  assign w_m32[gi] = i_m32[22*(gi+1)-1:22*gi];
263
  assign w_m33[gi] = i_m33[22*(gi+1)-1:22*gi];
264
end
265
endgenerate
266
 
267
assign w_m0_b = (r_state == P_ROW1_IN) ? w_m10[r_cur_mats] :
268
                (r_state == P_ROW2_IN) ? w_m20[r_cur_mats] :
269
                (r_state == P_ROW3_IN) ? w_m30[r_cur_mats] : w_m00[r_cur_mats];
270
assign w_m1_b = (r_state == P_ROW1_IN) ? w_m11[r_cur_mats] :
271
                (r_state == P_ROW2_IN) ? w_m21[r_cur_mats] :
272
                (r_state == P_ROW3_IN) ? w_m31[r_cur_mats] : w_m01[r_cur_mats];
273
assign w_m2_b = (r_state == P_ROW1_IN) ? w_m12[r_cur_mats] :
274
                (r_state == P_ROW2_IN) ? w_m22[r_cur_mats] :
275
                (r_state == P_ROW3_IN) ? w_m32[r_cur_mats] : w_m02[r_cur_mats];
276
assign w_m3_b = (r_state == P_ROW1_IN) ? w_m13[r_cur_mats] :
277
                (r_state == P_ROW2_IN) ? w_m23[r_cur_mats] :
278
                (r_state == P_ROW3_IN) ? w_m33[r_cur_mats] : w_m03[r_cur_mats];
279
assign w_cnt_inc = (r_state == P_ROW1_IN) |
280
                   (r_state == P_ROW2_IN) |
281
                   (r_state == P_ROW3_IN) |
282
                   (r_state == P_NEW_MAT) |
283
                   (r_state == P_WAIT);
284
assign w_cnt_clear = ((r_state == P_IDLE) & i_en)
285
                     | (r_state == P_NEW_MAT);
286
assign w_wait_calc_end = (i_num_mats == 2'd0) ? r_wait_end_3z :
287
                         (r_add_state == P_ADD_WAIT);
288
assign w_addp_in0 = (r_add_state == P_ADD_Y) ? r_vy :
289
                    (r_add_state == P_ADD_Z) ? r_vz :
290
                    (r_add_state == P_ADD_W) ? r_vw : r_vx;
291
assign w_addp_in1 = w_add0123_out;
292
assign w_pal_valid = (r_add_state ==  P_ADD_IDLE) & w_wait_end &
293
                     (i_num_mats != 2'd0) & (r_cur_mats_add != 2'd0);
294
assign w_set_vx = (w_wait_end & (r_cur_mats_add == 2'd0)) | r_lat_cnt_pal[2];
295
assign w_set_vy = (r_wait_end_1z & (r_cur_mats_add == 2'd0)) | r_wait_end_pal_1z;
296
assign w_set_vz = (r_wait_end_2z & (r_cur_mats_add == 2'd0)) | r_wait_end_pal_2z;
297
assign w_set_vw = (r_wait_end_3z & (r_cur_mats_add == 2'd0)) | r_wait_end_pal_3z;
298
assign o_vx = f_div(r_vx,w_mode);
299
assign o_vy = f_div(r_vy,w_mode);
300
assign o_vz = f_div(r_vz,w_mode);
301
assign o_vw = f_div(r_vw,w_mode);
302
assign w_mode = (i_num_mats == 2'd0) ? 2'd0 :
303
                (i_num_mats == 2'd1) ? 2'd1 : 2'd2;
304
`else
305
assign w_m0_b = (r_state == P_ROW1_IN) ? i_m10 :
306
                (r_state == P_ROW2_IN) ? i_m20 :
307
                (r_state == P_ROW3_IN) ? i_m30 : i_m00;
308
assign w_m1_b = (r_state == P_ROW1_IN) ? i_m11 :
309
                (r_state == P_ROW2_IN) ? i_m21 :
310
                (r_state == P_ROW3_IN) ? i_m31 : i_m01;
311
assign w_m2_b = (r_state == P_ROW1_IN) ? i_m12 :
312
                (r_state == P_ROW2_IN) ? i_m22 :
313
                (r_state == P_ROW3_IN) ? i_m32 : i_m02;
314
assign w_m3_b = (r_state == P_ROW1_IN) ? i_m13 :
315
                (r_state == P_ROW2_IN) ? i_m23 :
316
                (r_state == P_ROW3_IN) ? i_m33 : i_m03;
317
assign w_cnt_inc = (r_state == P_ROW1_IN) |
318
                   (r_state == P_ROW2_IN) |
319
                   (r_state == P_ROW3_IN) |
320
                   (r_state == P_WAIT);
321
assign w_cnt_clear = (r_state == P_IDLE) & i_en;
322
assign w_wait_calc_end = r_wait_end_3z;
323
assign w_set_vx = w_wait_end;
324
assign w_set_vy = r_wait_end_1z;
325
assign w_set_vz = r_wait_end_2z;
326
assign w_set_vw = r_wait_end_3z;
327
assign o_vx = r_vx;
328
assign o_vy = r_vy;
329
assign o_vz = r_vz;
330
assign o_vw = r_vw;
331
`endif
332
 
333
assign o_ack = (r_state == P_IDLE);
334
assign o_en = (r_state == P_DONE);
335
 
336
generate
337
assign w_wait_end = (r_lat_cnt[P_ROW_LAT]);
338
endgenerate
339
assign w_set_input = (r_state == P_IDLE) & i_en;
340
assign w_vx_in = (r_state == P_IDLE) ? i_vx : r_vx_in;
341
assign w_vy_in = (r_state == P_IDLE) ? i_vy : r_vy_in;
342
assign w_vz_in = (r_state == P_IDLE) ? i_vz : r_vz_in;
343
assign w_vw_in = (r_state == P_IDLE) ? i_vw : r_vw_in;
344
//////////////////////////////////
345
// always
346
//////////////////////////////////
347
 
348
`ifdef D3D_SYNC_RESET
349
always @(posedge clk_core) begin
350
`else
351
always @(posedge clk_core or negedge rst_x) begin
352
`endif
353
  if (rst_x == `D3D_RESET_POL) begin
354
    r_wait_end_1z <= 1'b0;
355
    r_wait_end_2z <= 1'b0;
356
    r_wait_end_3z <= 1'b0;
357
  end else begin
358
    r_wait_end_1z <= w_wait_end;
359
    r_wait_end_2z <= r_wait_end_1z;
360
    r_wait_end_3z <= r_wait_end_2z;
361
  end
362
end
363
 
364
`ifdef D3D_SYNC_RESET
365
always @(posedge clk_core) begin
366
`else
367
always @(posedge clk_core or negedge rst_x) begin
368
`endif
369
  if (rst_x == `D3D_RESET_POL) begin
370
    r_lat_cnt <= 12'h0;
371
  end else begin
372
    if ((r_state != P_IDLE) | w_cnt_clear) r_lat_cnt = {r_lat_cnt[10:0],w_cnt_clear};
373
  end
374
end
375
 
376
always @(posedge clk_core) begin
377
`ifdef D3D_USE_MATRIX_PALETTE
378
  if (w_set_vx) r_vx <= (r_lat_cnt_pal[2]) ? w_addp_out : w_add0123_out;
379
  if (w_set_vy) r_vy <= (r_wait_end_pal_1z) ? w_addp_out : w_add0123_out;
380
  if (w_set_vz) r_vz <= (r_wait_end_pal_2z) ? w_addp_out : w_add0123_out;
381
  if (w_set_vw) r_vw <= (r_wait_end_pal_3z) ? w_addp_out : w_add0123_out;
382
`else
383
  if (w_set_vx) r_vx <= w_add0123_out;
384
  if (w_set_vy) r_vy <= w_add0123_out;
385
  if (w_set_vz) r_vz <= w_add0123_out;
386
  if (w_set_vw) r_vw <= w_add0123_out;
387
`endif
388
end
389
 
390
always @(posedge clk_core) begin
391
  if (w_set_input) begin
392
    r_vx_in <= i_vx;
393
    r_vy_in <= i_vy;
394
    r_vz_in <= i_vz;
395
    r_vw_in <= i_vw;
396
  end
397
end
398
/*
399
`ifdef D3D_SYNC_RESET
400
always @(posedge clk_core) begin
401
`else
402
always @(posedge clk_core or negedge rst_x) begin
403
`endif
404
  if (rst_x == `D3D_RESET_POL) begin
405
    r_state <= P_IDLE;
406
`ifdef D3D_USE_MATRIX_PALETTE
407
    r_cur_mats <= 2'd0;
408
`endif
409
  end else begin
410
    case (r_state)
411
      P_IDLE: begin
412
`ifdef D3D_USE_MATRIX_PALETTE
413
        r_cur_mats <= 2'd0;
414
`endif
415
        if (i_en) r_state <= P_ROW1_IN;
416
      end
417
      P_ROW1_IN: begin
418
       r_state <= P_ROW2_IN;
419
      end
420
      P_ROW2_IN: begin
421
       r_state <= P_ROW3_IN;
422
      end
423
      P_ROW3_IN: begin
424
`ifdef D3D_USE_MATRIX_PALETTE
425
        r_cur_mats <= r_cur_mats + 1'b1;
426
        if (r_cur_mats == i_num_mats) r_state <= P_WAIT;
427
        else r_state <= P_NEW_MAT;
428
`else
429
       r_state <= P_WAIT;
430
`endif
431
      end
432
`ifdef D3D_USE_MATRIX_PALETTE
433
      P_NEW_MAT: r_state <= P_ROW1_IN;
434
`endif
435
      P_WAIT: begin
436
       if (w_wait_calc_end) r_state <= P_DONE;
437
      end
438
      P_DONE: begin
439
       if (i_ack) r_state <= P_IDLE;
440
      end
441
    endcase
442
  end
443
end
444
*/
445
 
446
`ifdef D3D_SYNC_RESET
447
always @(posedge clk_core) begin
448
`else
449
always @(posedge clk_core or negedge rst_x) begin
450
`endif
451
  if (rst_x == `D3D_RESET_POL) begin
452
    r_state <= P_IDLE;
453
`ifdef D3D_USE_MATRIX_PALETTE
454
    r_cur_mats <= 2'd0;
455
`endif
456
  end else begin
457
    case (r_state)
458
      P_IDLE: begin
459
        if (i_en) r_state <= P_ROW1_IN;
460
      end
461
      P_ROW1_IN: begin
462
       r_state <= P_ROW2_IN;
463
      end
464
      P_ROW2_IN: begin
465
       r_state <= P_ROW3_IN;
466
      end
467
      P_ROW3_IN: begin
468
`ifdef D3D_USE_MATRIX_PALETTE
469
//        r_cur_mats <= r_cur_mats + 1'b1;
470
        if (r_cur_mats == i_num_mats) r_state <= P_WAIT;
471
        else r_state <= P_NEW_MAT;
472
`else
473
       r_state <= P_WAIT;
474
`endif
475
      end
476
`ifdef D3D_USE_MATRIX_PALETTE
477
      P_NEW_MAT: r_state <= P_ROW1_IN;
478
`endif
479
      P_WAIT: begin
480
       if (w_wait_calc_end) r_state <= P_DONE;
481
      end
482
      P_DONE: begin
483
`ifdef D3D_USE_MATRIX_PALETTE
484
        r_cur_mats <= 2'd0;
485
`endif
486
       if (i_ack) r_state <= P_IDLE;
487
      end
488
    endcase
489
  end
490
end
491
 
492
`ifdef D3D_USE_MATRIX_PALETTE
493
`ifdef D3D_SYNC_RESET
494
always @(posedge clk_core) begin
495
`else
496
always @(posedge clk_core or negedge rst_x) begin
497
`endif
498
  if (rst_x == `D3D_RESET_POL) begin
499
    r_add_state <= P_ADD_IDLE;
500
    r_cur_mats_add <= 2'd0;
501
  end else begin
502
    case (r_add_state)
503
      P_ADD_IDLE: begin
504
        if (w_wait_end) begin
505
          if (i_num_mats != 2'd0) r_add_state <= P_ADD_Y;
506
        end
507
      end
508
      P_ADD_Y: r_add_state <= P_ADD_Z;
509
      P_ADD_Z: r_add_state <= P_ADD_W;
510
      P_ADD_W: begin
511
        r_cur_mats_add <= r_cur_mats_add + 1'b1;
512
        if (r_cur_mats_add == i_num_mats) r_add_state <= P_ADD_WAIT;
513
        else r_add_state <= P_ADD_IDLE;
514
      end
515
      P_ADD_WAIT: begin
516
        r_add_state <= P_ADD_IDLE;
517
      end
518
    endcase
519
  end
520
end
521
 
522
`ifdef D3D_SYNC_RESET
523
always @(posedge clk_core) begin
524
`else
525
always @(posedge clk_core or negedge rst_x) begin
526
`endif
527
  if (rst_x == `D3D_RESET_POL) begin
528
    r_lat_cnt_pal <= 3'h0;
529
    r_wait_end_pal_1z <= 1'b0;
530
    r_wait_end_pal_2z <= 1'b0;
531
    r_wait_end_pal_3z <= 1'b0;
532
  end else begin
533
    r_lat_cnt_pal <= {r_lat_cnt_pal[1:0],w_pal_valid};
534
    r_wait_end_pal_1z <= r_lat_cnt_pal[2];
535
    r_wait_end_pal_2z <= r_wait_end_pal_1z;
536
    r_wait_end_pal_3z <= r_wait_end_pal_2z;
537
  end
538
end
539
 
540
 
541
`endif
542
 
543
//////////////////////////////////
544
// module instance
545
//////////////////////////////////
546
// m0[0..3] x vx
547
fm_3d_fmul u_fmul_m0 (
548
  .clk_core(clk_core),
549
  .i_en(1'b1),
550
  .i_a(w_vx_in),
551
  .i_b(w_m0_b),
552
  .o_c(w_m0_out)
553
);
554
 
555
// m1[0..3] x vy
556
fm_3d_fmul u_fmul_m1 (
557
  .clk_core(clk_core),
558
  .i_en(1'b1),
559
  .i_a(w_vy_in),
560
  .i_b(w_m1_b),
561
  .o_c(w_m1_out)
562
);
563
 
564
// m2[0..3] x vz
565
fm_3d_fmul u_fmul_m2 (
566
  .clk_core(clk_core),
567
  .i_en(1'b1),
568
  .i_a(w_vz_in),
569
  .i_b(w_m2_b),
570
  .o_c(w_m2_out)
571
);
572
 
573
// m3[0..3] x vw
574
fm_3d_fmul u_fmul_m3 (
575
  .clk_core(clk_core),
576
  .i_en(1'b1),
577
  .i_a(w_vw_in),
578
  .i_b(w_m3_b),
579
  .o_c(w_m3_out)
580
);
581
 
582
fm_3d_fadd u_fadd_m01 (
583
  .clk_core(clk_core),
584
  .i_en(1'b1),
585
  .i_a(w_m0_out),
586
  .i_b(w_m1_out),
587
  .i_adsb(1'b0),
588
  .o_c(w_add01_out)
589
);
590
 
591
fm_3d_fadd u_fadd_m23 (
592
  .clk_core(clk_core),
593
  .i_en(1'b1),
594
  .i_a(w_m2_out),
595
  .i_b(w_m3_out),
596
  .i_adsb(1'b0),
597
  .o_c(w_add23_out)
598
);
599
 
600
fm_3d_fadd u_fadd_m0123 (
601
  .clk_core(clk_core),
602
  .i_en(1'b1),
603
  .i_a(w_add01_out),
604
  .i_b(w_add23_out),
605
  .i_adsb(1'b0),
606
  .o_c(w_add0123_out)
607
);
608
 
609
`ifdef D3D_USE_MATRIX_PALETTE
610
fm_3d_fadd u_fadd_pal (
611
  .clk_core(clk_core),
612
  .i_en(1'b1),
613
  .i_a(w_addp_in0),
614
  .i_b(w_addp_in1),
615
  .i_adsb(1'b0),
616
  .o_c(w_addp_out)
617
);
618
 
619
function [21:0] f_div;
620
  input [21:0] id;
621
  input [1:0]  mode;  // 0: throudh, 1:div2, 2: div4
622
  reg    a_sign;
623
  reg [15:0]  a_fraction;
624
  reg [4:0]   a_exp;
625
  reg [5:0]   a_exp_t;
626
  reg [4:0]   a_exp_t2;
627
  reg [21:0] result;
628
  begin
629
    {a_sign,a_exp,a_fraction} = id;
630
    if (mode == 2'd1) a_exp_t = a_exp - 1'b1;
631
    else if (mode == 2'd2) a_exp_t = a_exp - 2'b10;
632
    else a_exp_t = a_exp;
633
    if (a_exp_t[5]) a_exp_t2 = 5'd0;
634
    else a_exp_t2 = a_exp_t[4:0];
635
    result = {a_sign,a_exp_t2,a_fraction};
636
    f_div = result;
637
  end
638
endfunction
639
 
640
`endif
641
 
642
endmodule

powered by: WebSVN 2.1.0

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