AssemblyGeneratorX86.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "Instruction.hpp"
  17. #include <sstream>
  18. namespace RandomX {
  19. class AssemblyGeneratorX86;
  20. typedef void(AssemblyGeneratorX86::*InstructionGenerator)(Instruction&, int);
  21. class AssemblyGeneratorX86 {
  22. public:
  23. void generateProgram(const void* seed);
  24. void printCode(std::ostream& os) {
  25. os << asmCode.rdbuf();
  26. }
  27. private:
  28. static InstructionGenerator engine[256];
  29. std::stringstream asmCode;
  30. void gena(Instruction&, int);
  31. void genar(Instruction&, int);
  32. void genaf(Instruction&, int);
  33. void genbiashift(Instruction&, const char*);
  34. void genbia(Instruction&);
  35. void genbia32(Instruction&);
  36. void genbf(Instruction&, const char*);
  37. void gencr(Instruction&, bool);
  38. void gencf(Instruction&, bool);
  39. void genAddressReg(Instruction&, const char*);
  40. int32_t genAddressImm(Instruction&);
  41. void generateCode(Instruction&, int);
  42. void h_IADD_R(Instruction&, int);
  43. void h_IADD_M(Instruction&, int);
  44. void h_IADD_RC(Instruction&, int);
  45. void h_ISUB_R(Instruction&, int);
  46. void h_ISUB_M(Instruction&, int);
  47. void h_IMUL_9C(Instruction&, int);
  48. void h_IMUL_R(Instruction&, int);
  49. void h_IMUL_M(Instruction&, int);
  50. void h_IMULH_R(Instruction&, int);
  51. void h_IMULH_M(Instruction&, int);
  52. void h_ISMULH_R(Instruction&, int);
  53. void h_ISMULH_M(Instruction&, int);
  54. void h_IDIV_C(Instruction&, int);
  55. void h_ISDIV_C(Instruction&, int);
  56. void h_INEG_R(Instruction&, int);
  57. void h_IXOR_R(Instruction&, int);
  58. void h_IXOR_M(Instruction&, int);
  59. void h_IROR_R(Instruction&, int);
  60. void h_IROL_R(Instruction&, int);
  61. void h_FPSWAP_R(Instruction&, int);
  62. void h_FPADD_R(Instruction&, int);
  63. void h_FPADD_M(Instruction&, int);
  64. void h_FPSUB_R(Instruction&, int);
  65. void h_FPSUB_M(Instruction&, int);
  66. void h_FPNEG_R(Instruction&, int);
  67. void h_FPMUL_R(Instruction&, int);
  68. void h_FPMUL_M(Instruction&, int);
  69. void h_FPDIV_R(Instruction&, int);
  70. void h_FPDIV_M(Instruction&, int);
  71. void h_FPSQRT_R(Instruction&, int);
  72. void h_COND_R(Instruction&, int);
  73. void h_COND_M(Instruction&, int);
  74. void h_CFROUND(Instruction&, int);
  75. };
  76. }