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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [rtl/] [core/] [fm_3d_fcnv.v] - Blame information for rev 4

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_fcnv.v
7
//
8
// Abstract:
9
//   3D float conversion IEEE single floating point number to
10
//   22-bits floating point number
11
//
12
// Author:
13 4 specular
//   Kenji Ishimaru (info.wf3d@gmail.com)
14 2 specular
//
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_fcnv (
44
  i_f32,
45
  o_f22
46
);
47
 
48
////////////////////////////
49
// I/O definition
50
////////////////////////////
51
    input  [31:0] i_f32;
52
    output [21:0] o_f22;
53
 
54
////////////////////////////
55
// assign
56
////////////////////////////
57
    assign o_f22 = f_f32_to_f22(i_f32);
58
////////////////////////////
59
// function
60
////////////////////////////
61
    function [21:0] f_f32_to_f22;
62
        input [31:0] f32;
63
        reg s;
64
        reg [7:0]  e8;
65
        reg [8:0]  e8d;  // width sign bit
66
        reg [4:0]  e5;
67
        reg [23:0] m23;
68
        reg [14:0] m15;
69
        reg        carry;
70
        reg        zf;
71
        begin
72
            s = f32[31];
73
            e8 = f32[30:23];
74
            zf = (e8 == 8'h00);
75
            m23 = f32[22:0];
76
            {carry,m15} = m23[22:8] + m23[7];
77
            e8d = e8 - 112 + carry;  // -127+15 + carry
78
            if (zf|e8d[8]) begin
79
                e5 = 5'h0;
80
            end else begin
81
                e5 = e8d[4:0];
82
            end
83
            f_f32_to_f22 = {s,e5,!(zf|e8d[8]),m15};
84
        end
85
    endfunction
86
 
87
endmodule

powered by: WebSVN 2.1.0

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