在 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

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to