strcmp.S 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2004-2007 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. */
  8. #include <features.h>
  9. #define s1 r12
  10. #define s2 r11
  11. #define len r10
  12. .text
  13. .global strcmp
  14. .type strcmp, @function
  15. .align 1
  16. strcmp:
  17. mov r8, 3
  18. tst s1, r8
  19. brne .Lunaligned_s1
  20. tst s2, r8
  21. brne .Lunaligned_s2
  22. 1: ld.w r8, s1++
  23. ld.w r9, s2++
  24. cp.w r8, r9
  25. brne 2f
  26. tnbz r8
  27. brne 1b
  28. retal 0
  29. 2: bfextu r12, r8, 24, 8
  30. bfextu r11, r9, 24, 8
  31. sub r12, r11
  32. retne r12
  33. cp.w r11, 0
  34. reteq 0
  35. bfextu r12, r8, 16, 8
  36. bfextu r11, r9, 16, 8
  37. sub r12, r11
  38. retne r12
  39. cp.w r11, 0
  40. reteq 0
  41. bfextu r12, r8, 8, 8
  42. bfextu r11, r9, 8, 8
  43. sub r12, r11
  44. retne r12
  45. cp.w r11, 0
  46. reteq 0
  47. bfextu r12, r8, 0, 8
  48. bfextu r11, r9, 0, 8
  49. sub r12, r11
  50. retal r12
  51. .Lunaligned_s1:
  52. 3: tst s1, r8
  53. breq 4f
  54. ld.ub r10, s1++
  55. ld.ub r9, s2++
  56. sub r10, r9
  57. retne r10
  58. cp.w r9, 0
  59. brne 3b
  60. retal r10
  61. 4: tst s2, r8
  62. breq 1b
  63. .Lunaligned_s2:
  64. /*
  65. * s1 and s2 can't both be aligned, and unaligned word loads
  66. * can trigger spurious exceptions if we cross a page boundary.
  67. * Do it the slow way...
  68. */
  69. 1: ld.ub r8, s1++
  70. ld.ub r9, s2++
  71. sub r8, r9
  72. retne r8
  73. cp.w r9, 0
  74. brne 1b
  75. retal 0
  76. .size strcmp, . - strcmp
  77. libc_hidden_def(strcmp)
  78. #ifndef __UCLIBC_HAS_LOCALE__
  79. strong_alias(strcmp, strcoll)
  80. libc_hidden_def(strcoll)
  81. #endif