49 FpCondCompRegOp::generateDisassembly(
103 std::stringstream
ss;
115 std::stringstream
ss;
129 std::stringstream
ss;
143 std::stringstream
ss;
158 std::stringstream
ss;
175 int roundingMode = fegetround();
198 bool underflow =
false;
199 if ((exceptions &
FeInvalid) && mask.ioc) {
213 if ((exceptions &
FeInexact) && !(underflow && flush) && mask.ixc) {
219 template <
class fpType>
225 if (fpClass == FP_NAN) {
226 const bool single = (
sizeof(
val) ==
sizeof(
float));
227 const uint64_t qnan = single ? 0x7fc00000 :
ULL(0x7ff8000000000000);
228 const bool nan = std::isnan(op1);
229 if (!nan || defaultNan) {
234 }
else if (fpClass == FP_SUBNORMAL && flush == 1) {
236 uint64_t bitMask =
ULL(0x1) << (
sizeof(fpType) * 8 - 1);
249 template <
class fpType>
251 fixDest(
bool flush,
bool defaultNan, fpType
val, fpType op1, fpType op2)
255 if (fpClass == FP_NAN) {
256 const bool single = (
sizeof(
val) ==
sizeof(
float));
257 const uint64_t qnan = single ? 0x7fc00000 :
ULL(0x7ff8000000000000);
258 const bool nan1 = std::isnan(op1);
259 const bool nan2 = std::isnan(op2);
260 const bool signal1 = nan1 && ((
fpToBits(op1) & qnan) != qnan);
261 const bool signal2 = nan2 && ((
fpToBits(op2) & qnan) != qnan);
262 if ((!nan1 && !nan2) || defaultNan) {
264 }
else if (signal1) {
266 }
else if (signal2) {
273 }
else if (fpClass == FP_SUBNORMAL && flush) {
275 uint64_t bitMask =
ULL(0x1) << (
sizeof(fpType) * 8 - 1);
285 float val,
float op1,
float op2);
288 double val,
double op1,
double op2);
290 template <
class fpType>
294 fpType mid =
fixDest(flush, defaultNan, val, op1, op2);
295 const bool single = (
sizeof(fpType) ==
sizeof(
float));
296 const fpType junk = 0.0;
297 if ((single && (val ==
bitsToFp(0x00800000, junk) ||
298 val ==
bitsToFp(0x80800000, junk))) ||
299 (!single && (val ==
bitsToFp(
ULL(0x0010000000000000), junk) ||
302 __asm__ __volatile__(
"" :
"=m" (op1) :
"m" (op1));
305 __asm__ __volatile__(
"" :
"=m" (temp) :
"m" (temp));
314 __asm__ __volatile__(
"" ::
"m" (temp));
321 float val,
float op1,
float op2);
324 double val,
double op1,
double op2);
329 const float junk = 0.0;
331 if (std::isnan(val)) {
333 uint32_t op1Bits =
bits(valBits, 50, 29) |
335 (
bits(valBits, 63) << 31);
338 float mid =
fixDest(fpscr.fz, fpscr.dn, (
float)val, op1);
343 if (mid ==
bitsToFp(0x00800000, junk) ||
344 mid ==
bitsToFp(0x80800000, junk)) {
345 __asm__ __volatile__(
"" :
"=m" (val) :
"m" (val));
348 __asm__ __volatile__(
"" :
"=m" (temp) :
"m" (temp));
357 __asm__ __volatile__(
"" ::
"m" (temp));
365 const double junk = 0.0;
367 if (std::isnan(val)) {
369 uint64_t op1Bits = ((uint64_t)
bits(valBits, 21, 0) << 29) |
371 ((uint64_t)
bits(valBits, 31) << 63);
374 double mid =
fixDest(fpscr.fz, fpscr.dn, (
double)val, op1);
375 if (mid ==
bitsToFp(
ULL(0x0010000000000000), junk) ||
377 __asm__ __volatile__(
"" :
"=m" (val) :
"m" (val));
380 __asm__ __volatile__(
"" :
"=m" (temp) :
"m" (temp));
389 __asm__ __volatile__(
"" ::
"m" (temp));
394 static inline uint16_t
396 uint32_t
rMode,
bool ahp, uint64_t opBits,
bool isDouble)
410 sBitPos = eWidth + mWidth;
411 eHalfRange = (1 << (eWidth-1)) - 1;
414 bool neg =
bits(opBits, sBitPos);
415 uint32_t exponent =
bits(opBits, sBitPos-1, mWidth);
416 uint64_t oldMantissa =
bits(opBits, mWidth-1, 0);
417 uint32_t mantissa = oldMantissa >> (mWidth - 10);
419 uint64_t extra = oldMantissa &
mask(mWidth - 10);
420 if (exponent ==
mask(eWidth)) {
421 if (oldMantissa != 0) {
423 if (
bits(mantissa, 9) == 0) {
431 }
else if (defaultNan) {
437 mantissa |= (1 << 9);
449 }
else if (exponent == 0 && oldMantissa == 0) {
454 bool inexact = (extra != 0);
462 if (inexact || fpscr.ufe)
471 (extra == (1 << 9) &&
bits(mantissa, 0))))) {
476 if (mantissa == (1 << 10)) {
485 bool topOne =
bits(extra, mWidth - 10 - 1);
486 bool restZeros =
bits(extra, mWidth - 10 - 2, 0) == 0;
488 if (exponent <= (eHalfRange - 15)) {
490 mantissa |= (1 << 10);
491 while (mantissa && exponent <= (eHalfRange - 15)) {
492 restZeros = restZeros && !topOne;
493 topOne =
bits(mantissa, 0);
494 mantissa = mantissa >> 1;
497 if (topOne || !restZeros)
502 exponent -= (eHalfRange - 15);
505 if (exponent == 0 && (inexact || fpscr.ufe)) {
512 bool nonZero = topOne || !restZeros;
516 (!restZeros ||
bits(mantissa, 0)))) {
521 if (mantissa == (1 << 10)) {
528 if (exponent >= 0x20) {
536 if (exponent >= 0x1f) {
559 uint32_t result =
bits(mantissa, 9, 0);
571 return vcvtFpFpH(fpscr, flush, defaultNan, rMode, ahp, opBits,
false);
579 return vcvtFpFpH(fpscr, flush, defaultNan, rMode, ahp, opBits,
true);
582 static inline uint64_t
597 sBitPos = eWidth + mWidth;
598 eHalfRange = (1 << (eWidth-1)) - 1;
601 bool neg =
bits(op, 15);
602 uint32_t exponent =
bits(op, 14, 10);
603 uint64_t mantissa =
bits(op, 9, 0);
608 exponent = exponent + (eHalfRange - 15) + 1;
609 while (mantissa < (1 << 10)) {
610 mantissa = mantissa << 1;
614 mantissa = mantissa << (mWidth - 10);
615 }
else if (exponent == 0x1f && !ahp) {
617 exponent =
mask(eWidth);
620 mantissa = mantissa << (mWidth - 10);
621 if (
bits(mantissa, mWidth-1) == 0) {
624 mantissa |= (((uint64_t) 1) << (mWidth-1));
627 mantissa &= ~
mask(mWidth-1);
632 exponent = exponent + (eHalfRange - 15);
633 mantissa = mantissa << (mWidth - 10);
636 uint64_t result =
bits(mantissa, mWidth-1, 0);
639 result |= (((uint64_t) 1) << sBitPos);
650 result =
vcvtFpHFp(fpscr, defaultNan, ahp, op,
true);
660 result =
vcvtFpHFp(fpscr, defaultNan, ahp, op,
false);
671 else if (width == 32)
673 else if (width != 64)
674 panic(
"Unsupported width %d", width);
675 float scale = powf(2.0, imm);
676 __asm__ __volatile__(
"" :
"=m" (scale) :
"m" (scale));
678 __asm__ __volatile__(
"" :
"=m" (scale) :
"m" (scale));
679 return fixDivDest(flush, defaultNan, val / scale, (
float)val, scale);
688 val = sext<16>(val &
mask(16));
689 else if (width == 32)
690 val = sext<32>(val &
mask(32));
691 else if (width != 64)
692 panic(
"Unsupported width %d", width);
694 float scale = powf(2.0, imm);
695 __asm__ __volatile__(
"" :
"=m" (scale) :
"m" (scale));
697 __asm__ __volatile__(
"" :
"=m" (scale) :
"m" (scale));
698 return fixDivDest(flush, defaultNan, val / scale, (
float)val, scale);
709 else if (width == 32)
711 else if (width != 64)
712 panic(
"Unsupported width %d", width);
714 double scale = pow(2.0, imm);
715 __asm__ __volatile__(
"" :
"=m" (scale) :
"m" (scale));
717 __asm__ __volatile__(
"" :
"=m" (scale) :
"m" (scale));
718 return fixDivDest(flush, defaultNan, val / scale, (
double)val, scale);
727 val = sext<16>(val &
mask(16));
728 else if (width == 32)
729 val = sext<32>(val &
mask(32));
730 else if (width != 64)
731 panic(
"Unsupported width %d", width);
733 double scale = pow(2.0, imm);
734 __asm__ __volatile__(
"" :
"=m" (scale) :
"m" (scale));
736 __asm__ __volatile__(
"" :
"=m" (scale) :
"m" (scale));
737 return fixDivDest(flush, defaultNan, val / scale, (
double)val, scale);
748 q0 = (int64_t)(a * 512.0);
749 r = 1.0 / sqrt(((
double)q0 + 0.5) / 512.0);
751 q1 = (int64_t)(a * 256.0);
752 r = 1.0 / sqrt(((
double)q1 + 0.5) / 256.0);
754 s = (int64_t)(256.0 * r + 0.5);
755 return (
double)s / 256.0;
763 const uint32_t qnan = 0x7fc00000;
766 if (fpClass == FP_NAN) {
770 }
else if (fpClass == FP_ZERO) {
774 (0xFF << 23) | (0 << 0), junk);
779 }
else if (fpClass == FP_INFINITE) {
784 if (
bits(opBits, 23)) {
785 scaled =
bitsToFp((0 << 0) | (
bits(opBits, 22, 0) << 29) |
786 (
ULL(0x3fd) << 52) | (
bits(opBits, 31) << 63),
789 scaled =
bitsToFp((0 << 0) | (
bits(opBits, 22, 0) << 29) |
790 (
ULL(0x3fe) << 52) | (
bits(opBits, 31) << 63),
793 uint64_t resultExp = (380 -
bits(opBits, 30, 23)) / 2;
798 (
bits(resultExp, 7, 0) << 23) |
799 (
bits(estimate, 51, 29) << 0), junk);
806 if (
bits(op, 31, 30) == 0) {
813 (
bits((uint64_t)op, 30, 0) << 21) |
814 (0 << 0), (
double)0.0);
818 (
bits((uint64_t)op, 29, 0) << 22) |
819 (0 << 0), (
double)0.0);
822 return (1 << 31) |
bits(estimate, 51, 21);
834 q = (int64_t)(a * 512.0);
835 r = 1.0 / (((double)q + 0.5) / 512.0);
836 s = (int64_t)(256.0 * r + 0.5);
837 return (
double)s / 256.0;
845 const uint32_t qnan = 0x7fc00000;
848 if (fpClass == FP_NAN) {
852 }
else if (fpClass == FP_INFINITE) {
854 }
else if (fpClass == FP_ZERO) {
858 (0xFF << 23) | (0 << 0), junk);
859 }
else if (fabs(op) >= pow(2.0, 126)) {
865 scaled =
bitsToFp((0 << 0) | (
bits(opBits, 22, 0) << 29) |
866 (
ULL(0x3fe) << 52) | (
ULL(0) << 63),
868 uint64_t resultExp = 253 -
bits(opBits, 30, 23);
873 (
bits(resultExp, 7, 0) << 23) |
874 (
bits(estimate, 51, 29) << 0), junk);
881 if (
bits(op, 31) == 0) {
887 (
bits((uint64_t)op, 30, 0) << 21) |
888 (0 << 0), (
double)0.0);
890 return (1 << 31) |
bits(estimate, 51, 21);
894 template <
class fpType>
897 fpType op1, fpType op2)
const
902 const bool single = (
sizeof(fpType) ==
sizeof(
float));
903 const uint64_t qnan =
904 single ? 0x7fc00000 :
ULL(0x7ff8000000000000);
905 const bool nan1 = std::isnan(op1);
906 const bool nan2 = std::isnan(op2);
907 const bool signal1 = nan1 && ((
fpToBits(op1) & qnan) != qnan);
908 const bool signal2 = nan2 && ((
fpToBits(op2) & qnan) != qnan);
912 }
else if (signal1) {
914 }
else if (signal2) {
921 if (signal1 || signal2) {
932 float op1,
float op2)
const;
935 double op1,
double op2)
const;
938 template <
class fpType>
941 fpType (*func)(fpType, fpType, fpType),
942 bool flush,
bool defaultNan, uint32_t
rMode)
const
944 const bool single = (
sizeof(fpType) ==
sizeof(
float));
950 __asm__ __volatile__ (
"" :
"=m" (op1),
"=m" (op2),
"=m" (op3),
"=m" (state)
951 :
"m" (op1),
"m" (op2),
"m" (op3),
"m" (state));
952 fpType dest = func(op1, op2, op3);
953 __asm__ __volatile__ (
"" :
"=m" (dest) :
"m" (dest));
957 if (fpClass == FP_NAN) {
958 const uint64_t qnan =
959 single ? 0x7fc00000 :
ULL(0x7ff8000000000000);
960 const bool nan1 = std::isnan(op1);
961 const bool nan2 = std::isnan(op2);
962 const bool nan3 = std::isnan(op3);
963 const bool signal1 = nan1 && ((
fpToBits(op1) & qnan) != qnan);
964 const bool signal2 = nan2 && ((
fpToBits(op2) & qnan) != qnan);
965 const bool signal3 = nan3 && ((
fpToBits(op3) & qnan) != qnan);
966 if ((!nan1 && !nan2 && !nan3) || (defaultNan == 1)) {
968 }
else if (signal1) {
970 }
else if (signal2) {
972 }
else if (signal3) {
984 (single && (dest ==
bitsToFp(0x00800000, junk) ||
985 dest ==
bitsToFp(0x80800000, junk))) ||
987 (dest ==
bitsToFp(
ULL(0x0010000000000000), junk) ||
995 __asm__ __volatile__ (
"" :
"=m" (op1),
"=m" (op2),
"=m" (op3)
996 :
"m" (op1),
"m" (op2),
"m" (op3));
997 fpType temp = func(op1, op2, op2);
998 __asm__ __volatile__ (
"" :
"=m" (temp) :
"m" (temp));
1009 float (*func)(
float,
float,
float),
1010 bool flush,
bool defaultNan, uint32_t
rMode)
const;
1012 double FpOp::ternaryOp(FPSCR &fpscr,
double op1,
double op2,
double op3,
1013 double (*func)(
double,
double,
double),
1014 bool flush,
bool defaultNan, uint32_t
rMode)
const;
1016 template <
class fpType>
1019 fpType (*func)(fpType, fpType),
1020 bool flush,
bool defaultNan, uint32_t
rMode)
const
1022 const bool single = (
sizeof(fpType) ==
sizeof(
float));
1028 __asm__ __volatile__ (
"" :
"=m" (op1),
"=m" (op2),
"=m" (state)
1029 :
"m" (op1),
"m" (op2),
"m" (state));
1030 fpType dest = func(op1, op2);
1031 __asm__ __volatile__ (
"" :
"=m" (dest) :
"m" (dest));
1034 if (std::isnan(dest)) {
1035 const uint64_t qnan =
1036 single ? 0x7fc00000 :
ULL(0x7ff8000000000000);
1037 const bool nan1 = std::isnan(op1);
1038 const bool nan2 = std::isnan(op2);
1039 const bool signal1 = nan1 && ((
fpToBits(op1) & qnan) != qnan);
1040 const bool signal2 = nan2 && ((
fpToBits(op2) & qnan) != qnan);
1041 if ((!nan1 && !nan2) || (defaultNan == 1)) {
1043 }
else if (signal1) {
1045 }
else if (signal2) {
1055 (single && (dest ==
bitsToFp(0x00800000, junk) ||
1056 dest ==
bitsToFp(0x80800000, junk))) ||
1058 (dest ==
bitsToFp(
ULL(0x0010000000000000), junk) ||
1066 __asm__ __volatile__ (
"" :
"=m" (op1),
"=m" (op2)
1067 :
"m" (op1),
"m" (op2));
1068 fpType temp = func(op1, op2);
1069 __asm__ __volatile__ (
"" :
"=m" (temp) :
"m" (temp));
1080 float (*func)(
float,
float),
1081 bool flush,
bool defaultNan, uint32_t
rMode)
const;
1084 double (*func)(
double,
double),
1085 bool flush,
bool defaultNan, uint32_t
rMode)
const;
1087 template <
class fpType>
1090 bool flush, uint32_t
rMode)
const
1092 const bool single = (
sizeof(fpType) ==
sizeof(
float));
1098 __asm__ __volatile__ (
"" :
"=m" (op1),
"=m" (state)
1099 :
"m" (op1),
"m" (state));
1100 fpType dest = func(op1);
1101 __asm__ __volatile__ (
"" :
"=m" (dest) :
"m" (dest));
1104 if (std::isnan(dest)) {
1105 const uint64_t qnan =
1106 single ? 0x7fc00000 :
ULL(0x7ff8000000000000);
1107 const bool nan = std::isnan(op1);
1108 if (!nan || fpscr.dn == 1) {
1116 (single && (dest ==
bitsToFp(0x00800000, junk) ||
1117 dest ==
bitsToFp(0x80800000, junk))) ||
1119 (dest ==
bitsToFp(
ULL(0x0010000000000000), junk) ||
1127 __asm__ __volatile__ (
"" :
"=m" (op1) :
"m" (op1));
1128 fpType temp = func(op1);
1129 __asm__ __volatile__ (
"" :
"=m" (temp) :
"m" (temp));
1139 float FpOp::unaryOp(FPSCR &fpscr,
float op1,
float (*func)(
float),
1140 bool flush, uint32_t
rMode)
const;
1142 double FpOp::unaryOp(FPSCR &fpscr,
double op1,
double (*func)(
double),
1143 bool flush, uint32_t
rMode)
const;
1151 unsigned offset = idx % 8;
void ccprintf(cp::Print &print)
template double fixDest< double >(bool flush, bool defaultNan, double val, double op1)
double fixFpSFpDDest(FPSCR fpscr, float val)
static float bitsToFp(uint64_t, float)
fpType fixDivDest(bool flush, bool defaultNan, fpType val, fpType op1, fpType op2)
uint32_t unsignedRecipEstimate(uint32_t op)
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
void printCondition(std::ostream &os, unsigned code, bool noImplicit=false) const
Bitfield< 21, 20 > stride
void printMnemonic(std::ostream &os, const std::string &suffix="", bool withPred=true, bool withCond64=false, ConditionCode cond64=COND_UC) const
float fixFpDFpSDest(FPSCR fpscr, double val)
void printReg(std::ostream &os, int reg) const
Print a register name for disassembly given the unique dependence tag number (FP or int)...
bool fpclassify(T src0, uint32_t src1)
template float fixDivDest< float >(bool flush, bool defaultNan, float val, float op1, float op2)
static double recipSqrtEstimate(double a)
template double fixDivDest< double >(bool flush, bool defaultNan, double val, double op1, double op2)
uint16_t vcvtFpDFpH(FPSCR &fpscr, bool flush, bool defaultNan, uint32_t rMode, bool ahp, double op)
fpType ternaryOp(FPSCR &fpscr, fpType op1, fpType op2, fpType op3, fpType(*func)(fpType, fpType, fpType), bool flush, bool defaultNan, uint32_t rMode) const
double vcvtFpHFpD(FPSCR &fpscr, bool defaultNan, bool ahp, uint16_t op)
uint16_t vcvtFpSFpH(FPSCR &fpscr, bool flush, bool defaultNan, uint32_t rMode, bool ahp, float op)
uint32_t unsignedRSqrtEstimate(uint32_t op)
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
float fprSqrtEstimate(FPSCR &fpscr, float op)
const ExtMachInst machInst
The binary machine instruction.
static double recipEstimate(double a)
static uint32_t fpToBits(float)
static bool inScalarBank(IntRegIndex idx)
static uint16_t vcvtFpFpH(FPSCR &fpscr, bool flush, bool defaultNan, uint32_t rMode, bool ahp, uint64_t opBits, bool isDouble)
void finishVfp(FPSCR &fpscr, VfpSavedState state, bool flush, FPSCR mask)
void replaceBits(T &val, int first, int last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
double vfpUFixedToFpD(bool flush, bool defaultNan, uint64_t val, uint8_t width, uint8_t imm)
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
#define ULL(N)
uint64_t constant
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
double vfpSFixedToFpD(bool flush, bool defaultNan, int64_t val, uint8_t width, uint8_t imm)
void nextIdxs(IntRegIndex &dest, IntRegIndex &op1, IntRegIndex &op2)
fpType fixDest(bool flush, bool defaultNan, fpType val, fpType op1)
int signbit(uint64_t src, int sz)
fpType binaryOp(FPSCR &fpscr, fpType op1, fpType op2, fpType(*func)(fpType, fpType), bool flush, bool defaultNan, uint32_t rMode) const
fpType unaryOp(FPSCR &fpscr, fpType op1, fpType(*func)(fpType), bool flush, uint32_t rMode) const
float fpRecipEstimate(FPSCR &fpscr, float op)
VfpSavedState prepFpState(uint32_t rMode)
float vcvtFpHFpS(FPSCR &fpscr, bool defaultNan, bool ahp, uint16_t op)
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
template float fixDest< float >(bool flush, bool defaultNan, float val, float op1)
float vfpUFixedToFpS(bool flush, bool defaultNan, uint64_t val, uint8_t width, uint8_t imm)
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
fpType processNans(FPSCR &fpscr, bool &done, bool defaultNan, fpType op1, fpType op2) const
static uint64_t vcvtFpHFp(FPSCR &fpscr, bool defaultNan, bool ahp, uint16_t op, bool isDouble)
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const
Internal function to generate disassembly string.
float vfpSFixedToFpS(bool flush, bool defaultNan, int64_t val, uint8_t width, uint8_t imm)
IntRegIndex addStride(IntRegIndex idx, unsigned stride)