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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [Float128.h] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
#pragma once
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2016-2017  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch<remove>@finitron.ca
7
//       ||
8
//
9
// 128 bit floating point class
10
//
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
// Floats here are actually represented with a 128 bit mantissa for simpliity
25
// rather than 112 bits.
26
// ============================================================================
27
//
28
#define FLT128_WORDS    4
29
#define FLT_PREC                64
30
 
31
class Float128
32
{
33
public:
34
        static const __int16 bias = 0x3FFF;
35
        static const __int16 infxp = 0x7FFF;
36
public:
37
        unsigned __int32 pack[4];
38
        unsigned __int32 man[FLT128_WORDS];
39
        unsigned __int16 exp;
40
        bool sign;
41
        // The following is for compiler use
42
        //-----------------------------------
43
        Float128 *next; // next in a list
44
        int label;
45
        char *nmspace;
46
        //-----------------------------------
47
        void ShiftManLeft();
48
private:
49
        void ShiftManRight();
50
        static bool ManEQ(Float128 *a, Float128 *b);
51
        static bool ManGT(Float128 *a, Float128 *b);
52
        static bool ManGE(Float128 *a, Float128 *b) {
53
                if (ManGT(a,b))
54
                        return (true);
55
                if (ManEQ(a,b))
56
                        return (true);
57
                return (false);
58
        };
59
        static bool AddMan(Float128 *s, Float128 *a, Float128 *b);
60
        static bool SubMan(Float128 *d, Float128 *a, Float128 *b);
61
        void Denormalize(unsigned __int16 xp);
62
        void Denorm1();
63
public:
64
        Float128() {
65
                Zeroman();
66
                exp = 0;
67
                sign = false;
68
        };
69
        Float128(Float128 *a);
70
        void Zeroman() {
71
                int nn;
72
                for (nn = 0; nn < FLT128_WORDS; nn++)
73
                        man[nn] = 0;
74
        };
75
        static Float128 *Zero() {
76
                static Float128 p;
77
                p.Zeroman();
78
                p.exp = 0x0000;
79
                return (&p);
80
        };
81
        static Float128 *One() {
82
                static Float128 p;
83
                p.Zeroman();
84
                p.man[FLT128_WORDS-1] = 0x40000000;
85
                p.exp = 0x3FFF;
86
                return (&p);
87
        };
88
        static Float128 *Ten() {
89
                static Float128 p;
90
                p.Zeroman();
91
                p.man[FLT128_WORDS-1] = 0x50000000;
92
                p.exp = 0x4002;
93
                return (&p);
94
        };
95
        static Float128 *OneTenth() {
96
                int nn;
97
                static Float128 p;
98
                for (nn = 0; nn < FLT128_WORDS; nn++)
99
                        p.man[nn] = 0x66666666;
100
                p.exp = 0x3FFB;
101
                return (&p);
102
        };
103
        static Float128 *FloatMax() {
104
                int nn;
105
                static Float128 p;
106
                for (nn = 0; nn < FLT128_WORDS; nn++)
107
                        p.man[nn] = 0xFFFFFFFF;
108
                for (nn = 0; nn < FLT128_WORDS/2; nn++)
109
                        p.man[nn] = 0;
110
                for (; nn < FLT128_WORDS-1; nn++)
111
                        p.man[nn] = 0xFFFFFFFF;
112
                p.man[FLT128_WORDS/2-1] = 0x80000000;
113
                p.man[FLT128_WORDS-1] = 0x7FFFFFFF;
114
                p.exp = 0x7FFE;
115
                return (&p);
116
        };
117
        static Float128 *Neg(Float128 *p) {
118
                Float128 *q = new Float128;
119
                q->sign = !p->sign;
120
                return q;
121
        };
122
        static void Add(Float128 *s, Float128 *a, Float128 *b);
123
        static void Sub(Float128 *d, Float128 *a, Float128 *b) {
124
                Float128 *b1 = Neg(b);
125
                Add(d, a, b1);
126
                delete b1;
127
        };
128
        static void Mul(Float128 *p, Float128 *a, Float128 *b);
129
        static void Div(Float128 *q, Float128 *a, Float128 *b);
130
        static void Assign(Float128 *d, Float128 *s) {
131
                int nn;
132
                for (nn = 0; nn < FLT128_WORDS; nn++)
133
                        d->man[nn] = s->man[nn];
134
                d->exp = s->exp;
135
                d->sign = s->sign;
136
        };
137
        static void Normalize(Float128 *a);
138
        static void IntToFloat(Float128 *d, __int64 v);
139
        static void FloatToInt(__int64 *i, Float128 *a);
140
        static void Float128ToDouble(double *d, Float128 *a);
141
        void Pack(int);
142
        char *ToString();
143
        char *ToString(int);
144
        bool IsManZero() const;
145
        bool IsZero() const;
146
        bool IsInfinite() const;
147
        static bool IsEqual(Float128 *a, Float128 *b);
148
        static bool IsEqualNZ(Float128 *a, Float128 *b);
149
        static bool IsNaN(Float128 *a);
150
        bool IsNaN() { return (IsNaN(this)); };
151
};

powered by: WebSVN 2.1.0

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