strlen.S 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* strlen.S: Sparc optimized strlen code
  2. * Hand optimized from GNU libc's strlen
  3. * Copyright (C) 1991,1996 Free Software Foundation
  4. * Copyright (C) 1996,2008 David S. Miller (davem@davemloft.net)
  5. * Copyright (C) 1996, 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. */
  7. #include <linux/linkage.h>
  8. #include <asm/asm.h>
  9. #define LO_MAGIC 0x01010101
  10. #define HI_MAGIC 0x80808080
  11. .text
  12. ENTRY(strlen)
  13. mov %o0, %o1
  14. andcc %o0, 3, %g0
  15. BRANCH32(be, pt, 9f)
  16. sethi %hi(HI_MAGIC), %o4
  17. ldub [%o0], %o5
  18. BRANCH_REG_ZERO(pn, %o5, 11f)
  19. add %o0, 1, %o0
  20. andcc %o0, 3, %g0
  21. BRANCH32(be, pn, 4f)
  22. or %o4, %lo(HI_MAGIC), %o3
  23. ldub [%o0], %o5
  24. BRANCH_REG_ZERO(pn, %o5, 12f)
  25. add %o0, 1, %o0
  26. andcc %o0, 3, %g0
  27. BRANCH32(be, pt, 5f)
  28. sethi %hi(LO_MAGIC), %o4
  29. ldub [%o0], %o5
  30. BRANCH_REG_ZERO(pn, %o5, 13f)
  31. add %o0, 1, %o0
  32. BRANCH32(ba, pt, 8f)
  33. or %o4, %lo(LO_MAGIC), %o2
  34. 9:
  35. or %o4, %lo(HI_MAGIC), %o3
  36. 4:
  37. sethi %hi(LO_MAGIC), %o4
  38. 5:
  39. or %o4, %lo(LO_MAGIC), %o2
  40. 8:
  41. ld [%o0], %o5
  42. 2:
  43. sub %o5, %o2, %o4
  44. andcc %o4, %o3, %g0
  45. BRANCH32(be, pt, 8b)
  46. add %o0, 4, %o0
  47. /* Check every byte. */
  48. srl %o5, 24, %g7
  49. andcc %g7, 0xff, %g0
  50. BRANCH32(be, pn, 1f)
  51. add %o0, -4, %o4
  52. srl %o5, 16, %g7
  53. andcc %g7, 0xff, %g0
  54. BRANCH32(be, pn, 1f)
  55. add %o4, 1, %o4
  56. srl %o5, 8, %g7
  57. andcc %g7, 0xff, %g0
  58. BRANCH32(be, pn, 1f)
  59. add %o4, 1, %o4
  60. andcc %o5, 0xff, %g0
  61. BRANCH32_ANNUL(bne, pt, 2b)
  62. ld [%o0], %o5
  63. add %o4, 1, %o4
  64. 1:
  65. retl
  66. sub %o4, %o1, %o0
  67. 11:
  68. retl
  69. mov 0, %o0
  70. 12:
  71. retl
  72. mov 1, %o0
  73. 13:
  74. retl
  75. mov 2, %o0
  76. ENDPROC(strlen)