public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/94135] New: PPC: subfic instead of neg used for rotate right
@ 2020-03-11  7:06 jens.seifert at de dot ibm.com
  2020-03-11 20:44 ` [Bug target/94135] " segher at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jens.seifert at de dot ibm.com @ 2020-03-11  7:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94135
           Summary: PPC: subfic instead of neg used for rotate right
           Product: gcc
           Version: 8.3.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: ---

Input:

unsigned int rotr32(unsigned int v, unsigned int r)
{
   return (v>>r)|(v<<(32-r));
}

unsigned long long rotr64(unsigned long long v, unsigned long long r)
{
   return (v>>r)|(v<<(64-r));
}

Command line:
gcc -O2 -save-temps rotr.C

Output:
_Z6rotr32jj:
.LFB0:
        .cfi_startproc
        subfic 4,4,32
        rotlw 3,3,4
        blr
        .long 0
        .byte 0,9,0,0,0,0,0,0
        .cfi_endproc

_Z6rotr64yy:
.LFB1:
        .cfi_startproc
        subfic 4,4,64
        rotld 3,3,4
        blr
        .long 0
        .byte 0,9,0,0,0,0,0,0
        .cfi_endproc

subfic is a 2 cycle instruction, but can be replaced by 1 cycle instruction
neg.
rotr32(v,r) = rotl32(v,32-r) = rotl32(v,(32-r)%32) = rotl32(v,(-r)%32))=
rotl32(v,-r) as long as you have a modulo rotate like rotlw/rlwnm.

Same for 64-bit.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94135] PPC: subfic instead of neg used for rotate right
  2020-03-11  7:06 [Bug target/94135] New: PPC: subfic instead of neg used for rotate right jens.seifert at de dot ibm.com
@ 2020-03-11 20:44 ` segher at gcc dot gnu.org
  2020-03-11 20:44 ` segher at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: segher at gcc dot gnu.org @ 2020-03-11 20:44 UTC (permalink / raw)
  To: gcc-bugs

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

Segher Boessenkool <segher at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |segher at gcc dot gnu.org

--- Comment #1 from Segher Boessenkool <segher at gcc dot gnu.org> ---
On what CPU do subfic and neg execute at different speed?

(neg is better, of course, it doesn't write CA).

GCC does not know rotates work for any masking of the amount (with 1's in
the low 5 (resp. 6) bits); the rs6000 target code does not know about any
masking (the SHIFT_COUNT_TRUNCATED macro cannot be used, but we could have
more patterns, and then combine can do this in many cases).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94135] PPC: subfic instead of neg used for rotate right
  2020-03-11  7:06 [Bug target/94135] New: PPC: subfic instead of neg used for rotate right jens.seifert at de dot ibm.com
  2020-03-11 20:44 ` [Bug target/94135] " segher at gcc dot gnu.org
@ 2020-03-11 20:44 ` segher at gcc dot gnu.org
  2020-03-12  6:36 ` jens.seifert at de dot ibm.com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: segher at gcc dot gnu.org @ 2020-03-11 20:44 UTC (permalink / raw)
  To: gcc-bugs

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

Segher Boessenkool <segher at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-03-11
             Status|UNCONFIRMED                 |NEW

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94135] PPC: subfic instead of neg used for rotate right
  2020-03-11  7:06 [Bug target/94135] New: PPC: subfic instead of neg used for rotate right jens.seifert at de dot ibm.com
  2020-03-11 20:44 ` [Bug target/94135] " segher at gcc dot gnu.org
  2020-03-11 20:44 ` segher at gcc dot gnu.org
@ 2020-03-12  6:36 ` jens.seifert at de dot ibm.com
  2020-03-12 17:01 ` segher at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jens.seifert at de dot ibm.com @ 2020-03-12  6:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jens Seifert <jens.seifert at de dot ibm.com> ---
POWER8 Processor User’s Manual for the Single-Chip Module:

addi addis add add. subf subf. addic subfic adde addme subfme addze. subfze neg
neg. nego

1 - 2 cycles (GPR)
2 cycles (XER)
5 cycles (CR)

6/cycle, 2/cycle (with XER or CR updates)

CA is part of XER.

1-2 cycles versus 2 cycles.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94135] PPC: subfic instead of neg used for rotate right
  2020-03-11  7:06 [Bug target/94135] New: PPC: subfic instead of neg used for rotate right jens.seifert at de dot ibm.com
                   ` (2 preceding siblings ...)
  2020-03-12  6:36 ` jens.seifert at de dot ibm.com
@ 2020-03-12 17:01 ` segher at gcc dot gnu.org
  2020-03-16  7:54 ` jens.seifert at de dot ibm.com
  2020-03-16 17:59 ` segher at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: segher at gcc dot gnu.org @ 2020-03-12 17:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Segher Boessenkool <segher at gcc dot gnu.org> ---
Both subfic and neg are 1-2 if run on the integer units.  neg can run on
more units, but it is always 2 cycles then!  (And the conditions where you
*can* have 1 cycle are not very often satisfied, anyway).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94135] PPC: subfic instead of neg used for rotate right
  2020-03-11  7:06 [Bug target/94135] New: PPC: subfic instead of neg used for rotate right jens.seifert at de dot ibm.com
                   ` (3 preceding siblings ...)
  2020-03-12 17:01 ` segher at gcc dot gnu.org
@ 2020-03-16  7:54 ` jens.seifert at de dot ibm.com
  2020-03-16 17:59 ` segher at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jens.seifert at de dot ibm.com @ 2020-03-16  7:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jens Seifert <jens.seifert at de dot ibm.com> ---
Setting CA in XER increases issue to issue latency by 1 on Power8.
See:
Table 10-14. Issue-to-Issue Latencies

In addition, setting the CA restricts instruction reordering.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/94135] PPC: subfic instead of neg used for rotate right
  2020-03-11  7:06 [Bug target/94135] New: PPC: subfic instead of neg used for rotate right jens.seifert at de dot ibm.com
                   ` (4 preceding siblings ...)
  2020-03-16  7:54 ` jens.seifert at de dot ibm.com
@ 2020-03-16 17:59 ` segher at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: segher at gcc dot gnu.org @ 2020-03-16 17:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Segher Boessenkool <segher at gcc dot gnu.org> ---
Please try it out on hardware (or on a cycle-accurate simulator) if you don't
believe me ;-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-16 17:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11  7:06 [Bug target/94135] New: PPC: subfic instead of neg used for rotate right jens.seifert at de dot ibm.com
2020-03-11 20:44 ` [Bug target/94135] " segher at gcc dot gnu.org
2020-03-11 20:44 ` segher at gcc dot gnu.org
2020-03-12  6:36 ` jens.seifert at de dot ibm.com
2020-03-12 17:01 ` segher at gcc dot gnu.org
2020-03-16  7:54 ` jens.seifert at de dot ibm.com
2020-03-16 17:59 ` segher at gcc dot gnu.org

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).