memset.S 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <features.h>
  17. /*#include <sysdep.h>*/
  18. #include <endian.h>
  19. #include "sysdep.h"
  20. #ifdef __mips64
  21. #error mips32 code being compiled for mips64!
  22. #endif
  23. /* void *memset(void *s, int c, size_t n). */
  24. #if __BYTE_ORDER == __BIG_ENDIAN
  25. # define SWHI swl /* high part is left in big-endian */
  26. #else
  27. # define SWHI swr /* high part is right in little-endian */
  28. #endif
  29. ENTRY (memset)
  30. .set noreorder
  31. slti t1, a2, 8 # Less than 8?
  32. bne t1, zero, L(last8)
  33. move v0, a0 # Setup exit value before too late
  34. beq a1, zero, L(ueven) # If zero pattern, no need to extend
  35. andi a1, 0xff # Avoid problems with bogus arguments
  36. sll t0, a1, 8
  37. or a1, t0
  38. sll t0, a1, 16
  39. or a1, t0 # a1 is now pattern in full word
  40. L(ueven):
  41. subu t0, zero, a0 # Unaligned address?
  42. andi t0, 0x3
  43. beq t0, zero, L(chkw)
  44. subu a2, t0
  45. SWHI a1, 0(a0) # Yes, handle first unaligned part
  46. addu a0, t0 # Now both a0 and a2 are updated
  47. L(chkw):
  48. andi t0, a2, 0x7 # Enough left for one loop iteration?
  49. beq t0, a2, L(chkl)
  50. subu a3, a2, t0
  51. addu a3, a0 # a3 is last loop address +1
  52. move a2, t0 # a2 is now # of bytes left after loop
  53. L(loopw):
  54. addiu a0, 8 # Handle 2 words pr. iteration
  55. sw a1, -8(a0)
  56. bne a0, a3, L(loopw)
  57. sw a1, -4(a0)
  58. L(chkl):
  59. andi t0, a2, 0x4 # Check if there is at least a full
  60. beq t0, zero, L(last8) # word remaining after the loop
  61. subu a2, t0
  62. sw a1, 0(a0) # Yes...
  63. addiu a0, 4
  64. L(last8):
  65. blez a2, L(exit) # Handle last 8 bytes (if cnt>0)
  66. addu a3, a2, a0 # a3 is last address +1
  67. L(lst8l):
  68. addiu a0, 1
  69. bne a0, a3, L(lst8l)
  70. sb a1, -1(a0)
  71. L(exit):
  72. j ra # Bye, bye
  73. nop
  74. .set reorder
  75. END (memset)
  76. libc_hidden_def(memset)