memset.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Optimised simple memory fill
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <asm/cache.h>
  12. .section .text
  13. .balign L1_CACHE_BYTES
  14. ###############################################################################
  15. #
  16. # void *memset(void *dst, int c, size_t n)
  17. #
  18. ###############################################################################
  19. .globl memset
  20. .type memset,@function
  21. memset:
  22. movm [d2,d3],(sp)
  23. mov d0,(12,sp)
  24. mov d1,(16,sp)
  25. mov (20,sp),d2 # count
  26. mov d0,a0 # dst
  27. mov d0,e3 # the return value
  28. cmp +0,d2
  29. beq memset_done # return if zero-length fill
  30. # see if the region parameters are four-byte aligned
  31. or d0,d2,d3
  32. and +3,d3
  33. bne memset_1 # jump if not
  34. extbu d1
  35. mov_asl d1,d3,8,d1
  36. or_asl d1,d3,8,d1
  37. or_asl d1,d3,8,d1
  38. or d3,d1
  39. # we want to transfer as much as we can in chunks of 32 bytes
  40. cmp +31,d2
  41. bls memset_4_remainder # 4-byte aligned remainder
  42. add -32,d2
  43. mov +32,d3
  44. memset_4_loop:
  45. mov d1,(a0+)
  46. mov d1,(a0+)
  47. mov d1,(a0+)
  48. mov d1,(a0+)
  49. mov d1,(a0+)
  50. mov d1,(a0+)
  51. mov d1,(a0+)
  52. mov d1,(a0+)
  53. sub d3,d2
  54. bcc memset_4_loop
  55. add d3,d2
  56. beq memset_4_no_remainder
  57. memset_4_remainder:
  58. # cut 4-7 words down to 0-3
  59. cmp +16,d2
  60. bcs memset_4_three_or_fewer_words
  61. mov d1,(a0+)
  62. mov d1,(a0+)
  63. mov d1,(a0+)
  64. mov d1,(a0+)
  65. add -16,d2
  66. beq memset_4_no_remainder
  67. # copy the remaining 1, 2 or 3 words
  68. memset_4_three_or_fewer_words:
  69. cmp +8,d2
  70. bcs memset_4_one_word
  71. beq memset_4_two_words
  72. mov d1,(a0+)
  73. memset_4_two_words:
  74. mov d1,(a0+)
  75. memset_4_one_word:
  76. mov d1,(a0+)
  77. memset_4_no_remainder:
  78. # check we set the correct amount
  79. # TODO: REMOVE CHECK
  80. sub e3,a0,d2
  81. mov (20,sp),d1
  82. cmp d2,d1
  83. beq memset_done
  84. break
  85. break
  86. break
  87. memset_done:
  88. mov e3,a0
  89. ret [d2,d3],8
  90. # handle misaligned copying
  91. memset_1:
  92. add -1,d2
  93. mov +1,d3
  94. setlb # setlb requires the next insns
  95. # to occupy exactly 4 bytes
  96. sub d3,d2
  97. movbu d1,(a0)
  98. inc a0
  99. lcc
  100. mov e3,a0
  101. ret [d2,d3],8
  102. memset_end:
  103. .size memset, memset_end-memset