strlen_user_32.S 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* strlen_user.S: Sparc optimized strlen_user code
  2. *
  3. * Return length of string in userspace including terminating 0
  4. * or 0 for error
  5. *
  6. * Copyright (C) 1991,1996 Free Software Foundation
  7. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  8. * Copyright (C) 1996 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  9. */
  10. #define LO_MAGIC 0x01010101
  11. #define HI_MAGIC 0x80808080
  12. 10:
  13. ldub [%o0], %o5
  14. cmp %o5, 0
  15. be 1f
  16. add %o0, 1, %o0
  17. andcc %o0, 3, %g0
  18. be 4f
  19. or %o4, %lo(HI_MAGIC), %o3
  20. 11:
  21. ldub [%o0], %o5
  22. cmp %o5, 0
  23. be 2f
  24. add %o0, 1, %o0
  25. andcc %o0, 3, %g0
  26. be 5f
  27. sethi %hi(LO_MAGIC), %o4
  28. 12:
  29. ldub [%o0], %o5
  30. cmp %o5, 0
  31. be 3f
  32. add %o0, 1, %o0
  33. b 13f
  34. or %o4, %lo(LO_MAGIC), %o2
  35. 1:
  36. retl
  37. mov 1, %o0
  38. 2:
  39. retl
  40. mov 2, %o0
  41. 3:
  42. retl
  43. mov 3, %o0
  44. .align 4
  45. .global __strlen_user, __strnlen_user
  46. __strlen_user:
  47. sethi %hi(32768), %o1
  48. __strnlen_user:
  49. mov %o1, %g1
  50. mov %o0, %o1
  51. andcc %o0, 3, %g0
  52. bne 10b
  53. sethi %hi(HI_MAGIC), %o4
  54. or %o4, %lo(HI_MAGIC), %o3
  55. 4:
  56. sethi %hi(LO_MAGIC), %o4
  57. 5:
  58. or %o4, %lo(LO_MAGIC), %o2
  59. 13:
  60. ld [%o0], %o5
  61. 2:
  62. sub %o5, %o2, %o4
  63. andcc %o4, %o3, %g0
  64. bne 82f
  65. add %o0, 4, %o0
  66. sub %o0, %o1, %g2
  67. 81: cmp %g2, %g1
  68. blu 13b
  69. mov %o0, %o4
  70. ba,a 1f
  71. /* Check every byte. */
  72. 82: srl %o5, 24, %g5
  73. andcc %g5, 0xff, %g0
  74. be 1f
  75. add %o0, -3, %o4
  76. srl %o5, 16, %g5
  77. andcc %g5, 0xff, %g0
  78. be 1f
  79. add %o4, 1, %o4
  80. srl %o5, 8, %g5
  81. andcc %g5, 0xff, %g0
  82. be 1f
  83. add %o4, 1, %o4
  84. andcc %o5, 0xff, %g0
  85. bne 81b
  86. sub %o0, %o1, %g2
  87. add %o4, 1, %o4
  88. 1:
  89. retl
  90. sub %o4, %o1, %o0
  91. .section .fixup,#alloc,#execinstr
  92. .align 4
  93. 9:
  94. retl
  95. clr %o0
  96. .section __ex_table,#alloc
  97. .align 4
  98. .word 10b, 9b
  99. .word 11b, 9b
  100. .word 12b, 9b
  101. .word 13b, 9b