Skip to content

Commit

Permalink
Merge pull request #10178 from iNavFlight/dzikuvx-lulu-optimization
Browse files Browse the repository at this point in the history
Remove of register optimization in favor or relying on GCC optimization.
  • Loading branch information
DzikuVx authored Jun 26, 2024
2 parents 147734c + 596c025 commit 41c89a7
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/main/common/lulu.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ void luluFilterInit(luluFilter_t *filter, int N)

FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, int windowSize)
{
register float curVal = 0;
register float curValB = 0;
float curVal = 0;
float curValB = 0;
for (int N = 1; N <= filterN; N++)
{
int indexNeg = (index + windowSize - 2 * N) % windowSize;
register int curIndex = (indexNeg + 1) % windowSize;
register float prevVal = series[indexNeg];
register float prevValB = seriesB[indexNeg];
register int indexPos = (curIndex + N) % windowSize;
for (int i = windowSize - 2 * N; i < windowSize - N; i++)
int curIndex = (indexNeg + 1) % windowSize;
float prevVal = series[indexNeg];
float prevValB = seriesB[indexNeg];
int indexPos = (curIndex + N) % windowSize;

for (int i = windowSize - 2 * N; i < windowSize - N; i++)
{
if (indexPos >= windowSize)
{
Expand All @@ -50,16 +51,16 @@ FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, i
// curIndex = (2 - 1) % 3 = 1
curVal = series[curIndex];
curValB = seriesB[curIndex];
register float nextVal = series[indexPos];
register float nextValB = seriesB[indexPos];
float nextVal = series[indexPos];
float nextValB = seriesB[indexPos];
// onbump (s, 1, 1, 3)
// if(onBump(series, curIndex, N, windowSize))
if (prevVal < curVal && curVal > nextVal)
{
float maxValue = MAX(prevVal, nextVal);

series[curIndex] = maxValue;
register int k = curIndex;
int k = curIndex;
for (int j = 1; j < N; j++)
{
if (++k >= windowSize)
Expand All @@ -76,7 +77,7 @@ FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, i

curVal = maxValue;
seriesB[curIndex] = maxValue;
register int k = curIndex;
int k = curIndex;
for (int j = 1; j < N; j++)
{
if (++k >= windowSize)
Expand Down Expand Up @@ -109,16 +110,16 @@ FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, i
// curIndex = (2 - 1) % 3 = 1
curVal = series[curIndex];
curValB = seriesB[curIndex];
register float nextVal = series[indexPos];
register float nextValB = seriesB[indexPos];
float nextVal = series[indexPos];
float nextValB = seriesB[indexPos];

if (prevVal > curVal && curVal < nextVal)
{
float minValue = MIN(prevVal, nextVal);

curVal = minValue;
series[curIndex] = minValue;
register int k = curIndex;
int k = curIndex;
for (int j = 1; j < N; j++)
{
if (++k >= windowSize)
Expand All @@ -134,7 +135,7 @@ FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, i
float minValue = MIN(prevValB, nextValB);
curValB = minValue;
seriesB[curIndex] = minValue;
register int k = curIndex;
int k = curIndex;
for (int j = 1; j < N; j++)
{
if (++k >= windowSize)
Expand All @@ -156,13 +157,13 @@ FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, i
FAST_CODE float luluFilterPartialApply(luluFilter_t *filter, float input)
{
// This is the value N of the LULU filter.
register int filterN = filter->N;
int filterN = filter->N;
// This is the total window size for the rolling buffer
register int filterWindow = filter->windowSize;
int filterWindow = filter->windowSize;

register int windowIndex = filter->windowBufIndex;
register float inputVal = input;
register int newIndex = (windowIndex + 1) % filterWindow;
int windowIndex = filter->windowBufIndex;
float inputVal = input;
int newIndex = (windowIndex + 1) % filterWindow;
filter->windowBufIndex = newIndex;
filter->luluInterim[windowIndex] = inputVal;
filter->luluInterimB[windowIndex] = -inputVal;
Expand Down

0 comments on commit 41c89a7

Please sign in to comment.