Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: deuling@de.ibm.com (Markus Deuling)
Cc: gdb-patches@sourceware.org (GDB Patches)
Subject: Re: [rfc] Replace x86 register macros
Date: Tue, 19 Feb 2008 15:45:00 -0000	[thread overview]
Message-ID: <200802191544.m1JFibID007582@d12av02.megacenter.de.ibm.com> (raw)
In-Reply-To: <47B9ED1B.7070303@de.ibm.com> from "Markus Deuling" at Feb 18, 2008 09:39:55 PM

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


  reply	other threads:[~2008-02-19 15:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-18 20:42 Markus Deuling
2008-02-19 15:45 ` Ulrich Weigand [this message]
2008-02-19 16:21   ` Daniel Jacobowitz
2008-02-20 16:45   ` Markus Deuling
2008-03-04  0:32     ` Ulrich Weigand
2008-03-10  6:58       ` Markus Deuling
2008-03-10 12:13         ` Ulrich Weigand
2008-03-10 12:23           ` Mark Kettenis
2008-03-11  5:23             ` Markus Deuling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200802191544.m1JFibID007582@d12av02.megacenter.de.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=deuling@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox