only: wow, all of this was dead code

This commit is contained in:
Matthew Kennedy 2024-07-03 03:37:27 -04:00 committed by Andrey
parent caa1f568bf
commit e1d29141dc
4 changed files with 0 additions and 145 deletions

View File

@ -425,8 +425,6 @@ void commonInitEngineController() {
addConsoleAction("reset_accel", resetAccel);
#endif /* EFI_PROD_CODE */
initInterpolation();
#if EFI_SIMULATOR || EFI_UNIT_TEST
printf("commonInitEngineController\n");
#endif

View File

@ -22,8 +22,6 @@
#define INTERPOLATION_A(x1, y1, x2, y2) ((y1 - y2) / (x1 - x2))
int findIndex(const float array[], int size, float value);
int findIndex2(const float array[], unsigned size, float value);
float interpolateClampedWithValidation(float x1, float y1, float x2, float y2, float x);
float interpolateClamped(float x1, float y1, float x2, float y2, float x);
float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x);
@ -121,5 +119,3 @@ void setCurveValue(const kType bins[], VType values[], int size, float key, floa
index = 0;
values[index] = value;
}
void initInterpolation();

View File

@ -14,52 +14,6 @@
#include "efi_interpolation.h"
#define BINARY_PERF true
#if BINARY_PERF && ! EFI_UNIT_TEST
#define COUNT 10000
float array16[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
static void testBinary() {
const int size16 = 16;
uint32_t totalOld = 0;
uint32_t totalNew = 0;
for (int v = 0; v <= 16; v++) {
uint32_t timeOld;
{
uint32_t start = getTimeNowLowerNt();
int temp = 0;
for (int i = 0; i < COUNT; i++) {
temp += findIndex(array16, size16, v);
}
timeOld = getTimeNowLowerNt() - start;
}
uint32_t timeNew;
{
uint32_t start = getTimeNowLowerNt();
int temp = 0;
for (int i = 0; i < COUNT; i++) {
temp += findIndex2(array16, size16, v);
}
timeNew = getTimeNowLowerNt() - start;
}
efiPrintf("for v=%d old=%lu ticks", v, timeOld);
efiPrintf("for v=%d new=%lu ticks", v, timeNew);
totalOld += timeOld;
totalNew += timeNew;
}
efiPrintf("totalOld=%lu ticks", totalOld);
efiPrintf("totalNew=%lu ticks", totalNew);
}
#endif
/** @brief Linear interpolation by two points
*
* @param x1 key of the first point
@ -124,40 +78,3 @@ float interpolateClamped(float x1, float y1, float x2, float y2, float x) {
float b = y1 - a * x1;
return a * x + b;
}
/**
* Another implementation, which one is faster?
*/
int findIndex2(const float array[], unsigned size, float value) {
efiAssert(ObdCode::CUSTOM_ERR_ASSERT, !cisnan(value), "NaN in findIndex2", 0);
efiAssert(ObdCode::CUSTOM_ERR_ASSERT, size > 1, "size in findIndex", 0);
// if (size <= 1)
// return size && *array <= value ? 0 : -1;
signed i = 0;
//unsigned b = 1 << int(log(float(size) - 1) / 0.69314718055994530942);
unsigned b = size >> 1; // in our case size is always a power of 2
efiAssert(ObdCode::CUSTOM_ERR_ASSERT, b + b == size, "Size not power of 2", -1);
for (; b; b >>= 1) {
unsigned j = i | b;
/**
* it should be
* "if (j < size && array[j] <= value)"
* but in our case size is always power of 2 thus size is always more then j
*/
// efiAssert(ObdCode::CUSTOM_ERR_ASSERT, j < size, "size", 0);
if (array[j] <= value)
i = j;
}
return i || *array <= value ? i : -1;
}
int findIndex(const float array[], int size, float value) {
return findIndexMsg("", array, size, value);
}
void initInterpolation() {
#if BINARY_PERF && ! EFI_UNIT_TEST
addConsoleAction("binarytest", testBinary);
#endif
}

View File

@ -8,62 +8,6 @@
#include "pch.h"
#include "efi_interpolation.h"
static void testIndex(const int expected, const float array[], int size, float value) {
ASSERT_EQ(expected, findIndex(array, size, value));
ASSERT_EQ(expected, findIndex2(array, size, value));
}
TEST(misc, testFindIndex) {
printf("*************************************************** testFindIndex\r\n");
/*
{
// in real life we only use powers of 2 for sizes
float array5[] = { 1, 2, 3, 4, 5 };
const int size5 = 5;
printf("To the right5\r\n");
testIndex(4, array5, size5, 10.0);
printf("Middle2\r\n");
testIndex(3, array5, size5, 4);
printf("Middle2\r\n");
testIndex(2, array5, size5, 3.1);
}
*/
{
float array4[] = { 1, 2, 3, 4 };
const int size4 = 4;
printf("To the left\r\n");
testIndex(-1, array4, size4, -1.0);
printf("To the right4\r\n");
testIndex(3, array4, size4, 10.0);
printf("On the edge\r\n");
testIndex(3, array4, size4, 4.0);
printf("Another1\r\n");
testIndex(2, array4, size4, 3.9);
printf("Another2\r\n");
testIndex(3, array4, size4, 4.1);
printf("Another3\r\n");
testIndex(1, array4, size4, 2);
printf("Left edge1\r\n");
testIndex(0, array4, size4, 1);
printf("Left edge2\r\n");
testIndex(0, array4, size4, 1.1);
printf("Middle\r\n");
testIndex(2, array4, size4, 3);
}
}
TEST(misc, testSetTableValue) {
printf("*************************************************** testSetTableValue\r\n");