superscalar-avalanche.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright (c) 2019 tevador
  3. This file is part of RandomX.
  4. RandomX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. RandomX is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with RandomX. If not, see<http://www.gnu.org/licenses/>.
  14. */
  15. #include <iostream>
  16. #include <cstdint>
  17. #include <vector>
  18. #include "../LightProgramGenerator.hpp"
  19. #include "../InterpretedVirtualMachine.hpp"
  20. #include "../intrinPortable.h"
  21. 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 };
  22. int main() {
  23. int insensitiveProgCount[64] = { 0 };
  24. std::vector<uint64_t> dummy;
  25. for (int bit = 0; bit < 64; ++bit) {
  26. for (int i = 0; i < 10000; ++i) {
  27. uint64_t ra[8] = {
  28. 6364136223846793005ULL,
  29. 9298410992540426048ULL,
  30. 12065312585734608966ULL,
  31. 9306329213124610396ULL,
  32. 5281919268842080866ULL,
  33. 10536153434571861004ULL,
  34. 3398623926847679864ULL,
  35. 9549104520008361294ULL,
  36. };
  37. uint64_t rb[8];
  38. memcpy(rb, ra, sizeof rb);
  39. rb[0] ^= (1ULL << bit);
  40. RandomX::LightProgram p;
  41. RandomX::Blake2Generator gen(seed, i);
  42. RandomX::generateLightProg2(p, gen);
  43. RandomX::InterpretedVirtualMachine<false>::executeSuperscalar(ra, p, dummy);
  44. RandomX::InterpretedVirtualMachine<false>::executeSuperscalar(rb, p, dummy);
  45. uint64_t diff = 0;
  46. for (int j = 0; j < 8; ++j) {
  47. diff += __popcnt64(ra[j] ^ rb[j]);
  48. }
  49. if (diff < 192 || diff > 320) {
  50. std::cout << "Seed: " << i << " diff = " << diff << std::endl;
  51. insensitiveProgCount[bit]++;
  52. }
  53. }
  54. }
  55. for (int bit = 0; bit < 64; ++bit) {
  56. std::cout << bit << " " << insensitiveProgCount[bit] << std::endl;
  57. }
  58. return 0;
  59. }