From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26126 invoked by alias); 19 Feb 2008 15:45:07 -0000 Received: (qmail 26118 invoked by uid 22791); 19 Feb 2008 15:45:06 -0000 X-Spam-Check-By: sourceware.org Received: from mtagate7.de.ibm.com (HELO mtagate7.de.ibm.com) (195.212.29.156) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 19 Feb 2008 15:44:40 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate7.de.ibm.com (8.13.8/8.13.8) with ESMTP id m1JFibrm501988 for ; Tue, 19 Feb 2008 15:44:37 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v8.7) with ESMTP id m1JFibJL1757374 for ; Tue, 19 Feb 2008 16:44:37 +0100 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m1JFibt4007588 for ; Tue, 19 Feb 2008 15:44:37 GMT Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with SMTP id m1JFibID007582; Tue, 19 Feb 2008 15:44:37 GMT Message-Id: <200802191544.m1JFibID007582@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Tue, 19 Feb 2008 16:44:37 +0100 Subject: Re: [rfc] Replace x86 register macros To: deuling@de.ibm.com (Markus Deuling) Date: Tue, 19 Feb 2008 15:45:00 -0000 From: "Ulrich Weigand" Cc: gdb-patches@sourceware.org (GDB Patches) In-Reply-To: <47B9ED1B.7070303@de.ibm.com> from "Markus Deuling" at Feb 18, 2008 09:39:55 PM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-02/txt/msg00312.txt.bz2 Markus Deuling wrote: > in some places used by x86/amd64 architecture there is a weird mechanism to > get at the number of registers or the registers themselves which make the code hard to > read. > > One example is i386_sse_regnum_p in i386-tdep.c where two macros I387_ST0_REGNUM and > I387_NUM_XMM_REGS have to be defined so that other two macros I387_XMM0_REGNUM and > I387_MXCSR_REGNUM are valid. This was intended as a way to support both i386 and amd64 with the same code, even though register numbers differ. See the comment in i387-tdep.h: /* Because the number of general-purpose registers is different for AMD64, the floating-point registers and SSE registers get shifted. The following definitions are intended to help writing code that needs the register numbers of floating-point registers and SSE registers. In order to use these, one should provide a definition for I387_ST0_REGNUM, and possibly I387_NUM_XMM_REGS, preferably by using a local "#define" in the body of the function that uses this. Please "#undef" them before the end of the function. */ #define I387_FCTRL_REGNUM (I387_ST0_REGNUM + 8) #define I387_FSTAT_REGNUM (I387_FCTRL_REGNUM + 1) #define I387_FTAG_REGNUM (I387_FCTRL_REGNUM + 2) #define I387_FISEG_REGNUM (I387_FCTRL_REGNUM + 3) #define I387_FIOFF_REGNUM (I387_FCTRL_REGNUM + 4) #define I387_FOSEG_REGNUM (I387_FCTRL_REGNUM + 5) #define I387_FOOFF_REGNUM (I387_FCTRL_REGNUM + 6) #define I387_FOP_REGNUM (I387_FCTRL_REGNUM + 7) #define I387_XMM0_REGNUM (I387_ST0_REGNUM + 16) #define I387_MXCSR_REGNUM (I387_XMM0_REGNUM + I387_NUM_XMM_REGS) I agree that it would be nicer to handle this in a different fashion, but I don't like this approach either: > - return (I387_XMM0_REGNUM <= regnum && regnum < I387_MXCSR_REGNUM); > + /* True if REGNUM in [st0_regnum + 16, st0_regnum + 16 + num_xmm_regs). */ > + return (regnum >= tdep->st0_regnum + 16 > + && regnum < tdep->st0_regnum + 16 + tdep->num_xmm_regs); This leads to hard-coding those magic numbers like 16 all over the place. Having a symbolic name for these is much better. I'd suggest to keep the I387_..._REGNUM macros, but add a tdep parameter to them. All users would need to be changed to pass in the proper tdep, but that only makes the existing dependency explicit. #define I387_FCTRL_REGNUM(tdep) ((tdep)->st0_regnum + 8) #define I387_FSTAT_REGNUM(tdep) (I387_FCTRL_REGNUM (tdep) + 1) ... Bye, Ulrich -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com