Builtin for consulting value analysis (better ffs() code gen)
LIU Hao
lh_mouse@126.com
Thu Mar 21 08:15:04 GMT 2024
在 2024-03-14 23:33, Andrew Cooper via Gcc 写道:
> And for x86's arch_ffs(),
>
> unsigned int arch_ffs(unsigned int x)
> {
> unsigned int res;
>
> if ( __builtin_constant_p(x > 0) && x > 0 )
> {
> // Well defined when x is known non-zero
> asm("bsf %1, %0" : "=r"(res) : "rm"(x));
Even if you may assume that the destination operand is always destroyed, the hardware has no
knowledge about that, so this statement has a dependency on `res`, and shouldn't be declared `=r`.
I think it's better to remove this `if`. The other branch below clearly eliminates the dependency.
> }
> else
> {
> // The architects say this is safe even for 0.
> res = -1;
> asm("bsf %1, %0" : "+r"(res) : "rm"(x));
> }
>
> return res + 1;
> }
--
Best regards,
LIU Hao
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20240321/b64015d1/attachment.sig>
More information about the Gcc
mailing list