Ghidra Decompiler Analysis Engine
Public Types | Public Member Functions | List of all members
FloatFormat Class Reference

Encoding information for a single floating-point format. More...

#include <float.hh>

Public Types

enum  floatclass {
  normalized = 0, infinity = 1, zero = 2, nan = 3,
  denormalized = 4
}
 The various classes of floating-point encodings. More...
 

Public Member Functions

 FloatFormat (int4 sz)
 Construct default IEEE 754 standard settings. More...
 
double getHostFloat (uintb encoding, floatclass *type) const
 Convert an encoding into host's double. More...
 
uintb getEncoding (double host) const
 Convert host's double into this encoding. More...
 
uintb convertEncoding (uintb encoding, const FloatFormat *formin) const
 Convert between two different formats. More...
 
uintb extractFractionalCode (uintb x) const
 Extract the fractional part of the encoding. More...
 
bool extractSign (uintb x) const
 Extract the sign bit from the encoding. More...
 
int4 extractExponentCode (uintb x) const
 Extract the exponent from the encoding. More...
 
uintb opEqual (uintb a, uintb b) const
 Equality comparison (==) More...
 
uintb opNotEqual (uintb a, uintb b) const
 Inequality comparison (!=) More...
 
uintb opLess (uintb a, uintb b) const
 Less-than comparison (<) More...
 
uintb opLessEqual (uintb a, uintb b) const
 Less-than-or-equal comparison (<=) More...
 
uintb opNan (uintb a) const
 Test if Not-a-Number (NaN) More...
 
uintb opAdd (uintb a, uintb b) const
 Addition (+) More...
 
uintb opDiv (uintb a, uintb b) const
 Division (/) More...
 
uintb opMult (uintb a, uintb b) const
 Multiplication (*) More...
 
uintb opSub (uintb a, uintb b) const
 Subtraction (-) More...
 
uintb opNeg (uintb a) const
 Unary negate. More...
 
uintb opAbs (uintb a) const
 Absolute value (abs) More...
 
uintb opSqrt (uintb a) const
 Square root (sqrt) More...
 
uintb opTrunc (uintb a, int4 sizeout) const
 Convert floating-point to integer. More...
 
uintb opCeil (uintb a) const
 Ceiling (ceil) More...
 
uintb opFloor (uintb a) const
 Floor (floor) More...
 
uintb opRound (uintb a) const
 Round. More...
 
uintb opInt2Float (uintb a, int4 sizein) const
 Convert integer to floating-point. More...
 
uintb opFloat2Float (uintb a, const FloatFormat &outformat) const
 Convert between floating-point precisions. More...
 
void saveXml (ostream &s) const
 Save the format to an XML stream. More...
 
void restoreXml (const Element *el)
 Restore the format from XML. More...
 

Detailed Description

Encoding information for a single floating-point format.

This class supports manipulation of a single floating-point encoding. An encoding can be converted to and from the host format and convenience methods allow p-code floating-point operations to be performed on natively encoded operands. This follows the IEEE754 standards.

Member Enumeration Documentation

◆ floatclass

The various classes of floating-point encodings.

Enumerator
normalized 

A normal floating-point number.

infinity 

An encoding representing an infinite value.

zero 

An encoding of the value zero.

nan 

An invalid encoding, Not-a-Number.

denormalized 

A denormalized encoding (for very small values)

Constructor & Destructor Documentation

◆ FloatFormat()

FloatFormat::FloatFormat ( int4  sz)

Construct default IEEE 754 standard settings.

Set format for a given encoding size according to IEEE 754 standards

Parameters
szis the size of the encoding in bytes

Member Function Documentation

◆ convertEncoding()

uintb FloatFormat::convertEncoding ( uintb  encoding,
const FloatFormat formin 
) const

Convert between two different formats.

Parameters
encodingis the value in the other FloatFormat
forminis the other FloatFormat
Returns
the equivalent value in this FloatFormat

◆ extractExponentCode()

int4 FloatFormat::extractExponentCode ( uintb  x) const

Extract the exponent from the encoding.

Parameters
xis an encoded floating-point value
Returns
the (signed) exponent

◆ extractFractionalCode()

uintb FloatFormat::extractFractionalCode ( uintb  x) const

Extract the fractional part of the encoding.

Parameters
xis an encoded floating-point value
Returns
the fraction part of the value aligned to the top of the word

◆ extractSign()

bool FloatFormat::extractSign ( uintb  x) const

Extract the sign bit from the encoding.

Parameters
xis an encoded floating-point value
Returns
the sign bit

◆ getEncoding()

uintb FloatFormat::getEncoding ( double  host) const

Convert host's double into this encoding.

Parameters
hostis the double value to convert
Returns
the equivalent encoded value

◆ getHostFloat()

double FloatFormat::getHostFloat ( uintb  encoding,
floatclass type 
) const

Convert an encoding into host's double.

Parameters
encodingis the encoding value
typepoints to the floating-point class, which is passed back
Returns
the equivalent double value

◆ opAbs()

uintb FloatFormat::opAbs ( uintb  a) const

Absolute value (abs)

Parameters
ais an encoded floating-point value
Returns
abs(a)

◆ opAdd()

uintb FloatFormat::opAdd ( uintb  a,
uintb  b 
) const

Addition (+)

Parameters
ais the first floating-point value
bis the second floating-point value
Returns
a + b

◆ opCeil()

uintb FloatFormat::opCeil ( uintb  a) const

Ceiling (ceil)

Parameters
ais an encoded floating-point value
Returns
ceil(a)

◆ opDiv()

uintb FloatFormat::opDiv ( uintb  a,
uintb  b 
) const

Division (/)

Parameters
ais the first floating-point value
bis the second floating-point value
Returns
a / b

◆ opEqual()

uintb FloatFormat::opEqual ( uintb  a,
uintb  b 
) const

Equality comparison (==)

Parameters
ais the first floating-point value
bis the second floating-point value
Returns
true if (a == b)

◆ opFloat2Float()

uintb FloatFormat::opFloat2Float ( uintb  a,
const FloatFormat outformat 
) const

Convert between floating-point precisions.

Parameters
ais an encoded floating-point value
outformatis the desired output FloatFormat
Returns
a converted to the output FloatFormat

◆ opFloor()

uintb FloatFormat::opFloor ( uintb  a) const

Floor (floor)

Parameters
ais an encoded floating-point value
Returns
floor(a)

◆ opInt2Float()

uintb FloatFormat::opInt2Float ( uintb  a,
int4  sizein 
) const

Convert integer to floating-point.

Parameters
ais a signed integer value
sizeinis the number of bytes in the integer encoding
Returns
a converted to an encoded floating-point value

◆ opLess()

uintb FloatFormat::opLess ( uintb  a,
uintb  b 
) const

Less-than comparison (<)

Parameters
ais the first floating-point value
bis the second floating-point value
Returns
true if (a < b)

◆ opLessEqual()

uintb FloatFormat::opLessEqual ( uintb  a,
uintb  b 
) const

Less-than-or-equal comparison (<=)

Parameters
ais the first floating-point value
bis the second floating-point value
Returns
true if (a <= b)

◆ opMult()

uintb FloatFormat::opMult ( uintb  a,
uintb  b 
) const

Multiplication (*)

Parameters
ais the first floating-point value
bis the second floating-point value
Returns
a * b

◆ opNan()

uintb FloatFormat::opNan ( uintb  a) const

Test if Not-a-Number (NaN)

Parameters
ais an encoded floating-point value
Returns
true if a is Not-a-Number

◆ opNeg()

uintb FloatFormat::opNeg ( uintb  a) const

Unary negate.

Parameters
ais an encoded floating-point value
Returns
-a

◆ opNotEqual()

uintb FloatFormat::opNotEqual ( uintb  a,
uintb  b 
) const

Inequality comparison (!=)

Parameters
ais the first floating-point value
bis the second floating-point value
Returns
true if (a != b)

◆ opRound()

uintb FloatFormat::opRound ( uintb  a) const

Round.

Parameters
ais an encoded floating-point value
Returns
round(a)

◆ opSqrt()

uintb FloatFormat::opSqrt ( uintb  a) const

Square root (sqrt)

Parameters
ais an encoded floating-point value
Returns
sqrt(a)

◆ opSub()

uintb FloatFormat::opSub ( uintb  a,
uintb  b 
) const

Subtraction (-)

Parameters
ais the first floating-point value
bis the second floating-point value
Returns
a - b

◆ opTrunc()

uintb FloatFormat::opTrunc ( uintb  a,
int4  sizeout 
) const

Convert floating-point to integer.

Parameters
ais an encoded floating-point value
sizeoutis the desired encoding size of the output
Returns
an integer encoding of a

◆ restoreXml()

void FloatFormat::restoreXml ( const Element el)

Restore the format from XML.

Restore object from a <floatformat> XML tag

Parameters
elis the element

◆ saveXml()

void FloatFormat::saveXml ( ostream &  s) const

Save the format to an XML stream.

Write the format out to a <floatformat> XML tag.

Parameters
sis the output stream

The documentation for this class was generated from the following files: