strlen.S 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2004-2007 Atmel Corporation
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. */
  8. #include <features.h>
  9. #define str r12
  10. .text
  11. .global strlen
  12. .type strlen, @function
  13. strlen:
  14. mov r11, r12
  15. mov r9, str
  16. andl r9, 3, COH
  17. brne .Lunaligned_str
  18. 1: ld.w r8, str++
  19. tnbz r8
  20. brne 1b
  21. sub r12, r11
  22. bfextu r9, r8, 24, 8
  23. cp.w r9, 0
  24. subeq r12, 4
  25. reteq r12
  26. bfextu r9, r8, 16, 8
  27. cp.w r9, 0
  28. subeq r12, 3
  29. reteq r12
  30. bfextu r9, r8, 8, 8
  31. cp.w r9, 0
  32. subeq r12, 2
  33. reteq r12
  34. sub r12, 1
  35. retal r12
  36. .Lunaligned_str:
  37. add pc, pc, r9 << 3
  38. sub r0, r0, 0 /* 4-byte nop */
  39. ld.ub r8, str++
  40. sub r8, r8, 0
  41. breq 1f
  42. ld.ub r8, str++
  43. sub r8, r8, 0
  44. breq 1f
  45. ld.ub r8, str++
  46. sub r8, r8, 0
  47. brne 1b
  48. 1: sub r12, 1
  49. sub r12, r11
  50. retal r12
  51. .size strlen, . - strlen
  52. libc_hidden_def(strlen)