summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorjonathan <jonathan@NetBSD.org>1999-03-15 06:34:10 +0000
committerjonathan <jonathan@NetBSD.org>1999-03-15 06:34:10 +0000
commite22fd3b59dbd197d7a01594b8ee6bb52dfe354ff (patch)
treea6809f8048cfa2a803ffa83ea28a155132f9520d /sys
parent1990f5b094e3148bde18e95d120a5b36121a1bb4 (diff)
Fix bug in construction of word-length version of 'c'.
Preserve input string and return it as per userlevel spec.
Diffstat (limited to 'sys')
-rw-r--r--sys/lib/libkern/arch/mips/memset.S22
1 files changed, 14 insertions, 8 deletions
diff --git a/sys/lib/libkern/arch/mips/memset.S b/sys/lib/libkern/arch/mips/memset.S
index d3bd69a4151..f8e617c6e6f 100644
--- a/sys/lib/libkern/arch/mips/memset.S
+++ b/sys/lib/libkern/arch/mips/memset.S
@@ -1,4 +1,4 @@
-/* $NetBSD: memset.S,v 1.1 1999/01/28 03:08:57 jonathan Exp $ */
+/* $NetBSD: memset.S,v 1.2 1999/03/15 06:34:10 jonathan Exp $ */
#include <machine/cdefs.h>
#include <mips/asm.h>
#include <machine/endian.h>
@@ -10,11 +10,15 @@
* memset(void *s1, int c, int len)
*/
LEAF(memset)
+ .set noreorder
blt a2, 12, smallclr # small amount to clear?
- sll t1, a1, 8
- or t1, t1, a1
- sll t1, a1, 16
- or t1, t1, a1
+ move v0, a0 # save s1 for result
+
+ sll t1, a1, 8 # compute c << 8 in t1
+ or t1, t1, a1 # compute c << 8 | c in 11
+ sll t2, t1, 16 # shift that left 16
+ or t1, t2, t1 # or together
+
subu t0, zero, a0 # compute # bytes to word align address
and t0, t0, 3
beq t0, zero, 1f # skip if word aligned
@@ -22,14 +26,15 @@ LEAF(memset)
SWHI t1, 0(a0) # store 1, 2, or 3 bytes to align
addu a0, a0, t0
1:
- and v0, a2, 3 # compute number of words left
- subu t0, a2, v0
- move a2, v0
+ and v1, a2, 3 # compute number of whole words left
+ subu t0, a2, v1
+ subu a2, a2, t0
addu t0, t0, a0 # compute ending address
2:
addu a0, a0, 4 # clear words
bne a0, t0, 2b # unrolling loop does not help
sw t1, -4(a0) # since we are limited by memory speed
+
smallclr:
ble a2, zero, 2f
addu t0, a2, a0 # compute ending address
@@ -40,4 +45,5 @@ smallclr:
2:
j ra
nop
+ .set reorder
END(memset)