strlen_user_64.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* strlen_user.S: Sparc64 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,1999 David S. Miller (davem@redhat.com)
  8. * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  9. */
  10. #include <asm/asi.h>
  11. #define LO_MAGIC 0x01010101
  12. #define HI_MAGIC 0x80808080
  13. .align 4
  14. .global __strlen_user, __strnlen_user
  15. __strlen_user:
  16. sethi %hi(32768), %o1
  17. __strnlen_user:
  18. mov %o1, %g1
  19. mov %o0, %o1
  20. andcc %o0, 3, %g0
  21. be,pt %icc, 9f
  22. sethi %hi(HI_MAGIC), %o4
  23. 10: lduba [%o0] %asi, %o5
  24. brz,pn %o5, 21f
  25. add %o0, 1, %o0
  26. andcc %o0, 3, %g0
  27. be,pn %icc, 4f
  28. or %o4, %lo(HI_MAGIC), %o3
  29. 11: lduba [%o0] %asi, %o5
  30. brz,pn %o5, 22f
  31. add %o0, 1, %o0
  32. andcc %o0, 3, %g0
  33. be,pt %icc, 13f
  34. srl %o3, 7, %o2
  35. 12: lduba [%o0] %asi, %o5
  36. brz,pn %o5, 23f
  37. add %o0, 1, %o0
  38. ba,pt %icc, 2f
  39. 15: lda [%o0] %asi, %o5
  40. 9: or %o4, %lo(HI_MAGIC), %o3
  41. 4: srl %o3, 7, %o2
  42. 13: lda [%o0] %asi, %o5
  43. 2: sub %o5, %o2, %o4
  44. andcc %o4, %o3, %g0
  45. bne,pn %icc, 82f
  46. add %o0, 4, %o0
  47. sub %o0, %o1, %g2
  48. 81: cmp %g2, %g1
  49. blu,pt %icc, 13b
  50. mov %o0, %o4
  51. ba,a,pt %xcc, 1f
  52. /* Check every byte. */
  53. 82: srl %o5, 24, %g7
  54. andcc %g7, 0xff, %g0
  55. be,pn %icc, 1f
  56. add %o0, -3, %o4
  57. srl %o5, 16, %g7
  58. andcc %g7, 0xff, %g0
  59. be,pn %icc, 1f
  60. add %o4, 1, %o4
  61. srl %o5, 8, %g7
  62. andcc %g7, 0xff, %g0
  63. be,pn %icc, 1f
  64. add %o4, 1, %o4
  65. andcc %o5, 0xff, %g0
  66. bne,pt %icc, 81b
  67. sub %o0, %o1, %g2
  68. add %o4, 1, %o4
  69. 1: retl
  70. sub %o4, %o1, %o0
  71. 21: retl
  72. mov 1, %o0
  73. 22: retl
  74. mov 2, %o0
  75. 23: retl
  76. mov 3, %o0
  77. .section .fixup,#alloc,#execinstr
  78. .align 4
  79. 30:
  80. retl
  81. clr %o0
  82. .section __ex_table,"a"
  83. .align 4
  84. .word 10b, 30b
  85. .word 11b, 30b
  86. .word 12b, 30b
  87. .word 15b, 30b
  88. .word 13b, 30b