strlen.S 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (C) 1999-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Kazumoto Kojima <kkojima@rr.iij4u.or.jp>
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. /* size_t strlen (const char *s) */
  17. ENTRY(strlen)
  18. mov r4, r0
  19. and #3, r0
  20. tst r0, r0
  21. bt/s 1f
  22. mov #0, r2
  23. add #-1, r0
  24. shll2 r0
  25. shll r0
  26. braf r0
  27. nop
  28. mov.b @r4+, r1
  29. tst r1, r1
  30. bt 8f
  31. add #1, r2
  32. mov.b @r4+, r1
  33. tst r1, r1
  34. bt 8f
  35. add #1, r2
  36. mov.b @r4+, r1
  37. tst r1, r1
  38. bt 8f
  39. add #1, r2
  40. 1:
  41. mov #0, r3
  42. 2:
  43. mov.l @r4+, r1
  44. cmp/str r3, r1
  45. bf/s 2b
  46. add #4, r2
  47. add #-4, r2
  48. #ifdef __BIG_ENDIAN__
  49. swap.b r1, r1
  50. swap.w r1, r1
  51. swap.b r1, r1
  52. #endif
  53. extu.b r1, r0
  54. tst r0, r0
  55. bt/s 8f
  56. shlr8 r1
  57. add #1, r2
  58. extu.b r1, r0
  59. tst r0, r0
  60. bt/s 8f
  61. shlr8 r1
  62. add #1, r2
  63. extu.b r1, r0
  64. tst r0, r0
  65. bt 8f
  66. add #1, r2
  67. 8:
  68. rts
  69. mov r2, r0
  70. END(strlen)
  71. libc_hidden_builtin_def (strlen)