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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [rtl/] [core/] [fm_3d_frcp.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_frcp.v
7
//
8
// Abstract:
9
//   floating point 1/x, latency = 2
10
//     if i_a = 0, o_c = 0
11
//
12
// Author:
13
//   Kenji Ishimaru (kenji.ishimaru@prtissimo.com)
14
//
15
//======================================================================
16
//
17
// Copyright (c) 2015, Kenji Ishimaru
18
// All rights reserved.
19
//
20
// Redistribution and use in source and binary forms, with or without
21
// modification, are permitted provided that the following conditions are met:
22
//
23
//  -Redistributions of source code must retain the above copyright notice,
24
//   this list of conditions and the following disclaimer.
25
//  -Redistributions in binary form must reproduce the above copyright notice,
26
//   this list of conditions and the following disclaimer in the documentation
27
//   and/or other materials provided with the distribution.
28
//
29
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
31
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
33
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
36
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
37
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
38
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
39
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
//
41
// Revision History
42
 
43
module fm_3d_frcp (
44
  clk_core,
45
  i_en,
46
  i_a,
47
  o_c
48
);
49
 
50
////////////////////////////
51
// I/O definition
52
////////////////////////////
53
    input         clk_core;
54
    input         i_en;
55
    input  [21:0] i_a;          // input A
56
    output [21:0] o_c;          // result
57
 
58
 
59
///////////////////////////////////////////
60
//  register definition
61
///////////////////////////////////////////
62
    reg    [21:0] r_c;           // result
63
 
64
    reg           r_a_sign;
65
    reg    [4:0]  r_ce_tmp;
66
    reg    [7:0]  r_a_frac_l;
67
 
68
///////////////////////////////////////////
69
//  wire 
70
///////////////////////////////////////////
71
    wire          w_a_sign;
72
    wire   [4:0]  w_a_exp;
73
    wire   [15:0] w_a_fraction;
74
    wire   [4:0]  w_2bias;
75
    wire   [4:0]  w_ce_tmp;
76
    wire   [15:0] w_cf_tmp;
77
    wire   [31:0] w_rom_out;
78
    wire   [15:0] w_rom_base;
79
    wire   [15:0] w_rom_diff;
80
    wire   [6:0]  w_rom_address;
81
    wire   [7:0]  w_a_frac_l;
82
    //wire   [31:0] w_rom_correct;
83
    wire   [23:0] w_rom_correct;
84
    wire   [21:0] w_c;
85
    wire          w_zero_flag;
86
///////////////////////////////////////////
87
//  assign
88
///////////////////////////////////////////
89
    assign w_a_sign = i_a[21];
90
    assign w_a_exp = i_a[20:16];
91
    assign w_a_fraction = i_a[15:0];
92
    assign w_2bias = 5'h1e;  // x2
93
    assign w_ce_tmp = w_2bias - w_a_exp;
94
 
95
    assign w_rom_address = w_a_fraction[14:8];
96
    assign w_a_frac_l = w_a_fraction[7:0];
97
/* // original implementation
98
    assign w_rom_base = w_rom_out[31:16];   // 1.15
99
    assign w_rom_diff = w_rom_out[15:0];    // 0.16
100
    assign w_rom_correct = w_rom_diff * {r_a_frac_l,8'b0};
101
    assign w_cf_tmp = w_rom_base - {1'b0,w_rom_correct[31:17]};
102
*/
103
    // timing improvement
104
    assign w_rom_base = w_rom_out[31:16];   // 1.15
105
    assign w_rom_diff = w_rom_out[15:0];    // 0.16
106
    assign w_rom_correct = w_rom_diff * r_a_frac_l;
107
    assign w_cf_tmp = w_rom_base - {1'b0,w_rom_correct[23:9]};
108
 
109
    assign w_zero_flag = (w_a_exp == 5'h0);
110
 
111
    // output port
112
    assign o_c = r_c;
113
 
114
///////////////////////////////////////////
115
//  always statement
116
///////////////////////////////////////////
117
 
118
    always @(posedge clk_core) begin
119
        if (i_en) begin
120
            r_a_sign <= w_a_sign;
121
            r_ce_tmp <= w_ce_tmp;
122
            r_a_frac_l <= w_a_frac_l;
123
        end
124
    end
125
 
126
    always @(posedge clk_core) begin
127
        if (i_en) begin
128
            r_c <= (w_zero_flag) ? 16'h0 : w_c;
129
        end
130
    end
131
 
132
 
133
///////////////////////////////////////////
134
//  module instance
135
///////////////////////////////////////////
136
// table rom
137
    fm_3d_frcp_rom frcp_rom (
138
        .clk_core(clk_core),
139
        .i_a(w_rom_address),
140
        .o_c(w_rom_out)
141
    );
142
// normalize
143
    fm_3d_norm norm (
144
        .i_s(r_a_sign),
145
        .i_e(r_ce_tmp),
146
        .i_f({1'b0,w_cf_tmp[15:0]}),
147
        .o_b(w_c)
148
    );
149
 
150
endmodule

powered by: WebSVN 2.1.0

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