I retract my second concern. I misread a purity error for a CTFE error. This does work as expected.

import core.cpuid: hasPopcnt;

/// Returns the number of bits which are set.
uint popcnt(ulong bits) nothrow
{
   version(X86_64) {
      if(hasPopcnt()) {
         asm {
            ....
         }
      }
      else {
         ...
      }
   }
}

Is there any reason that core.cpuid.hasPopcnt() cannot be made pure? Hopefully, calling it won't change my processor :)

Reply via email to