softfloat-parts-addsub.c.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Floating point arithmetic implementation
  3. *
  4. * The code in this source file is derived from release 2a of the SoftFloat
  5. * IEC/IEEE Floating-point Arithmetic Package. Those parts of the code (and
  6. * some later contributions) are provided under that license, as detailed below.
  7. * It has subsequently been modified by contributors to the QEMU Project,
  8. * so some portions are provided under:
  9. * the SoftFloat-2a license
  10. * the BSD license
  11. * GPL-v2-or-later
  12. *
  13. * Any future contributions to this file after December 1st 2014 will be
  14. * taken to be licensed under the Softfloat-2a license unless specifically
  15. * indicated otherwise.
  16. */
  17. static void partsN(add_normal)(FloatPartsN *a, FloatPartsN *b)
  18. {
  19. int exp_diff = a->exp - b->exp;
  20. if (exp_diff > 0) {
  21. frac_shrjam(b, exp_diff);
  22. } else if (exp_diff < 0) {
  23. frac_shrjam(a, -exp_diff);
  24. a->exp = b->exp;
  25. }
  26. if (frac_add(a, a, b)) {
  27. frac_shrjam(a, 1);
  28. a->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
  29. a->exp += 1;
  30. }
  31. }
  32. static bool partsN(sub_normal)(FloatPartsN *a, FloatPartsN *b)
  33. {
  34. int exp_diff = a->exp - b->exp;
  35. int shift;
  36. if (exp_diff > 0) {
  37. frac_shrjam(b, exp_diff);
  38. frac_sub(a, a, b);
  39. } else if (exp_diff < 0) {
  40. a->exp = b->exp;
  41. a->sign ^= 1;
  42. frac_shrjam(a, -exp_diff);
  43. frac_sub(a, b, a);
  44. } else if (frac_sub(a, a, b)) {
  45. /* Overflow means that A was less than B. */
  46. frac_neg(a);
  47. a->sign ^= 1;
  48. }
  49. shift = frac_normalize(a);
  50. if (likely(shift < N)) {
  51. a->exp -= shift;
  52. return true;
  53. }
  54. a->cls = float_class_zero;
  55. return false;
  56. }