Skip to content
Snippets Groups Projects
Commit 64bd3599 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Moved include asmjit to CompiledExpression.cpp

Currently, this allows avoiding an exploding number of warnings
originating from amsjit header files to be shown when compiling.

In general, it better decouples asmjit from lepton. Later on
we might allow one to switch asmjit on/off with an environment variable
if desired.
parent fcc08f8b
No related branches found
No related tags found
No related merge requests found
......@@ -64,6 +64,9 @@
#include "CompiledExpression.h"
#include "Operation.h"
#include "ParsedExpression.h"
#ifdef __PLUMED_HAS_ASMJIT
#include "asmjit/asmjit.h"
#endif
#include <utility>
namespace PLMD {
......@@ -73,6 +76,19 @@ using namespace std;
using namespace asmjit;
#endif
AsmJitRuntimePtr::AsmJitRuntimePtr()
#ifdef __PLUMED_HAS_ASMJIT
: ptr(new asmjit::JitRuntime)
#endif
{}
AsmJitRuntimePtr::~AsmJitRuntimePtr()
{
#ifdef __PLUMED_HAS_ASMJIT
delete static_cast<asmjit::JitRuntime*>(ptr);
#endif
}
CompiledExpression::CompiledExpression() : jitCode(NULL) {
}
......@@ -225,8 +241,11 @@ static double evaluateOperation(Operation* op, double* args) {
return op->evaluate(args, *dummyVariables);
}
static void generateSingleArgCall(X86Compiler& c, X86Xmm& dest, X86Xmm& arg, double (*function)(double));
void CompiledExpression::generateJitCode() {
CodeHolder code;
auto & runtime(*static_cast<asmjit::JitRuntime*>(runtimeptr.get()));
code.init(runtime.getCodeInfo());
X86Assembler a(&code);
X86Compiler c(&code);
......@@ -431,7 +450,7 @@ void CompiledExpression::generateJitCode() {
jitCode = (void*) func0;
}
void CompiledExpression::generateSingleArgCall(X86Compiler& c, X86Xmm& dest, X86Xmm& arg, double (*function)(double)) {
void generateSingleArgCall(X86Compiler& c, X86Xmm& dest, X86Xmm& arg, double (*function)(double)) {
X86Gp fn = c.newIntPtr();
c.mov(fn, imm_ptr((void*) function));
CCFuncCall* call = c.call(fn, FuncSignature1<double, double>(CallConv::kIdHost));
......
......@@ -71,13 +71,31 @@
#include <string>
#include <utility>
#include <vector>
#ifdef __PLUMED_HAS_ASMJIT
#include "asmjit/asmjit.h"
#endif
namespace PLMD {
namespace lepton {
// Utility class.
// Implement an unique pointer to asmjit::JitRuntime.
// Needed to decouple asmjit header file from this one.
class AsmJitRuntimePtr {
/// if ASMJIT is not defined, just set the pointer to null
void* ptr=nullptr;
public:
/// constructor
AsmJitRuntimePtr();
/// destructor
~AsmJitRuntimePtr();
/// deleted copy constructor
AsmJitRuntimePtr(const AsmJitRuntimePtr&) = delete;
/// deleted assignment
AsmJitRuntimePtr & operator=(const AsmJitRuntimePtr&) = delete;
/// get the pointer
void* get() {
return ptr;
}
};
class Operation;
class ParsedExpression;
......@@ -133,12 +151,9 @@ private:
mutable std::vector<double> argValues;
std::map<std::string, double> dummyVariables;
void* jitCode;
#ifdef __PLUMED_HAS_ASMJIT
void generateJitCode();
void generateSingleArgCall(asmjit::X86Compiler& c, asmjit::X86Xmm& dest, asmjit::X86Xmm& arg, double (*function)(double));
std::vector<double> constants;
asmjit::JitRuntime runtime;
#endif
AsmJitRuntimePtr runtimeptr;
};
} // namespace lepton
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment