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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [rtl/] [core/] [fm_3d_fmul.v] - Blame information for rev 3

Go to most recent revision | 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_3d_fmul.v
7
//
8
// Abstract:
9
//   floating point multiplyer, latency = 3
10
//
11
// Author:
12
//   Kenji Ishimaru (kenji.ishimaru@prtissimo.com)
13
//
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
module fm_3d_fmul (
43
  clk_core,
44
  i_en,
45
  i_a,
46
  i_b,
47
  o_c
48
);
49
 
50
///////////////////////////////////////////
51
//  port definition
52
///////////////////////////////////////////
53
    input         clk_core;
54
    input         i_en;
55
    input  [21:0] i_a;
56
    input  [21:0] i_b;
57
    output [21:0] o_c;
58
 
59
///////////////////////////////////////////
60
//  register
61
///////////////////////////////////////////
62
    reg    [21:0] r_c;
63
 
64
    reg           r_sign_1z;
65
    reg           r_sign_2z;
66
    reg    [17:0] r_cf_tmp;
67
    reg    [4:0]  r_ce_tmp_1z;
68
    reg    [4:0]  r_ce_tmp_2z;
69
    reg    [16:0] r_cf_tmp2;
70
 
71
///////////////////////////////////////////
72
//  wire definition
73
///////////////////////////////////////////
74
    // input data separation
75
    wire        w_a_sign;
76
    wire [15:0] w_a_fraction;
77
    wire [4:0]  w_a_exp;
78
    wire        w_b_sign;
79
    wire [15:0] w_b_fraction;
80
    wire [4:0]  w_b_exp;
81
 
82
    // intermidiate wire
83
    wire [5:0]  w_adder_out;   // result of exp addition
84
    wire        w_sign;
85
    wire [31:0] w_cf_tmp;      // multplyer out 1.15 * 1.15 = 2.30
86
    wire [16:0] w_cf_tmp2;     // multplyer out (rounded) 2.15
87
    wire [4:0]  w_ce_tmp;      // temporary exp out
88
    wire [21:0] w_c;
89
///////////////////////////////////////////
90
//  stage0
91
///////////////////////////////////////////
92
    // separate input and add implied fraction msb
93
    assign w_a_sign = i_a[21];
94
    assign w_a_exp  = i_a[20:16];
95
    assign w_a_fraction = i_a[15:0];
96
 
97
    assign w_b_sign = i_b[21];
98
    assign w_b_exp  = i_b[20:16];
99
    assign w_b_fraction = i_b[15:0];
100
 
101
    // exponent calculation
102
    //    (ea + eb - bias)
103
    wire [5:0] w_exp_add;
104
    assign w_exp_add = w_a_exp + w_b_exp;
105
    assign w_adder_out = w_exp_add -  4'hf;
106
    assign w_ce_tmp = (w_exp_add < 5'hf) ? 5'h00 :
107
                      (w_adder_out[5])   ? 5'h1f :
108
                                           w_adder_out[4:0];
109
    assign w_sign = w_a_sign ^ w_b_sign;
110
    // fraction multiplyer
111
    assign w_cf_tmp = w_a_fraction * w_b_fraction;
112
 
113
///////////////////////////////////////////
114
//  stage1
115
///////////////////////////////////////////
116
    always @(posedge clk_core) begin
117
        if (i_en) begin
118
            r_sign_1z <= w_sign;
119
            r_cf_tmp <= w_cf_tmp[31:14];
120
            r_ce_tmp_1z <= w_ce_tmp;
121
        end
122
    end
123
    // round
124
    //assign w_cf_tmp2 = w_cf_tmp[14] ? w_cf_tmp[31:15] + 1'b1 :
125
    //                                  w_cf_tmp[31:15];
126
    wire [16:0] w_rounded;
127
    assign w_rounded = r_cf_tmp[17:1] + 1'b1;
128
    assign w_cf_tmp2 = r_cf_tmp[0] ?  w_rounded :               // 2.15
129
                                      r_cf_tmp[17:1];
130
 
131
 
132
 
133
///////////////////////////////////////////
134
//  stage2
135
///////////////////////////////////////////
136
    always @(posedge clk_core) begin
137
        if (i_en) begin
138
            r_sign_2z <= r_sign_1z;
139
            r_ce_tmp_2z <= r_ce_tmp_1z;
140
            r_cf_tmp2 <= w_cf_tmp2;
141
        end
142
    end
143
 
144
// normalize
145
    fm_3d_norm norm (
146
        .i_s(r_sign_2z),
147
        .i_e(r_ce_tmp_2z),
148
        .i_f(r_cf_tmp2),
149
        .o_b(w_c)
150
    );
151
 
152
 
153
///////////////////////////////////////////
154
//  stage3
155
///////////////////////////////////////////
156
    // final register
157
    always @(posedge clk_core) begin
158
        if (i_en) r_c <= w_c;
159
    end
160
 
161
    // output port connection
162
    assign o_c = r_c;
163
endmodule

powered by: WebSVN 2.1.0

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