My Project
float.hh
Go to the documentation of this file.
1 /* ###
2  * IP: GHIDRA
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
18 
19 #ifndef __CPUI_FLOATFORMAT__
20 #define __CPUI_FLOATFORMAT__
21 
22 #include "xml.hh"
23 
30 class FloatFormat {
31 public:
33  enum floatclass {
34  normalized = 0,
35  infinity = 1,
36  zero = 2,
37  nan = 3,
39  };
40 private:
41  int4 size;
42  int4 signbit_pos;
43  int4 frac_pos;
44  int4 frac_size;
45  int4 exp_pos;
46  int4 exp_size;
47  int4 bias;
48  int4 maxexponent;
49  bool jbitimplied;
50  static double createFloat(bool sign,uintb signif,int4 exp);
51  static floatclass extractExpSig(double x,bool *sgn,uintb *signif,int4 *exp);
52  uintb setFractionalCode(uintb x,uintb code) const;
53  uintb setSign(uintb x,bool sign) const;
54  uintb setExponentCode(uintb x,uintb code) const;
55  uintb getZeroEncoding(bool sgn) const;
56  uintb getInfinityEncoding(bool sgn) const;
57  uintb getNaNEncoding(bool sgn) const;
58 public:
59  FloatFormat(void) {}
60  FloatFormat(int4 sz);
61  int4 getSize(void) const { return size; }
62  double getHostFloat(uintb encoding,floatclass *type) const;
63  uintb getEncoding(double host) const;
64  uintb convertEncoding(uintb encoding,const FloatFormat *formin) const;
65 
66  uintb extractFractionalCode(uintb x) const;
67  bool extractSign(uintb x) const;
68  int4 extractExponentCode(uintb x) const;
69 
70  // Operations on floating point values
71 
72  uintb opEqual(uintb a,uintb b) const;
73  uintb opNotEqual(uintb a,uintb b) const;
74  uintb opLess(uintb a,uintb b) const;
75  uintb opLessEqual(uintb a,uintb b) const;
76  uintb opNan(uintb a) const;
77  uintb opAdd(uintb a,uintb b) const;
78  uintb opDiv(uintb a,uintb b) const;
79  uintb opMult(uintb a,uintb b) const;
80  uintb opSub(uintb a,uintb b) const;
81  uintb opNeg(uintb a) const;
82  uintb opAbs(uintb a) const;
83  uintb opSqrt(uintb a) const;
84  uintb opTrunc(uintb a,int4 sizeout) const;
85  uintb opCeil(uintb a) const;
86  uintb opFloor(uintb a) const;
87  uintb opRound(uintb a) const;
88  uintb opInt2Float(uintb a,int4 sizein) const;
89  uintb opFloat2Float(uintb a,const FloatFormat &outformat) const;
90 
91  void saveXml(ostream &s) const;
92  void restoreXml(const Element *el);
93 };
94 
95 #endif
A normal floating-point number.
Definition: float.hh:34
uintb opNotEqual(uintb a, uintb b) const
Inequality comparison (!=)
Definition: float.cc:365
uintb opAdd(uintb a, uintb b) const
Addition (+)
Definition: float.cc:415
uintb opFloor(uintb a) const
Floor (floor)
Definition: float.cc:539
uintb opLessEqual(uintb a, uintb b) const
Less-than-or-equal comparison (<=)
Definition: float.cc:391
void restoreXml(const Element *el)
Restore the format from XML.
Definition: float.cc:576
uintb opInt2Float(uintb a, int4 sizein) const
Convert integer to floating-point.
Definition: float.cc:493
uintb opMult(uintb a, uintb b) const
Multiplication (*)
Definition: float.cc:439
bool extractSign(uintb x) const
Extract the sign bit from the encoding.
Definition: float.cc:136
void saveXml(ostream &s) const
Save the format to an XML stream.
Definition: float.cc:559
uintb opDiv(uintb a, uintb b) const
Division (/)
Definition: float.cc:427
uintb opEqual(uintb a, uintb b) const
Equality comparison (==)
Definition: float.cc:352
floatclass
The various classes of floating-point encodings.
Definition: float.hh:33
int4 getSize(void) const
Get the size of the encoding in bytes.
Definition: float.hh:61
An invalid encoding, Not-a-Number.
Definition: float.hh:37
uintb extractFractionalCode(uintb x) const
Extract the fractional part of the encoding.
Definition: float.cc:126
uintb opLess(uintb a, uintb b) const
Less-than comparison (<)
Definition: float.cc:378
uintb opSub(uintb a, uintb b) const
Subtraction (-)
Definition: float.cc:451
Lightweight (and incomplete) XML parser for marshaling data to and from the decompiler.
uintb opNeg(uintb a) const
Unary negate.
Definition: float.cc:462
uintb opAbs(uintb a) const
Absolute value (abs)
Definition: float.cc:472
An encoding representing an infinite value.
Definition: float.hh:35
uintb opRound(uintb a) const
Round.
Definition: float.cc:549
uintb opTrunc(uintb a, int4 sizeout) const
Convert floating-point to integer.
Definition: float.cc:516
uintb opNan(uintb a) const
Test if Not-a-Number (NaN)
Definition: float.cc:403
An XML element. A node in the DOM tree.
Definition: xml.hh:150
uintb opFloat2Float(uintb a, const FloatFormat &outformat) const
Convert between floating-point precisions.
Definition: float.cc:505
double getHostFloat(uintb encoding, floatclass *type) const
Convert an encoding into host&#39;s double.
Definition: float.cc:233
uintb opSqrt(uintb a) const
Square root (sqrt)
Definition: float.cc:482
uintb getEncoding(double host) const
Convert host&#39;s double into this encoding.
Definition: float.cc:277
A denormalized encoding (for very small values)
Definition: float.hh:38
Encoding information for a single floating-point format.
Definition: float.hh:30
uintb convertEncoding(uintb encoding, const FloatFormat *formin) const
Convert between two different formats.
Definition: float.cc:311
An encoding of the value zero.
Definition: float.hh:36
uintb opCeil(uintb a) const
Ceiling (ceil)
Definition: float.cc:529
int4 extractExponentCode(uintb x) const
Extract the exponent from the encoding.
Definition: float.cc:145
FloatFormat(void)
Construct for use with restoreXml()
Definition: float.hh:59