strcmp-archs.S 1.3 KB

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