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.

Reply via email to