On Mon, Jun 03, 2013 at 10:00:19AM -0700, Richard Henderson wrote:
> On 06/03/2013 09:37 AM, Kai Tietz wrote:
> > foo:
> >         .seh_endprologue
> >         cmpb    %cl, %dl
> >         seta    %al
> >         ret
> >         .seh_endproc
> >         .p2align 4,,15
> >         .globl  boo
> >         .def    boo;    .scl    2;      .type   32;     .endef
> >         .seh_proc       boo
> > boo:
> >         .seh_endprologue
> >         movl    %ecx, %eax
> >         notl    %eax
> >         andl    %edx, %eax
> >         andl    $1, %eax
> >         ret
> 
> Try arm or s390 or ppc for significantly different results.

Lets see for powerpc:

.L.foo:
        cmpw 7,3,4
        mfcr 3,1
        rlwinm 3,3,29,1
        blr

.L.boo:
        andc 3,4,3
        rldicl 3,3,0,63
        blr
 
So for powerpc, the second is the preferred method.

However, in looking at it, if we rewrite the code to have come from
comparisons:

_Bool foo_cmp (long w, long x, long y, long z)
{
  _Bool a = (w < x);
  _Bool b = (y < z);
  _Bool r = a < b;
  return r;
}

_Bool bfoo_cmp (long w, long x, long y, long z)
{
  _Bool a = (w < x);
  _Bool b = (y < z);
  _Bool r = ~a & b;
  return r;
}

We get:

.L.foo_cmp:
        cmpd 7,5,6
        cmpd 6,3,4
        mfcr 6
        rlwinm 3,6,25,1
        rlwinm 6,6,29,1
        cmpw 7,3,6
        mfcr 3,1
        rlwinm 3,3,29,1
        blr

.L.bfoo_cmp:
        cmpd 6,3,4
        cmpd 7,5,6
        mfcr 3,2
        rlwinm 3,3,25,1
        mfcr 6,1
        rlwinm 6,6,29,1
        andc 3,6,3
        blr

And it would have been nice to use the logcal comparison operations in the CR
register unit (i.e. doing a crandc in the CR unit rather than moving the value
from a CR to a GPR -- cmpd/mfcr/rlwinm instructions).

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460, USA
email: meiss...@linux.vnet.ibm.com, phone: +1 (978) 899-4797

Reply via email to