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]

[csl-arm] Improve Thumb-2 negdi


The patch below improves the Thumb-2 code generated for negdi.
Thumb-2 doesn't have rsc. Richard Earnshaw pointed out that we can use a 
sneaky trick with rsc shifter operands to implement negation.

Tested with cross to arm-none-eabi.
Applied to branches/csl/sourcerygxx-4_1.

Paul

2006-09-26  Paul Brook  <paul@codesourcery.com>

	gcc/
	* config/arm/thumb2.md (thumb2_negdi2): Use shorter code sequence.
	* config/arm/ieee754-df.S: Ditto.
	* config/arm/ieee754-sf.S: Ditto.

Index: gcc/config/arm/ieee754-df.S
===================================================================
--- gcc/config/arm/ieee754-df.S	(revision 117227)
+++ gcc/config/arm/ieee754-df.S	(working copy)
@@ -132,9 +132,8 @@ ARM_FUNC_ALIAS aeabi_dadd adddf3
 	orr	xh, ip, xh, lsr #12
 	beq	1f
 #if defined(__thumb2__)
-	mov	lr, #0
 	negs	xl, xl
-	sbc	xh, lr, xh
+	sbc	xh, xh, xh, lsl #1
 #else
 	rsbs	xl, xl, #0
 	rsc	xh, xh, #0
@@ -145,9 +144,8 @@ ARM_FUNC_ALIAS aeabi_dadd adddf3
 	orr	yh, ip, yh, lsr #12
 	beq	1f
 #if defined(__thumb2__)
-	mov	lr, #0
 	negs	yl, yl
-	sbc	yh, lr, yh
+	sbc	yh, yh, yh, lsl #1
 #else
 	rsbs	yl, yl, #0
 	rsc	yh, yh, #0
@@ -546,9 +544,8 @@ ARM_FUNC_ALIAS aeabi_l2d floatdidf
 	ands	r5, ah, #0x80000000	@ sign bit in r5
 	bpl	2f
 #if defined(__thumb2__)
-	movs	r4, #0
 	negs	al, al
-	sbc	ah, r4, ah
+	sbc	ah, ah, ah, lsl #1
 #else
 	rsbs	al, al, #0
 	rsc	ah, ah, #0
Index: gcc/config/arm/thumb2.md
===================================================================
--- gcc/config/arm/thumb2.md	(revision 117227)
+++ gcc/config/arm/thumb2.md	(working copy)
@@ -162,15 +162,15 @@ (define_insn "*thumb2_not_shiftsi_compar
    (set_attr "type" "alu_shift")]
 )
 
-;; Thumb-2 does not have rsc, so the source and destination must be 
different.
+;; Thumb-2 does not have rsc, so use a clever trick with shifter operands.
 (define_insn "*thumb2_negdi2"
-  [(set (match_operand:DI         0 "s_register_operand" "=&r")
-	(neg:DI (match_operand:DI 1 "s_register_operand"  "r")))
+  [(set (match_operand:DI         0 "s_register_operand" "=&r,r")
+	(neg:DI (match_operand:DI 1 "s_register_operand"  "?r,0")))
    (clobber (reg:CC CC_REGNUM))]
   "TARGET_THUMB2"
-  "negs\\t%Q0, %Q1\;mov\\t%R0, #0\;sbc\\t%R0, %R0, %R1"
+  "negs\\t%Q0, %Q1\;sbc\\t%R0, %R1, %R1, lsl #1"
   [(set_attr "conds" "clob")
-   (set_attr "length" "12")]
+   (set_attr "length" "8")]
 )
 
 (define_insn "*thumb2_abssi2"
Index: gcc/config/arm/ieee754-sf.S
===================================================================
--- gcc/config/arm/ieee754-sf.S	(revision 117227)
+++ gcc/config/arm/ieee754-sf.S	(working copy)
@@ -128,9 +128,8 @@ LSYM(Lad_x):
 	and	r3, r0, #0x80000000
 	bpl	LSYM(Lad_p)
 #if defined(__thumb2__)
-	mov	ip, #0
 	negs	r1, r1
-	sbc	r0, ip, r0
+	sbc	r0, r0, r0, lsl #1
 #else
 	rsbs	r1, r1, #0
 	rsc	r0, r0, #0
@@ -357,9 +356,8 @@ ARM_FUNC_ALIAS aeabi_l2f floatdisf
 	ands	r3, ah, #0x80000000	@ sign bit in r3
 	bpl	1f
 #if defined(__thumb2__)
-	movs	r2, #0
 	negs	al, al
-	sbc	ah, r2, ah
+	sbc	ah, ah, ah, lsl #1
 #else
 	rsbs	al, al, #0
 	rsc	ah, ah, #0


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