kobalicek / mathpresso Goto Github PK
View Code? Open in Web Editor NEWMathematical Expression Parser and JIT Compiler
License: Other
Mathematical Expression Parser and JIT Compiler
License: Other
I'm not sure if you've seen this, but I'm embedding mathpresso-ng and asmjit, get a linker warning
1>LINK : warning C4744: 'struct asmjit::X86RegData const asmjit::x86RegData' has different type in 'C:\work\sim\common\asmjit\src\x86operand_regs.cpp' and 'C:\work\sim\common\asmjit\src\mathpresso_jit.cpp': 'union (3152 bytes)' and 'struct (3152 bytes)'
I'm using Visual Studio 2013 on Windows 7, if that's useful.
would it be possible to add support for the "&&" and the "||" operator inside the library?
While working with the code, i noticed, that the assemblerimplementation of isinf gives a wrong result.
In mpCompiler in Line 380 the operand gets compared with the constant 0xFF80000000000000. Correct, as of IEEE754, would be 0xFFF0000000000000, as the exponent is 11 bit (with one signbit)(src).
Regards
Hades
In the current CMake configuration, AsmJit
is assumed to be a source dependency and is included from themathpresso
CMakeLists.txt. Once included, AsmJit
gets statically compiled with the default CMake flags.
I was wondering if it would be possible to compile with AsmJit
as a pre-compiled shared library?
Numbers like 10.5 are parsed as 15.0
I believe this can be fixed by removing
size_t scale = 0;
at mptokenizer.cpp, line 233
As I am interested in this project, i played around with it a bit. I noticed that while compiling under Windows for x86 that the Context-object is not destroyed, when it is not referenced anymore, while that is with x86_64 it is destroyed correctly. If i call the destructor by hand, under x86 it works as expected, while under x86_64 i get a memory-access-vioation.
I dug a bit deeper and noticed, that the function mpAtomicDec
has diffrent implementations, depending on the platform:
# if defined(__x86_64__) || defined(_WIN64) || defined(_M_IA64) || defined(_M_X64)
[...]
//! \internal
static MATHPRESSO_INLINE uintptr_t mpAtomicDec(uintptr_t* atomic) {
return _InterlockedDecrement64((__int64 volatile *)&atomic);
}
# else
[...]
//! \internal
static MATHPRESSO_INLINE uintptr_t mpAtomicDec(uintptr_t* atomic) {
return _InterlockedDecrement((long volatile *)atomic);
}
# endif // _64BIT
(mpatomic_p.h, lines 31+)
I'm confused with the &atomic
with x86_63 and atomic
under x86.
As I am not shure what the intended behaviour is, and as my experience with C++ is limited, i cannot give a direct fix for this.
cmake only installs include/mathpresso/mathpresso.h
. It builds libmathpresso.so
but doesn't install it.
There is a benchmark project (https://github.com/ArashPartow/math-parser-benchmark-project).
It would be interesting to see how mathpressos performance compares to others.
Hello!
It seems that the declared vars work in a strange way. I tried to swap values of x and y via a temporary variable t, and here's what I ended up with:
x=1; y=2; var t=x; t
1.000000
x=1; y=2; var t=x; x=y; t
2.000000
Thanks for the nice project.
During finding out, whether is can use it within one of my (so far not official) projects, I found a bug in mathpresso.cpp:
/*349*/ if (sym != NULL) \
/*350*/ return MATHPRESSO_TRACE_ERROR(kErrorSymbolAlreadyExists); \
/*351*/ \
/*352*/ sym = d->_builder.newSymbol(StringRef(name, nlen), hVal, kAstSymbolVariable, kAstScopeGlobal); \
/*353*/ if (sym == NULL) \
should be changed to:
/*349*/ if (sym != NULL) \
/*350*/ return MATHPRESSO_TRACE_ERROR(kErrorSymbolAlreadyExists); \
/*351*/ \
/*352*/ sym = d->_builder.newSymbol(StringRef(name, nlen), hVal, type, kAstScopeGlobal); \
/*353*/ if (sym == NULL) \
otherwise it asserts "not a function" and, if the assert was skipped, will "syntax error" for the "(" after the function name in an expression.
BR, Juergen
I'm working with your latest code, trying to take the 'var' keyword for a test drive. It's very useful!
I'm curious as to how difficult it would be to add arrays, something like
var a[] = {1, 2, 3, 4};
var index = 0;
a[index];
or, using addConstant, something like addConstant(varname, double* ptr, size_t length), after which varname[index] could be retrieved in jitted code.
in mptest.cpp, I saw something like
e1.create(ctx, "expression", mathpresso::kMPOptionNone)
and in mathpresso.cpp,
// Fallback to evaluation if JIT compiling failed or not enabled.
What might cause the JIT to fail? Is there some place in the interface where I can detect whether or not the JIT failed?
I noticed that the generated asm code loads the same value into the same register multiple times.
The old Mathpresso (with an old AsmJit) version that I used before didn't do this:
x = y =1
lea rax, [L2]
movsd xmm0, [rax]
movsd [rdx], xmm0
movsd xmm0, [rax]
movsd [rdx+8], xmm0
movsd xmm0, [rax]
movsd [rcx], xmm0
ret
Another thing - a combination of an unary operation ("-", sqrt, etc.) and a function call somehow makes it use xmm6, that apparently needs to be savied/restored:
-x / sin(y)
sub rsp, 72
movaps oword ptr [rsp+48], xmm6
xorpd xmm6, xmm6
subsd xmm6, [rdx]
...
movaps xmm6, oword ptr [rsp+48]
add rsp, 72
ret
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.