ots_cmp.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Software floating-point emulation: comparison.
  2. Copyright (C) 1997-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include "local-soft-fp.h"
  16. static long
  17. internal_equality (long al, long ah, long bl, long bh, long neq)
  18. {
  19. FP_DECL_EX;
  20. FP_DECL_Q(A); FP_DECL_Q(B);
  21. long r;
  22. AXP_UNPACK_RAW_Q(A, a);
  23. AXP_UNPACK_RAW_Q(B, b);
  24. if ((A_e == _FP_EXPMAX_Q && !_FP_FRAC_ZEROP_2(A))
  25. || (B_e == _FP_EXPMAX_Q && !_FP_FRAC_ZEROP_2(B)))
  26. {
  27. /* EQ and NE signal invalid operation only if either operand is SNaN. */
  28. if (FP_ISSIGNAN_Q(A) || FP_ISSIGNAN_Q(B))
  29. {
  30. FP_SET_EXCEPTION(FP_EX_INVALID);
  31. FP_HANDLE_EXCEPTIONS;
  32. }
  33. return -1;
  34. }
  35. r = (A_e == B_e
  36. && _FP_FRAC_EQ_2 (A, B)
  37. && (A_s == B_s || (!A_e && _FP_FRAC_ZEROP_2(A))));
  38. r ^= neq;
  39. return r;
  40. }
  41. long
  42. _OtsEqlX (long al, long ah, long bl, long bh)
  43. {
  44. return internal_equality (al, ah, bl, bh, 0);
  45. }
  46. long
  47. _OtsNeqX (long al, long ah, long bl, long bh)
  48. {
  49. return internal_equality (al, ah, bl, bh, 1);
  50. }