From: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
---|---|
To: | Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp> |
Cc: | tgl(at)sss(dot)pgh(dot)pa(dot)us, andres(at)anarazel(dot)de, thomas(dot)munro(at)enterprisedb(dot)com, andrew(at)tao11(dot)riddles(dot)org(dot)uk, david(dot)rowley(at)2ndquadrant(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: Using POPCNT and other advanced bit manipulation instructions |
Date: | 2019-02-15 14:41:23 |
Message-ID: | 20190215144123.GA31671@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 2019-Feb-15, Alvaro Herrera wrote:
> On 2019-Feb-15, Kyotaro HORIGUCHI wrote:
> > And even worse lzcntx is accidentially "fallback"s to bsrx on
> > unsupported CPUs, which leads to bogus results.
> > __builtin_clzll(8) = 3, which should be 60.
>
> I'm not sure I understand this point. Are you saying that if we use
> -mlzcnt to compile, then the compiler builtin is broken in platforms
> that don't support the lzcnt instruction? That's horrible. Let's stay
> away from -mlzcnt then.
Ah, I understand it now:
https://stackoverflow.com/questions/25683690/confusion-about-bsr-and-lzcnt/43443701#43443701
if you call LZCNT/TZCNT on a CPU that doesn't support it, it won't raise
SIGILL or anything ... it'll just silently compute the wrong result.
That's certainly not what I call a fallback!
I think David's code was correct because it was testing CPUID for
instruction support before using the specialized code (well, except that
he forgot to add the right compiler option to *enable* the LZCNT/TZCNT
instructions in the first place); but given subsequent discussion that
the instruction is not worth it anyway, we might as well ignore it.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2019-02-15 14:54:25 | Re: Using POPCNT and other advanced bit manipulation instructions |
Previous Message | Alvaro Herrera | 2019-02-15 14:28:42 | Re: Using POPCNT and other advanced bit manipulation instructions |