strchr-700.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  4. */
  5. /* ARC700 has a relatively long pipeline and branch prediction, so we want
  6. to avoid branches that are hard to predict. On the other hand, the
  7. presence of the norm instruction makes it easier to operate on whole
  8. words branch-free. */
  9. #include <linux/linkage.h>
  10. ENTRY_CFI(strchr)
  11. extb_s r1,r1
  12. asl r5,r1,8
  13. bmsk r2,r0,1
  14. or r5,r5,r1
  15. mov_s r3,0x01010101
  16. breq.d r2,r0,.Laligned
  17. asl r4,r5,16
  18. sub_s r0,r0,r2
  19. asl r7,r2,3
  20. ld_s r2,[r0]
  21. #ifdef __LITTLE_ENDIAN__
  22. asl r7,r3,r7
  23. #else
  24. lsr r7,r3,r7
  25. #endif
  26. or r5,r5,r4
  27. ror r4,r3
  28. sub r12,r2,r7
  29. bic_s r12,r12,r2
  30. and r12,r12,r4
  31. brne.d r12,0,.Lfound0_ua
  32. xor r6,r2,r5
  33. ld.a r2,[r0,4]
  34. sub r12,r6,r7
  35. bic r12,r12,r6
  36. #ifdef __LITTLE_ENDIAN__
  37. and r7,r12,r4
  38. breq r7,0,.Loop ; For speed, we want this branch to be unaligned.
  39. b .Lfound_char ; Likewise this one.
  40. #else
  41. and r12,r12,r4
  42. breq r12,0,.Loop ; For speed, we want this branch to be unaligned.
  43. lsr_s r12,r12,7
  44. bic r2,r7,r6
  45. b.d .Lfound_char_b
  46. and_s r2,r2,r12
  47. #endif
  48. ; /* We require this code address to be unaligned for speed... */
  49. .Laligned:
  50. ld_s r2,[r0]
  51. or r5,r5,r4
  52. ror r4,r3
  53. ; /* ... so that this code address is aligned, for itself and ... */
  54. .Loop:
  55. sub r12,r2,r3
  56. bic_s r12,r12,r2
  57. and r12,r12,r4
  58. brne.d r12,0,.Lfound0
  59. xor r6,r2,r5
  60. ld.a r2,[r0,4]
  61. sub r12,r6,r3
  62. bic r12,r12,r6
  63. and r7,r12,r4
  64. breq r7,0,.Loop /* ... so that this branch is unaligned. */
  65. ; Found searched-for character. r0 has already advanced to next word.
  66. #ifdef __LITTLE_ENDIAN__
  67. /* We only need the information about the first matching byte
  68. (i.e. the least significant matching byte) to be exact,
  69. hence there is no problem with carry effects. */
  70. .Lfound_char:
  71. sub r3,r7,1
  72. bic r3,r3,r7
  73. norm r2,r3
  74. sub_s r0,r0,1
  75. asr_s r2,r2,3
  76. j.d [blink]
  77. sub_s r0,r0,r2
  78. .balign 4
  79. .Lfound0_ua:
  80. mov r3,r7
  81. .Lfound0:
  82. sub r3,r6,r3
  83. bic r3,r3,r6
  84. and r2,r3,r4
  85. or_s r12,r12,r2
  86. sub_s r3,r12,1
  87. bic_s r3,r3,r12
  88. norm r3,r3
  89. add_s r0,r0,3
  90. asr_s r12,r3,3
  91. asl.f 0,r2,r3
  92. sub_s r0,r0,r12
  93. j_s.d [blink]
  94. mov.pl r0,0
  95. #else /* BIG ENDIAN */
  96. .Lfound_char:
  97. lsr r7,r7,7
  98. bic r2,r7,r6
  99. .Lfound_char_b:
  100. norm r2,r2
  101. sub_s r0,r0,4
  102. asr_s r2,r2,3
  103. j.d [blink]
  104. add_s r0,r0,r2
  105. .Lfound0_ua:
  106. mov_s r3,r7
  107. .Lfound0:
  108. asl_s r2,r2,7
  109. or r7,r6,r4
  110. bic_s r12,r12,r2
  111. sub r2,r7,r3
  112. or r2,r2,r6
  113. bic r12,r2,r12
  114. bic.f r3,r4,r12
  115. norm r3,r3
  116. add.pl r3,r3,1
  117. asr_s r12,r3,3
  118. asl.f 0,r2,r3
  119. add_s r0,r0,r12
  120. j_s.d [blink]
  121. mov.mi r0,0
  122. #endif /* ENDIAN */
  123. END_CFI(strchr)