patch-2.3.23 linux/arch/sh/lib/memset.S

Next file: linux/arch/sh/lib/old-checksum.c
Previous file: linux/arch/sh/lib/memmove.S
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.22/linux/arch/sh/lib/memset.S linux/arch/sh/lib/memset.S
@@ -1,72 +1,57 @@
-! Taken from newlib-1.8.0
+/* $Id: memset.S,v 1.1 1999/09/18 16:57:09 gniibe Exp $
+ *
+ * "memset" implementation of SuperH
+ *
+ * Copyright (C) 1999  Niibe Yutaka
+ *
+ */
+
+/*
+ *            void *memset(void *s, int c, size_t n);
+ */
 
-!
-! Fast SH memset
-!
-! by Toshiyasu Morita (tm@netcom.com)
-!
-! Entry: r4: destination pointer
-!        r5: fill value
-!        r6: byte count
-!
-! Exit:  r0-r3: trashed
-!
 #include <linux/linkage.h>
 
 ENTRY(memset)
-	mov	r4,r3	! Save return value
-	
-	mov	r6,r0	! Check explicitly for zero
-	cmp/eq	#0,r0
-	bt	L_exit
-
-	mov	#12,r0	! Check for small number of bytes
+	tst	r6,r6
+	bt/s	5f		! if n=0, do nothing
+	 add	r6,r4
+	mov	#12,r0
 	cmp/gt	r6,r0
-	bt	L_store_byte_loop
-
-	neg	r4,r0	! Align destination
-	add	#4,r0
+	bt/s	4f		! if it's too small, set a byte at once
+	 mov	r4,r0
 	and	#3,r0
-	tst	r0,r0
-	bt	L_dup_bytes
-	.balignw 4,0x0009
-L_align_loop:
-	mov.b	r5,@r4
-	add	#-1,r6
-	add	#1,r4
+	cmp/eq	#0,r0
+	bt/s	2f		! It's aligned
+	 sub	r0,r6
+1:
 	dt	r0
-	bf	L_align_loop
-
-L_dup_bytes:	
-	extu.b	r5,r5	! Duplicate bytes across longword
-	swap.b	r5,r0
-	or	r0,r5
-	swap.w	r5,r0
-	or	r0,r5
-
-	mov	r6,r2	! Calculate number of double longwords
-	shlr2	r2
-	shlr	r2
-
-	.balignw 4,0x0009
-L_store_long_loop:
-	mov.l	r5,@r4	! Store double longs to memory
-	dt	r2
-	mov.l	r5,@(4,r4)
-	add	#8,r4
-	bf	L_store_long_loop
-
+	bf/s	1b
+	 mov.b	r5,@-r4
+2:				! make VVVV
+	swap.b	r5,r0		!   V0
+	or	r0,r5		!   VV
+	swap.w	r5,r0		! VV00
+	or	r0,r5		! VVVV
+	!
+	mov	r6,r0
+	shlr2	r0
+	shlr	r0		! r0 = r6 >> 3
+3:
+	dt	r0
+	mov.l	r5,@-r4		! set 8-byte at once
+	bf/s	3b
+	 mov.l	r5,@-r4
+	!
 	mov	#7,r0
 	and	r0,r6
 	tst	r6,r6
-	bt	L_exit
-	.balignw 4,0x0009
-L_store_byte_loop:
-	mov.b	r5,@r4	! Store bytes to memory
-	add	#1,r4
+	bt	5f
+	! fill bytes
+4:
 	dt	r6
-	bf	L_store_byte_loop
-
-L_exit:
+	bf/s	4b
+	 mov.b	r5,@-r4
+5:
 	rts
-	 mov	r3,r0
+	 mov	r4,r0

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)