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

            Bug ID: 115857
           Summary: New missed optimisation for hamming weight to simple
                    popcnt
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: etienne_lorrain at yahoo dot fr
  Target Milestone: ---

Created attachment 58623
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58623&action=edit
test for identical

Some people use such function to calculate popcount():

static unsigned hammWeight(unsigned char a)
{
a = ((a & 0xAA) >> 1) + (a & 0x55);
a = ((a & 0xCC) >> 2) + (a & 0x33);
a = ((a & 0xF0) >> 4) + (a & 0x0F);
return a;
}

// with possibly:
static unsigned hammWeight32(unsigned a)
{
return hammWeight(a & 0xFF) + hammWeight((a>>8) & 0xFF)
     + hammWeight((a>>16) & 0xFF) + hammWeight((a>>24) & 0xFF);
}

for instance page 5 of: https://www.ti.com/lit/an/swra313/swra313.pdf

It would be nice to directly replace hammWeight32(), I just checked it is
identical to __builtin_popcount() from 0 to 0xFFFFFFFF.

Reply via email to