strlen.S 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2013, 2022 Synopsys, Inc. (www.synopsys.com)
  3. * Copyright (C) 2007 ARC International (UK) LTD
  4. *
  5. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  6. */
  7. #include <sysdep.h>
  8. #include <asm.h>
  9. ENTRY(strlen)
  10. or r3,r0,7
  11. ld r2,[r3,-7]
  12. ld.a r6,[r3,-3]
  13. mov r4,0x01010101
  14. ; uses long immediate
  15. #ifdef __LITTLE_ENDIAN__
  16. ASLR_S r1,r0,3
  17. btst_s r0,2
  18. asl r7,r4,r1
  19. ror r5,r4
  20. sub r1,r2,r7
  21. bic_s r1,r1,r2
  22. mov.eq r7,r4
  23. sub r12,r6,r7
  24. bic r12,r12,r6
  25. or.eq r12,r12,r1
  26. and r12,r12,r5
  27. brne r12,0,.Learly_end
  28. #else /* BIG ENDIAN */
  29. ror r5,r4
  30. btst_s r0,2
  31. mov_s r1,31
  32. sub3 r7,r1,r0
  33. sub r1,r2,r4
  34. bic_s r1,r1,r2
  35. bmsk r1,r1,r7
  36. sub r12,r6,r4
  37. bic r12,r12,r6
  38. bmsk.ne r12,r12,r7
  39. or.eq r12,r12,r1
  40. and r12,r12,r5
  41. brne r12,0,.Learly_end
  42. #endif /* ENDIAN */
  43. .Loop:
  44. ld_s r2,[r3,4]
  45. ld.a r6,[r3,8]
  46. ; stall for load result
  47. sub r1,r2,r4
  48. bic_s r1,r1,r2
  49. sub r12,r6,r4
  50. bic r12,r12,r6
  51. or r12,r12,r1
  52. and r12,r12,r5
  53. breq r12,0,.Loop
  54. .Lend:
  55. and.f r1,r1,r5
  56. sub.ne r3,r3,4
  57. mov.eq r1,r12
  58. #ifdef __LITTLE_ENDIAN__
  59. SUBR_S r2,r1,1
  60. bic_s r2,r2,r1
  61. norm r1,r2
  62. sub_s r0,r0,3
  63. lsr_s r1,r1,3
  64. sub r0,r3,r0
  65. j_s.d [blink]
  66. sub r0,r0,r1
  67. #else /* BIG ENDIAN */
  68. lsr_s r1,r1,7
  69. mov.eq r2,r6
  70. bic_s r1,r1,r2
  71. norm r1,r1
  72. sub r0,r3,r0
  73. lsr_s r1,r1,3
  74. j_s.d [blink]
  75. add r0,r0,r1
  76. #endif /* ENDIAN */
  77. .Learly_end:
  78. b.d .Lend
  79. sub_s.ne r1,r1,r1
  80. END(strlen)
  81. libc_hidden_def(strlen)