diff options
| author | Martin BaĆinka <marun1@email.cz> | 2021-05-03 12:43:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-03 13:43:54 +0300 |
| commit | 0c88e55fa8f132e8ac15426911d155f136078302 (patch) | |
| tree | 03fc1b22c0582bd57ae3a14095d3d9c9f949f0c9 /benchmarks/benchmark.c | |
| parent | 4ea8f3ff12da61a5ceba690bf1e39d9385b42880 (diff) | |
| download | libfixmath-0c88e55fa8f132e8ac15426911d155f136078302.tar.gz | |
fixed division, undefined behaviors and some improvements (#33)
* testing using ctest
* emove old testing script
* added github workflow CI
* updated CI
* added unit test for macros
* F16() and F16C() are both rounding allways, so fix16_from_dbl should as well
* added tests for strign operations, but these functions are in my opinion unreliable and tests are failing
* removed old unittests
* removed old unittests from cmake
* problem with division using gcc
* improved benchmark
* clarification of problem with division
* attempt to fix
* fixed some undefined behaviors, fixed division
Diffstat (limited to 'benchmarks/benchmark.c')
| -rw-r--r-- | benchmarks/benchmark.c | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/benchmarks/benchmark.c b/benchmarks/benchmark.c index 70a2aeb..3942abc 100644 --- a/benchmarks/benchmark.c +++ b/benchmarks/benchmark.c @@ -9,15 +9,6 @@ /* Autogenerated testcases */ #include "testcases.c" -/* Tools for profiling */ - -typedef struct { - uint32_t min; - uint32_t max; - uint32_t sum; - uint32_t count; -} cyclecount_t; - // Initializer for cyclecount_t structure. // Max is initialized to 0 and min is 2^32-1 so that first call to cyclecount_update will set them. #define CYCLECOUNT_INIT {0xFFFFFFFF, 0, 0, 0} @@ -40,12 +31,6 @@ static void cyclecount_update(cyclecount_t *data, uint32_t cycles) cyclecount_update(&variable, end_timing()); \ } -#define PRINT(variable, label) { \ - print_value(label " min", variable.min); \ - print_value(label " max", variable.max); \ - print_value(label " avg", variable.sum / variable.count); \ -} - static cyclecount_t exp_cycles = CYCLECOUNT_INIT; static cyclecount_t sqrt_cycles = CYCLECOUNT_INIT; static cyclecount_t add_cycles = CYCLECOUNT_INIT; @@ -53,13 +38,12 @@ static cyclecount_t sub_cycles = CYCLECOUNT_INIT; static cyclecount_t div_cycles = CYCLECOUNT_INIT; static cyclecount_t mul_cycles = CYCLECOUNT_INIT; -#ifndef NO_FLOAT static cyclecount_t float_sqrtf_cycles = CYCLECOUNT_INIT; +static cyclecount_t float_expf_cycles = CYCLECOUNT_INIT; static cyclecount_t float_add_cycles = CYCLECOUNT_INIT; static cyclecount_t float_sub_cycles = CYCLECOUNT_INIT; static cyclecount_t float_div_cycles = CYCLECOUNT_INIT; static cyclecount_t float_mul_cycles = CYCLECOUNT_INIT; -#endif static fix16_t delta(fix16_t result, fix16_t expected) { @@ -119,8 +103,6 @@ int main() print_value("Failed EXP, expected", expected); } } - PRINT(sqrt_cycles, "fix16_sqrt"); - PRINT(exp_cycles, "fix16_exp"); for (i = 0; i < TESTCASES2_COUNT; i++) { @@ -175,10 +157,6 @@ int main() } } } - PRINT(add_cycles, "fix16_add"); - PRINT(sub_cycles, "fix16_sub"); - PRINT(mul_cycles, "fix16_mul"); - PRINT(div_cycles, "fix16_div"); /* Compare with floating point performance */ #ifndef NO_FLOAT @@ -187,8 +165,8 @@ int main() float input = fix16_to_float(testcases1[i].a); volatile float result; MEASURE(float_sqrtf_cycles, result = sqrtf(input)); + MEASURE(float_expf_cycles, result = expf(input)); } - PRINT(float_sqrtf_cycles, "float sqrtf"); for (i = 0; i < TESTCASES2_COUNT; i++) { @@ -204,11 +182,20 @@ int main() MEASURE(float_div_cycles, result = a / b); } } - PRINT(float_add_cycles, "float add"); - PRINT(float_sub_cycles, "float sub"); - PRINT(float_mul_cycles, "float mul"); - PRINT(float_div_cycles, "float div"); -#endif +#endif + + print("fix16_sqrt", &sqrt_cycles); + print("float sqrtf", &float_sqrtf_cycles); + print("fix16_exp", &exp_cycles); + print("float expf", &float_expf_cycles); + print("fix16_add", &add_cycles); + print("float add", &float_add_cycles); + print("fix16_sub", &sub_cycles); + print("float sub", &float_sub_cycles); + print("fix16_mul", &mul_cycles); + print("float mul", &float_mul_cycles); + print("fix16_div", &div_cycles); + print("float div", &float_div_cycles); return 0; } |
