Compiling Mathematical Expressions with muparser and asmjit

muparserSSE is an mathematical expression parser able to compile a given mathematical
expression into machine code for Intel processors at runtime. It will take an expression
as well as variable definitions as its input and return the pointer to a just in time
compiled function made up of fast
SSE instructions.
You can extend it with custom callback functions and operators. muparserSSE is based
on asmjit a just in time
compiler written by *Petr Kobalicek* and the original
muparser project.

Since this is a fork of muparser its interface and features are pretty similar. However i had to remove some of muparsers more "esotheric" features in order to get the work done. A complete implementation just would have taken to much time and muparser has some features that are rarely used anyway. On the other side i added some operators in order to expose as much of the SSE instructions to the user as possible. The following table compares muparserSSE with the other parsers of the muparser family. A detailed description of the differences is listed below.

Parser | Data types | Precision | User defined operators | User defined functions | Locale support |
Licence | Performance (Expr. per second)* |
||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|

complex | scalar | string | vector | Binary | Postfix | Infix | Strings as parameters |
Arbitrary number of parameters |
|||||

muparser | (1) | (2) | double | MIT | ~ 10.000.000 | ||||||||

muparserSSE | float | max. 5 | MIT | ~ 20.000.000 - 100.000.000 |
|||||||||

muparserX | double | BSD New | ~ 1.600.000 |

The current release contains a DLL and Project files for 32 bit Windows only. Since both asmjit and muparser are running on Linux too compiling the library under Linux should be possible but has'nt been tested. The same applies to 64 bit systems as well as Apples OSX. The following features are supported by muparserSSE:

- Extensible with custom operators (binary, infix or postfix)
- Extensible with custom functions with up to 5 Parameters
- Support for an unlimited number of variables and constants
- No limit on expression complexity
- Reads binary, hexadecimal values from expressions and can be extended to read user defined values as well.
- Supports a large variety of predefined operators, functions and constants.
- Written in standard compliant C++ code with no external dependencies.
- Evaluation is using fast SSE instructions for improved performance

- Data type is
*float*rather than*double*as used by the original muparser - No assignment operators
- Neither string constants nor string parameters to functions are supported
- No callbacks for functions with unlimited number of parameters
- Platform independence (technically impossible when using a just in time compiler)

- The eulerian number with:

*e = 2.718281828459045235360287* - The mathematical constant equal to a circle's circumference divided by its diameter.

*pi = 3.141592653589793238462643*

- Triginometric functions:

*sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh* - Exponential and logarithmic functions:

*log2, log10, ln, exp* - Other functions:

*abs, rint, sign, ite*

- Standard operators:

*"+", "-", "*", "/", "^"* - Boolean operators:

*"==", "!=", ">", "<", "<=", ">="* - Min/max operators:

*"<?", ">?"*

- Postfix operators:

*"{n}", "{mu}", "{m}", "{k}", "{G}", "{M}"* - Infix operators:

*"-"*

Special thanks to *Petr Kobalicek* for writing the asmjit just in time compiler
and making it available as open source. Writing muparserSSE wouldn't have been possible without asmjit!

You might also like: