#if defined(__BMI2__)
// BMI2 has a single instruction for this operation.
return _pext_u32(x, m);
-#endif
+#else
// Return zero quickly on trivial cases
if ((x & m) == 0) {
}
return x;
+#endif
}
static really_inline
#if defined(ARCH_X86_64) && defined(__BMI2__)
// BMI2 has a single instruction for this operation.
return _pext_u64(x, m);
-#endif
+#else
// Return zero quickly on trivial cases
if ((x & m) == 0) {
}
return x;
+#endif
}
static really_inline
#if defined(__BMI2__)
// BMI2 has a single instruction for this operation.
return _pdep_u32(x, m);
-#endif
+#else
// Return zero quickly on trivial cases
if (!x || !m) {
}
return x & m0; // clear out extraneous bits
+#endif
}
static really_inline
#if defined(ARCH_X86_64) && defined(__BMI2__)
// BMI2 has a single instruction for this operation.
return _pdep_u64(x, m);
-#endif
+#else
// Return zero quickly on trivial cases
if (!x || !m) {
}
return x & m0; // clear out extraneous bits
+#endif
}
#if defined(HAVE_PEXT)
// Intel BMI2 can do this operation in one instruction.
return _pext_u32(x, mask);
-#endif
+#else
u32 result = 0, num = 1;
while (mask != 0) {
num <<= 1;
}
return result;
+#endif
}
static really_inline
#if defined(HAVE_PEXT) && defined(ARCH_64_BIT)
// Intel BMI2 can do this operation in one instruction.
return _pext_u64(x, mask);
-#endif
+#else
u32 result = 0, num = 1;
while (mask != 0) {
num <<= 1;
}
return result;
+#endif
}
#undef HAVE_PEXT