diff --git a/lib/colvars/lepton/include/lepton/CompiledExpression.h b/lib/colvars/lepton/include/lepton/CompiledExpression.h index 84ec2eb410..82d66d5c6a 100644 --- a/lib/colvars/lepton/include/lepton/CompiledExpression.h +++ b/lib/colvars/lepton/include/lepton/CompiledExpression.h @@ -56,9 +56,9 @@ class ParsedExpression; * A CompiledExpression is a highly optimized representation of an expression for cases when you want to evaluate * it many times as quickly as possible. You should treat it as an opaque object; none of the internal representation * is visible. - * + * * A CompiledExpression is created by calling createCompiledExpression() on a ParsedExpression. - * + * * WARNING: CompiledExpression is NOT thread safe. You should never access a CompiledExpression from two threads at * the same time. */ diff --git a/lib/colvars/lepton/include/lepton/CompiledVectorExpression.h b/lib/colvars/lepton/include/lepton/CompiledVectorExpression.h index a9dd936750..ea3586f1b0 100644 --- a/lib/colvars/lepton/include/lepton/CompiledVectorExpression.h +++ b/lib/colvars/lepton/include/lepton/CompiledVectorExpression.h @@ -59,12 +59,12 @@ class ParsedExpression; * vector unit (AVX on x86, NEON on ARM) to evaluate the expression for multiple sets of arguments at once. It also differs * from CompiledExpression and ParsedExpression in using single precision rather than double precision to evaluate the expression. * You should treat it as an opaque object; none of the internal representation is visible. - * + * * A CompiledVectorExpression is created by calling createCompiledVectorExpression() on a ParsedExpression. When you create * it, you must specify the width of the vectors on which to compute the expression. The allowed widths depend on the type of * CPU it is running on. 4 is always allowed, and 8 is allowed on x86 processors with AVX. Call getAllowedWidths() to query * the allowed values. - * + * * WARNING: CompiledVectorExpression is NOT thread safe. You should never access a CompiledVectorExpression from two threads at * the same time. */ @@ -86,7 +86,7 @@ public: /** * Get a pointer to the memory location where the value of a particular variable is stored. This can be used * to set the value of the variable before calling evaluate(). - * + * * @param name the name of the variable to query * @return a pointer to N floating point values, where N is the vector width */ @@ -100,7 +100,7 @@ public: void setVariableLocations(std::map& variableLocations); /** * Evaluate the expression. The values of all variables should have been set before calling this. - * + * * @return a pointer to N floating point values, where N is the vector width */ const float* evaluate() const; diff --git a/lib/colvars/lepton/include/lepton/CustomFunction.h b/lib/colvars/lepton/include/lepton/CustomFunction.h index 7b6a2b6834..fbb0ddd52a 100644 --- a/lib/colvars/lepton/include/lepton/CustomFunction.h +++ b/lib/colvars/lepton/include/lepton/CustomFunction.h @@ -83,7 +83,7 @@ class LEPTON_EXPORT PlaceholderFunction : public CustomFunction { public: /** * Create a Placeholder function. - * + * * @param numArgs the number of arguments the function expects */ PlaceholderFunction(int numArgs) : numArgs(numArgs) { diff --git a/lib/colvars/lepton/include/lepton/ExpressionProgram.h b/lib/colvars/lepton/include/lepton/ExpressionProgram.h index e989906288..a49a9094d0 100644 --- a/lib/colvars/lepton/include/lepton/ExpressionProgram.h +++ b/lib/colvars/lepton/include/lepton/ExpressionProgram.h @@ -67,7 +67,7 @@ public: const Operation& getOperation(int index) const; /** * Change an Operation in this program. - * + * * The Operation must have been allocated on the heap with the "new" operator. * The ExpressionProgram assumes ownership of it and will delete it when it * is no longer needed. diff --git a/lib/colvars/lepton/include/lepton/Operation.h b/lib/colvars/lepton/include/lepton/Operation.h index 4b8969cd59..1ddde0b8c0 100644 --- a/lib/colvars/lepton/include/lepton/Operation.h +++ b/lib/colvars/lepton/include/lepton/Operation.h @@ -1017,7 +1017,7 @@ public: double evaluate(double* args, const std::map& variables) const { if (isIntPower) { // Integer powers can be computed much more quickly by repeated multiplication. - + int exponent = intValue; double base = args[0]; if (exponent < 0) { diff --git a/lib/colvars/lepton/include/lepton/ParsedExpression.h b/lib/colvars/lepton/include/lepton/ParsedExpression.h index 6c6526e525..e2a7572c4a 100644 --- a/lib/colvars/lepton/include/lepton/ParsedExpression.h +++ b/lib/colvars/lepton/include/lepton/ParsedExpression.h @@ -106,7 +106,7 @@ public: /** * Create a CompiledVectorExpression that allows the expression to be evaluated efficiently * using the CPU's vector unit. - * + * * @param width the width of the vectors to evaluate it on. The allowed values * depend on the CPU. 4 is always allowed, and 8 is allowed on * x86 processors with AVX. Call CompiledVectorExpression::getAllowedWidths() diff --git a/lib/colvars/lepton/src/CompiledExpression.cpp b/lib/colvars/lepton/src/CompiledExpression.cpp index 8a0239b04f..d8b6e112b2 100644 --- a/lib/colvars/lepton/src/CompiledExpression.cpp +++ b/lib/colvars/lepton/src/CompiledExpression.cpp @@ -84,17 +84,17 @@ CompiledExpression& CompiledExpression::operator=(const CompiledExpression& expr void CompiledExpression::compileExpression(const ExpressionTreeNode& node, vector >& temps) { if (findTempIndex(node, temps) != -1) return; // We have already processed a node identical to this one. - + // Process the child nodes. - + vector args; for (int i = 0; i < node.getChildren().size(); i++) { compileExpression(node.getChildren()[i], temps); args.push_back(findTempIndex(node.getChildren()[i], temps)); } - + // Process this node. - + if (node.getOperation().getId() == Operation::VARIABLE) { variableIndices[node.getOperation().getName()] = (int) workspace.size(); variableNames.insert(node.getOperation().getName()); @@ -108,7 +108,7 @@ void CompiledExpression::compileExpression(const ExpressionTreeNode& node, vecto arguments[stepIndex].push_back(0); // The value won't actually be used. We just need something there. else { // If the arguments are sequential, we can just pass a pointer to the first one. - + bool sequential = true; for (int i = 1; i < args.size(); i++) if (args[i] != args[i-1]+1) @@ -148,12 +148,12 @@ void CompiledExpression::setVariableLocations(map& variableLoca variablePointers = variableLocations; #ifdef LEPTON_USE_JIT // Rebuild the JIT code. - + if (workspace.size() > 0) generateJitCode(); #endif // Make a list of all variables we will need to copy before evaluating the expression. - + variablesToCopy.clear(); for (map::const_iterator iter = variableIndices.begin(); iter != variableIndices.end(); ++iter) { map::iterator pointer = variablePointers.find(iter->first); @@ -169,7 +169,7 @@ double CompiledExpression::evaluate() const { *variablesToCopy[i].first = *variablesToCopy[i].second; // Loop over the operations and evaluate each one. - + for (int step = 0; step < operation.size(); step++) { const vector& args = arguments[step]; if (args.size() == 1) @@ -245,9 +245,9 @@ void CompiledExpression::generateJitCode() { vector > groups, groupPowers; vector stepGroup; findPowerGroups(groups, groupPowers, stepGroup); - + // Load the arguments into variables. - + for (set::const_iterator iter = variableNames.begin(); iter != variableNames.end(); ++iter) { map::iterator index = variableIndices.find(*iter); arm::Gp variablePointer = c.newIntPtr(); @@ -256,11 +256,11 @@ void CompiledExpression::generateJitCode() { } // Make a list of all constants that will be needed for evaluation. - + vector operationConstantIndex(operation.size(), -1); for (int step = 0; step < (int) operation.size(); step++) { // Find the constant value (if any) used by this operation. - + Operation& op = *operation[step]; double value; if (op.getId() == Operation::CONSTANT) @@ -283,9 +283,9 @@ void CompiledExpression::generateJitCode() { } else continue; - + // See if we already have a variable for this constant. - + for (int i = 0; i < (int) constants.size(); i++) if (value == constants[i]) { operationConstantIndex[step] = i; @@ -296,9 +296,9 @@ void CompiledExpression::generateJitCode() { constants.push_back(value); } } - + // Load constants into variables. - + vector constantVar(constants.size()); if (constants.size() > 0) { arm::Gp constantsPointer = c.newIntPtr(); @@ -360,13 +360,13 @@ void CompiledExpression::generateJitCode() { vector args = arguments[step]; if (args.size() == 1) { // One or more sequential arguments. Fill out the list. - + for (int i = 1; i < op.getNumArguments(); i++) args.push_back(args[0]+i); } - + // Generate instructions to execute this operation. - + switch (op.getId()) { case Operation::CONSTANT: c.fmov(workspaceVar[target[step]], constantVar[operationConstantIndex[step]]); @@ -476,7 +476,7 @@ void CompiledExpression::generateJitCode() { break; default: // Just invoke evaluateOperation(). - + for (int i = 0; i < (int) args.size(); i++) c.str(workspaceVar[args[i]], arm::ptr(argsPointer, 8*i)); arm::Gp fn = c.newIntPtr(); @@ -532,7 +532,7 @@ void CompiledExpression::generateJitCode() { findPowerGroups(groups, groupPowers, stepGroup); // Load the arguments into variables. - + x86::Gp variablePointer = c.newIntPtr(); for (set::const_iterator iter = variableNames.begin(); iter != variableNames.end(); ++iter) { map::iterator index = variableIndices.find(*iter); @@ -541,11 +541,11 @@ void CompiledExpression::generateJitCode() { } // Make a list of all constants that will be needed for evaluation. - + vector operationConstantIndex(operation.size(), -1); for (int step = 0; step < (int) operation.size(); step++) { // Find the constant value (if any) used by this operation. - + Operation& op = *operation[step]; double value; if (op.getId() == Operation::CONSTANT) @@ -572,9 +572,9 @@ void CompiledExpression::generateJitCode() { } else continue; - + // See if we already have a variable for this constant. - + for (int i = 0; i < (int) constants.size(); i++) if (value == constants[i]) { operationConstantIndex[step] = i; @@ -585,9 +585,9 @@ void CompiledExpression::generateJitCode() { constants.push_back(value); } } - + // Load constants into variables. - + vector constantVar(constants.size()); if (constants.size() > 0) { x86::Gp constantsPointer = c.newIntPtr(); @@ -597,9 +597,9 @@ void CompiledExpression::generateJitCode() { c.vmovsd(constantVar[i], x86::ptr(constantsPointer, 8*i, 0)); } } - + // Evaluate the operations. - + vector hasComputedPower(operation.size(), false); for (int step = 0; step < (int) operation.size(); step++) { if (hasComputedPower[step]) @@ -649,13 +649,13 @@ void CompiledExpression::generateJitCode() { vector args = arguments[step]; if (args.size() == 1) { // One or more sequential arguments. Fill out the list. - + for (int i = 1; i < op.getNumArguments(); i++) args.push_back(args[0]+i); } - + // Generate instructions to execute this operation. - + switch (op.getId()) { case Operation::CONSTANT: c.vmovsd(workspaceVar[target[step]], constantVar[operationConstantIndex[step]], constantVar[operationConstantIndex[step]]); @@ -772,7 +772,7 @@ void CompiledExpression::generateJitCode() { } default: // Just invoke evaluateOperation(). - + for (int i = 0; i < (int) args.size(); i++) c.vmovsd(x86::ptr(argsPointer, 8*i, 0), workspaceVar[args[i]]); x86::Gp fn = c.newIntPtr(); diff --git a/lib/colvars/lepton/src/ExpressionTreeNode.cpp b/lib/colvars/lepton/src/ExpressionTreeNode.cpp index 78432c1bfc..b7a376528d 100644 --- a/lib/colvars/lepton/src/ExpressionTreeNode.cpp +++ b/lib/colvars/lepton/src/ExpressionTreeNode.cpp @@ -132,7 +132,7 @@ void ExpressionTreeNode::assignTags(vector& examples) child.assignTags(examples); if (numTags == examples.size()) { // All the children matched existing tags, so possibly this node does too. - + for (int i = 0; i < examples.size(); i++) { const ExpressionTreeNode& example = *examples[i]; bool matches = (getChildren().size() == example.getChildren().size() && getOperation() == example.getOperation()); @@ -145,9 +145,9 @@ void ExpressionTreeNode::assignTags(vector& examples) } } } - + // This node does not match any previous node, so assign a new tag. - + tag = examples.size(); examples.push_back(this); } diff --git a/lib/colvars/lepton/src/MSVC_erfc.h b/lib/colvars/lepton/src/MSVC_erfc.h index 2c6b619e89..b1cd87a289 100644 --- a/lib/colvars/lepton/src/MSVC_erfc.h +++ b/lib/colvars/lepton/src/MSVC_erfc.h @@ -3,7 +3,7 @@ /* * Up to version 11 (VC++ 2012), Microsoft does not support the - * standard C99 erf() and erfc() functions so we have to fake them here. + * standard C99 erf() and erfc() functions so we have to fake them here. * These were added in version 12 (VC++ 2013), which sets _MSC_VER=1800 * (VC11 has _MSC_VER=1700). */ @@ -15,7 +15,7 @@ #endif #if defined(_MSC_VER) -#if _MSC_VER <= 1700 // 1700 is VC11, 1800 is VC12 +#if _MSC_VER <= 1700 // 1700 is VC11, 1800 is VC12 /*************************** * erf.cpp * author: Steve Strand diff --git a/lib/colvars/lepton/src/ParsedExpression.cpp b/lib/colvars/lepton/src/ParsedExpression.cpp index f3f18fccd2..ea2cf707d6 100644 --- a/lib/colvars/lepton/src/ParsedExpression.cpp +++ b/lib/colvars/lepton/src/ParsedExpression.cpp @@ -152,10 +152,10 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio else children[i] = cached->second; } - + // Collect some info on constant expressions in children bool first_const = children.size() > 0 && isConstant(children[0]); // is first child constant? - bool second_const = children.size() > 1 && isConstant(children[1]); ; // is second child constant? + bool second_const = children.size() > 1 && isConstant(children[1]); ; // is second child constant? double first, second; // if yes, value of first and second child if (first_const) first = getConstantValue(children[0]); @@ -205,7 +205,7 @@ ExpressionTreeNode ParsedExpression::substituteSimplerExpression(const Expressio break; } case Operation::MULTIPLY: - { + { if ((first_const && first == 0.0) || (second_const && second == 0.0)) // Multiply by 0 return ExpressionTreeNode(new Operation::Constant(0.0)); if (first_const && first == 1.0) // Multiply by 1 diff --git a/lib/colvars/lepton/src/Parser.cpp b/lib/colvars/lepton/src/Parser.cpp index 47ebac464a..e284add258 100644 --- a/lib/colvars/lepton/src/Parser.cpp +++ b/lib/colvars/lepton/src/Parser.cpp @@ -66,7 +66,7 @@ private: string Parser::trim(const string& expression) { // Remove leading and trailing spaces. - + int start, end; for (start = 0; start < (int) expression.size() && isspace(expression[start]); start++) ;