superscalar-avalanche.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <iostream>
  2. #include <cstdint>
  3. #include <vector>
  4. #include "../superscalar.hpp"
  5. #include "../intrin_portable.h"
  6. const uint8_t seed[32] = { 191, 182, 222, 175, 249, 89, 134, 104, 241, 68, 191, 62, 162, 166, 61, 64, 123, 191, 227, 193, 118, 60, 188, 53, 223, 133, 175, 24, 123, 230, 55, 74 };
  7. int main() {
  8. int insensitiveProgCount[64] = { 0 };
  9. std::vector<uint64_t> dummy;
  10. for (int bit = 0; bit < 64; ++bit) {
  11. for (int i = 0; i < 10000; ++i) {
  12. uint64_t ra[8] = {
  13. 6364136223846793005ULL,
  14. 9298410992540426748ULL,
  15. 12065312585734608966ULL,
  16. 9306329213124610396ULL,
  17. 5281919268842080866ULL,
  18. 10536153434571861004ULL,
  19. 3398623926847679864ULL,
  20. 9549104520008361294ULL,
  21. };
  22. uint64_t rb[8];
  23. memcpy(rb, ra, sizeof rb);
  24. rb[0] ^= (1ULL << bit);
  25. randomx::SuperscalarProgram p;
  26. randomx::Blake2Generator gen(seed, sizeof seed, i);
  27. randomx::generateSuperscalar(p, gen);
  28. randomx::executeSuperscalar(ra, p, nullptr);
  29. randomx::executeSuperscalar(rb, p, nullptr);
  30. uint64_t diff = 0;
  31. for (int j = 0; j < 8; ++j) {
  32. diff += __popcnt64(ra[j] ^ rb[j]);
  33. }
  34. if (diff < 192 || diff > 320) {
  35. std::cout << "Seed: " << i << " diff = " << diff << std::endl;
  36. insensitiveProgCount[bit]++;
  37. }
  38. }
  39. }
  40. for (int bit = 0; bit < 64; ++bit) {
  41. std::cout << bit << " " << insensitiveProgCount[bit] << std::endl;
  42. }
  43. return 0;
  44. }