Advertisement

muparserSSE - A Math Expression Compiler

Compiling Mathematical Expressions with muparser and asmjit


Introducing the muparserSSE math parsing library

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 partially(1) ok partially(2) fail double ok ok ok ok ok ok MIT ~ 10.000.000
muparserSSE fail ok fail fail float ok ok ok fail max. 5 ok MIT ~ 20.000.000 -
100.000.000
muparserX ok ok ok ok double ok ok ok ok ok fail BSD New ~ 1.600.000
Table 1: Feature comparison with other derivatives of muparser. (* Average performance calculated using this set of expressions; (1) muparser comes with an implementation for complex numbers but this is rather limited and more of a hack; (2) muparser can define strings but only as constants.)

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:

The following features are present in the original muparser but were removed in order to speed up the development:

Features

Predefined Constants

By default the parser supports the following mathematical constants:

Predefined Functions

By default muparserSSE supports the following functions:

Binary operators:

Unary operators:

The following lists the unary operators defined by muparserSSE. Unary operators can be either postfix operators or infix operators. Postfix operators can be used to easily distinguish value quantities, whilst infix operators are used to implement the sign operator:

Credits

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: