Commit 6c8c0dd3 authored by peastman's avatar peastman
Browse files

Added #ifdefs and CMake logic for deciding when to use JIT

parent 4a25dc79
...@@ -269,6 +269,14 @@ IF (ANDROID OR PNACL) ...@@ -269,6 +269,14 @@ IF (ANDROID OR PNACL)
ELSE (ANDROID OR PNACL) ELSE (ANDROID OR PNACL)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/libraries/sfmt/src/SFMT.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_SSE2=1") SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/libraries/sfmt/src/SFMT.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_SSE2=1")
ENDIF(ANDROID OR PNACL) ENDIF(ANDROID OR PNACL)
IF (NOT (ANDROID OR PNACL))
FILE(GLOB src_files ${CMAKE_CURRENT_SOURCE_DIR}/libraries/asmjit/*/*.cpp)
FILE(GLOB incl_files ${CMAKE_CURRENT_SOURCE_DIR}/libraries/asmjit/*.h)
SET(SOURCE_FILES ${SOURCE_FILES} ${src_files})
SET(SOURCE_INCLUDE_FILES ${SOURCE_INCLUDE_FILES} ${incl_files})
INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/libraries/asmjit")
SET(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DLEPTON_USE_JIT")
ENDIF (NOT (ANDROID OR PNACL))
# If API wrappers are being generated, and add them to the build. # If API wrappers are being generated, and add them to the build.
SET(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS ON CACHE BOOL "Build wrappers for C and Fortran") SET(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS ON CACHE BOOL "Build wrappers for C and Fortran")
......
...@@ -34,11 +34,13 @@ ...@@ -34,11 +34,13 @@
#include "ExpressionTreeNode.h" #include "ExpressionTreeNode.h"
#include "windowsIncludes.h" #include "windowsIncludes.h"
#include "asmjit.h"
#include <map> #include <map>
#include <set> #include <set>
#include <string> #include <string>
#include <vector> #include <vector>
#ifdef LEPTON_USE_JIT
#include "asmjit.h"
#endif
namespace Lepton { namespace Lepton {
...@@ -79,8 +81,6 @@ private: ...@@ -79,8 +81,6 @@ private:
friend class ParsedExpression; friend class ParsedExpression;
CompiledExpression(const ParsedExpression& expression); CompiledExpression(const ParsedExpression& expression);
void compileExpression(const ExpressionTreeNode& node, std::vector<std::pair<ExpressionTreeNode, int> >& temps); void compileExpression(const ExpressionTreeNode& node, std::vector<std::pair<ExpressionTreeNode, int> >& temps);
void generateJitCode();
void generateSingleArgCall(asmjit::X86Compiler& c, asmjit::X86XmmVar& dest, asmjit::X86XmmVar& arg, double (*function)(double));
int findTempIndex(const ExpressionTreeNode& node, std::vector<std::pair<ExpressionTreeNode, int> >& temps); int findTempIndex(const ExpressionTreeNode& node, std::vector<std::pair<ExpressionTreeNode, int> >& temps);
std::vector<std::vector<int> > arguments; std::vector<std::vector<int> > arguments;
std::vector<int> target; std::vector<int> target;
...@@ -90,9 +90,13 @@ private: ...@@ -90,9 +90,13 @@ private:
mutable std::vector<double> workspace; mutable std::vector<double> workspace;
mutable std::vector<double> argValues; mutable std::vector<double> argValues;
std::map<std::string, double> dummyVariables; std::map<std::string, double> dummyVariables;
void* jitCode;
#ifdef LEPTON_USE_JIT
void generateJitCode();
void generateSingleArgCall(asmjit::X86Compiler& c, asmjit::X86XmmVar& dest, asmjit::X86XmmVar& arg, double (*function)(double));
std::vector<double> constants; std::vector<double> constants;
asmjit::JitRuntime runtime; asmjit::JitRuntime runtime;
void* jitCode; #endif
}; };
} // namespace Lepton } // namespace Lepton
......
...@@ -36,7 +36,9 @@ ...@@ -36,7 +36,9 @@
using namespace Lepton; using namespace Lepton;
using namespace std; using namespace std;
using namespace asmjit; #ifdef LEPTON_USE_JIT
using namespace asmjit;
#endif
CompiledExpression::CompiledExpression() : jitCode(NULL) { CompiledExpression::CompiledExpression() : jitCode(NULL) {
} }
...@@ -50,7 +52,9 @@ CompiledExpression::CompiledExpression(const ParsedExpression& expression) : jit ...@@ -50,7 +52,9 @@ CompiledExpression::CompiledExpression(const ParsedExpression& expression) : jit
if (operation[i]->getNumArguments() > maxArguments) if (operation[i]->getNumArguments() > maxArguments)
maxArguments = operation[i]->getNumArguments(); maxArguments = operation[i]->getNumArguments();
argValues.resize(maxArguments); argValues.resize(maxArguments);
#ifdef LEPTON_USE_JIT
generateJitCode(); generateJitCode();
#endif
} }
CompiledExpression::~CompiledExpression() { CompiledExpression::~CompiledExpression() {
...@@ -73,7 +77,9 @@ CompiledExpression& CompiledExpression::operator=(const CompiledExpression& expr ...@@ -73,7 +77,9 @@ CompiledExpression& CompiledExpression::operator=(const CompiledExpression& expr
operation.resize(expression.operation.size()); operation.resize(expression.operation.size());
for (int i = 0; i < (int) operation.size(); i++) for (int i = 0; i < (int) operation.size(); i++)
operation[i] = expression.operation[i]->clone(); operation[i] = expression.operation[i]->clone();
#ifdef LEPTON_USE_JIT
generateJitCode(); generateJitCode();
#endif
return *this; return *this;
} }
...@@ -138,9 +144,9 @@ double& CompiledExpression::getVariableReference(const string& name) { ...@@ -138,9 +144,9 @@ double& CompiledExpression::getVariableReference(const string& name) {
} }
double CompiledExpression::evaluate() const { double CompiledExpression::evaluate() const {
if (jitCode != NULL) #ifdef LEPTON_USE_JIT
return ((double (*)()) jitCode)(); return ((double (*)()) jitCode)();
#else
// Loop over the operations and evaluate each one. // Loop over the operations and evaluate each one.
for (int step = 0; step < operation.size(); step++) { for (int step = 0; step < operation.size(); step++) {
...@@ -154,8 +160,10 @@ double CompiledExpression::evaluate() const { ...@@ -154,8 +160,10 @@ double CompiledExpression::evaluate() const {
} }
} }
return workspace[workspace.size()-1]; return workspace[workspace.size()-1];
#endif
} }
#ifdef LEPTON_USE_JIT
static double evaluateOperation(Operation* op, double* args) { static double evaluateOperation(Operation* op, double* args) {
map<string, double>* dummyVariables = NULL; map<string, double>* dummyVariables = NULL;
return op->evaluate(args, *dummyVariables); return op->evaluate(args, *dummyVariables);
...@@ -358,3 +366,4 @@ void CompiledExpression::generateSingleArgCall(X86Compiler& c, X86XmmVar& dest, ...@@ -358,3 +366,4 @@ void CompiledExpression::generateSingleArgCall(X86Compiler& c, X86XmmVar& dest,
call->setArg(0, arg); call->setArg(0, arg);
call->setRet(0, dest); call->setRet(0, dest);
} }
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment