Does anybody know the difference of "fadd" and "fadds" in Power ISA? As I got, it should be for single precision, but the results are like this:
In a floating point register I have {0,0,1,0}
When I use fadd with itself, the result is 1.7014 that makes sense. But when I use fadds the result is "0". And I don't get why.
https://www.ibm.com/docs/en/aix/7.2?topic=set-fadd-fa-floating-add-instruction says
fadd
is double-precision FP addition, not integer.But note that adding two subnormal (all-zero exponent field)
double
s of the same sign just adds their mantissas, like integer addition, if the result is also subnormaldouble
. (And at least when adding to itself the whole bit-pattern does just shift left by 1, even if the result becomes normalized, as long as it started subnormal. Otherwise the mantissa stays the same and the exponent increments by 1.)It looks like you have a single-precision bit-pattern like 0x3f800000 (which represents
1.0f
) in the low half of adouble
, and all-zero in the high half. So you have adouble
with bit-pattern 0x000000003f800000. Adding it to itself doubles it to 0x000000007f000000, left-shifting the mantissa because the result is still subnormal, no change in the exponent. (Representing the value2.056...E-317
)Taking the low half of that
double
bit-pattern as a single-precisionfloat
with bit-pattern0x7f000000
, it represents a value of 1.7014118346e+38. (https://www.h-schmidt.net/FloatConverter/IEEE754.html)That's 38 orders of magnitude larger than the 1.7014 result you claimed you got, but those 5 matching digits can't be a concidence. I'm pretty sure this must be what you did. Check how you're printing or viewing your single-precision floating-point numbers to make sure you're not somehow truncating strings to lose the exponent from scientific notation.
IDK what your
{0,0,1,0}
notation is supposed to mean; the manual saysfadd
andfadds
operate on 64-bit or 32-bit FP registers, not vectors. OTOH I don't know much about POWER / PowerPC or Altivec.