strcmp.S 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <features.h>
  7. #include <sysdep.h>
  8. ENTRY(strcmp)
  9. or r2, r0, r1
  10. bmsk_s r2, r2, 1
  11. brne r2, 0, @.Lcharloop
  12. ;;; s1 and s2 are word aligned
  13. ld.ab r2, [r0, 4]
  14. mov_s r12, 0x01010101
  15. ror r11, r12
  16. .align 4
  17. .LwordLoop:
  18. ld.ab r3, [r1, 4]
  19. ;; Detect NULL char in str1
  20. sub r4, r2, r12
  21. ld.ab r5, [r0, 4]
  22. bic r4, r4, r2
  23. and r4, r4, r11
  24. brne.d.nt r4, 0, .LfoundNULL
  25. ;; Check if the read locations are the same
  26. cmp r2, r3
  27. beq.d .LwordLoop
  28. mov.eq r2, r5
  29. ;; A match is found, spot it out
  30. #ifdef __LITTLE_ENDIAN__
  31. swape r3, r3
  32. mov_s r0, 1
  33. swape r2, r2
  34. #else
  35. mov_s r0, 1
  36. #endif
  37. cmp_s r2, r3
  38. j_s.d [blink]
  39. bset.lo r0, r0, 31
  40. .align 4
  41. .LfoundNULL:
  42. #ifdef __BIG_ENDIAN__
  43. swape r4, r4
  44. swape r2, r2
  45. swape r3, r3
  46. #endif
  47. ;; Find null byte
  48. ffs r0, r4
  49. bmsk r2, r2, r0
  50. bmsk r3, r3, r0
  51. swape r2, r2
  52. swape r3, r3
  53. ;; make the return value
  54. sub.f r0, r2, r3
  55. mov.hi r0, 1
  56. j_s.d [blink]
  57. bset.lo r0, r0, 31
  58. .align 4
  59. .Lcharloop:
  60. ldb.ab r2, [r0, 1]
  61. ldb.ab r3, [r1, 1]
  62. nop
  63. breq r2, 0, .Lcmpend
  64. breq r2, r3, .Lcharloop
  65. .align 4
  66. .Lcmpend:
  67. j_s.d [blink]
  68. sub r0, r2, r3
  69. END(strcmp)
  70. libc_hidden_def(strcmp)
  71. #ifndef __UCLIBC_HAS_LOCALE__
  72. strong_alias(strcmp,strcoll)
  73. libc_hidden_def(strcoll)
  74. #endif