From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3660 invoked by alias); 31 Oct 2010 22:46:46 -0000 Received: (qmail 3650 invoked by uid 22791); 31 Oct 2010 22:46:45 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from eddie.linux-mips.org (HELO cvs.linux-mips.org) (78.24.191.182) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 31 Oct 2010 22:46:40 +0000 Received: from localhost.localdomain ([127.0.0.1]:34542 "EHLO localhost.localdomain" rhost-flags-OK-OK-OK-OK) by eddie.linux-mips.org with ESMTP id S1491155Ab0JaWqk (ORCPT ); Sun, 31 Oct 2010 23:46:40 +0100 Date: Sun, 31 Oct 2010 22:46:00 -0000 From: "Maciej W. Rozycki" To: Richard Sandiford cc: binutils@sourceware.org Subject: [PATCH 1/5] MIPS/GAS: Fix o32 LD to the base register In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (LFD 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2010-10/txt/msg00548.txt.bz2 On Mon, 18 Oct 2010, Maciej W. Rozycki wrote: > > > Disassembly of section .text: > > > > > > 00000000 <.text>: > > > 0: 00800821 move at,a0 > > > 4: 8c240000 lw a0,0(at) > > > 8: 8c250004 lw a1,4(at) > > > > Why are you doing it this way, rather than reversing the loads? > > Because I've got a hole in my imagination here? :/ > > > Seems a shame to use $at when we don't need to. > > Indeed, although we're no better elsewhere, consider e.g.: > > $ cat ld-base-1.s > .comm foo, 1024 > ld $4, foo > $ as -32 -o ld-base-1.o ld-base-1.s > $ objdump -dr ld-base-1.o > > ld-base-1.o: file format elf32-tradbigmips > > > Disassembly of section .text: > > 00000000 <.text>: > 0: 3c010000 lui at,0x0 > 0: R_MIPS_HI16 foo > 4: 8c240000 lw a0,0(at) > 4: R_MIPS_LO16 foo > 8: 8c250004 lw a1,4(at) > 8: R_MIPS_LO16 foo > c: 00000000 nop > > where $a1 could be used in place of $at, couldn't it? So this has evolved into a mini-batch now too. I have verified changes in this series with mips-linux, mips64-linux, mipstx39-elf, mipsisa64-elf and mips-ecoff targets and their little-endian counterparts (including binutils and LD tests too :) ). These patches apply on top of the NewABI reloc LD/SD fix where applicable. 2010-10-31 Maciej W. Rozycki gas/ * config/tc-mips.c (macro)[M_LD_OB]: If the first load of the pair would overwrite the base register, then swap the accesses. OK? binutils-2.20.51-20100925-mips-gas-ld-o-base.patch Index: binutils-2.20.51/gas/config/tc-mips.c =================================================================== --- binutils-2.20.51.orig/gas/config/tc-mips.c +++ binutils-2.20.51/gas/config/tc-mips.c @@ -7346,17 +7346,29 @@ macro (struct mips_cl_insn *ip) case M_LD_OB: s = HAVE_64BIT_GPRS ? "ld" : "lw"; + off = 1; + /* If the first load would overwrite the base register, + then swap the accesses. */ + if (!HAVE_64BIT_GPRS && treg == breg && breg != ZERO) + { + offset_expr.X_add_number += 4; + treg += 1; + off = -1; + } goto sd_ob; + case M_SD_OB: s = HAVE_64BIT_GPRS ? "sd" : "sw"; + off = 1; + sd_ob: macro_build (&offset_expr, s, "t,o(b)", treg, -1, offset_reloc[0], offset_reloc[1], offset_reloc[2], breg); if (!HAVE_64BIT_GPRS) { - offset_expr.X_add_number += 4; - macro_build (&offset_expr, s, "t,o(b)", treg + 1, + offset_expr.X_add_number += 4 * off; + macro_build (&offset_expr, s, "t,o(b)", treg + off, -1, offset_reloc[0], offset_reloc[1], offset_reloc[2], breg); }