5/* long double __gcc_qsub(long double x, long double y); 6 * This file implements the PowerPC 128-bit double-double add operation. 7 * This implementation is shamelessly cribbed from Apple's DDRT, circa 1993(!) 8 */
| 5// long double __gcc_qsub(long double x, long double y); 6// This file implements the PowerPC 128-bit double-double add operation. 7// This implementation is shamelessly cribbed from Apple's DDRT, circa 1993(!)
|
12long double __gcc_qsub(long double x, long double y) 13{ 14 static const uint32_t infinityHi = UINT32_C(0x7ff00000); 15 16 DD dst = { .ld = x }, src = { .ld = y }; 17 18 register double A = dst.s.hi, a = dst.s.lo, 19 B = -src.s.hi, b = -src.s.lo; 20 21 /* If both operands are zero: */ 22 if ((A == 0.0) && (B == 0.0)) { 23 dst.s.hi = A + B; 24 dst.s.lo = 0.0; 25 return dst.ld; 26 } 27 28 /* If either operand is NaN or infinity: */ 29 const doublebits abits = { .d = A }; 30 const doublebits bbits = { .d = B }; 31 if ((((uint32_t)(abits.x >> 32) & infinityHi) == infinityHi) || 32 (((uint32_t)(bbits.x >> 32) & infinityHi) == infinityHi)) { 33 dst.s.hi = A + B; 34 dst.s.lo = 0.0; 35 return dst.ld; 36 } 37 38 /* If the computation overflows: */ 39 /* This may be playing things a little bit fast and loose, but it will do for a start. */ 40 const double testForOverflow = A + (B + (a + b)); 41 const doublebits testbits = { .d = testForOverflow }; 42 if (((uint32_t)(testbits.x >> 32) & infinityHi) == infinityHi) { 43 dst.s.hi = testForOverflow; 44 dst.s.lo = 0.0; 45 return dst.ld; 46 } 47 48 double H, h; 49 double T, t; 50 double W, w; 51 double Y; 52 53 H = B + (A - (A + B)); 54 T = b + (a - (a + b)); 55 h = A + (B - (A + B)); 56 t = a + (b - (a + b)); 57 58 if (local_fabs(A) <= local_fabs(B)) 59 w = (a + b) + h; 60 else 61 w = (a + b) + H; 62 63 W = (A + B) + w; 64 Y = (A + B) - W; 65 Y += w; 66 67 if (local_fabs(a) <= local_fabs(b)) 68 w = t + Y; 69 else 70 w = T + Y; 71 72 dst.s.hi = Y = W + w; 73 dst.s.lo = (W - Y) + w; 74 75 return dst.ld;
| 11long double __gcc_qsub(long double x, long double y) { 12 static const uint32_t infinityHi = UINT32_C(0x7ff00000); 13 14 DD dst = {.ld = x}, src = {.ld = y}; 15 16 register double A = dst.s.hi, a = dst.s.lo, B = -src.s.hi, b = -src.s.lo; 17 18 // If both operands are zero: 19 if ((A == 0.0) && (B == 0.0)) { 20 dst.s.hi = A + B; 21 dst.s.lo = 0.0; 22 return dst.ld; 23 } 24 25 // If either operand is NaN or infinity: 26 const doublebits abits = {.d = A}; 27 const doublebits bbits = {.d = B}; 28 if ((((uint32_t)(abits.x >> 32) & infinityHi) == infinityHi) || 29 (((uint32_t)(bbits.x >> 32) & infinityHi) == infinityHi)) { 30 dst.s.hi = A + B; 31 dst.s.lo = 0.0; 32 return dst.ld; 33 } 34 35 // If the computation overflows: 36 // This may be playing things a little bit fast and loose, but it will do for 37 // a start. 38 const double testForOverflow = A + (B + (a + b)); 39 const doublebits testbits = {.d = testForOverflow}; 40 if (((uint32_t)(testbits.x >> 32) & infinityHi) == infinityHi) { 41 dst.s.hi = testForOverflow; 42 dst.s.lo = 0.0; 43 return dst.ld; 44 } 45 46 double H, h; 47 double T, t; 48 double W, w; 49 double Y; 50 51 H = B + (A - (A + B)); 52 T = b + (a - (a + b)); 53 h = A + (B - (A + B)); 54 t = a + (b - (a + b)); 55 56 if (local_fabs(A) <= local_fabs(B)) 57 w = (a + b) + h; 58 else 59 w = (a + b) + H; 60 61 W = (A + B) + w; 62 Y = (A + B) - W; 63 Y += w; 64 65 if (local_fabs(a) <= local_fabs(b)) 66 w = t + Y; 67 else 68 w = T + Y; 69 70 dst.s.hi = Y = W + w; 71 dst.s.lo = (W - Y) + w; 72 73 return dst.ld;
|