Removed unused table code

This commit is contained in:
VitorBoss 2017-08-28 02:32:18 -03:00
parent cd3bc547b9
commit d4876f5883
1 changed files with 0 additions and 198 deletions

View File

@ -408,201 +408,3 @@ int get3DTableValue(struct table3D *fromTable, int Y_in, int X_in)
}
return tableResult;
}
/* Executed a benchmark on all options and this is the results
* @Mega: Stadard:464276 92 |FP Math:893104 92.57 |Clean code:641280 92 , Number of loops:5000
* @STM32F1: Stadard:21449 92 |FP Math:125707 92.57 |Clean code:11634 92 , Number of loops:5000
* @STM32F4: Stadard:7275 92 |FP Math:5724 92.57 |Clean code:4742 92 , Number of loops:5000
//This function pulls a value from a 3D table given a target for X and Y coordinates.
//It performs a 2D linear interpolation as descibred in: http://www.megamanual.com/v22manual/ve_tuner.pdf
float get3DTableValueF(struct table3D *fromTable, int Y, int X)
{
byte xMin, xMax;
byte yMin, yMax;
float tableResult = 0;
xMin = fromTable->lastXMin;
yMin = fromTable->lastYMin;
if(xMin == 0) { xMin = fromTable->xSize-1; }
if(yMin == 0) { yMin = fromTable->ySize-1; }
do //RPM axis
{
if(X == fromTable->axisX[xMin])
{
xMax = xMin;
break;
}
else if(X > fromTable->axisX[xMin])
{
if (xMin == fromTable->xSize-1) { xMax = xMin; } //Overflow protection
else { xMax = xMin + 1; }
break;
}
xMin--;
}while(true);
do //MAP axis
{
if(Y == fromTable->axisY[yMin])
{
yMax = yMin;
break;
}
else if(Y < fromTable->axisY[yMin])
{
if (yMin == fromTable->ySize-1) { yMax = yMin; } //Overflow protection
else { yMax = yMin + 1; }
break;
}
yMin--;
}while(true);
fromTable->lastXMin = xMax;
fromTable->lastYMin = yMax;
int A = fromTable->values[yMin][xMin];
int B = fromTable->values[yMin][xMax];
int C = fromTable->values[yMax][xMin];
int D = fromTable->values[yMax][xMax];
if( (A == B) && (A == C) && (A == D) ) { tableResult = A; }
else if(xMin == xMax) // Same RPM axys do a simple 2D (27% faster on Mega on worst case, up to 500%)
{
int yMaxValue = fromTable->axisY[yMax];
int yMinValue = fromTable->axisY[yMin];
float q;
q = ((float)(Y - yMinValue) * (C - A)) / (yMaxValue - yMinValue);
tableResult = A + q;
}
else if(yMin == yMax) // Same MAP axys do a simple 2D (27% faster on Mega on worst case, up to 500%)
{
int xMaxValue = fromTable->axisX[xMax];
int xMinValue = fromTable->axisX[xMin];
float q;
q = ((float)(X - xMinValue) * (B - A)) / (xMaxValue - xMinValue);
tableResult = A + q;
}
else
{
int yMaxValue = fromTable->axisY[yMax];
int yMinValue = fromTable->axisY[yMin];
int xMaxValue = fromTable->axisX[xMax];
int xMinValue = fromTable->axisX[xMin];
float m, n, o , p, q, r;
if (xMaxValue == xMinValue) { p = (float)X - xMinValue; }
else { p = ((float)X - xMinValue) / (xMaxValue - xMinValue); }
if (yMaxValue == yMinValue) { q = (float)Y - yMinValue; }
else { q = ((float)Y - yMinValue) / (yMaxValue - yMinValue); }
m = (1.0-p) * (1.0-q);
n = p * (1-q);
o = (1-p) * q;
r = p * q;
tableResult = ( (A * m) + (B * n) + (C * o) + (D * r) );
}
return tableResult;
}
//This function pulls a value from a 3D table given a target for X and Y coordinates.
//It performs a 2D linear interpolation as descibred in: http://www.megamanual.com/v22manual/ve_tuner.pdf
int get3DTableValueS(struct table3D *fromTable, int Y, int X)
{
byte xMin, xMax;
byte yMin, yMax;
int tableResult = 0;
xMin = fromTable->lastXMin;
yMin = fromTable->lastYMin;
if(xMin == 0) { xMin = fromTable->xSize-1; }
if(yMin == 0) { yMin = fromTable->ySize-1; }
do //RPM axis
{
if(X == fromTable->axisX[xMin])
{
xMax = xMin;
break;
}
else if(X > fromTable->axisX[xMin])
{
if (xMin == fromTable->xSize-1) { xMax = xMin; } //Overflow protection
else { xMax = xMin + 1; }
break;
}
xMin--;
}while(true);
do //MAP axis
{
if(Y == fromTable->axisY[yMin])
{
yMax = yMin;
break;
}
else if(Y < fromTable->axisY[yMin])
{
if (yMin == fromTable->ySize-1) { yMax = yMin; } //Overflow protection
else { yMax = yMin + 1; }
break;
}
yMin--;
}while(true);
fromTable->lastXMin = xMax;
fromTable->lastYMin = yMax;
int A = fromTable->values[yMin][xMin];
int B = fromTable->values[yMin][xMax];
int C = fromTable->values[yMax][xMin];
int D = fromTable->values[yMax][xMax];
if( (A == B) && (A == C) && (A == D) ) { tableResult = A; }
else if(xMin == xMax) // Same RPM axys do a simple 2D (27% faster on Mega on worst case, up to 500%)
{
int yMaxValue = fromTable->axisY[yMax];
int yMinValue = fromTable->axisY[yMin];
long q;
q = (((long)(Y - yMinValue) << 6) * (C - A)) / (yMaxValue - yMinValue);
tableResult = A + (q >> 6);
}
else if(yMin == yMax) // Same MAP axys do a simple 2D (27% faster on Mega on worst case, up to 500%)
{
int xMaxValue = fromTable->axisX[xMax];
int xMinValue = fromTable->axisX[xMin];
long q;
q = (((long)(X - xMinValue) << 6) * (B - A)) / (xMaxValue - xMinValue);
tableResult = A + (q >> 6);
}
else
{
int yMaxValue = fromTable->axisY[yMax];
int yMinValue = fromTable->axisY[yMin];
int xMaxValue = fromTable->axisX[xMax];
int xMinValue = fromTable->axisX[xMin];
long p = (long)X - xMinValue;
if (xMaxValue == xMinValue) { p = (p << 8); } //This only occurs if the requested X value was equal to one of the X axis bins
else { p = ( (p << 8) / (xMaxValue - xMinValue) ); } //This is the standard case
long q;
if (yMaxValue == yMinValue)
{
q = (long)Y - yMinValue;
q = (q << 8);
}
//Standard case
else
{
q = long(Y) - yMaxValue;
q = 256 - ( (q << 8) / (yMinValue - yMaxValue) );
}
int m = ((256-p) * (256-q)) >> 8;
int n = (p * (256-q)) >> 8;
int o = ((256-p) * q) >> 8;
int r = (p * q) >> 8;
tableResult = ( (A * m) + (B * n) + (C * o) + (D * r) ) >> 8;
}
return tableResult;
}
*/