This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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 07/20] MIPS/GAS: Compare against -1 in BGTU/BLEU macros


Hi,

 The BGTU/BGTUL and BLEU/BLEUL macros are meant to be transformed into 
corresponding always-false/always-true code sequences when an immediate 
argument of all-ones is used for comparison and a 32-bit ABI has been 
selected.  That does not happen, because the immediate expression used -- 
((offsetT) 0xffffffff) -- is zero-extended to 64 bits, while 
imm_expr.X_add_number used to compare the former against has been 
sign-extended from 32 bits to 64.

 To illustrate:

$ cat bxxu.s
	bgtu	$0, 1, .
	bgtu	$2, 0xffffffff, .
	bleu	$0, 1, .
	bleu	$2, 0xffffffff, .
$ mips-sde-elf-as -o bxxu.o bxxu.s
bxxu.s: Assembler messages:
bxxu.s:2: Warning: Branch bgtu is always true
bxxu.s:3: Warning: Branch bleu is always true
$ mips-sde-elf-objdump -d bxxu.o

bxxu.o:     file format elf32-tradbigmips

Disassembly of section .text:

00000000 <.text>:
   0:	00000000 	nop
   4:	1000ffff 	b	0x4
   8:	00000000 	nop
   c:	1000ffff 	b	0xc
  10:	00000000 	nop
  14:	00000000 	nop
$

With the fix below I get the expected:

$ mips-sde-elf-as -o bxxu-fixed.o bxxu.s
bxxu.s: Assembler messages:
bxxu.s:3: Warning: Branch bleu is always true
bxxu.s:4: Warning: Branch bleu is always true
$ mips-sde-elf-objdump -d bxxu-fixed.o

bxxu-fixed.o:     file format elf32-tradbigmips

Disassembly of section .text:

00000000 <.text>:
	...
   8:	1000ffff 	b	0x8
   c:	00000000 	nop
  10:	1000ffff 	b	0x10
  14:	00000000 	nop
$

 Arguably the always-false case should issue a similar warning for 
consistency, but that's more of a cosmetical than a corectness issue and 
can be done separately if you think it's worth doing.

2010-12-02  Maciej W. Rozycki  <macro@codesourcery.com>

	gas/
	* config/tc-mips.c (macro)
	[M_BGTUL_I, M_BGTU_I, M_BLEUL_I, M_BLEU_I]: Fix the constant
	used to compare against for the always-false/true case.

 OK to apply?

  Maciej

binutils-gas-mips-bminusone.diff
Index: binutils-fsf-trunk-quilt/gas/config/tc-mips.c
===================================================================
--- binutils-fsf-trunk-quilt.orig/gas/config/tc-mips.c	2010-12-01 21:05:50.000000000 +0000
+++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c	2010-12-01 21:05:50.000000000 +0000
@@ -5074,7 +5074,7 @@ macro (struct mips_cl_insn *ip)
       if (sreg == 0
 	  || (HAVE_32BIT_GPRS
 	      && imm_expr.X_op == O_constant
-	      && imm_expr.X_add_number == (offsetT) 0xffffffff))
+	      && imm_expr.X_add_number == -1))
 	goto do_false;
       if (imm_expr.X_op != O_constant)
 	as_bad (_("Unsupported large constant"));
@@ -5209,7 +5209,7 @@ macro (struct mips_cl_insn *ip)
       if (sreg == 0
 	  || (HAVE_32BIT_GPRS
 	      && imm_expr.X_op == O_constant
-	      && imm_expr.X_add_number == (offsetT) 0xffffffff))
+	      && imm_expr.X_add_number == -1))
 	goto do_true;
       if (imm_expr.X_op != O_constant)
 	as_bad (_("Unsupported large constant"));


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