strlen.S 1.6 KB

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