public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jens.seifert at de dot ibm.com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/107949] New: PPC: Unnecessary rlwinm after lbzx
Date: Fri, 02 Dec 2022 08:13:13 +0000	[thread overview]
Message-ID: <bug-107949-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107949

            Bug ID: 107949
           Summary: PPC: Unnecessary rlwinm after lbzx
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jens.seifert at de dot ibm.com
  Target Milestone: ---

extern unsigned char magic1[256];

unsigned int hash(const unsigned char inp[4])
{
   const unsigned long long INIT = 0x1ULL;
   unsigned long long h1 = INIT;
   h1 = magic1[((unsigned long long)inp[0]) ^ h1];
   h1 = magic1[((unsigned long long)inp[1]) ^ h1];
   h1 = magic1[((unsigned long long)inp[2]) ^ h1];
   h1 = magic1[((unsigned long long)inp[3]) ^ h1];
   return h1;
}

#ifdef __powerpc__
#define lbzx(b,c) ({ unsigned long long r; __asm__("lbzx
%0,%1,%2":"=r"(r):"b"(b),"r"(c)); r; })
unsigned int hash2(const unsigned char inp[4])
{
   const unsigned long long INIT = 0x1ULL;
   unsigned long long h1 = INIT;
   h1 = lbzx(magic1, inp[0] ^ h1);
   h1 = lbzx(magic1, inp[1] ^ h1);
   h1 = lbzx(magic1, inp[2] ^ h1);
   h1 = lbzx(magic1, inp[3] ^ h1);
   return h1;
}
#endif

Extra rlwinm get added.

hash(unsigned char const*):
.LCF0:
        addi 2,2,.TOC.-.LCF0@l
        lbz 9,0(3)
        addis 10,2,.LC0@toc@ha
        ld 10,.LC0@toc@l(10)
        lbz 6,1(3)
        lbz 7,2(3)
        lbz 8,3(3)
        xori 9,9,0x1
        lbzx 9,10,9
        xor 9,9,6
        rlwinm 9,9,0,0xff <= not necessary
        lbzx 9,10,9
        xor 9,9,7
        rlwinm 9,9,0,0xff <= not necessary
        lbzx 9,10,9
        xor 9,9,8
        rlwinm 9,9,0,0xff <= not necessary
        lbzx 3,10,9
        blr
        .long 0
        .byte 0,9,0,0,0,0,0,0
hash2(unsigned char const*):
.LCF1:
        addi 2,2,.TOC.-.LCF1@l
        lbz 7,0(3)
        lbz 8,1(3)
        lbz 10,2(3)
        lbz 6,3(3)
        addis 9,2,.LC1@toc@ha
        ld 9,.LC1@toc@l(9)
        xori 7,7,0x1
        lbzx 7,9,7
        xor 8,8,7
        lbzx 8,9,8
        xor 10,10,8
        lbzx 10,9,10
        xor 10,6,10
        lbzx 3,9,10
        rldicl 3,3,0,32
        blr

Tiny sample:
unsigned long long tiny(const unsigned char *inp)
{
  return inp[0] ^ inp[1];
}

tiny(unsigned char const*):
        lbz 9,0(3)
        lbz 10,1(3)
        xor 3,9,10
        rlwinm 3,3,0,0xff
        blr
        .long 0
        .byte 0,9,0,0,0,0,0,0

unsigned long long tiny2(const unsigned char *inp)
{
  unsigned long long a = inp[0];
  unsigned long long b = inp[1];
  return a ^ b;
}

tiny2(unsigned char const*):
        lbz 9,0(3)
        lbz 10,1(3)
        xor 3,9,10
        rlwinm 3,3,0,0xff
        blr
        .long 0
        .byte 0,9,0,0,0,0,0,0

lbz/lbzx creates a value 0 <= x < 256. xor of 2 such values does not change
value range.

             reply	other threads:[~2022-12-02  8:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02  8:13 jens.seifert at de dot ibm.com [this message]
2022-12-02 10:23 ` [Bug target/107949] " jens.seifert at de dot ibm.com
2022-12-02 16:07 ` [Bug rtl-optimization/107949] " pinskia at gcc dot gnu.org
2022-12-10 12:09 ` jens.seifert at de dot ibm.com
2023-01-08 17:31 ` segher at gcc dot gnu.org
2023-02-17 17:21 ` bergner at gcc dot gnu.org
2023-02-17 17:33 ` segher at gcc dot gnu.org

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=bug-107949-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).