Ghidra 11.3.2
Ghidra internal decompiler documentation.
|
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. | |
int4 | getSize (void) const |
Get the size of the encoding in bytes. | |
double | getHostFloat (uintb encoding, floatclass *type) const |
Convert an encoding into host's double. | |
uintb | getEncoding (double host) const |
Convert host's double into this encoding. | |
uintb | convertEncoding (uintb encoding, const FloatFormat *formin) const |
Convert between two different formats. | |
uintb | extractFractionalCode (uintb x) const |
Extract the fractional part of the encoding. | |
bool | extractSign (uintb x) const |
Extract the sign bit from the encoding. | |
int4 | extractExponentCode (uintb x) const |
Extract the exponent from the encoding. | |
string | printDecimal (double host, bool forcesci) const |
Print given value as a decimal string. | |
uintb | opEqual (uintb a, uintb b) const |
Equality comparison (==) | |
uintb | opNotEqual (uintb a, uintb b) const |
Inequality comparison (!=) | |
uintb | opLess (uintb a, uintb b) const |
Less-than comparison (<) | |
uintb | opLessEqual (uintb a, uintb b) const |
Less-than-or-equal comparison (<=) | |
uintb | opNan (uintb a) const |
Test if Not-a-Number (NaN) | |
uintb | opAdd (uintb a, uintb b) const |
Addition (+) | |
uintb | opDiv (uintb a, uintb b) const |
Division (/) | |
uintb | opMult (uintb a, uintb b) const |
Multiplication (*) | |
uintb | opSub (uintb a, uintb b) const |
Subtraction (-) | |
uintb | opNeg (uintb a) const |
Unary negate. | |
uintb | opAbs (uintb a) const |
Absolute value (abs) | |
uintb | opSqrt (uintb a) const |
Square root (sqrt) | |
uintb | opTrunc (uintb a, int4 sizeout) const |
Convert floating-point to integer. | |
uintb | opCeil (uintb a) const |
Ceiling (ceil) | |
uintb | opFloor (uintb a) const |
Floor (floor) | |
uintb | opRound (uintb a) const |
Round. | |
uintb | opInt2Float (uintb a, int4 sizein) const |
Convert integer to floating-point. | |
uintb | opFloat2Float (uintb a, const FloatFormat &outformat) const |
Convert between floating-point precisions. | |
Private Member Functions | |
uintb | setFractionalCode (uintb x, uintb code) const |
Set the fractional part of an encoded value. | |
uintb | setSign (uintb x, bool sign) const |
Set the sign bit of an encoded value. | |
uintb | setExponentCode (uintb x, uintb code) const |
Set the exponent of an encoded value. | |
uintb | getZeroEncoding (bool sgn) const |
Get an encoded zero value. | |
uintb | getInfinityEncoding (bool sgn) const |
Get an encoded infinite value. | |
uintb | getNaNEncoding (bool sgn) const |
Get an encoded NaN value. | |
void | calcPrecision (void) |
Calculate the decimal precision of this format. | |
Static Private Member Functions | |
static double | createFloat (bool sign, uintb signif, int4 exp) |
Create a double given sign, fractional, and exponent. | |
static floatclass | extractExpSig (double x, bool *sgn, uintb *signif, int4 *exp) |
Extract the sign, fractional, and exponent from a given floating-point value. | |
static bool | roundToNearestEven (uintb &signif, int4 lowbitpos) |
Round a floating point value to the nearest even. | |
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.
ghidra::FloatFormat::FloatFormat | ( | int4 | sz | ) |
Construct default IEEE 754 standard settings.
Set format for a given encoding size according to IEEE 754 standards
sz | is the size of the encoding in bytes |
References bias, calcPrecision(), exp_pos, exp_size, frac_pos, frac_size, jbitimplied, maxexponent, signbit_pos, and size.
uintb ghidra::FloatFormat::convertEncoding | ( | uintb | encoding, |
const FloatFormat * | formin | ||
) | const |
Convert between two different formats.
encoding | is the value in the other FloatFormat |
formin | is the other FloatFormat |
References bias, extractExponentCode(), extractFractionalCode(), extractSign(), frac_size, getInfinityEncoding(), getNaNEncoding(), getZeroEncoding(), jbitimplied, maxexponent, roundToNearestEven(), setExponentCode(), setFractionalCode(), and setSign().
Referenced by opFloat2Float(), and ghidra::SubfloatFlow::setReplacement().
|
staticprivate |
Create a double given sign, fractional, and exponent.
sign | is set to true if the value should be negative |
signif | is the fractional part |
exp | is the exponent |
Referenced by getHostFloat().
int4 ghidra::FloatFormat::extractExponentCode | ( | uintb | x | ) | const |
Extract the exponent from the encoding.
x | is an encoded floating-point value |
References exp_pos, and exp_size.
Referenced by convertEncoding(), getHostFloat(), and ghidra::ScoreUnionFields::scoreConstantFit().
|
staticprivate |
Extract the sign, fractional, and exponent from a given floating-point value.
x | is the given value |
sgn | passes back the sign |
signif | passes back the fractional part |
exp | passes back the exponent |
References infinity, nan, normalized, and zero.
Referenced by getEncoding().
uintb ghidra::FloatFormat::extractFractionalCode | ( | uintb | x | ) | const |
Extract the fractional part of the encoding.
x | is an encoded floating-point value |
References frac_pos, and frac_size.
Referenced by convertEncoding(), and getHostFloat().
bool ghidra::FloatFormat::extractSign | ( | uintb | x | ) | const |
Extract the sign bit from the encoding.
x | is an encoded floating-point value |
References signbit_pos.
Referenced by convertEncoding(), getHostFloat(), and ghidra::PrintC::push_float().
uintb ghidra::FloatFormat::getEncoding | ( | double | host | ) | const |
Convert host's double into this encoding.
host | is the double value to convert |
References bias, extractExpSig(), frac_size, getInfinityEncoding(), getNaNEncoding(), getZeroEncoding(), infinity, jbitimplied, maxexponent, nan, roundToNearestEven(), setExponentCode(), setFractionalCode(), setSign(), and zero.
Referenced by opAbs(), opAdd(), opCeil(), opDiv(), opFloor(), opInt2Float(), opMult(), opNeg(), opRound(), opSqrt(), and opSub().
double ghidra::FloatFormat::getHostFloat | ( | uintb | encoding, |
floatclass * | type | ||
) | const |
Convert an encoding into host's double.
encoding | is the encoding value |
type | points to the floating-point class, which is passed back |
References bias, createFloat(), denormalized, extractExponentCode(), extractFractionalCode(), extractSign(), infinity, jbitimplied, maxexponent, nan, normalized, and zero.
Referenced by opAbs(), opAdd(), opCeil(), opDiv(), opEqual(), opFloor(), opLess(), opLessEqual(), opMult(), opNan(), opNeg(), opNotEqual(), opRound(), opSqrt(), opSub(), opTrunc(), and ghidra::PrintC::push_float().
|
private |
Get an encoded infinite value.
sgn | is set to true for negative infinity, false for positive |
References maxexponent, setExponentCode(), setFractionalCode(), and setSign().
Referenced by convertEncoding(), and getEncoding().
|
private |
Get an encoded NaN value.
sgn | is set to true for negative NaN, false for positive |
References maxexponent, setExponentCode(), setFractionalCode(), and setSign().
Referenced by convertEncoding(), and getEncoding().
|
private |
Get an encoded zero value.
sgn | is set to true for negative zero, false for positive |
References setExponentCode(), setFractionalCode(), and setSign().
Referenced by convertEncoding(), and getEncoding().
uintb ghidra::FloatFormat::opAbs | ( | uintb | a | ) | const |
Absolute value (abs)
a | is an encoded floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatAbs::evaluateUnary().
uintb ghidra::FloatFormat::opAdd | ( | uintb | a, |
uintb | b | ||
) | const |
Addition (+)
a | is the first floating-point value |
b | is the second floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatAdd::evaluateBinary().
uintb ghidra::FloatFormat::opCeil | ( | uintb | a | ) | const |
Ceiling (ceil)
a | is an encoded floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatCeil::evaluateUnary().
uintb ghidra::FloatFormat::opDiv | ( | uintb | a, |
uintb | b | ||
) | const |
Division (/)
a | is the first floating-point value |
b | is the second floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatDiv::evaluateBinary().
uintb ghidra::FloatFormat::opEqual | ( | uintb | a, |
uintb | b | ||
) | const |
Equality comparison (==)
a | is the first floating-point value |
b | is the second floating-point value |
References getHostFloat().
Referenced by ghidra::OpBehaviorFloatEqual::evaluateBinary().
uintb ghidra::FloatFormat::opFloat2Float | ( | uintb | a, |
const FloatFormat & | outformat | ||
) | const |
Convert between floating-point precisions.
a | is an encoded floating-point value |
outformat | is the desired output FloatFormat |
References convertEncoding().
Referenced by ghidra::OpBehaviorFloatFloat2Float::evaluateUnary().
uintb ghidra::FloatFormat::opFloor | ( | uintb | a | ) | const |
Floor (floor)
a | is an encoded floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatFloor::evaluateUnary().
uintb ghidra::FloatFormat::opInt2Float | ( | uintb | a, |
int4 | sizein | ||
) | const |
Convert integer to floating-point.
a | is a signed integer value |
sizein | is the number of bytes in the integer encoding |
References getEncoding().
Referenced by ghidra::OpBehaviorFloatInt2Float::evaluateUnary().
uintb ghidra::FloatFormat::opLess | ( | uintb | a, |
uintb | b | ||
) | const |
Less-than comparison (<)
a | is the first floating-point value |
b | is the second floating-point value |
References getHostFloat().
Referenced by ghidra::OpBehaviorFloatLess::evaluateBinary().
uintb ghidra::FloatFormat::opLessEqual | ( | uintb | a, |
uintb | b | ||
) | const |
Less-than-or-equal comparison (<=)
a | is the first floating-point value |
b | is the second floating-point value |
References getHostFloat().
Referenced by ghidra::OpBehaviorFloatLessEqual::evaluateBinary().
uintb ghidra::FloatFormat::opMult | ( | uintb | a, |
uintb | b | ||
) | const |
Multiplication (*)
a | is the first floating-point value |
b | is the second floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatMult::evaluateBinary().
uintb ghidra::FloatFormat::opNan | ( | uintb | a | ) | const |
Test if Not-a-Number (NaN)
a | is an encoded floating-point value |
References getHostFloat(), and nan.
Referenced by ghidra::OpBehaviorFloatNan::evaluateUnary().
uintb ghidra::FloatFormat::opNeg | ( | uintb | a | ) | const |
Unary negate.
a | is an encoded floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatNeg::evaluateUnary().
uintb ghidra::FloatFormat::opNotEqual | ( | uintb | a, |
uintb | b | ||
) | const |
Inequality comparison (!=)
a | is the first floating-point value |
b | is the second floating-point value |
References getHostFloat().
Referenced by ghidra::OpBehaviorFloatNotEqual::evaluateBinary().
uintb ghidra::FloatFormat::opRound | ( | uintb | a | ) | const |
Round.
a | is an encoded floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatRound::evaluateUnary().
uintb ghidra::FloatFormat::opSqrt | ( | uintb | a | ) | const |
Square root (sqrt)
a | is an encoded floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatSqrt::evaluateUnary().
uintb ghidra::FloatFormat::opSub | ( | uintb | a, |
uintb | b | ||
) | const |
Subtraction (-)
a | is the first floating-point value |
b | is the second floating-point value |
References getEncoding(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatSub::evaluateBinary().
uintb ghidra::FloatFormat::opTrunc | ( | uintb | a, |
int4 | sizeout | ||
) | const |
Convert floating-point to integer.
a | is an encoded floating-point value |
sizeout | is the desired encoding size of the output |
References ghidra::calc_mask(), and getHostFloat().
Referenced by ghidra::OpBehaviorFloatTrunc::evaluateUnary().
string ghidra::FloatFormat::printDecimal | ( | double | host, |
bool | forcesci | ||
) | const |
Print given value as a decimal string.
The string should be printed with the minimum number of digits to uniquely specify the underlying binary value. This currently only works for the 32-bit and 64-bit IEEE 754 formats. If the forcesci parameter is true, the string will always be printed using scientific notation.
host | is the given value already converted to the host's double format. |
forcesci | is true if the value should be printed in scientific notation. |
References decimalMaxPrecision, decimalMinPrecision, and size.
Referenced by ghidra::PrintC::push_float().
|
staticprivate |
Round a floating point value to the nearest even.
signif | the significant bits of a floating point value |
lowbitpos | the position in signif of the floating point |
Referenced by convertEncoding(), and getEncoding().
|
private |
Set the exponent of an encoded value.
x | is an encoded value (with exponent set to zero) |
code | is the exponent to set |
References exp_pos.
Referenced by convertEncoding(), getEncoding(), getInfinityEncoding(), getNaNEncoding(), and getZeroEncoding().
|
private |
Set the fractional part of an encoded value.
x | is an encoded value (with fraction part set to zero) |
code | is the new fractional value to set |
References frac_pos, and frac_size.
Referenced by convertEncoding(), getEncoding(), getInfinityEncoding(), getNaNEncoding(), and getZeroEncoding().
|
private |
Set the sign bit of an encoded value.
x | is an encoded value (with sign set to zero) |
sign | is the sign bit to set |
References signbit_pos.
Referenced by convertEncoding(), getEncoding(), getInfinityEncoding(), getNaNEncoding(), and getZeroEncoding().