aeabi_cdcmp.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //===-- aeabi_cdcmp.S - EABI cdcmp* implementation ------------------------===//
  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. #include "../assembly.h"
  9. #define APSR_Z (1 << 30)
  10. #define APSR_C (1 << 29)
  11. // void __aeabi_cdcmpeq(double a, double b) {
  12. // if (isnan(a) || isnan(b)) {
  13. // Z = 0; C = 1;
  14. // } else {
  15. // __aeabi_cdcmple(a, b);
  16. // }
  17. // }
  18. .syntax unified
  19. .p2align 2
  20. DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
  21. push {r0-r3, lr}
  22. bl __aeabi_cdcmpeq_check_nan
  23. cmp r0, #1
  24. #if defined(USE_THUMB_1)
  25. beq 1f
  26. // NaN has been ruled out, so __aeabi_cdcmple can't trap
  27. mov r0, sp
  28. ldm r0, {r0-r3}
  29. bl __aeabi_cdcmple
  30. pop {r0-r3, pc}
  31. 1:
  32. // Z = 0, C = 1
  33. movs r0, #0xF
  34. lsls r0, r0, #31
  35. pop {r0-r3, pc}
  36. #else
  37. pop {r0-r3, lr}
  38. // NaN has been ruled out, so __aeabi_cdcmple can't trap
  39. // Use "it ne" + unconditional branch to guarantee a supported relocation if
  40. // __aeabi_cdcmple is in a different section for some builds.
  41. IT(ne)
  42. bne __aeabi_cdcmple
  43. #if defined(USE_THUMB_2)
  44. mov ip, #APSR_C
  45. msr APSR_nzcvq, ip
  46. #else
  47. msr APSR_nzcvq, #APSR_C
  48. #endif
  49. JMP(lr)
  50. #endif
  51. END_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)
  52. // void __aeabi_cdcmple(double a, double b) {
  53. // if (__aeabi_dcmplt(a, b)) {
  54. // Z = 0; C = 0;
  55. // } else if (__aeabi_dcmpeq(a, b)) {
  56. // Z = 1; C = 1;
  57. // } else {
  58. // Z = 0; C = 1;
  59. // }
  60. // }
  61. .syntax unified
  62. .p2align 2
  63. DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmple)
  64. // Per the RTABI, this function must preserve r0-r11.
  65. // Save lr in the same instruction for compactness
  66. push {r0-r3, lr}
  67. bl __aeabi_dcmplt
  68. cmp r0, #1
  69. #if defined(USE_THUMB_1)
  70. bne 1f
  71. // Z = 0, C = 0
  72. movs r0, #1
  73. lsls r0, r0, #1
  74. pop {r0-r3, pc}
  75. 1:
  76. mov r0, sp
  77. ldm r0, {r0-r3}
  78. bl __aeabi_dcmpeq
  79. cmp r0, #1
  80. bne 2f
  81. // Z = 1, C = 1
  82. movs r0, #2
  83. lsls r0, r0, #31
  84. pop {r0-r3, pc}
  85. 2:
  86. // Z = 0, C = 1
  87. movs r0, #0xF
  88. lsls r0, r0, #31
  89. pop {r0-r3, pc}
  90. #else
  91. ITT(eq)
  92. moveq ip, #0
  93. beq 1f
  94. ldm sp, {r0-r3}
  95. bl __aeabi_dcmpeq
  96. cmp r0, #1
  97. ITE(eq)
  98. moveq ip, #(APSR_C | APSR_Z)
  99. movne ip, #(APSR_C)
  100. 1:
  101. msr APSR_nzcvq, ip
  102. pop {r0-r3}
  103. POP_PC()
  104. #endif
  105. END_COMPILERRT_FUNCTION(__aeabi_cdcmple)
  106. // int __aeabi_cdrcmple(double a, double b) {
  107. // return __aeabi_cdcmple(b, a);
  108. // }
  109. .syntax unified
  110. .p2align 2
  111. DEFINE_COMPILERRT_FUNCTION(__aeabi_cdrcmple)
  112. // Swap r0 and r2
  113. mov ip, r0
  114. mov r0, r2
  115. mov r2, ip
  116. // Swap r1 and r3
  117. mov ip, r1
  118. mov r1, r3
  119. mov r3, ip
  120. b __aeabi_cdcmple
  121. END_COMPILERRT_FUNCTION(__aeabi_cdrcmple)
  122. NO_EXEC_STACK_DIRECTIVE