abiv2_strcmp.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #include <endian.h>
  2. #include "macro.S"
  3. #ifdef WANT_WIDE
  4. # define Wstrcmp wcscmp
  5. # define Wstrcoll wcscoll
  6. #else
  7. # define Wstrcmp strcmp
  8. # define Wstrcoll strcoll
  9. #endif
  10. /* FIXME attention!!! it may be a bug when WANT_WIDE define */
  11. /*libc_hidden_proto(Wstrcmp)*/
  12. .align 2
  13. .global Wstrcmp
  14. .type Wstrcmp, @function
  15. Wstrcmp:
  16. mov a3, a0
  17. or a0, a1
  18. andi a0, 0x3
  19. M_BNEZ a0, 4f
  20. 1: // if aligned, load word each time.
  21. ldw a0, (a3, 0)
  22. ldw t0, (a1, 0)
  23. M_BNE a0, t0, 1f // if d[i] != s[i], goto 1f
  24. tstnbz a0 // if d[i] == s[i], check if d or s is at the end.
  25. bf 3f // if at the end, goto 3f (finish comparing)
  26. ldw a0, (a3, 4)
  27. ldw t0, (a1, 4)
  28. M_BNE a0, t0, 1f
  29. tstnbz a0
  30. bf 3f
  31. ldw a0, (a3, 8)
  32. ldw t0, (a1, 8)
  33. M_BNE a0, t0, 1f
  34. tstnbz a0
  35. bf 3f
  36. ldw a0, (a3, 12)
  37. ldw t0, (a1, 12)
  38. M_BNE a0, t0, 1f
  39. tstnbz a0
  40. bf 3f
  41. ldw a0, (a3, 16)
  42. ldw t0, (a1, 16)
  43. M_BNE a0, t0, 1f
  44. tstnbz a0
  45. bf 3f
  46. ldw a0, (a3, 20)
  47. ldw t0, (a1, 20)
  48. M_BNE a0, t0, 1f
  49. tstnbz a0
  50. bf 3f
  51. ldw a0, (a3, 24)
  52. ldw t0, (a1, 24)
  53. M_BNE a0, t0, 1f
  54. tstnbz a0
  55. bf 3f
  56. ldw a0, (a3, 28)
  57. ldw t0, (a1, 28)
  58. M_BNE a0, t0, 1f
  59. tstnbz a0
  60. bf 3f
  61. addi a3, 32
  62. addi a1, 32
  63. br 1b
  64. #ifdef __CSKYBE__
  65. /* d[i] != s[i] in word, so we check byte 0 ? */
  66. 1:
  67. xtrb0 t1, a0
  68. mov a2, t1
  69. xtrb0 t1, t0
  70. M_BNE a2, t1, 2f
  71. cmpnei a2, 0
  72. bf 2f
  73. /* d[i] != s[i] in word, so we check byte 1 ? */
  74. xtrb1 t1, a0
  75. mov a2, t1
  76. xtrb1 t1, t0
  77. M_BNE a2, t1, 2f
  78. cmpnei a2, 0
  79. bf 2f
  80. /* d[i] != s[i] in word, so we check byte 1 ? */
  81. xtrb2 t1, a0
  82. mov a2, t1
  83. xtrb2 t1, t0
  84. M_BNE a2, t1, 2f
  85. cmpnei a2, 0
  86. bf 2f
  87. /* d[i] != s[i] in word, so we check byte 1 ? */
  88. xtrb3 t1, a0
  89. mov a2, t1
  90. xtrb3 t1, t0
  91. #else /* little endian */
  92. /* d[i] != s[i] in word, so we check byte 0 ? */
  93. 1:
  94. xtrb3 t1, a0
  95. mov a2, t1
  96. xtrb3 t1, t0
  97. M_BNE a2, t1, 2f
  98. cmpnei a2, 0
  99. bf 2f
  100. /* d[i] != s[i] in word, so we check byte 1 ? */
  101. xtrb2 t1, a0
  102. mov a2, t1
  103. xtrb2 t1, t0
  104. M_BNE a2, t1, 2f
  105. cmpnei a2, 0
  106. bf 2f
  107. /* d[i] != s[i] in word, so we check byte 1 ? */
  108. xtrb1 t1, a0
  109. mov a2, t1
  110. xtrb1 t1, t0
  111. M_BNE a2, t1, 2f
  112. cmpnei a2, 0
  113. bf 2f
  114. /* d[i] != s[i] in word, so we check byte 1 ? */
  115. xtrb0 t1, a0
  116. mov a2, t1
  117. xtrb0 t1, t0
  118. #endif
  119. /* get the result when d[i] != s[i] */
  120. 2:
  121. subu a2, t1
  122. mov a0, a2
  123. jmp r15
  124. /* return when d[i] == s[i] */
  125. 3:
  126. subu a0, t0
  127. jmp r15
  128. /* cmp when d or s is not aligned */
  129. 4:
  130. ldb a0, (a3,0)
  131. ldb t0, (a1, 0)
  132. M_BNE a0, t0, 3b
  133. addi a1, 1
  134. addi a3, 1
  135. M_BNEZ a0, 4b
  136. jmp r15
  137. .size Wstrcmp, .-Wstrcmp
  138. libc_hidden_def(Wstrcmp)
  139. .weak Wstrcmp
  140. #ifndef __UCLIBC_HAS_LOCALE__
  141. /* libc_hidden_proto(Wstrcoll) */
  142. strong_alias(Wstrcmp,Wstrcoll)
  143. libc_hidden_def(Wstrcoll)
  144. #endif