1
0

NaiveIRGenerator.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef MANDEL_NAIVEIRGENERATOR_H
  2. #define MANDEL_NAIVEIRGENERATOR_H
  3. #include "IterationIR.h"
  4. #include "Generators.h"
  5. #include <memory>
  6. #include <variant>
  7. namespace mnd
  8. {
  9. template<typename T>
  10. class NaiveIRGenerator;
  11. namespace eval
  12. {
  13. struct Load;
  14. struct Store;
  15. struct Add;
  16. struct Sub;
  17. struct Mul;
  18. struct Div;
  19. struct Neg;
  20. struct Atan2;
  21. struct Pow;
  22. struct Cos;
  23. struct Sin;
  24. struct Exp;
  25. struct Ln;
  26. using EvalNode = std::variant<
  27. Load,
  28. Store,
  29. Add,
  30. Sub,
  31. Mul,
  32. Div,
  33. Neg,
  34. Atan2,
  35. Pow,
  36. Cos,
  37. Sin,
  38. Exp,
  39. Ln
  40. >;
  41. struct Load { size_t index; };
  42. struct Store
  43. {
  44. size_t index;
  45. std::unique_ptr<EvalNode> v;
  46. };
  47. struct BinaryOperation
  48. {
  49. std::unique_ptr<EvalNode> a;
  50. std::unique_ptr<EvalNode> b;
  51. };
  52. struct UnaryOperation
  53. {
  54. std::unique_ptr<EvalNode> a;
  55. };
  56. struct Add : BinaryOperation {};
  57. struct Sub : BinaryOperation {};
  58. struct Mul : BinaryOperation {};
  59. struct Div : BinaryOperation {};
  60. struct Neg : UnaryOperation {};
  61. struct Atan2 : BinaryOperation {};
  62. struct Pow : BinaryOperation {};
  63. struct Cos : UnaryOperation {};
  64. struct Sin : UnaryOperation {};
  65. struct Exp : UnaryOperation {};
  66. struct Ln : UnaryOperation {};
  67. template<typename T>
  68. struct EvalStruct
  69. {
  70. std::map<std::string, size_t> variableNames;
  71. std::vector<T*> variables;
  72. std::vector<T> temporaries;
  73. void prepare(T* zre, T* zim, T* cre, T* cim)
  74. {
  75. auto z_re = variableNames.find("z_re");
  76. auto z_im = variableNames.find("z_im");
  77. auto c_re = variableNames.find("c_re");
  78. auto c_im = variableNames.find("c_im");
  79. if (z_re != variableNames.end())
  80. variables[z_re->second] = zre;
  81. if (z_im != variableNames.end())
  82. variables[z_im->second] = zre;
  83. if (c_re != variableNames.end())
  84. variables[c_re->second] = zre;
  85. if (c_im != variableNames.end())
  86. variables[c_im->second] = zre;
  87. }
  88. };
  89. }
  90. }
  91. template<typename T>
  92. class mnd::NaiveIRGenerator : public mnd::MandelGenerator
  93. {
  94. const ir::Formula& form;
  95. eval::EvalStruct<T> es;
  96. std::unique_ptr<eval::EvalNode> newz_re;
  97. std::unique_ptr<eval::EvalNode> newz_im;
  98. std::unique_ptr<eval::EvalNode> start_re;
  99. std::unique_ptr<eval::EvalNode> start_im;
  100. public:
  101. NaiveIRGenerator(const ir::Formula& irf, mnd::Precision prec = mnd::getType<T>());
  102. NaiveIRGenerator(NaiveIRGenerator&&) = default;
  103. virtual void generate(const MandelInfo& info, float* data);
  104. };
  105. extern template class mnd::NaiveIRGenerator<float>;
  106. extern template class mnd::NaiveIRGenerator<double>;
  107. extern template class mnd::NaiveIRGenerator<mnd::DoubleDouble>;
  108. extern template class mnd::NaiveIRGenerator<mnd::QuadDouble>;
  109. #endif // MANDEL_NAIVEIRGENERATOR_H