superscalar-init.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <unordered_set>
  19. #include "../superscalar.hpp"
  20. #include "../common.hpp"
  21. int main() {
  22. std::cout << "THIS PROGRAM REQUIRES MORE THAN 16 GB OF RAM TO COMPLETE" << std::endl;
  23. std::vector<uint64_t> dummy;
  24. constexpr uint64_t superscalarMul0 = 6364136223846793005ULL;
  25. constexpr uint64_t superscalarAdd1 = 0x810A978A59F5A1FC; //9298410992540426748ULL; //9298410992540426048ULL
  26. constexpr uint64_t superscalarAdd2 = 12065312585734608966ULL;
  27. constexpr uint64_t superscalarAdd3 = 0x8126B91CBF22495C; //9306329213124610396ULL;
  28. constexpr uint64_t superscalarAdd4 = 5281919268842080866ULL;
  29. constexpr uint64_t superscalarAdd5 = 10536153434571861004ULL;
  30. constexpr uint64_t superscalarAdd6 = 3398623926847679864ULL;
  31. constexpr uint64_t superscalarAdd7 = 9549104520008361294ULL;
  32. constexpr uint32_t totalItems = randomx::DatasetSize / randomx::CacheLineSize;
  33. std::unordered_set<uint64_t> registerValues;
  34. registerValues.reserve(totalItems);
  35. registerValues.rehash(totalItems);
  36. int collisionCount[9] = { 0 };
  37. for (uint32_t itemNumber = 0; itemNumber < totalItems; ++itemNumber) {
  38. uint64_t rl[8];
  39. rl[0] = (itemNumber + 1) * superscalarMul0;
  40. rl[1] = rl[0] ^ superscalarAdd1;
  41. rl[2] = rl[0] ^ superscalarAdd2;
  42. rl[3] = rl[0] ^ superscalarAdd3;
  43. rl[4] = rl[0] ^ superscalarAdd4;
  44. rl[5] = rl[0] ^ superscalarAdd5;
  45. rl[6] = rl[0] ^ superscalarAdd6;
  46. rl[7] = rl[0] ^ superscalarAdd7;
  47. int blockCollisions = 0;
  48. for (int i = 0; i < 8; ++i) {
  49. uint64_t reducedValue = rl[i] & 0x3FFFFFFFFFFFF8; //bits 3-53 only
  50. if (registerValues.find(reducedValue) != registerValues.end()) {
  51. blockCollisions++;
  52. std::cout << "Item " << itemNumber << ": collision of register r" << i << std::endl;
  53. }
  54. else {
  55. registerValues.insert(reducedValue);
  56. }
  57. }
  58. collisionCount[blockCollisions]++;
  59. if ((itemNumber % (320 * 1024)) == 0)
  60. std::cout << "Item " << itemNumber << " processed" << std::endl;
  61. }
  62. for (int i = 0; i < 9; ++i) {
  63. std::cout << i << " register(s) collide in " << collisionCount[i] << " items" << std::endl;
  64. }
  65. return 0;
  66. }