public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Dmitry Selyutin <ghostmansd@gmail.com>
Cc: binutils@sourceware.org, Luke Leighton <luke.leighton@gmail.com>,
	Jan Beulich <jbeulich@suse.com>
Subject: Re: [PATCH v2] ppc: use reg_name_search for CFI register lookup
Date: Fri, 15 Jul 2022 08:31:47 +0930	[thread overview]
Message-ID: <YtCgWyo1hQnvcNx0@squeak.grove.modra.org> (raw)
In-Reply-To: <20220714082112.181581-1-ghostmansd@gmail.com>

On Thu, Jul 14, 2022 at 11:21:12AM +0300, Dmitry Selyutin wrote:
> ---
>  gas/config/tc-ppc.c | 41 +++++++++++++++++++----------------------
>  1 file changed, 19 insertions(+), 22 deletions(-)
> 
> diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
> index 452fab1cbf..c6715535c7 100644
> --- a/gas/config/tc-ppc.c
> +++ b/gas/config/tc-ppc.c
> @@ -7713,10 +7713,8 @@ ppc_cfi_frame_initial_instructions (void)
>  int
>  tc_ppc_regname_to_dw2regnum (char *regname)
>  {
> -  unsigned int regnum = -1;
>    unsigned int i;
> -  const char *p;
> -  char *q;
> +  const struct pd_reg *reg;
>    static struct { const char *name; int dw2regnum; } regnames[] =
>      {
>        { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
> @@ -7729,23 +7727,22 @@ tc_ppc_regname_to_dw2regnum (char *regname)
>      if (strcmp (regnames[i].name, regname) == 0)
>        return regnames[i].dw2regnum;
>  
> -  if (regname[0] == 'r' || regname[0] == 'f' || regname[0] == 'v')
> -    {
> -      p = regname + 1 + (regname[1] == '.');
> -      regnum = strtoul (p, &q, 10);
> -      if (p == q || *q || regnum >= 32)
> -	return -1;
> -      if (regname[0] == 'f')
> -	regnum += 32;
> -      else if (regname[0] == 'v')
> -	regnum += 77;
> -    }
> -  else if (regname[0] == 'c' && regname[1] == 'r')
> -    {
> -      p = regname + 2 + (regname[2] == '.');
> -      if (p[0] < '0' || p[0] > '7' || p[1])
> -	return -1;
> -      regnum = p[0] - '0' + 68;
> -    }
> -  return regnum;
> +  if (regname[0] == '%' && ISALPHA (regname[1]))
> +    ++regname;

No need for the above, any '%' is trimmed off and regname is
guaranteed to be a name by the caller of tc_regname_to_dw2regnum.

> +  reg = reg_name_search (pre_defined_registers,
> +    ARRAY_SIZE (pre_defined_registers), regname);

Doing the reg_name_search before the odd ones in regnames[] would be
better, wouldn't it?  And you can delete the first row of regnames[].
OK with those changes.

> +  if (reg == NULL)
> +    return -1;
> +
> +  if ((reg->flags & PPC_OPERAND_GPR) == PPC_OPERAND_GPR)
> +    return reg->value;
> +  else if ((reg->flags & PPC_OPERAND_FPR) == PPC_OPERAND_FPR)
> +    return (reg->value + 32);
> +  else if ((reg->flags & PPC_OPERAND_VR) == PPC_OPERAND_VR)
> +    return (reg->value + 77);
> +  else if ((reg->flags & PPC_OPERAND_CR_REG) == PPC_OPERAND_CR_REG)
> +    return (reg->value + 68);
> +  else
> +    return -1;
>  }
> -- 
> 2.37.0

-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2022-07-14 23:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 13:50 [PATCH 0/1] ppc: support register names in macros Dmitry Selyutin
2022-07-12 13:50 ` [PATCH 1/1] " Dmitry Selyutin
2022-07-12 14:13   ` Dmitry Selyutin
2022-07-12 14:18   ` lkcl
2022-07-12 14:24     ` Dmitry Selyutin
2022-07-12 21:22 ` [PATCH v2 0/1] " Dmitry Selyutin
2022-07-12 21:22   ` [PATCH v2 1/1] " Dmitry Selyutin
2022-07-12 21:29     ` [PATCH v3 0/1] " Dmitry Selyutin
2022-07-12 21:29       ` [PATCH v3 1/1] " Dmitry Selyutin
2022-07-13 15:34         ` Alan Modra
2022-07-14  6:03           ` PowerPC: implement md_operand to parse register names Alan Modra
2022-07-14  6:04           ` [PATCH v3 1/1] ppc: support register names in macros Dmitry Selyutin
2022-07-14  6:05             ` [PATCH] ppc: use reg_name_search for CFI register lookup Dmitry Selyutin
2022-07-14  7:25               ` Alan Modra
2022-07-14  8:21                 ` [PATCH v2] " Dmitry Selyutin
2022-07-14 23:01                   ` Alan Modra [this message]
2022-07-14  8:23                 ` [PATCH] " Dmitry Selyutin
2022-07-14  8:25                   ` Dmitry Selyutin
2022-07-14 23:02                     ` Alan Modra

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=YtCgWyo1hQnvcNx0@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=ghostmansd@gmail.com \
    --cc=jbeulich@suse.com \
    --cc=luke.leighton@gmail.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).