diff options
Diffstat (limited to 'Client/ThirdParty/libfixmath/fixtest')
-rw-r--r-- | Client/ThirdParty/libfixmath/fixtest/fixtest.cbp | 52 | ||||
-rw-r--r-- | Client/ThirdParty/libfixmath/fixtest/fixtest.depend | 67 | ||||
-rw-r--r-- | Client/ThirdParty/libfixmath/fixtest/fixtest.layout | 13 | ||||
-rw-r--r-- | Client/ThirdParty/libfixmath/fixtest/hiclock.c | 28 | ||||
-rw-r--r-- | Client/ThirdParty/libfixmath/fixtest/hiclock.h | 33 | ||||
-rw-r--r-- | Client/ThirdParty/libfixmath/fixtest/main.c | 96 |
6 files changed, 289 insertions, 0 deletions
diff --git a/Client/ThirdParty/libfixmath/fixtest/fixtest.cbp b/Client/ThirdParty/libfixmath/fixtest/fixtest.cbp new file mode 100644 index 0000000..2671252 --- /dev/null +++ b/Client/ThirdParty/libfixmath/fixtest/fixtest.cbp @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_project_file> + <FileVersion major="1" minor="6" /> + <Project> + <Option title="fixtest" /> + <Option pch_mode="2" /> + <Option compiler="gcc" /> + <Build> + <Target title="dbg"> + <Option output="bin\dbg\fixtest" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\dbg\" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-g" /> + </Compiler> + </Target> + <Target title="rel"> + <Option output="bin\rel\fixtest" prefix_auto="1" extension_auto="1" /> + <Option object_output="obj\rel\" /> + <Option type="1" /> + <Option compiler="gcc" /> + <Compiler> + <Add option="-O2" /> + </Compiler> + <Linker> + <Add option="-s" /> + </Linker> + </Target> + </Build> + <Compiler> + <Add option="-Wall" /> + <Add directory="..\" /> + </Compiler> + <Linker> + <Add library="..\libfixmath\libfixmath.a" /> + </Linker> + <Unit filename="hiclock.c"> + <Option compilerVar="CC" /> + </Unit> + <Unit filename="hiclock.h" /> + <Unit filename="main.c"> + <Option compilerVar="CC" /> + </Unit> + <Extensions> + <code_completion /> + <envvars /> + <debugger /> + <lib_finder disable_auto="1" /> + </Extensions> + </Project> +</CodeBlocks_project_file> diff --git a/Client/ThirdParty/libfixmath/fixtest/fixtest.depend b/Client/ThirdParty/libfixmath/fixtest/fixtest.depend new file mode 100644 index 0000000..7227a2f --- /dev/null +++ b/Client/ThirdParty/libfixmath/fixtest/fixtest.depend @@ -0,0 +1,67 @@ +# depslib dependency file v1.0 +1298636296 source:g:\vrfx\libfixmath\fixtest\main.c + <stdio.h> + <stdlib.h> + <math.h> + <time.h> + <inttypes.h> + <libfixmath/fixmath.h> + "hiclock.h" + +1298453688 g:\vrfx\libfixmath\\libfixmath\fixmath.h + "uint32.h" + "fract32.h" + "fix16.h" + +1298453688 g:\vrfx\libfixmath\\libfixmath\uint32.h + <stdint.h> + +1298453688 g:\vrfx\libfixmath\\libfixmath\fract32.h + <stdint.h> + +1298648502 g:\vrfx\libfixmath\\libfixmath\fix16.h + <stdint.h> + +1298562746 source:g:\vrfx\libfixmath\fixtest\hiclock.c + "hiclock.h" + +1298564182 g:\vrfx\libfixmath\fixtest\hiclock.h + <stdint.h> + <inttypes.h> + <sys/time.h> + <windows.h> + <time.h> + +1298567472 source:i:\vrfx\libfixmath\fixtest\main.c + <stdio.h> + <stdlib.h> + <math.h> + <time.h> + <inttypes.h> + <libfixmath/fixmath.h> + "hiclock.h" + +1298453688 i:\vrfx\libfixmath\\libfixmath\fixmath.h + "uint32.h" + "fract32.h" + "fix16.h" + +1298453688 i:\vrfx\libfixmath\\libfixmath\uint32.h + <stdint.h> + +1298453688 i:\vrfx\libfixmath\\libfixmath\fract32.h + <stdint.h> + +1298577432 i:\vrfx\libfixmath\\libfixmath\fix16.h + <stdint.h> + +1298564182 i:\vrfx\libfixmath\fixtest\hiclock.h + <stdint.h> + <inttypes.h> + <sys/time.h> + <windows.h> + <time.h> + +1298562746 source:i:\vrfx\libfixmath\fixtest\hiclock.c + "hiclock.h" + diff --git a/Client/ThirdParty/libfixmath/fixtest/fixtest.layout b/Client/ThirdParty/libfixmath/fixtest/fixtest.layout new file mode 100644 index 0000000..36f21e7 --- /dev/null +++ b/Client/ThirdParty/libfixmath/fixtest/fixtest.layout @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<CodeBlocks_layout_file> + <ActiveTarget name="rel" /> + <File name="hiclock.c" open="1" top="0" tabpos="6"> + <Cursor position="520" topLine="0" /> + </File> + <File name="hiclock.h" open="1" top="0" tabpos="5"> + <Cursor position="578" topLine="0" /> + </File> + <File name="main.c" open="1" top="1" tabpos="4"> + <Cursor position="392" topLine="36" /> + </File> +</CodeBlocks_layout_file> diff --git a/Client/ThirdParty/libfixmath/fixtest/hiclock.c b/Client/ThirdParty/libfixmath/fixtest/hiclock.c new file mode 100644 index 0000000..81f5b94 --- /dev/null +++ b/Client/ThirdParty/libfixmath/fixtest/hiclock.c @@ -0,0 +1,28 @@ +#include "hiclock.h" +#include <stddef.h> + +#if defined(__WIN32) || defined(__WIN64) +LONGLONG HICLOCKS_PER_SEC = 0; + +void hiclock_init() +{ + 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; +#elif defined(__WIN32) || defined(__WIN64) + LARGE_INTEGER clocks; + QueryPerformanceCounter(&clocks); + return clocks.QuadPart; +#else + return clock(); +#endif +} diff --git a/Client/ThirdParty/libfixmath/fixtest/hiclock.h b/Client/ThirdParty/libfixmath/fixtest/hiclock.h new file mode 100644 index 0000000..7cabf47 --- /dev/null +++ b/Client/ThirdParty/libfixmath/fixtest/hiclock.h @@ -0,0 +1,33 @@ +#ifndef __hiclock_h__ +#define __hiclock_h__ + +#include <stdint.h> +#include <inttypes.h> + +#if defined(__unix__) +#include <sys/time.h> +#define PRIuHICLOCK PRIu64 +#define PRIiHICLOCK PRIi64 +typedef uint64_t hiclock_t; +#define HICLOCKS_PER_SEC 1000000 +#define hiclock_init() +#elif defined(__WIN32) || defined(__WIN64) +#include <windows.h> +#define PRIuHICLOCK PRIu64 +#define PRIiHICLOCK PRIi64 +typedef LONGLONG hiclock_t; +extern LONGLONG HICLOCKS_PER_SEC; +extern void hiclock_init(); +#else +#include <time.h> +#define PRIuHICLOCK PRIu32 +#define PRIiHICLOCK PRIi32 +typedef clock_t hiclock_t; +#define HICLOCKS_PER_SEC CLOCKS_PER_SEC +#define hiclock_init() +#endif + +extern hiclock_t hiclock(); + +#endif + diff --git a/Client/ThirdParty/libfixmath/fixtest/main.c b/Client/ThirdParty/libfixmath/fixtest/main.c new file mode 100644 index 0000000..822f290 --- /dev/null +++ b/Client/ThirdParty/libfixmath/fixtest/main.c @@ -0,0 +1,96 @@ +#include "hiclock.h" +#include <inttypes.h> +#include <libfixmath/fixmath.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +#define EXP +//#define ATAN +//#define SIN +//#define SQRT + +#ifdef EXP +#define fix_func fix16_exp +#define fix_func_str "fix16_exp" +#define flt_func expf +#define flt_func_str "expf" +#endif + +#ifdef ATAN +#define fix_func fix16_atan +#define fix_func_str "fix16_atan" +#define flt_func atanf +#define flt_func_str "atanf" +#endif + +#ifdef SIN +#define fix_func fix16_sin +#define fix_func_str "fix16_sin" +#define flt_func sinf +#define flt_func_str "sinf" +#endif + +#ifdef SQRT +#define fix_func fix16_sqrt +#define fix_func_str "fix16_sqrt" +#define flt_func sqrtf +#define flt_func_str "sqrtf" +#endif + +int main(int argc, char **argv) +{ + printf("libfixmath test tool\n"); + + hiclock_init(); + + uintptr_t args = (1 << 8); + uintptr_t iter = (1 << 8); + uintptr_t pass = (1 << 8); + + uintptr_t i; + srand(time(NULL)); + + 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(); + + 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); + } + + 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; +} |