strlen.S 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include <asm/export.h>
  10. #define LO_MAGIC 0x01010101
  11. #define HI_MAGIC 0x80808080
  12. .text
  13. ENTRY(strlen)
  14. mov %o0, %o1
  15. andcc %o0, 3, %g0
  16. BRANCH32(be, pt, 9f)
  17. sethi %hi(HI_MAGIC), %o4
  18. ldub [%o0], %o5
  19. BRANCH_REG_ZERO(pn, %o5, 11f)
  20. add %o0, 1, %o0
  21. andcc %o0, 3, %g0
  22. BRANCH32(be, pn, 4f)
  23. or %o4, %lo(HI_MAGIC), %o3
  24. ldub [%o0], %o5
  25. BRANCH_REG_ZERO(pn, %o5, 12f)
  26. add %o0, 1, %o0
  27. andcc %o0, 3, %g0
  28. BRANCH32(be, pt, 5f)
  29. sethi %hi(LO_MAGIC), %o4
  30. ldub [%o0], %o5
  31. BRANCH_REG_ZERO(pn, %o5, 13f)
  32. add %o0, 1, %o0
  33. BRANCH32(ba, pt, 8f)
  34. or %o4, %lo(LO_MAGIC), %o2
  35. 9:
  36. or %o4, %lo(HI_MAGIC), %o3
  37. 4:
  38. sethi %hi(LO_MAGIC), %o4
  39. 5:
  40. or %o4, %lo(LO_MAGIC), %o2
  41. 8:
  42. ld [%o0], %o5
  43. 2:
  44. sub %o5, %o2, %o4
  45. andcc %o4, %o3, %g0
  46. BRANCH32(be, pt, 8b)
  47. add %o0, 4, %o0
  48. /* Check every byte. */
  49. srl %o5, 24, %g7
  50. andcc %g7, 0xff, %g0
  51. BRANCH32(be, pn, 1f)
  52. add %o0, -4, %o4
  53. srl %o5, 16, %g7
  54. andcc %g7, 0xff, %g0
  55. BRANCH32(be, pn, 1f)
  56. add %o4, 1, %o4
  57. srl %o5, 8, %g7
  58. andcc %g7, 0xff, %g0
  59. BRANCH32(be, pn, 1f)
  60. add %o4, 1, %o4
  61. andcc %o5, 0xff, %g0
  62. BRANCH32_ANNUL(bne, pt, 2b)
  63. ld [%o0], %o5
  64. add %o4, 1, %o4
  65. 1:
  66. retl
  67. sub %o4, %o1, %o0
  68. 11:
  69. retl
  70. mov 0, %o0
  71. 12:
  72. retl
  73. mov 1, %o0
  74. 13:
  75. retl
  76. mov 2, %o0
  77. ENDPROC(strlen)
  78. EXPORT_SYMBOL(strlen)