popcount.cpp 929 B

123456789101112131415161718192021222324252627282930
  1. #include "popcount.h"
  2. #include <util/system/defaults.h>
  3. #include <util/system/yassert.h>
  4. #include <string.h>
  5. static const ui8 PopCountLUT8Impl[1 << 8] = {
  6. #define B2(n) n, n + 1, n + 1, n + 2
  7. #define B4(n) B2(n), B2(n + 1), B2(n + 1), B2(n + 2)
  8. #define B6(n) B4(n), B4(n + 1), B4(n + 1), B4(n + 2)
  9. B6(0), B6(1), B6(1), B6(2)};
  10. ui8 const* PopCountLUT8 = PopCountLUT8Impl;
  11. #if !defined(_MSC_VER)
  12. //ICE here for msvc
  13. static const ui8 PopCountLUT16Impl[1 << 16] = {
  14. #define B2(n) n, n + 1, n + 1, n + 2
  15. #define B4(n) B2(n), B2(n + 1), B2(n + 1), B2(n + 2)
  16. #define B6(n) B4(n), B4(n + 1), B4(n + 1), B4(n + 2)
  17. #define B8(n) B6(n), B6(n + 1), B6(n + 1), B6(n + 2)
  18. #define B10(n) B8(n), B8(n + 1), B8(n + 1), B8(n + 2)
  19. #define B12(n) B10(n), B10(n + 1), B10(n + 1), B10(n + 2)
  20. #define B14(n) B12(n), B12(n + 1), B12(n + 1), B12(n + 2)
  21. B14(0), B14(1), B14(1), B14(2)};
  22. ui8 const* PopCountLUT16 = PopCountLUT16Impl;
  23. #endif