strcmp-archs.S 1.2 KB

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