strchr-700.S 2.7 KB

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