This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Thumb rsb #0 -> neg
- From: Paul Brook <paul at codesourcery dot com>
- To: binutils at sourceware dot org
- Date: Wed, 18 Apr 2007 14:49:15 +0100
- Subject: Thumb rsb #0 -> neg
The patch below teaches gas how to use the 16-bit negs instruction to encode
rsbs reg, reg, #0.
Tested on arm-none-eabi.
Applied to CVS head.
Paul
2007-04-18 Paul Brook <paul@codesourcery.com>
gas/testsuite/
* gas/arm/thumb2_add.s: Add rsb #0 test.
* gas/arm/thumb2_add.d: Update expected output.
gas/
* config/tc-arm.c (do_t_rsb): Use 16-bit encoding when possible.
Index: gas/testsuite/gas/arm/thumb2_add.d
===================================================================
--- gas/testsuite/gas/arm/thumb2_add.d (revision 169105)
+++ gas/testsuite/gas/arm/thumb2_add.d (working copy)
@@ -27,4 +27,4 @@ Disassembly of section .text:
0+04c <[^>]+> a840 add r0, sp, #256
0+04e <[^>]+> f50d 6580 add.w r5, sp, #1024 ; 0x400
0+052 <[^>]+> f20d 1901 addw r9, sp, #257 ; 0x101
-0+056 <[^>]+> bf00 nop
+0+056 <[^>]+> 4271 negs r1, r6
Index: gas/testsuite/gas/arm/thumb2_add.s
===================================================================
--- gas/testsuite/gas/arm/thumb2_add.s (revision 169105)
+++ gas/testsuite/gas/arm/thumb2_add.s (working copy)
@@ -29,4 +29,4 @@ thumb2_add:
add r0, sp, #0x100
add r5, sp, #0x400
add r9, sp, #0x101
- nop
+ rsbs r1, r6, #0
Index: gas/config/tc-arm.c
===================================================================
--- gas/config/tc-arm.c (revision 169105)
+++ gas/config/tc-arm.c (working copy)
@@ -9942,8 +9942,37 @@ do_t_rsb (void)
inst.instruction |= Rs << 16;
if (!inst.operands[2].isreg)
{
- inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
- inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
+ bfd_boolean narrow;
+
+ if ((inst.instruction & 0x00100000) != 0)
+ narrow = (current_it_mask == 0);
+ else
+ narrow = (current_it_mask != 0);
+
+ if (Rd > 7 || Rs > 7)
+ narrow = FALSE;
+
+ if (inst.size_req == 4 || !unified_syntax)
+ narrow = FALSE;
+
+ if (inst.reloc.exp.X_op != O_constant
+ || inst.reloc.exp.X_add_number != 0)
+ narrow = FALSE;
+
+ /* Turn rsb #0 into 16-bit neg. We should probably do this via
+ relaxation, but it doesn't seem worth the hassle. */
+ if (narrow)
+ {
+ inst.reloc.type = BFD_RELOC_UNUSED;
+ inst.instruction = THUMB_OP16 (T_MNEM_negs);
+ inst.instruction |= Rs << 3;
+ inst.instruction |= Rd;
+ }
+ else
+ {
+ inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
+ inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
+ }
}
else
encode_thumb32_shifted_operand (2);