Instruction.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright (c) 2018 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. #pragma once
  16. #include <cstdint>
  17. #include <iostream>
  18. namespace RandomX {
  19. class Instruction {
  20. public:
  21. uint8_t opcode;
  22. uint8_t loca;
  23. uint8_t rega;
  24. uint8_t locb;
  25. uint8_t regb;
  26. uint8_t locc;
  27. uint8_t regc;
  28. uint8_t imm8;
  29. int32_t addra;
  30. union {
  31. uint32_t addrc;
  32. int32_t imm32;
  33. };
  34. const char* getName() const {
  35. return names[opcode];
  36. }
  37. friend std::ostream& operator<<(std::ostream& os, const Instruction& i) {
  38. i.print(os);
  39. return os;
  40. }
  41. private:
  42. void print(std::ostream&) const;
  43. static const char* names[256];
  44. };
  45. static_assert(sizeof(Instruction) == 16, "Invalid alignment of struct Instruction");
  46. }