|
Project Information
Featured
|
IntroductionMathPresso is C++ library that is able to parse and evaluate mathematical expressions. Because evaluating expressions can be slow MathPresso contains jit compiler that can compile expressions into machine code. Jit compiled expressions are many times faster than built-in evaluator. Thanks to AsmJit library MathPresso is able to compile functions for 32-bit (x86) and 64-bit (x64) processors. Currently MathPresso is only example how is possible to do with AsmJit library. ExampleMathPresso library is currently designed for static linking. Everything you need is to embed MathPresso.cpp and MathPresso.h files in your project. Example how to compile and evaluate expression: // Include C headers.
#include <stdio.h>
#include <stdlib.h>
// Include MathPresso.
#include <MathPresso/MathPresso.h>
// Application entry point.
int main(int argc, char* argv[])
{
// Create expression instance.
MathPresso::Expression expression;
// Create variables that can be used in expression.
MathPresso::mreal_t variables[] = { 1, 2, 3 };
const char* names[] = { "x", "y", "z" };
// Create expression string.
const char expstr[] = "1 + (x + y) * z";
// Compile expression.
if (expression.create(expstr, names, 3) != MathPresso::MRESULT_OK)
{
// Compilation error..
printf("Error compiling expression:\n%s\n", expstr);
}
else
{
// Success, lets evaluate it.
printf("%f\n", expression.evaluate(variables));
}
// Exit.
return 0;
}Currently MathPresso can only use SSE instructions, the compiled expression in assembler may look like the code below: lea ecx, [L.0] mov edx, [esp + 12] ; Alloc arg_2 movss xmm0, [edx] addss xmm0, [edx + 4] mulss xmm0, [edx + 8] addss xmm0, [ecx] mov ecx, [esp + 8] ; Alloc arg_1 movss [ecx], xmm0 ret L.0: .data 0000803F You can see that generated code can be better and more parallelized. On the other hand given code will beat any parser based on AST/ByteCode evaluation. DownloadCurrently MathPresso is only available through SVN repository. Related Projects
Google Groups and Mailing ListsMathPresso is very small project to have its own mailing list. If you are interested about JIT compiling use AsmJit mailing list or contact MathPresso author directly. |