Commit 87ea8433 authored by Peter Eastman's avatar Peter Eastman
Browse files

Minor optimization to discrete tabulated functions

parent 98652498
...@@ -239,7 +239,7 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express ...@@ -239,7 +239,7 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express
if (derivOrder[0] == 0) { if (derivOrder[0] == 0) {
out << "real x = " << getTempName(node.getChildren()[0], temps) << ";\n"; out << "real x = " << getTempName(node.getChildren()[0], temps) << ";\n";
out << "if (x >= 0 && x < " << paramsInt[0] << ") {\n"; out << "if (x >= 0 && x < " << paramsInt[0] << ") {\n";
out << "int index = (int) round(x);\n"; out << "int index = (int) floor(x+0.5f);\n";
out << nodeNames[j] << " = " << functionNames[i].second << "[index];\n"; out << nodeNames[j] << " = " << functionNames[i].second << "[index];\n";
out << "}\n"; out << "}\n";
} }
...@@ -249,8 +249,8 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express ...@@ -249,8 +249,8 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express
for (int j = 0; j < nodes.size(); j++) { for (int j = 0; j < nodes.size(); j++) {
const vector<int>& derivOrder = dynamic_cast<const Operation::Custom*>(&nodes[j]->getOperation())->getDerivOrder(); const vector<int>& derivOrder = dynamic_cast<const Operation::Custom*>(&nodes[j]->getOperation())->getDerivOrder();
if (derivOrder[0] == 0 && derivOrder[1] == 0) { if (derivOrder[0] == 0 && derivOrder[1] == 0) {
out << "int x = (int) round(" << getTempName(node.getChildren()[0], temps) << ");\n"; out << "int x = (int) floor(" << getTempName(node.getChildren()[0], temps) << "+0.5f);\n";
out << "int y = (int) round(" << getTempName(node.getChildren()[1], temps) << ");\n"; out << "int y = (int) floor(" << getTempName(node.getChildren()[1], temps) << "+0.5f);\n";
out << "int xsize = (int) " << paramsInt[0] << ";\n"; out << "int xsize = (int) " << paramsInt[0] << ";\n";
out << "int ysize = (int) " << paramsInt[1] << ";\n"; out << "int ysize = (int) " << paramsInt[1] << ";\n";
out << "int index = x+y*xsize;\n"; out << "int index = x+y*xsize;\n";
...@@ -263,9 +263,9 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express ...@@ -263,9 +263,9 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express
for (int j = 0; j < nodes.size(); j++) { for (int j = 0; j < nodes.size(); j++) {
const vector<int>& derivOrder = dynamic_cast<const Operation::Custom*>(&nodes[j]->getOperation())->getDerivOrder(); const vector<int>& derivOrder = dynamic_cast<const Operation::Custom*>(&nodes[j]->getOperation())->getDerivOrder();
if (derivOrder[0] == 0 && derivOrder[1] == 0 && derivOrder[2] == 0) { if (derivOrder[0] == 0 && derivOrder[1] == 0 && derivOrder[2] == 0) {
out << "int x = (int) round(" << getTempName(node.getChildren()[0], temps) << ");\n"; out << "int x = (int) floor(" << getTempName(node.getChildren()[0], temps) << "+0.5f);\n";
out << "int y = (int) round(" << getTempName(node.getChildren()[1], temps) << ");\n"; out << "int y = (int) floor(" << getTempName(node.getChildren()[1], temps) << "+0.5f);\n";
out << "int z = (int) round(" << getTempName(node.getChildren()[2], temps) << ");\n"; out << "int z = (int) floor(" << getTempName(node.getChildren()[2], temps) << "+0.5f);\n";
out << "int xsize = (int) " << paramsInt[0] << ";\n"; out << "int xsize = (int) " << paramsInt[0] << ";\n";
out << "int ysize = (int) " << paramsInt[1] << ";\n"; out << "int ysize = (int) " << paramsInt[1] << ";\n";
out << "int zsize = (int) " << paramsInt[2] << ";\n"; out << "int zsize = (int) " << paramsInt[2] << ";\n";
......
...@@ -239,7 +239,7 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre ...@@ -239,7 +239,7 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre
if (derivOrder[0] == 0) { if (derivOrder[0] == 0) {
out << "real x = " << getTempName(node.getChildren()[0], temps) << ";\n"; out << "real x = " << getTempName(node.getChildren()[0], temps) << ";\n";
out << "if (x >= 0 && x < " << paramsInt[0] << ") {\n"; out << "if (x >= 0 && x < " << paramsInt[0] << ") {\n";
out << "int index = (int) round(x);\n"; out << "int index = (int) floor(x+0.5f);\n";
out << nodeNames[j] << " = " << functionNames[i].second << "[index];\n"; out << nodeNames[j] << " = " << functionNames[i].second << "[index];\n";
out << "}\n"; out << "}\n";
} }
...@@ -249,8 +249,8 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre ...@@ -249,8 +249,8 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre
for (int j = 0; j < nodes.size(); j++) { for (int j = 0; j < nodes.size(); j++) {
const vector<int>& derivOrder = dynamic_cast<const Operation::Custom*>(&nodes[j]->getOperation())->getDerivOrder(); const vector<int>& derivOrder = dynamic_cast<const Operation::Custom*>(&nodes[j]->getOperation())->getDerivOrder();
if (derivOrder[0] == 0 && derivOrder[1] == 0) { if (derivOrder[0] == 0 && derivOrder[1] == 0) {
out << "int x = (int) round(" << getTempName(node.getChildren()[0], temps) << ");\n"; out << "int x = (int) floor(" << getTempName(node.getChildren()[0], temps) << "+0.5f);\n";
out << "int y = (int) round(" << getTempName(node.getChildren()[1], temps) << ");\n"; out << "int y = (int) floor(" << getTempName(node.getChildren()[1], temps) << "+0.5f);\n";
out << "int xsize = " << paramsInt[0] << ";\n"; out << "int xsize = " << paramsInt[0] << ";\n";
out << "int ysize = " << paramsInt[1] << ";\n"; out << "int ysize = " << paramsInt[1] << ";\n";
out << "int index = x+y*xsize;\n"; out << "int index = x+y*xsize;\n";
...@@ -263,9 +263,9 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre ...@@ -263,9 +263,9 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre
for (int j = 0; j < nodes.size(); j++) { for (int j = 0; j < nodes.size(); j++) {
const vector<int>& derivOrder = dynamic_cast<const Operation::Custom*>(&nodes[j]->getOperation())->getDerivOrder(); const vector<int>& derivOrder = dynamic_cast<const Operation::Custom*>(&nodes[j]->getOperation())->getDerivOrder();
if (derivOrder[0] == 0 && derivOrder[1] == 0 && derivOrder[2] == 0) { if (derivOrder[0] == 0 && derivOrder[1] == 0 && derivOrder[2] == 0) {
out << "int x = (int) round(" << getTempName(node.getChildren()[0], temps) << ");\n"; out << "int x = (int) floor(" << getTempName(node.getChildren()[0], temps) << "+0.5f);\n";
out << "int y = (int) round(" << getTempName(node.getChildren()[1], temps) << ");\n"; out << "int y = (int) floor(" << getTempName(node.getChildren()[1], temps) << "+0.5f);\n";
out << "int z = (int) round(" << getTempName(node.getChildren()[2], temps) << ");\n"; out << "int z = (int) floor(" << getTempName(node.getChildren()[2], temps) << "+0.5f);\n";
out << "int xsize = " << paramsInt[0] << ";\n"; out << "int xsize = " << paramsInt[0] << ";\n";
out << "int ysize = " << paramsInt[1] << ";\n"; out << "int ysize = " << paramsInt[1] << ";\n";
out << "int zsize = " << paramsInt[2] << ";\n"; out << "int zsize = " << paramsInt[2] << ";\n";
......
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