svn commit: r206334 - user/jmallett/octeon/lib/libc/mips/string

Juli Mallett jmallett at FreeBSD.org
Wed Apr 7 01:48:37 UTC 2010


Author: jmallett
Date: Wed Apr  7 01:48:37 2010
New Revision: 206334
URL: http://svn.freebsd.org/changeset/base/206334

Log:
  Merge matt at NetBSD's PTRization of string functions and PTRize the ones that
  NetBSD doesn't seem to bother implementing in assembly anymore, at least not
  in common libc.

Modified:
  user/jmallett/octeon/lib/libc/mips/string/bcmp.S
  user/jmallett/octeon/lib/libc/mips/string/bcopy.S
  user/jmallett/octeon/lib/libc/mips/string/bzero.S
  user/jmallett/octeon/lib/libc/mips/string/ffs.S
  user/jmallett/octeon/lib/libc/mips/string/index.S
  user/jmallett/octeon/lib/libc/mips/string/rindex.S
  user/jmallett/octeon/lib/libc/mips/string/strcmp.S
  user/jmallett/octeon/lib/libc/mips/string/strlen.S

Modified: user/jmallett/octeon/lib/libc/mips/string/bcmp.S
==============================================================================
--- user/jmallett/octeon/lib/libc/mips/string/bcmp.S	Wed Apr  7 01:11:35 2010	(r206333)
+++ user/jmallett/octeon/lib/libc/mips/string/bcmp.S	Wed Apr  7 01:48:37 2010	(r206334)
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcmp.S,v 1.8 2003/08/07 16:42:16 agc Exp $	*/
+/*	$NetBSD: bcmp.S,v 1.9 2009/12/14 01:07:42 matt Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -35,9 +35,15 @@
 #include <machine/asm.h>
 __FBSDID("$FreeBSD$");
 
+#define _LOCORE		/* XXX not really, just assembly-code source */
+#include <machine/endian.h>	/* LWLO/LWHI, SWLO/SWHI */
+
 #if defined(LIBC_SCCS) && !defined(lint)
+#if 0
 	ASMSTR("from: @(#)bcmp.s	8.1 (Berkeley) 6/4/93")
-	ASMSTR("$NetBSD: bcmp.S,v 1.8 2003/08/07 16:42:16 agc Exp $")
+#else
+	ASMSTR("$NetBSD: bcmp.S,v 1.9 2009/12/14 01:07:42 matt Exp $")
+#endif
 #endif /* LIBC_SCCS and not lint */
 
 #ifdef __ABICALLS__
@@ -49,86 +55,76 @@ __FBSDID("$FreeBSD$");
 
 LEAF(bcmp)
 	.set	noreorder
-	blt	a2, 16, small		# is it worth any trouble?
-	xor	v0, a0, a1		# compare low two bits of addresses
-	and	v0, v0, 3
-	subu	a3, zero, a1		# compute # bytes to word align address
-	bne	v0, zero, unaligned	# not possible to align addresses
-	and	a3, a3, 3
-
-	beq	a3, zero, 1f
-	subu	a2, a2, a3		# subtract from remaining count
-	move	v0, v1			# init v0,v1 so unmodified bytes match
-#ifdef __MIPSEB__
-	lwl	v0, 0(a0)		# read 1, 2, or 3 bytes
-	lwl	v1, 0(a1)
-#else
-	lwr	v0, 0(a0)		# read 1, 2, or 3 bytes
-	lwr	v1, 0(a1)
-#endif
-	addu	a1, a1, a3
-	bne	v0, v1, nomatch
-	addu	a0, a0, a3
+	blt		a2, 16, small	# is it worth any trouble?
+	xor		v0, a0, a1	# compare low two bits of addresses
+	and		v0, v0, 3
+	PTR_SUBU	a3, zero, a1	# compute # bytes to word align address
+	bne		v0, zero, unaligned # not possible to align addresses
+	and		a3, a3, 3
+
+	beq		a3, zero, 1f
+	PTR_SUBU	a2, a2, a3	# subtract from remaining count
+	move		v0, v1		# init v0,v1 so unmodified bytes match
+	LWHI		v0, 0(a0)	# read 1, 2, or 3 bytes
+	LWHI		v1, 0(a1)
+	PTR_ADDU	a1, a1, a3
+	bne		v0, v1, nomatch
+	PTR_ADDU	a0, a0, a3
 1:
-	and	a3, a2, ~3		# compute number of whole words left
-	subu	a2, a2, a3		#   which has to be >= (16-3) & ~3
-	addu	a3, a3, a0		# compute ending address
+	and		a3, a2, ~3	# compute number of whole words left
+	PTR_SUBU	a2, a2, a3	#   which has to be >= (16-3) & ~3
+	PTR_ADDU	a3, a3, a0	# compute ending address
 2:
-	lw	v0, 0(a0)		# compare words
-	lw	v1, 0(a1)
-	addu	a0, a0, 4
-	bne	v0, v1, nomatch
-	addu	a1, a1, 4
-	bne	a0, a3, 2b
+	lw		v0, 0(a0)	# compare words
+	lw		v1, 0(a1)
+	PTR_ADDU	a0, a0, 4
+	bne		v0, v1, nomatch
+	PTR_ADDU	a1, a1, 4
+	bne		a0, a3, 2b
 	nop
-	b	small			# finish remainder
+	b		small		# finish remainder
 	nop
 unaligned:
-	beq	a3, zero, 2f
-	subu	a2, a2, a3		# subtract from remaining count
-	addu	a3, a3, a0		# compute ending address
+	beq		a3, zero, 2f
+	PTR_SUBU	a2, a2, a3	# subtract from remaining count
+	PTR_ADDU	a3, a3, a0	# compute ending address
 1:
-	lbu	v0, 0(a0)		# compare bytes until a1 word aligned
-	lbu	v1, 0(a1)
-	addu	a0, a0, 1
-	bne	v0, v1, nomatch
-	addu	a1, a1, 1
-	bne	a0, a3, 1b
+	lbu		v0, 0(a0)	# compare bytes until a1 word aligned
+	lbu		v1, 0(a1)
+	PTR_ADDU	a0, a0, 1
+	bne		v0, v1, nomatch
+	PTR_ADDU	a1, a1, 1
+	bne		a0, a3, 1b
 	nop
 2:
-	and	a3, a2, ~3		# compute number of whole words left
-	subu	a2, a2, a3		#   which has to be >= (16-3) & ~3
-	addu	a3, a3, a0		# compute ending address
+	and		a3, a2, ~3	# compute number of whole words left
+	PTR_SUBU	a2, a2, a3	#   which has to be >= (16-3) & ~3
+	PTR_ADDU	a3, a3, a0	# compute ending address
 3:
-#ifdef __MIPSEB__
-	lwl	v0, 0(a0)		# compare words a0 unaligned, a1 aligned
-	lwr	v0, 3(a0)
-#else
-	lwr	v0, 0(a0)		# compare words a0 unaligned, a1 aligned
-	lwl	v0, 3(a0)
-#endif
-	lw	v1, 0(a1)
-	addu	a0, a0, 4
-	bne	v0, v1, nomatch
-	addu	a1, a1, 4
-	bne	a0, a3, 3b
+	LWHI		v0, 0(a0)	# compare words a0 unaligned, a1 aligned
+	LWLO		v0, 3(a0)
+	lw		v1, 0(a1)
+	PTR_ADDU	a0, a0, 4
+	bne		v0, v1, nomatch
+	PTR_ADDU	a1, a1, 4
+	bne		a0, a3, 3b
 	nop
 small:
-	ble	a2, zero, match
-	addu	a3, a2, a0		# compute ending address
+	ble		a2, zero, match
+	PTR_ADDU	a3, a2, a0		# compute ending address
 1:
-	lbu	v0, 0(a0)
-	lbu	v1, 0(a1)
-	addu	a0, a0, 1
-	bne	v0, v1, nomatch
-	addu	a1, a1, 1
-	bne	a0, a3, 1b
+	lbu		v0, 0(a0)
+	lbu		v1, 0(a1)
+	PTR_ADDU	a0, a0, 1
+	bne		v0, v1, nomatch
+	PTR_ADDU	a1, a1, 1
+	bne		a0, a3, 1b
 	nop
 match:
-	j	ra
-	move	v0, zero
+	j		ra
+	move		v0, zero
 nomatch:
-	j	ra
-	li	v0, 1
+	j		ra
+	li		v0, 1
 	.set	reorder
 END(bcmp)

Modified: user/jmallett/octeon/lib/libc/mips/string/bcopy.S
==============================================================================
--- user/jmallett/octeon/lib/libc/mips/string/bcopy.S	Wed Apr  7 01:11:35 2010	(r206333)
+++ user/jmallett/octeon/lib/libc/mips/string/bcopy.S	Wed Apr  7 01:48:37 2010	(r206334)
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcopy.S,v 1.2 2005/12/27 11:23:53 tsutsui Exp $	*/
+/*	$NetBSD: bcopy.S,v 1.3 2009/12/14 00:39:00 matt Exp $	*/
 
 /*
  * Mach Operating System
@@ -38,9 +38,15 @@
 #include <machine/asm.h>
 __FBSDID("$FreeBSD$");
 
+#define _LOCORE		/* XXX not really, just assembly-code source */
+#include <machine/endian.h>
+
 #if defined(LIBC_SCCS) && !defined(lint)
+#if 0
 	ASMSTR("from: @(#)mips_bcopy.s	2.2 CMU 18/06/93")
-	ASMSTR("$NetBSD: bcopy.S,v 1.2 2005/12/27 11:23:53 tsutsui Exp $")
+#else
+	ASMSTR("$NetBSD: bcopy.S,v 1.3 2009/12/14 00:39:00 matt Exp $")
+#endif
 #endif /* LIBC_SCCS and not lint */
 
 #ifdef __ABICALLS__
@@ -99,71 +105,72 @@ LEAF(FUNCTION)
 	 *	copy is alignable.  eg if src and dest are both
 	 *	on a halfword boundary.
 	 */
-	andi	t1,DSTREG,3		# get last 3 bits of dest
-	bne	t1,zero,3f
-	andi	t0,SRCREG,3		# get last 3 bits of src
-	bne	t0,zero,5f
+	andi		t1,DSTREG,(SZREG-1)	# get last bits of dest
+	bne		t1,zero,3f		# dest unaligned
+	andi		t0,SRCREG,(SZREG-1)	# get last bits of src
+	bne		t0,zero,5f
 
 	/*
-	 *	Forward aligned->aligned copy, 8*4 bytes at a time.
+	 *	Forward aligned->aligned copy, 8 words at a time.
 	 */
-	li	AT,-32
-	and	t0,SIZEREG,AT		# count truncated to multiple of 32 */
-	addu	a3,SRCREG,t0		# run fast loop up to this address
-	sltu	AT,SRCREG,a3		# any work to do?
-	beq	AT,zero,2f
-	subu	SIZEREG,t0
+98:
+	li		AT,-(SZREG*8)
+	and		t0,SIZEREG,AT		# count truncated to multiples
+	PTR_ADDU	a3,SRCREG,t0		# run fast loop up to this addr
+	sltu		AT,SRCREG,a3		# any work to do?
+	beq		AT,zero,2f
+	PTR_SUBU	SIZEREG,t0
 
 	/*
 	 *	loop body
 	 */
 1:	# cp
-	lw	t3,0(SRCREG)
-	lw	v1,4(SRCREG)
-	lw	t0,8(SRCREG)
-	lw	t1,12(SRCREG)
-	addu	SRCREG,32
-	sw	t3,0(DSTREG)
-	sw	v1,4(DSTREG)
-	sw	t0,8(DSTREG)
-	sw	t1,12(DSTREG)
-	lw	t1,-4(SRCREG)
-	lw	t0,-8(SRCREG)
-	lw	v1,-12(SRCREG)
-	lw	t3,-16(SRCREG)
-	addu	DSTREG,32
-	sw	t1,-4(DSTREG)
-	sw	t0,-8(DSTREG)
-	sw	v1,-12(DSTREG)
-	bne	SRCREG,a3,1b
-	sw	t3,-16(DSTREG)
+	REG_L		t3,(0*SZREG)(SRCREG)
+	REG_L		v1,(1*SZREG)(SRCREG)
+	REG_L		t0,(2*SZREG)(SRCREG)
+	REG_L		t1,(3*SZREG)(SRCREG)
+	PTR_ADDU	SRCREG,SZREG*8
+	REG_S		t3,(0*SZREG)(DSTREG)
+	REG_S		v1,(1*SZREG)(DSTREG)
+	REG_S		t0,(2*SZREG)(DSTREG)
+	REG_S		t1,(3*SZREG)(DSTREG)
+	REG_L		t1,(-1*SZREG)(SRCREG)
+	REG_L		t0,(-2*SZREG)(SRCREG)
+	REG_L		v1,(-3*SZREG)(SRCREG)
+	REG_L		t3,(-4*SZREG)(SRCREG)
+	PTR_ADDU	DSTREG,SZREG*8
+	REG_S		t1,(-1*SZREG)(DSTREG)
+	REG_S		t0,(-2*SZREG)(DSTREG)
+	REG_S		v1,(-3*SZREG)(DSTREG)
+	bne		SRCREG,a3,1b
+	REG_S		t3,(-4*SZREG)(DSTREG)
 
 	/*
 	 *	Copy a word at a time, no loop unrolling.
 	 */
 2:	# wordcopy
-	andi	t2,SIZEREG,3		# get byte count / 4
-	subu	t2,SIZEREG,t2		# t2 = number of words to copy * 4
-	beq	t2,zero,3f
-	addu	t0,SRCREG,t2		# stop at t0
-	subu	SIZEREG,SIZEREG,t2
+	andi		t2,SIZEREG,(SZREG-1)	# get byte count / SZREG
+	PTR_SUBU	t2,SIZEREG,t2		# t2 = words to copy * SZREG
+	beq		t2,zero,3f
+	PTR_ADDU	t0,SRCREG,t2		# stop at t0
+	PTR_SUBU	SIZEREG,SIZEREG,t2
 1:
-	lw	t3,0(SRCREG)
-	addu	SRCREG,4
-	sw	t3,0(DSTREG)
-	bne	SRCREG,t0,1b
-	addu	DSTREG,4
+	REG_L		t3,0(SRCREG)
+	PTR_ADDU	SRCREG,SZREG
+	REG_S		t3,0(DSTREG)
+	bne		SRCREG,t0,1b
+	PTR_ADDU	DSTREG,SZREG
 
 3:	# bytecopy
-	beq	SIZEREG,zero,4f	# nothing left to do?
+	beq		SIZEREG,zero,4f		# nothing left to do?
 	nop
 1:
-	lb	t3,0(SRCREG)
-	addu	SRCREG,1
-	sb	t3,0(DSTREG)
-	subu	SIZEREG,1
-	bgtz	SIZEREG,1b
-	addu	DSTREG,1
+	lb		t3,0(SRCREG)
+	PTR_ADDU	SRCREG,1
+	sb		t3,0(DSTREG)
+	PTR_SUBU	SIZEREG,1
+	bgtz		SIZEREG,1b
+	PTR_ADDU	DSTREG,1
 
 4:	# copydone
 	j	ra
@@ -173,96 +180,91 @@ LEAF(FUNCTION)
 	 *	Copy from unaligned source to aligned dest.
 	 */
 5:	# destaligned
-	andi	t0,SIZEREG,3		# t0 = bytecount mod 4
-	subu	a3,SIZEREG,t0		# number of words to transfer
-	beq	a3,zero,3b
+	andi		t0,SIZEREG,(SZREG-1)	# t0 = bytecount mod SZREG
+	PTR_SUBU	a3,SIZEREG,t0		# number of words to transfer
+	beq		a3,zero,3b
 	nop
-	move	SIZEREG,t0		# this many to do after we are done
-	addu	a3,SRCREG,a3		# stop point
+	move		SIZEREG,t0		# this many to do after we are done
+	PTR_ADDU	a3,SRCREG,a3		# stop point
 
 1:
-#ifdef __MIPSEB__
-	lwl	t3,0(SRCREG)
-	lwr	t3,3(SRCREG)
-#else
-	lwr	t3,0(SRCREG)
-	lwl	t3,3(SRCREG)
-#endif
-	addi	SRCREG,4
-	sw	t3,0(DSTREG)
-	bne	SRCREG,a3,1b
-	addi	DSTREG,4
+	REG_LHI		t3,0(SRCREG)
+	REG_LLO		t3,SZREG-1(SRCREG)
+	PTR_ADDI	SRCREG,SZREG
+	REG_S		t3,0(DSTREG)
+	bne		SRCREG,a3,1b
+	PTR_ADDI	DSTREG,SZREG
 
-	j	3b
+	b		3b
 	nop
 
 6:	# backcopy -- based on above
-	addu	SRCREG,SIZEREG
-	addu	DSTREG,SIZEREG
-	andi	t1,DSTREG,3		# get last 3 bits of dest
-	bne	t1,zero,3f
-	andi	t0,SRCREG,3		# get last 3 bits of src
-	bne	t0,zero,5f
+	PTR_ADDU	SRCREG,SIZEREG
+	PTR_ADDU	DSTREG,SIZEREG
+	andi		t1,DSTREG,SZREG-1	# get last 3 bits of dest
+	bne		t1,zero,3f
+	andi		t0,SRCREG,SZREG-1	# get last 3 bits of src
+	bne		t0,zero,5f
 
 	/*
 	 *	Forward aligned->aligned copy, 8*4 bytes at a time.
 	 */
-	li	AT,-32
-	and	t0,SIZEREG,AT		# count truncated to multiple of 32
-	beq	t0,zero,2f		# any work to do?
-	subu	SIZEREG,t0
-	subu	a3,SRCREG,t0
+	li		AT,(-8*SZREG)
+	and		t0,SIZEREG,AT		# count truncated to multiple of 32
+	beq		t0,zero,2f		# any work to do?
+	PTR_SUBU	SIZEREG,t0
+	PTR_SUBU	a3,SRCREG,t0
 
 	/*
 	 *	loop body
 	 */
 1:	# cp
-	lw	t3,-16(SRCREG)
-	lw	v1,-12(SRCREG)
-	lw	t0,-8(SRCREG)
-	lw	t1,-4(SRCREG)
-	subu	SRCREG,32
-	sw	t3,-16(DSTREG)
-	sw	v1,-12(DSTREG)
-	sw	t0,-8(DSTREG)
-	sw	t1,-4(DSTREG)
-	lw	t1,12(SRCREG)
-	lw	t0,8(SRCREG)
-	lw	v1,4(SRCREG)
-	lw	t3,0(SRCREG)
-	subu	DSTREG,32
-	sw	t1,12(DSTREG)
-	sw	t0,8(DSTREG)
-	sw	v1,4(DSTREG)
-	bne	SRCREG,a3,1b
-	sw	t3,0(DSTREG)
+	REG_L		t3,(-4*SZREG)(SRCREG)
+	REG_L		v1,(-3*SZREG)(SRCREG)
+	REG_L		t0,(-2*SZREG)(SRCREG)
+	REG_L		t1,(-1*SZREG)(SRCREG)
+	PTR_SUBU	SRCREG,8*SZREG
+	REG_S		t3,(-4*SZREG)(DSTREG)
+	REG_S		v1,(-3*SZREG)(DSTREG)
+	REG_S		t0,(-2*SZREG)(DSTREG)
+	REG_S		t1,(-1*SZREG)(DSTREG)
+	REG_L		t1,(3*SZREG)(SRCREG)
+	REG_L		t0,(2*SZREG)(SRCREG)
+	REG_L		v1,(1*SZREG)(SRCREG)
+	REG_L		t3,(0*SZREG)(SRCREG)
+	PTR_SUBU	DSTREG,8*SZREG
+	REG_S		t1,(3*SZREG)(DSTREG)
+	REG_S		t0,(2*SZREG)(DSTREG)
+	REG_S		v1,(1*SZREG)(DSTREG)
+	bne		SRCREG,a3,1b
+	REG_S		t3,(0*SZREG)(DSTREG)
 
 	/*
 	 *	Copy a word at a time, no loop unrolling.
 	 */
 2:	# wordcopy
-	andi	t2,SIZEREG,3		# get byte count / 4
-	subu	t2,SIZEREG,t2		# t2 = number of words to copy * 4
-	beq	t2,zero,3f
-	subu	t0,SRCREG,t2		# stop at t0
-	subu	SIZEREG,SIZEREG,t2
+	andi		t2,SIZEREG,SZREG-1	# get byte count / 4
+	PTR_SUBU	t2,SIZEREG,t2		# t2 = number of words to copy
+	beq		t2,zero,3f
+	PTR_SUBU	t0,SRCREG,t2		# stop at t0
+	PTR_SUBU	SIZEREG,SIZEREG,t2
 1:
-	lw	t3,-4(SRCREG)
-	subu	SRCREG,4
-	sw	t3,-4(DSTREG)
-	bne	SRCREG,t0,1b
-	subu	DSTREG,4
+	REG_L		t3,-SZREG(SRCREG)
+	PTR_SUBU	SRCREG,SZREG
+	REG_S		t3,-SZREG(DSTREG)
+	bne		SRCREG,t0,1b
+	PTR_SUBU	DSTREG,SZREG
 
 3:	# bytecopy
-	beq	SIZEREG,zero,4f		# nothing left to do?
+	beq		SIZEREG,zero,4f		# nothing left to do?
 	nop
 1:
-	lb	t3,-1(SRCREG)
-	subu	SRCREG,1
-	sb	t3,-1(DSTREG)
-	subu	SIZEREG,1
-	bgtz	SIZEREG,1b
-	subu	DSTREG,1
+	lb		t3,-1(SRCREG)
+	PTR_SUBU	SRCREG,1
+	sb		t3,-1(DSTREG)
+	PTR_SUBU	SIZEREG,1
+	bgtz		SIZEREG,1b
+	PTR_SUBU	DSTREG,1
 
 4:	# copydone
 	j	ra
@@ -272,27 +274,22 @@ LEAF(FUNCTION)
 	 *	Copy from unaligned source to aligned dest.
 	 */
 5:	# destaligned
-	andi	t0,SIZEREG,3		# t0 = bytecount mod 4
-	subu	a3,SIZEREG,t0		# number of words to transfer
-	beq	a3,zero,3b
+	andi		t0,SIZEREG,SZREG-1	# t0 = bytecount mod 4
+	PTR_SUBU	a3,SIZEREG,t0		# number of words to transfer
+	beq		a3,zero,3b
 	nop
-	move	SIZEREG,t0		# this many to do after we are done
-	subu	a3,SRCREG,a3		# stop point
+	move		SIZEREG,t0		# this many to do after we are done
+	PTR_SUBU	a3,SRCREG,a3		# stop point
 
 1:
-#ifdef __MIPSEB__
-	lwl	t3,-4(SRCREG)
-	lwr	t3,-1(SRCREG)
-#else
-	lwr	t3,-4(SRCREG)
-	lwl	t3,-1(SRCREG)
-#endif
-	subu	SRCREG,4
-	sw	t3,-4(DSTREG)
-	bne	SRCREG,a3,1b
-	subu	DSTREG,4
+	REG_LHI		t3,-SZREG(SRCREG)
+	REG_LLO		t3,-1(SRCREG)
+	PTR_SUBU	SRCREG,SZREG
+	REG_S		t3,-SZREG(DSTREG)
+	bne		SRCREG,a3,1b
+	PTR_SUBU	DSTREG,SZREG
 
-	j	3b
+	b		3b
 	nop
 
 	.set	reorder

Modified: user/jmallett/octeon/lib/libc/mips/string/bzero.S
==============================================================================
--- user/jmallett/octeon/lib/libc/mips/string/bzero.S	Wed Apr  7 01:11:35 2010	(r206333)
+++ user/jmallett/octeon/lib/libc/mips/string/bzero.S	Wed Apr  7 01:48:37 2010	(r206334)
@@ -1,4 +1,4 @@
-/*	$NetBSD: bzero.S,v 1.8 2003/08/07 16:42:16 agc Exp $	*/
+/*	$NetBSD: bzero.S,v 1.10 2009/12/14 02:53:52 matt Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -36,10 +36,15 @@
 __FBSDID("$FreeBSD$");
 
 #if defined(LIBC_SCCS) && !defined(lint)
+#if 0
 	ASMSTR("from: @(#)bzero.s	8.1 (Berkeley) 6/4/93")
-	ASMSTR("$NetBSD: bzero.S,v 1.8 2003/08/07 16:42:16 agc Exp $")
+#else
+	ASMSTR("$NetBSD: bzero.S,v 1.10 2009/12/14 02:53:52 matt Exp $")
+#endif
 #endif /* LIBC_SCCS and not lint */
 
+#define _LOCORE		/* XXX not really, just assembly-code source */
+#include <machine/endian.h>
 
 #ifdef __ABICALLS__
 	.abicalls
@@ -49,34 +54,48 @@ __FBSDID("$FreeBSD$");
 
 LEAF(bzero)
 	.set	noreorder
-	blt	a1, 12, smallclr	# small amount to clear?
-	subu	a3, zero, a0		# compute # bytes to word align address
-	and	a3, a3, 3
-	beq	a3, zero, 1f		# skip if word aligned
-	subu	a1, a1, a3		# subtract from remaining count
-#ifdef __MIPSEB__
-	swl	zero, 0(a0)		# clear 1, 2, or 3 bytes to align
-#else
-	swr	zero, 0(a0)		# clear 1, 2, or 3 bytes to align
+	blt		a1, 3*SZREG, smallclr # small amount to clear?
+	PTR_SUBU	a3, zero, a0	# compute # bytes to word align address
+	and		a3, a3, SZREG-1
+	beq		a3, zero, 1f	# skip if word aligned
+#if SZREG == 4
+	PTR_SUBU	a1, a1, a3	# subtract from remaining count
+	SWHI		zero, 0(a0)	# clear 1, 2, or 3 bytes to align
+	PTR_ADDU	a0, a0, a3
+#endif
+#if SZREG == 8
+	PTR_SUBU	a1, a1, a3	# subtract from remaining count
+	PTR_ADDU	a0, a0, a3	# align dst to next word
+	sll		a3, a3, 3	# bits to bytes
+	li		a2, -1		# make a mask
+#if _BYTE_ORDER == _BIG_ENDIAN
+	REG_SRLV	a2, a2, a3	# we want to keep the MSB bytes
+#endif
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+	REG_SLLV	a2, a2, a3	# we want to keep the LSB bytes
+#endif
+	nor		a2, zero, a2	# complement the mask
+	REG_L		v0, -SZREG(a0)	# load the word to partially clear
+	and		v0, v0, a2	# clear the bytes
+	REG_S		v0, -SZREG(a0)	# store it back
 #endif
-	addu	a0, a0, a3
 1:
-	and	v0, a1, 3		# compute number of words left
-	subu	a3, a1, v0
-	move	a1, v0
-	addu	a3, a3, a0		# compute ending address
+	and		v0, a1, SZREG-1	# compute number of words left
+	PTR_SUBU	a3, a1, v0
+	move		a1, v0
+	PTR_ADDU	a3, a3, a0	# compute ending address
 2:
-	addu	a0, a0, 4		# clear words
-	bne	a0, a3, 2b		#   unrolling loop doesnt help
-	sw	zero, -4(a0)		#   since we are limited by memory speed
+	PTR_ADDU	a0, a0, SZREG	# clear words
+	bne		a0, a3, 2b	#  unrolling loop doesnt help
+	REG_S		zero, -SZREG(a0) # since we are limited by memory speed
 smallclr:
-	ble	a1, zero, 2f
-	addu	a3, a1, a0		# compute ending address
+	ble		a1, zero, 2f
+	PTR_ADDU	a3, a1, a0	# compute ending address
 1:
-	addu	a0, a0, 1		# clear bytes
-	bne	a0, a3, 1b
-	sb	zero, -1(a0)
+	PTR_ADDU	a0, a0, 1	# clear bytes
+	bne		a0, a3, 1b
+	sb		zero, -1(a0)
 2:
-	j	ra
+	j		ra
 	nop
 END(bzero)

Modified: user/jmallett/octeon/lib/libc/mips/string/ffs.S
==============================================================================
--- user/jmallett/octeon/lib/libc/mips/string/ffs.S	Wed Apr  7 01:11:35 2010	(r206333)
+++ user/jmallett/octeon/lib/libc/mips/string/ffs.S	Wed Apr  7 01:48:37 2010	(r206334)
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs.S,v 1.1 2005/12/20 19:28:49 christos Exp $	*/
+/*	$NetBSD: ffs.S,v 1.2 2009/12/14 00:39:00 matt Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@ __FBSDID("$FreeBSD$");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 	ASMSTR("from: @(#)ffs.s	8.1 (Berkeley) 6/4/93")
-	ASMSTR("$NetBSD: ffs.S,v 1.1 2005/12/20 19:28:49 christos Exp $")
+	ASMSTR("$NetBSD: ffs.S,v 1.2 2009/12/14 00:39:00 matt Exp $")
 #endif /* LIBC_SCCS and not lint */
 
 #ifdef __ABICALLS__

Modified: user/jmallett/octeon/lib/libc/mips/string/index.S
==============================================================================
--- user/jmallett/octeon/lib/libc/mips/string/index.S	Wed Apr  7 01:11:35 2010	(r206333)
+++ user/jmallett/octeon/lib/libc/mips/string/index.S	Wed Apr  7 01:48:37 2010	(r206334)
@@ -46,14 +46,14 @@ __FBSDID("$FreeBSD$");
 
 LEAF(index)
 1:
-	lbu	a2, 0(a0)		# get a byte
-	addu	a0, a0, 1
-	beq	a2, a1, fnd
-	bne	a2, zero, 1b
+	lbu		a2, 0(a0)		# get a byte
+	PTR_ADDU	a0, a0, 1
+	beq		a2, a1, fnd
+	bne		a2, zero, 1b
 notfnd:
-	move	v0, zero
-	j	ra
+	move		v0, zero
+	j		ra
 fnd:
-	subu	v0, a0, 1
-	j	ra
+	PTR_SUBU	v0, a0, 1
+	j		ra
 END(index)

Modified: user/jmallett/octeon/lib/libc/mips/string/rindex.S
==============================================================================
--- user/jmallett/octeon/lib/libc/mips/string/rindex.S	Wed Apr  7 01:11:35 2010	(r206333)
+++ user/jmallett/octeon/lib/libc/mips/string/rindex.S	Wed Apr  7 01:48:37 2010	(r206334)
@@ -45,13 +45,13 @@ __FBSDID("$FreeBSD$");
 #endif
 
 LEAF(rindex)
-	move	v0, zero		# default if not found
+	move		v0, zero		# default if not found
 1:
-	lbu	a3, 0(a0)		# get a byte
-	addu	a0, a0, 1
-	bne	a3, a1, 2f
-	subu	v0, a0, 1		# save address of last match
+	lbu		a3, 0(a0)		# get a byte
+	PTR_ADDU	a0, a0, 1
+	bne		a3, a1, 2f
+	PTR_SUBU	v0, a0, 1		# save address of last match
 2:
-	bne	a3, zero, 1b		# continue if not end
-	j	ra
+	bne		a3, zero, 1b		# continue if not end
+	j		ra
 END(rindex)

Modified: user/jmallett/octeon/lib/libc/mips/string/strcmp.S
==============================================================================
--- user/jmallett/octeon/lib/libc/mips/string/strcmp.S	Wed Apr  7 01:11:35 2010	(r206333)
+++ user/jmallett/octeon/lib/libc/mips/string/strcmp.S	Wed Apr  7 01:48:37 2010	(r206334)
@@ -1,4 +1,4 @@
-/*	$NetBSD: strcmp.S,v 1.1 2005/12/20 19:28:50 christos Exp $	*/
+/*	$NetBSD: strcmp.S,v 1.2 2009/12/14 00:39:00 matt Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@ __FBSDID("$FreeBSD$");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 	ASMSTR("from: @(#)strcmp.s	8.1 (Berkeley) 6/4/93")
-	ASMSTR("$NetBSD: strcmp.S,v 1.1 2005/12/20 19:28:50 christos Exp $")
+	ASMSTR("$NetBSD: strcmp.S,v 1.2 2009/12/14 00:39:00 matt Exp $")
 #endif /* LIBC_SCCS and not lint */
 
 #ifdef __ABICALLS__
@@ -55,9 +55,9 @@ LEAF(strcmp)
 	bne	t0, t1, NotEq
 	lbu	t0, 1(a0)		# unroll loop
 	lbu	t1, 1(a1)
-	add	a0, a0, 2
+	PTR_ADD	a0, a0, 2
 	beq	t0, zero, LessOrEq	# end of first string?
-	add	a1, a1, 2
+	PTR_ADD	a1, a1, 2
 	beq	t0, t1, 1b
 NotEq:
 	subu	v0, t0, t1

Modified: user/jmallett/octeon/lib/libc/mips/string/strlen.S
==============================================================================
--- user/jmallett/octeon/lib/libc/mips/string/strlen.S	Wed Apr  7 01:11:35 2010	(r206333)
+++ user/jmallett/octeon/lib/libc/mips/string/strlen.S	Wed Apr  7 01:48:37 2010	(r206334)
@@ -1,4 +1,4 @@
-/*	$NetBSD: strlen.S,v 1.1 2005/12/20 19:28:50 christos Exp $	*/
+/*	$NetBSD: strlen.S,v 1.2 2009/12/14 00:39:00 matt Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@ __FBSDID("$FreeBSD$");
 
 #if defined(LIBC_SCCS) && !defined(lint)
 	ASMSTR("from: @(#)strlen.s	8.1 (Berkeley) 6/4/93")
-	ASMSTR("$NetBSD: strlen.S,v 1.1 2005/12/20 19:28:50 christos Exp $")
+	ASMSTR("$NetBSD: strlen.S,v 1.2 2009/12/14 00:39:00 matt Exp $")
 #endif /* LIBC_SCCS and not lint */
 
 #ifdef __ABICALLS__
@@ -45,11 +45,11 @@ __FBSDID("$FreeBSD$");
 #endif
 
 LEAF(strlen)
-	addu	v1, a0, 1
+	PTR_ADDU	v1, a0, 1
 1:
-	lb	v0, 0(a0)		# get byte from string
-	addu	a0, a0, 1		# increment pointer
-	bne	v0, zero, 1b		# continue if not end
-	subu	v0, a0, v1		# compute length - 1 for '\0' char
-	j	ra
+	lb		v0, 0(a0)	# get byte from string
+	PTR_ADDU	a0, a0, 1	# increment pointer
+	bne		v0, zero, 1b	# continue if not end
+	PTR_SUBU 	v0, a0, v1	# compute length - 1 for '\0' char
+	j		ra
 END(strlen)


More information about the svn-src-user mailing list