fix formatting
This commit is contained in:
parent
edcfdea949
commit
17a6197819
|
@ -6,23 +6,23 @@ LONGLONG HICLOCKS_PER_SEC = 0;
|
|||
|
||||
void hiclock_init()
|
||||
{
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceFrequency(&freq);
|
||||
HICLOCKS_PER_SEC = freq.QuadPart;
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceFrequency(&freq);
|
||||
HICLOCKS_PER_SEC = freq.QuadPart;
|
||||
}
|
||||
#endif
|
||||
|
||||
hiclock_t hiclock()
|
||||
{
|
||||
#if defined(__unix__)
|
||||
struct timeval clocks;
|
||||
gettimeofday(&clocks, NULL);
|
||||
return ((uint64_t)clocks.tv_sec * 1000000ULL) + clocks.tv_usec;
|
||||
struct timeval clocks;
|
||||
gettimeofday(&clocks, NULL);
|
||||
return ((uint64_t)clocks.tv_sec * 1000000ULL) + clocks.tv_usec;
|
||||
#elif defined(__WIN32) || defined(__WIN64)
|
||||
LARGE_INTEGER clocks;
|
||||
QueryPerformanceCounter(&clocks);
|
||||
return clocks.QuadPart;
|
||||
LARGE_INTEGER clocks;
|
||||
QueryPerformanceCounter(&clocks);
|
||||
return clocks.QuadPart;
|
||||
#else
|
||||
return clock();
|
||||
return clock();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -41,61 +41,56 @@
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("libfixmath test tool\n");
|
||||
printf("libfixmath test tool\n");
|
||||
|
||||
hiclock_init();
|
||||
hiclock_init();
|
||||
|
||||
uintptr_t args = (1 << 8);
|
||||
uintptr_t iter = (1 << 8);
|
||||
uintptr_t pass = (1 << 8);
|
||||
uintptr_t args = (1 << 8);
|
||||
uintptr_t iter = (1 << 8);
|
||||
uintptr_t pass = (1 << 8);
|
||||
|
||||
uintptr_t i;
|
||||
srand(time(NULL));
|
||||
uintptr_t i;
|
||||
srand(time(NULL));
|
||||
|
||||
hiclock_t fix_duration = 0;
|
||||
hiclock_t flt_duration = 0;
|
||||
fix16_t fix_error = 0;
|
||||
hiclock_t fix_duration = 0;
|
||||
hiclock_t flt_duration = 0;
|
||||
fix16_t fix_error = 0;
|
||||
|
||||
uintptr_t k;
|
||||
for (k = 0; k < pass; k++)
|
||||
{
|
||||
fix16_t fix_args[args];
|
||||
for (i = 0; i < args; i++) fix_args[i] = (rand() ^ (rand() << 16));
|
||||
fix16_t fix_result[args];
|
||||
hiclock_t fix_start = hiclock();
|
||||
for (i = 0; i < iter; i++)
|
||||
{
|
||||
uintptr_t j;
|
||||
for (j = 0; j < args; j++) fix_result[j] = fix_func(fix_args[j]);
|
||||
}
|
||||
hiclock_t fix_end = hiclock();
|
||||
uintptr_t k;
|
||||
for (k = 0; k < pass; k++)
|
||||
{
|
||||
fix16_t fix_args[args];
|
||||
for (i = 0; i < args; i++) fix_args[i] = (rand() ^ (rand() << 16));
|
||||
fix16_t fix_result[args];
|
||||
hiclock_t fix_start = hiclock();
|
||||
for (i = 0; i < iter; i++)
|
||||
{
|
||||
uintptr_t j;
|
||||
for (j = 0; j < args; j++) fix_result[j] = fix_func(fix_args[j]);
|
||||
}
|
||||
hiclock_t fix_end = hiclock();
|
||||
|
||||
float flt_args[args];
|
||||
for (i = 0; i < args; i++) flt_args[i] = fix16_to_float(fix_args[i]);
|
||||
float flt_result[args];
|
||||
hiclock_t flt_start = hiclock();
|
||||
for (i = 0; i < iter; i++)
|
||||
{
|
||||
uintptr_t j;
|
||||
for (j = 0; j < args; j++) flt_result[j] = flt_func(flt_args[j]);
|
||||
}
|
||||
hiclock_t flt_end = hiclock();
|
||||
float flt_args[args];
|
||||
for (i = 0; i < args; i++) flt_args[i] = fix16_to_float(fix_args[i]);
|
||||
float flt_result[args];
|
||||
hiclock_t flt_start = hiclock();
|
||||
for (i = 0; i < iter; i++)
|
||||
{
|
||||
uintptr_t j;
|
||||
for (j = 0; j < args; j++) flt_result[j] = flt_func(flt_args[j]);
|
||||
}
|
||||
hiclock_t flt_end = hiclock();
|
||||
|
||||
for (i = 0; i < args; i++)
|
||||
fix_error += abs(fix16_from_float(flt_result[i]) - fix_result[i]);
|
||||
flt_duration += (flt_end - flt_start);
|
||||
fix_duration += (fix_end - fix_start);
|
||||
}
|
||||
for (i = 0; i < args; i++)
|
||||
fix_error += abs(fix16_from_float(flt_result[i]) - fix_result[i]);
|
||||
flt_duration += (flt_end - flt_start);
|
||||
fix_duration += (fix_end - fix_start);
|
||||
}
|
||||
|
||||
printf("%16s: %08" PRIuHICLOCK " @ %" PRIu32 "Hz\n", flt_func_str,
|
||||
flt_duration, HICLOCKS_PER_SEC);
|
||||
printf("%16s: %08" PRIuHICLOCK " @ %" PRIu32 "Hz\n", fix_func_str,
|
||||
fix_duration, HICLOCKS_PER_SEC);
|
||||
printf(" Difference: %08" PRIiHICLOCK " (% 3.2f%%)\n",
|
||||
(flt_duration - fix_duration),
|
||||
((fix_duration * 100.0) / flt_duration));
|
||||
printf(" Error: %f%%\n",
|
||||
((fix16_to_dbl(fix_error) * 100.0) / (args * pass)));
|
||||
printf("%16s: %08" PRIuHICLOCK " @ %" PRIu32 "Hz\n", flt_func_str, flt_duration, HICLOCKS_PER_SEC);
|
||||
printf("%16s: %08" PRIuHICLOCK " @ %" PRIu32 "Hz\n", fix_func_str, fix_duration, HICLOCKS_PER_SEC);
|
||||
printf(" Difference: %08" PRIiHICLOCK " (% 3.2f%%)\n", (flt_duration - fix_duration), ((fix_duration * 100.0) / flt_duration));
|
||||
printf(" Error: %f%%\n", ((fix16_to_dbl(fix_error) * 100.0) / (args * pass)));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -8,11 +8,11 @@ class Fix16 {
|
|||
fix16_t value;
|
||||
|
||||
Fix16() { value = 0; }
|
||||
Fix16(const Fix16 &inValue) { value = inValue.value; }
|
||||
Fix16(const fix16_t inValue) { value = inValue; }
|
||||
Fix16(const float inValue) { value = fix16_from_float(inValue); }
|
||||
Fix16(const double inValue) { value = fix16_from_dbl(inValue); }
|
||||
Fix16(const int16_t inValue) { value = fix16_from_int(inValue); }
|
||||
Fix16(const Fix16 &inValue) { value = inValue.value; }
|
||||
Fix16(const fix16_t inValue) { value = inValue; }
|
||||
Fix16(const float inValue) { value = fix16_from_float(inValue); }
|
||||
Fix16(const double inValue) { value = fix16_from_dbl(inValue); }
|
||||
Fix16(const int16_t inValue) { value = fix16_from_int(inValue); }
|
||||
|
||||
operator fix16_t() const { return value; }
|
||||
operator double() const { return fix16_to_dbl(value); }
|
||||
|
@ -105,41 +105,41 @@ class Fix16 {
|
|||
const Fix16 sdiv(const int16_t other) const { Fix16 ret = fix16_sdiv(value, fix16_from_int(other)); return ret; }
|
||||
#endif
|
||||
|
||||
int operator==(const Fix16 &other) const { return (value == other.value); }
|
||||
int operator==(const fix16_t other) const { return (value == other); }
|
||||
int operator==(const double other) const { return (value == fix16_from_dbl(other)); }
|
||||
int operator==(const float other) const { return (value == fix16_from_float(other)); }
|
||||
int operator==(const int16_t other) const { return (value == fix16_from_int(other)); }
|
||||
int operator==(const Fix16 &other) const { return (value == other.value); }
|
||||
int operator==(const fix16_t other) const { return (value == other); }
|
||||
int operator==(const double other) const { return (value == fix16_from_dbl(other)); }
|
||||
int operator==(const float other) const { return (value == fix16_from_float(other)); }
|
||||
int operator==(const int16_t other) const { return (value == fix16_from_int(other)); }
|
||||
|
||||
int operator!=(const Fix16 &other) const { return (value != other.value); }
|
||||
int operator!=(const fix16_t other) const { return (value != other); }
|
||||
int operator!=(const double other) const { return (value != fix16_from_dbl(other)); }
|
||||
int operator!=(const float other) const { return (value != fix16_from_float(other)); }
|
||||
int operator!=(const int16_t other) const { return (value != fix16_from_int(other)); }
|
||||
int operator!=(const Fix16 &other) const { return (value != other.value); }
|
||||
int operator!=(const fix16_t other) const { return (value != other); }
|
||||
int operator!=(const double other) const { return (value != fix16_from_dbl(other)); }
|
||||
int operator!=(const float other) const { return (value != fix16_from_float(other)); }
|
||||
int operator!=(const int16_t other) const { return (value != fix16_from_int(other)); }
|
||||
|
||||
int operator<=(const Fix16 &other) const { return (value <= other.value); }
|
||||
int operator<=(const fix16_t other) const { return (value <= other); }
|
||||
int operator<=(const double other) const { return (value <= fix16_from_dbl(other)); }
|
||||
int operator<=(const float other) const { return (value <= fix16_from_float(other)); }
|
||||
int operator<=(const int16_t other) const { return (value <= fix16_from_int(other)); }
|
||||
int operator<=(const Fix16 &other) const { return (value <= other.value); }
|
||||
int operator<=(const fix16_t other) const { return (value <= other); }
|
||||
int operator<=(const double other) const { return (value <= fix16_from_dbl(other)); }
|
||||
int operator<=(const float other) const { return (value <= fix16_from_float(other)); }
|
||||
int operator<=(const int16_t other) const { return (value <= fix16_from_int(other)); }
|
||||
|
||||
int operator>=(const Fix16 &other) const { return (value >= other.value); }
|
||||
int operator>=(const fix16_t other) const { return (value >= other); }
|
||||
int operator>=(const double other) const { return (value >= fix16_from_dbl(other)); }
|
||||
int operator>=(const float other) const { return (value >= fix16_from_float(other)); }
|
||||
int operator>=(const int16_t other) const { return (value >= fix16_from_int(other)); }
|
||||
int operator>=(const Fix16 &other) const { return (value >= other.value); }
|
||||
int operator>=(const fix16_t other) const { return (value >= other); }
|
||||
int operator>=(const double other) const { return (value >= fix16_from_dbl(other)); }
|
||||
int operator>=(const float other) const { return (value >= fix16_from_float(other)); }
|
||||
int operator>=(const int16_t other) const { return (value >= fix16_from_int(other)); }
|
||||
|
||||
int operator< (const Fix16 &other) const { return (value < other.value); }
|
||||
int operator< (const fix16_t other) const { return (value < other); }
|
||||
int operator< (const double other) const { return (value < fix16_from_dbl(other)); }
|
||||
int operator< (const float other) const { return (value < fix16_from_float(other)); }
|
||||
int operator< (const int16_t other) const { return (value < fix16_from_int(other)); }
|
||||
int operator< (const Fix16 &other) const { return (value < other.value); }
|
||||
int operator< (const fix16_t other) const { return (value < other); }
|
||||
int operator< (const double other) const { return (value < fix16_from_dbl(other)); }
|
||||
int operator< (const float other) const { return (value < fix16_from_float(other)); }
|
||||
int operator< (const int16_t other) const { return (value < fix16_from_int(other)); }
|
||||
|
||||
int operator> (const Fix16 &other) const { return (value > other.value); }
|
||||
int operator> (const fix16_t other) const { return (value > other); }
|
||||
int operator> (const double other) const { return (value > fix16_from_dbl(other)); }
|
||||
int operator> (const float other) const { return (value > fix16_from_float(other)); }
|
||||
int operator> (const int16_t other) const { return (value > fix16_from_int(other)); }
|
||||
int operator> (const Fix16 &other) const { return (value > other.value); }
|
||||
int operator> (const fix16_t other) const { return (value > other); }
|
||||
int operator> (const double other) const { return (value > fix16_from_dbl(other)); }
|
||||
int operator> (const float other) const { return (value > fix16_from_float(other)); }
|
||||
int operator> (const int16_t other) const { return (value > fix16_from_int(other)); }
|
||||
|
||||
Fix16 sin() const { return Fix16(fix16_sin(value)); }
|
||||
Fix16 cos() const { return Fix16(fix16_cos(value)); }
|
||||
|
|
Loading…
Reference in New Issue