summaryrefslogtreecommitdiff
path: root/libc/string/mips/memset.S
diff options
context:
space:
mode:
Diffstat (limited to 'libc/string/mips/memset.S')
-rw-r--r--libc/string/mips/memset.S71
1 files changed, 69 insertions, 2 deletions
diff --git a/libc/string/mips/memset.S b/libc/string/mips/memset.S
index 9169ad58a..ff0554ff9 100644
--- a/libc/string/mips/memset.S
+++ b/libc/string/mips/memset.S
@@ -22,11 +22,76 @@
#include <endian.h>
#include "sysdep.h"
+/* void *memset(void *s, int c, size_t n). */
+
#ifdef __mips64
-#error mips32 code being compiled for mips64!
+
+#include <sys/asm.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+# define SDHI sdl /* high part is left in big-endian */
+#else
+# define SDHI sdr /* high part is right in little-endian */
#endif
-/* void *memset(void *s, int c, size_t n). */
+ENTRY (memset)
+ .set noreorder
+
+ slti ta1, a2, 16 # Less than 16?
+ bne ta1, zero, L(last16)
+ move v0, a0 # Setup exit value before too late
+
+ beq a1, zero, L(ueven) # If zero pattern, no need to extend
+ andi a1, 0xff # Avoid problems with bogus arguments
+ dsll ta0, a1, 8
+ or a1, ta0
+ dsll ta0, a1, 16
+ or a1, ta0 # a1 is now pattern in full word
+ dsll ta0, a1, 32
+ or a1, ta0 # a1 is now pattern in double word
+
+L(ueven):
+ PTR_SUBU ta0, zero, a0 # Unaligned address?
+ andi ta0, 0x7
+ beq ta0, zero, L(chkw)
+ PTR_SUBU a2, ta0
+ SDHI a1, 0(a0) # Yes, handle first unaligned part
+ PTR_ADDU a0, ta0 # Now both a0 and a2 are updated
+
+L(chkw):
+ andi ta0, a2, 0xf # Enough left for one loop iteration?
+ beq ta0, a2, L(chkl)
+ PTR_SUBU a3, a2, ta0
+ PTR_ADDU a3, a0 # a3 is last loop address +1
+ move a2, ta0 # a2 is now # of bytes left after loop
+L(loopw):
+ PTR_ADDIU a0, 16 # Handle 2 dwords pr. iteration
+ sd a1, -16(a0)
+ bne a0, a3, L(loopw)
+ sd a1, -8(a0)
+
+L(chkl):
+ andi ta0, a2, 0x8 # Check if there is at least a double
+ beq ta0, zero, L(last16) # word remaining after the loop
+ PTR_SUBU a2, ta0
+ sd a1, 0(a0) # Yes...
+ PTR_ADDIU a0, 8
+
+L(last16):
+ blez a2, L(exit) # Handle last 16 bytes (if cnt>0)
+ PTR_ADDU a3, a2, a0 # a3 is last address +1
+L(lst16l):
+ PTR_ADDIU a0, 1
+ bne a0, a3, L(lst16l)
+ sb a1, -1(a0)
+L(exit):
+ j ra # Bye, bye
+ nop
+
+ .set reorder
+END (memset)
+
+#else /* !__mips64 */
#if __BYTE_ORDER == __BIG_ENDIAN
# define SWHI swl /* high part is left in big-endian */
@@ -89,4 +154,6 @@ L(exit):
.set reorder
END (memset)
+#endif /* !__mips64 */
+
libc_hidden_def(memset)