memscan_32.S 1.9 KB

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