This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] h8300/lib1funcs.asm: Optimize divnorm and modnorm.


Hi,

Attached is a patch to optimize divnorm and modnorm.

For ___divsi3 to use ___udivsi3 as a subroutine, divnorm makes
dividend and divisor positive and stores a flag to tell whether we
shuold negate the quotient.

We can efficiently store the flag simply by copying the condition code
register to an ordinary register.

The patch cuts down one instruction when a negative dividend is given.

Tested on h8300 port.  Committed.

Kazu Hirata

2003-11-15  Kazu Hirata  <kazu@cs.umass.edu>

	* config/h8300/lib1funcs.asm (divnorm): Store the sign in bit
	3 of S2L.
	(modnorm): Likewise.
	(exitdiv): Look at bit 3 of S2L only.

Index: lib1funcs.asm
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/lib1funcs.asm,v
retrieving revision 1.29
diff -u -r1.29 lib1funcs.asm
--- lib1funcs.asm	14 Nov 2003 20:39:30 -0000	1.29
+++ lib1funcs.asm	15 Nov 2003 16:30:20 -0000
@@ -323,8 +323,8 @@
 #ifdef __H8300__
 
 divnorm:
-	mov.b	#0,S2L		; keep the sign in S2
 	mov.b	A0H,A0H		; is the numerator -ve
+	stc	ccr,S2L		; keep the sign in bit 3 of S2L
 	bge	postive
 
 	; negate arg
@@ -337,8 +337,6 @@
 	addx	#0,A1H
 	addx	#0,A0L
 	addx	#0,A0H
-
-	mov.b	#1,S2L		; the sign will be -ve
 postive:
 	mov.b	A2H,A2H		; is the denominator -ve
 	bge	postive2
@@ -350,15 +348,15 @@
 	addx	#0,A3H
 	addx	#0,A2L
 	addx	#0,A2H
-	xor	#1,S2L		; toggle result sign
+	xor.b	#0x08,S2L	; toggle the result sign
 postive2:
 	rts
 
 ;; Basically the same, except that the sign of the divisor determines
 ;; the sign.
 modnorm:
-	mov.b	#0,S2L		; keep the sign in S2
 	mov.b	A0H,A0H		; is the numerator -ve
+	stc	ccr,S2L		; keep the sign in bit 3 of S2L
 	bge	mpostive
 
 	; negate arg
@@ -371,8 +369,6 @@
 	addx	#0,A1H
 	addx	#0,A0L
 	addx	#0,A0H
-
-	mov.b	#1,S2L		; the sign will be -ve
 mpostive:
 	mov.b	A2H,A2H		; is the denominator -ve
 	bge	mpostive2
@@ -390,19 +386,18 @@
 #else /* __H8300H__ */
 
 divnorm:
-	mov.b	#0,S2L		; keep the sign in S2
 	mov.l	A0P,A0P		; is the numerator -ve
+	stc	ccr,S2L		; keep the sign in bit 3 of S2L
 	bge	postive
 
 	neg.l	A0P		; negate arg
-	mov.b	#1,S2L		; the sign will be -ve
 
 postive:
 	mov.l	A1P,A1P		; is the denominator -ve
 	bge	postive2
 
 	neg.l	A1P		; negate arg
-	xor.b	#1,S2L		; toggle result sign
+	xor.b	#0x08,S2L	; toggle the result sign
 
 postive2:
 	rts
@@ -410,12 +405,11 @@
 ;; Basically the same, except that the sign of the divisor determines
 ;; the sign.
 modnorm:
-	mov.b	#0,S2L		; keep the sign in S2
 	mov.l	A0P,A0P		; is the numerator -ve
+	stc	ccr,S2L		; keep the sign in bit 3 of S2L
 	bge	mpostive
 
 	neg.l	A0P		; negate arg
-	mov.b	#1,S2L		; the sign will be -ve
 
 mpostive:
 	mov.l	A1P,A1P		; is the denominator -ve
@@ -493,7 +487,7 @@
 
 	; examine what the sign should be
 exitdiv:
-	or	S2L,S2L
+	btst	#3,S2L
 	beq	reti
 
 	; should be -ve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]