Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
calc2.cpp File Reference
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_container.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>
#include <boost/timer.hpp>
#include <stdio.h>
#include <assert.h>
#include <string>
#include <vector>
#include "xbyak/xbyak.h"
Include dependency graph for calc2.cpp:

Go to the source code of this file.

Classes

struct  Code
 
struct  Vm
 
class  Jit
 
struct  Parser< Iterator >
 
struct  ParserJit< Iterator >
 

Macros

#define XBYAK_NO_OP_NAMES
 

Typedefs

typedef std::vector< CodeCodeSet
 

Enumerations

enum  Operand {
  OpAdd , OpSub , OpMul , OpDiv ,
  OpNeg , OpImm , OpVarX
}
 

Functions

template<class Func >
void Test (const char *msg, const Func &f)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ XBYAK_NO_OP_NAMES

#define XBYAK_NO_OP_NAMES

Definition at line 25 of file calc2.cpp.

Typedef Documentation

◆ CodeSet

typedef std::vector<Code> CodeSet

Definition at line 53 of file calc2.cpp.

Enumeration Type Documentation

◆ Operand

enum Operand
Enumerator
OpAdd 
OpSub 
OpMul 
OpDiv 
OpNeg 
OpImm 
OpVarX 

Definition at line 28 of file calc2.cpp.

28 {
29 OpAdd,
30 OpSub,
31 OpMul,
32 OpDiv,
33 OpNeg,
34 OpImm,
35 OpVarX
36};
@ OpVarX
Definition calc2.cpp:35
@ OpMul
Definition calc2.cpp:31
@ OpNeg
Definition calc2.cpp:33
@ OpSub
Definition calc2.cpp:30
@ OpDiv
Definition calc2.cpp:32
@ OpImm
Definition calc2.cpp:34
@ OpAdd
Definition calc2.cpp:29

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 267 of file calc2.cpp.

268{
269 if (argc < 2) {
270 fprintf(stderr, "input formula\n");
271 return 1;
272 }
273 const std::string str(argv[1]);
274
275 try {
276 Vm vm;
279
280 const std::string::const_iterator end = str.end();
281
282 std::string::const_iterator i = str.begin();
283 if (!phrase_parse(i, end, parser, boost::spirit::ascii::space) || i != end) {
284 puts("err 1");
285 return 1;
286 }
287 printf("ret=%f\n", vm(2.3));
288
289 i = str.begin();
290 if (!phrase_parse(i, end, parserJit, boost::spirit::ascii::space) || i != end) {
291 puts("err 2");
292 return 1;
293 }
294 parserJit.code_.complete();
295 double (*jit)(double) = parserJit.code_.getCode<double (*)(double)>();
296
297 Test("VM ", vm);
298 Test("JIT", jit);
299 } catch (...) {
300 fprintf(stderr, "err\n");
301 }
302}
void Test(const char *msg, const Func &f)
Definition calc2.cpp:256
void complete()
Definition calc2.cpp:182
const uint8 * getCode() const
Definition xbyak.h:905
char ** argv
return str
Definition CLI11.hpp:1359
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
Jit code_
Definition calc2.cpp:230
Definition calc2.cpp:55
CodeSet code_
Definition calc2.cpp:56
Here is the call graph for this function:

◆ Test()

template<class Func >
void Test ( const char * msg,
const Func & f )

Definition at line 256 of file calc2.cpp.

257{
258 printf("%s:", msg);
259 boost::timer t;
260 double sum = 0;
261 for (double x = 0; x < 1000; x += 0.0001) {
262 sum += f(x);
263 }
264 printf("sum=%f, %fsec\n", sum, t.elapsed());
265}
Here is the caller graph for this function: