cpu_popcnt.c 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. #if defined(DETECT_FEATURES) && defined(__INTEL_COMPILER)
  2. /*
  3. * Unlike GCC and CLANG, Intel Compiler exposes all supported intrinsics,
  4. * whether or not the build options for those features are specified.
  5. * Therefore, we must test #definitions of CPU features when option native/host
  6. * is enabled via `--cpu-baseline` or through env vr `CFLAGS` otherwise
  7. * the test will be broken and leads to enable all possible features.
  8. */
  9. #if !defined(__SSE4_2__) && !defined(__POPCNT__)
  10. #error "HOST/ARCH doesn't support POPCNT"
  11. #endif
  12. #endif
  13. #ifdef _MSC_VER
  14. #include <nmmintrin.h>
  15. #else
  16. #include <popcntintrin.h>
  17. #endif
  18. int main(int argc, char **argv)
  19. {
  20. // To make sure popcnt instructions are generated
  21. // and been tested against the assembler
  22. unsigned long long a = *((unsigned long long*)argv[argc-1]);
  23. unsigned int b = *((unsigned int*)argv[argc-2]);
  24. #if defined(_M_X64) || defined(__x86_64__)
  25. a = _mm_popcnt_u64(a);
  26. #endif
  27. b = _mm_popcnt_u32(b);
  28. return (int)a + b;
  29. }