<div dir="ltr">I don't believe clang/llvm will ever emit a call to the parity library routines today. But it might be needed so we can say that we match the libgcc interface. gcc doesn't use it for x86 either as far as I know. And I don't know if they have it in their x86 libgcc. But it might be easier for compiler-rt to be a superset of libgcc rather than trying to track exactly what they have on each target.<div><br></div><div>Not sure about the inlining question.</div><div><div><br></div><div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 4, 2018 at 11:51 AM Stefan Kanthak via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi @ll,<br>
<br>
compiler-rt/lib/builtins/parityti2.c<br>
compiler-rt/lib/builtins/paritydi2.c<br>
compiler-rt/lib/builtins/paritysi2.c<br>
<br>
implement the parity function as matroschka:<br>
<br>
si_int<br>
__paritysi2(si_int a)<br>
{<br>
    su_int x = (su_int)a;<br>
    x ^= x >> 16;<br>
    x ^= x >> 8;<br>
    x ^= x >> 4;<br>
    return (0x6996 >> (x & 0xF)) & 1; // see optimisation below!<br>
}<br>
<br>
si_int<br>
__paritydi2(di_int a)<br>
{<br>
    dwords x;<br>
    x.all = a;<br>
    return __paritysi2(x.s.high ^ x.s.low);<br>
}<br>
<br>
si_int<br>
__parityti2(ti_int a)<br>
{<br>
    twords x;<br>
    x.all = a;<br>
    return __paritydi2(x.s.high ^ x.s.low);<br>
}<br>
<br>
Questions:<br>
~~~~~~~~~~<br>
<br>
1. are these functions still needed, given that __builtin_parity is available?<br>
<br>
2. will the optimiser "inline" the internal function calls (as part of LTO)?<br>
<br>
   If NOT, they should be inlined manually!<br>
<br>
   JFTR: if the 3 functions are part of a single source or compilation unit,<br>
         they are inlined by the compiler!<br>
<br>
   Yes, parity is seldomly used, so this optimisation may not seem necessary.<br>
<br>
si_int<br>
__paritydi2(di_int a)<br>
{<br>
    su_int x = (su_int)a;<br>
    x ^= (du_int)a >> 32;<br>
    x ^= x >> 16;<br>
    x ^= x >> 8;<br>
    x ^= x >> 4;<br>
    return (0x69966996 >> x) & 1;<br>
}<br>
<br>
si_int<br>
__parityti2(ti_int a)<br>
{<br>
    du_int x = (du_int)a;<br>
    x ^= (tu_int)a >> 64;<br>
    x ^= x >> 32;<br>
    x ^= x >> 16;<br>
    x ^= x >> 8;<br>
    x ^= x >> 4;<br>
    return (0x69966996 >> x) & 1;<br>
}<br>
<br>
CAVEAT: the last right-shift MAY BE undefined behaviour, the optimisation<br>
        shown here only works on CPUs which perform shifts modulo word-size!<br>
<br>
stay tuned<br>
Stefan Kanthak<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>