memset.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Hartvig Ekner <hartvige@mips.com>, 2002.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /*#include <sysdep.h>*/
  17. #include <endian.h>
  18. #include "sysdep.h"
  19. #ifdef __mips64
  20. #error mips32 code being compiled for mips64!
  21. #endif
  22. /* void *memset(void *s, int c, size_t n). */
  23. #if __BYTE_ORDER == __BIG_ENDIAN
  24. # define SWHI swl /* high part is left in big-endian */
  25. #else
  26. # define SWHI swr /* high part is right in little-endian */
  27. #endif
  28. ENTRY (memset)
  29. .set noreorder
  30. slti t1, a2, 8 # Less than 8?
  31. bne t1, zero, L(last8)
  32. move v0, a0 # Setup exit value before too late
  33. beq a1, zero, L(ueven) # If zero pattern, no need to extend
  34. andi a1, 0xff # Avoid problems with bogus arguments
  35. sll t0, a1, 8
  36. or a1, t0
  37. sll t0, a1, 16
  38. or a1, t0 # a1 is now pattern in full word
  39. L(ueven):
  40. subu t0, zero, a0 # Unaligned address?
  41. andi t0, 0x3
  42. beq t0, zero, L(chkw)
  43. subu a2, t0
  44. SWHI a1, 0(a0) # Yes, handle first unaligned part
  45. addu a0, t0 # Now both a0 and a2 are updated
  46. L(chkw):
  47. andi t0, a2, 0x7 # Enough left for one loop iteration?
  48. beq t0, a2, L(chkl)
  49. subu a3, a2, t0
  50. addu a3, a0 # a3 is last loop address +1
  51. move a2, t0 # a2 is now # of bytes left after loop
  52. L(loopw):
  53. addiu a0, 8 # Handle 2 words pr. iteration
  54. sw a1, -8(a0)
  55. bne a0, a3, L(loopw)
  56. sw a1, -4(a0)
  57. L(chkl):
  58. andi t0, a2, 0x4 # Check if there is at least a full
  59. beq t0, zero, L(last8) # word remaining after the loop
  60. subu a2, t0
  61. sw a1, 0(a0) # Yes...
  62. addiu a0, 4
  63. L(last8):
  64. blez a2, L(exit) # Handle last 8 bytes (if cnt>0)
  65. addu a3, a2, a0 # a3 is last address +1
  66. L(lst8l):
  67. addiu a0, 1
  68. bne a0, a3, L(lst8l)
  69. sb a1, -1(a0)
  70. L(exit):
  71. j ra # Bye, bye
  72. nop
  73. .set reorder
  74. END (memset)
  75. libc_hidden_builtin_def (memset)