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

            Bug ID: 107328
           Summary: bzhi pattern not recognized
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: serge.guel...@telecom-bretagne.eu
  Target Milestone: ---

This bug looks similar to #93346 and #94860 but the pattern is slightly
different. My understanding is that it is still a valid one (my understanding
is that the shift invokes UB for values of `sz' that would be troublesome for
bzhi)

The pattern: 

unsigned bzhi(unsigned y, unsigned sz) {
    return y & (~0u >> (CHAR_BIT * sizeof(unsigned) - sz));
}

it should work if `sizeof(unsigned)` is either 4 or 8.

Reproducer on godbolt: https://godbolt.org/z/4PfesvY7Y

Reply via email to