10 #pragma warning(disable : 4127)
11 #pragma warning(disable : 4512)
12 #pragma warning(disable : 4819)
14#include <boost/config/warning_disable.hpp>
15#include <boost/spirit/include/qi.hpp>
16#include <boost/spirit/include/phoenix_core.hpp>
17#include <boost/spirit/include/phoenix_container.hpp>
18#include <boost/spirit/include/phoenix_bind.hpp>
19#include <boost/timer.hpp>
25#define XBYAK_NO_OP_NAMES
59 const size_t maxStack = 16;
60 double stack[maxStack];
62 CodeSet::const_iterator pc =
code_.begin();
64 while (pc !=
code_.end()) {
93 assert(
p < stack + maxStack);
104 MIE_ALIGN(16)
double constTbl_[MAX_CONST_NUM];
111 const Xbyak::Reg64& tbl_;
126#elif defined(XBYAK64_WIN)
142 mov(tbl_, (
size_t)constTbl_);
146 if (constTblPos_ >= MAX_CONST_NUM)
throw;
147 constTbl_[constTblPos_] = n;
148 if (regIdx_ == 7)
throw;
155 if (regIdx_ == 7)
throw;
158 if (regIdx_ == 6)
throw;
199template<
typename Iterator>
200struct Parser : boost::spirit::qi::grammar<Iterator, boost::spirit::ascii::space_type> {
207 namespace qi = boost::spirit::qi;
208 using namespace qi::labels;
210 using boost::phoenix::ref;
211 using boost::phoenix::push_back;
227template<
typename Iterator>
228struct ParserJit : boost::spirit::qi::grammar<Iterator, boost::spirit::ascii::space_type> {
234 namespace qi = boost::spirit::qi;
235 using namespace qi::labels;
237 using boost::phoenix::ref;
238 using boost::phoenix::push_back;
239 using boost::phoenix::bind;
256void Test(
const char *msg,
const Func&
f)
261 for (
double x = 0; x < 1000; x += 0.0001) {
264 printf(
"sum=%f, %fsec\n", sum, t.elapsed());
270 fprintf(stderr,
"input formula\n");
273 const std::string str(
argv[1]);
280 const std::string::const_iterator end = str.end();
282 std::string::const_iterator i = str.begin();
283 if (!phrase_parse(i, end, parser, boost::spirit::ascii::space) || i != end) {
287 printf(
"ret=%f\n", vm(2.3));
290 if (!phrase_parse(i, end, parserJit, boost::spirit::ascii::space) || i != end) {
295 double (*jit)(double) = parserJit.
code_.
getCode<double (*)(double)>();
300 fprintf(stderr,
"err\n");
std::vector< Code > CodeSet
void Test(const char *msg, const Func &f)
const uint8 * getCode() const
void subsd(const Xmm &xmm, const Operand &op)
void fld(const Address &addr)
void add(const Operand &op, uint32 imm)
void sub(const Operand &op, uint32 imm)
void addsd(const Xmm &xmm, const Operand &op)
void movaps(const Address &addr, const Xmm &xmm)
void mov(const Operand ®1, const Operand ®2)
void mulsd(const Xmm &xmm, const Operand &op)
void lea(const Reg ®, const Address &addr)
void xorpd(const Xmm &xmm, const Operand &op)
void divsd(const Xmm &xmm, const Operand &op)
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > term
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > expression
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > factor
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > factor
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > expression
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > term
double operator()(double x) const
Xbyak ; JIT assembler for x86(IA32)/x64 by C++.