https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98226

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amonakov at gcc dot gnu.org

--- Comment #10 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
(In reply to Oleg Zaikin from comment #6)
> There
> we have a function firstzero(unsigned x) that returns 2^i, with i the
> position of the first 0 of x, and 0 iff there is no 0. Its implementation is:
>   unsigned firstzero(const unsigned x) noexcept {
> #if __cplusplus > 201703L
>     return x == unsigned(-1) ? 0 : unsigned(1) << std::countr_one(x);
> #else
>     const unsigned y = x+1; return (y ^ x) & y;
> #endif
>   }

But why you are trying to use a more complex branchy expression in C++17 mode
when you already have a more efficient expression as a "fallback"?

Note that a cheaper way is available:

    return (x+1) & ~x;

(though gcc can optimize '(y ^ x) & y' you have to the same machine code)

Reply via email to