comparesf2.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //===-- lib/comparesf2.c - Single-precision comparisons -----------*- C -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the following soft-fp_t comparison routines:
  10. //
  11. // __eqsf2 __gesf2 __unordsf2
  12. // __lesf2 __gtsf2
  13. // __ltsf2
  14. // __nesf2
  15. //
  16. // The semantics of the routines grouped in each column are identical, so there
  17. // is a single implementation for each, and wrappers to provide the other names.
  18. //
  19. // The main routines behave as follows:
  20. //
  21. // __lesf2(a,b) returns -1 if a < b
  22. // 0 if a == b
  23. // 1 if a > b
  24. // 1 if either a or b is NaN
  25. //
  26. // __gesf2(a,b) returns -1 if a < b
  27. // 0 if a == b
  28. // 1 if a > b
  29. // -1 if either a or b is NaN
  30. //
  31. // __unordsf2(a,b) returns 0 if both a and b are numbers
  32. // 1 if either a or b is NaN
  33. //
  34. // Note that __lesf2( ) and __gesf2( ) are identical except in their handling of
  35. // NaN values.
  36. //
  37. //===----------------------------------------------------------------------===//
  38. #define SINGLE_PRECISION
  39. #include "fp_lib.h"
  40. #include "fp_compare_impl.inc"
  41. COMPILER_RT_ABI CMP_RESULT __lesf2(fp_t a, fp_t b) { return __leXf2__(a, b); }
  42. #if defined(__ELF__)
  43. // Alias for libgcc compatibility
  44. COMPILER_RT_ALIAS(__lesf2, __cmpsf2)
  45. #endif
  46. COMPILER_RT_ALIAS(__lesf2, __eqsf2)
  47. COMPILER_RT_ALIAS(__lesf2, __ltsf2)
  48. COMPILER_RT_ALIAS(__lesf2, __nesf2)
  49. COMPILER_RT_ABI CMP_RESULT __gesf2(fp_t a, fp_t b) { return __geXf2__(a, b); }
  50. COMPILER_RT_ALIAS(__gesf2, __gtsf2)
  51. COMPILER_RT_ABI CMP_RESULT __unordsf2(fp_t a, fp_t b) {
  52. return __unordXf2__(a, b);
  53. }
  54. #if defined(__ARM_EABI__)
  55. #if defined(COMPILER_RT_ARMHF_TARGET)
  56. AEABI_RTABI int __aeabi_fcmpun(fp_t a, fp_t b) { return __unordsf2(a, b); }
  57. #else
  58. COMPILER_RT_ALIAS(__unordsf2, __aeabi_fcmpun)
  59. #endif
  60. #endif
  61. #if defined(_WIN32) && !defined(__MINGW32__)
  62. // The alias mechanism doesn't work on Windows except for MinGW, so emit
  63. // wrapper functions.
  64. int __eqsf2(fp_t a, fp_t b) { return __lesf2(a, b); }
  65. int __ltsf2(fp_t a, fp_t b) { return __lesf2(a, b); }
  66. int __nesf2(fp_t a, fp_t b) { return __lesf2(a, b); }
  67. int __gtsf2(fp_t a, fp_t b) { return __gesf2(a, b); }
  68. #endif