memscan_32.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * memscan.S: Optimized memscan for the Sparc.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #include <asm/export.h>
  7. /* In essence, this is just a fancy strlen. */
  8. #define LO_MAGIC 0x01010101
  9. #define HI_MAGIC 0x80808080
  10. .text
  11. .align 4
  12. .globl __memscan_zero, __memscan_generic
  13. .globl memscan
  14. EXPORT_SYMBOL(__memscan_zero)
  15. EXPORT_SYMBOL(__memscan_generic)
  16. __memscan_zero:
  17. /* %o0 = addr, %o1 = size */
  18. cmp %o1, 0
  19. bne,a 1f
  20. andcc %o0, 3, %g0
  21. retl
  22. nop
  23. 1:
  24. be mzero_scan_word
  25. sethi %hi(HI_MAGIC), %g2
  26. ldsb [%o0], %g3
  27. mzero_still_not_word_aligned:
  28. cmp %g3, 0
  29. bne 1f
  30. add %o0, 1, %o0
  31. retl
  32. sub %o0, 1, %o0
  33. 1:
  34. subcc %o1, 1, %o1
  35. bne,a 1f
  36. andcc %o0, 3, %g0
  37. retl
  38. nop
  39. 1:
  40. bne,a mzero_still_not_word_aligned
  41. ldsb [%o0], %g3
  42. sethi %hi(HI_MAGIC), %g2
  43. mzero_scan_word:
  44. or %g2, %lo(HI_MAGIC), %o3
  45. sethi %hi(LO_MAGIC), %g3
  46. or %g3, %lo(LO_MAGIC), %o2
  47. mzero_next_word:
  48. ld [%o0], %g2
  49. mzero_next_word_preloaded:
  50. sub %g2, %o2, %g2
  51. mzero_next_word_preloaded_next:
  52. andcc %g2, %o3, %g0
  53. bne mzero_byte_zero
  54. add %o0, 4, %o0
  55. mzero_check_out_of_fuel:
  56. subcc %o1, 4, %o1
  57. bg,a 1f
  58. ld [%o0], %g2
  59. retl
  60. nop
  61. 1:
  62. b mzero_next_word_preloaded_next
  63. sub %g2, %o2, %g2
  64. /* Check every byte. */
  65. mzero_byte_zero:
  66. ldsb [%o0 - 4], %g2
  67. cmp %g2, 0
  68. bne mzero_byte_one
  69. sub %o0, 4, %g3
  70. retl
  71. mov %g3, %o0
  72. mzero_byte_one:
  73. ldsb [%o0 - 3], %g2
  74. cmp %g2, 0
  75. bne,a mzero_byte_two_and_three
  76. ldsb [%o0 - 2], %g2
  77. retl
  78. sub %o0, 3, %o0
  79. mzero_byte_two_and_three:
  80. cmp %g2, 0
  81. bne,a 1f
  82. ldsb [%o0 - 1], %g2
  83. retl
  84. sub %o0, 2, %o0
  85. 1:
  86. cmp %g2, 0
  87. bne,a mzero_next_word_preloaded
  88. ld [%o0], %g2
  89. retl
  90. sub %o0, 1, %o0
  91. mzero_found_it:
  92. retl
  93. sub %o0, 2, %o0
  94. memscan:
  95. __memscan_generic:
  96. /* %o0 = addr, %o1 = c, %o2 = size */
  97. cmp %o2, 0
  98. bne,a 0f
  99. ldub [%o0], %g2
  100. b,a 2f
  101. 1:
  102. ldub [%o0], %g2
  103. 0:
  104. cmp %g2, %o1
  105. be 2f
  106. addcc %o2, -1, %o2
  107. bne 1b
  108. add %o0, 1, %o0
  109. 2:
  110. retl
  111. nop