NaiveIRGenerator.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef MANDEL_NAIVEIRGENERATOR_H
  2. #define MANDEL_NAIVEIRGENERATOR_H
  3. #include "IterationIR.h"
  4. #include "Generators.h"
  5. #include <variant>
  6. namespace mnd
  7. {
  8. template<typename T>
  9. class NaiveIRGenerator;
  10. namespace eval
  11. {
  12. struct Load;
  13. struct Store;
  14. struct Add;
  15. struct Sub;
  16. struct Mul;
  17. struct Div;
  18. struct Neg;
  19. struct Atan2;
  20. struct Pow;
  21. struct Cos;
  22. struct Sin;
  23. struct Exp;
  24. struct Ln;
  25. using EvalNode = std::variant<
  26. Load,
  27. Store,
  28. Add,
  29. Sub,
  30. Mul,
  31. Div,
  32. Neg,
  33. Atan2,
  34. Pow,
  35. Cos,
  36. Sin,
  37. Exp,
  38. Ln
  39. >;
  40. template<typename T>
  41. struct EvalStruct
  42. {
  43. std::map<std::string, size_t> variableNames;
  44. std::vector<T> variables;
  45. void prepare(const T& zre, const T& zim, const T& cre, const T& cim)
  46. {
  47. auto z_re = variableNames.find("z_re");
  48. auto z_im = variableNames.find("z_im");
  49. auto c_re = variableNames.find("c_re");
  50. auto c_im = variableNames.find("c_im");
  51. if (z_re != variableNames.end())
  52. variables[z_re->second] = zre;
  53. if (z_im != variableNames.end())
  54. variables[z_im->second] = zre;
  55. if (c_re != variableNames.end())
  56. variables[c_re->second] = zre;
  57. if (c_im != variableNames.end())
  58. variables[c_im->second] = zre;
  59. }
  60. };
  61. }
  62. }
  63. template<typename T>
  64. class mnd::NaiveIRGenerator : public mnd::MandelGenerator
  65. {
  66. const ir::Formula& form;
  67. eval::EvalStruct<T> es;
  68. std::unique_ptr<eval::EvalNode> newz_re;
  69. std::unique_ptr<eval::EvalNode> newz_im;
  70. std::unique_ptr<eval::EvalNode> start_re;
  71. std::unique_ptr<eval::EvalNode> start_im;
  72. public:
  73. NaiveIRGenerator(const ir::Formula& irf, mnd::Precision prec = mnd::getType<T>());
  74. NaiveIRGenerator(NaiveIRGenerator&&) = default;
  75. virtual void generate(const MandelInfo& info, float* data);
  76. };
  77. #endif // MANDEL_NAIVEIRGENERATOR_H