added cmake project file
This commit is contained in:
parent
24488b16cc
commit
7541eae325
|
@ -0,0 +1,160 @@
|
||||||
|
# This file is used to ignore files which are generated
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
*~
|
||||||
|
*.autosave
|
||||||
|
*.a
|
||||||
|
*.core
|
||||||
|
*.moc
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.orig
|
||||||
|
*.rej
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*_pch.h.cpp
|
||||||
|
*_resource.rc
|
||||||
|
*.qm
|
||||||
|
.#*
|
||||||
|
*.*#
|
||||||
|
core
|
||||||
|
!core/
|
||||||
|
tags
|
||||||
|
.DS_Store
|
||||||
|
.directory
|
||||||
|
*.debug
|
||||||
|
Makefile*
|
||||||
|
*.prl
|
||||||
|
*.app
|
||||||
|
moc_*.cpp
|
||||||
|
ui_*.h
|
||||||
|
qrc_*.cpp
|
||||||
|
Thumbs.db
|
||||||
|
*.res
|
||||||
|
*.rc
|
||||||
|
/.qmake.cache
|
||||||
|
/.qmake.stash
|
||||||
|
|
||||||
|
# qtcreator generated files
|
||||||
|
*.pro.user*
|
||||||
|
|
||||||
|
# xemacs temporary files
|
||||||
|
*.flc
|
||||||
|
|
||||||
|
# Vim temporary files
|
||||||
|
.*.swp
|
||||||
|
|
||||||
|
# Visual Studio generated files
|
||||||
|
*.ib_pdb_index
|
||||||
|
*.idb
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
|
*.sln
|
||||||
|
*.suo
|
||||||
|
*.vcproj
|
||||||
|
*vcproj.*.*.user
|
||||||
|
*.ncb
|
||||||
|
*.sdf
|
||||||
|
*.opensdf
|
||||||
|
*.vcxproj
|
||||||
|
*vcxproj.*
|
||||||
|
|
||||||
|
# MinGW generated files
|
||||||
|
*.Debug
|
||||||
|
*.Release
|
||||||
|
|
||||||
|
# Python byte code
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Binaries
|
||||||
|
# --------
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
|
||||||
|
# Prerequisites
|
||||||
|
*.d
|
||||||
|
|
||||||
|
# Compiled Object files
|
||||||
|
*.slo
|
||||||
|
*.lo
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Compiled Dynamic libraries
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Fortran module files
|
||||||
|
*.mod
|
||||||
|
*.smod
|
||||||
|
|
||||||
|
# Compiled Static libraries
|
||||||
|
*.lai
|
||||||
|
*.la
|
||||||
|
*.a
|
||||||
|
*.lib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
|
||||||
|
# C++ objects and libs
|
||||||
|
*.slo
|
||||||
|
*.lo
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.lai
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*.dll
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Qt-es
|
||||||
|
object_script.*.Release
|
||||||
|
object_script.*.Debug
|
||||||
|
*_plugin_import.cpp
|
||||||
|
/.qmake.cache
|
||||||
|
/.qmake.stash
|
||||||
|
*.pro.user
|
||||||
|
*.pro.user.*
|
||||||
|
*.qbs.user
|
||||||
|
*.qbs.user.*
|
||||||
|
*.moc
|
||||||
|
moc_*.cpp
|
||||||
|
moc_*.h
|
||||||
|
qrc_*.cpp
|
||||||
|
ui_*.h
|
||||||
|
*.qmlc
|
||||||
|
*.jsc
|
||||||
|
Makefile*
|
||||||
|
*build-*
|
||||||
|
*.qm
|
||||||
|
*.prl
|
||||||
|
|
||||||
|
# Qt unit tests
|
||||||
|
target_wrapper.*
|
||||||
|
|
||||||
|
# QtCreator
|
||||||
|
*.autosave
|
||||||
|
|
||||||
|
# QtCreator Qml
|
||||||
|
*.qmlproject.user
|
||||||
|
*.qmlproject.user.*
|
||||||
|
|
||||||
|
# QtCreator CMake
|
||||||
|
CMakeLists.txt.user*
|
||||||
|
|
||||||
|
# QtCreator 4.8< compilation database
|
||||||
|
compile_commands.json
|
||||||
|
|
||||||
|
# QtCreator local machine specific files for imported projects
|
||||||
|
*creator.user*
|
||||||
|
|
||||||
|
*_qmlcache.qrc
|
|
@ -0,0 +1,28 @@
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
project(libfixmath LANGUAGES CXX C)
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_C_FLAGS "-Wall -pedantic -Wextra")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_FLAGS "-Wall -pedantic -Wextra")
|
||||||
|
|
||||||
|
file(GLOB libfixmath-srcs libfixmath/*.h libfixmath/*.hpp libfixmath/*.c)
|
||||||
|
file(GLOB contrib-srcs contrib/*.c)
|
||||||
|
file(GLOB fixsingen-srcs fixsingen/*.c)
|
||||||
|
file(GLOB fixtest-srcs fixtest/*.c fixtest/*.h)
|
||||||
|
|
||||||
|
add_library(libfixmath STATIC ${libfixmath-srcs} ${contrib-srcs})
|
||||||
|
target_include_directories(libfixmath PRIVATE ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
add_executable(fixtest ${fixtest-srcs})
|
||||||
|
target_link_libraries(fixtest PRIVATE libfixmath m)
|
||||||
|
target_include_directories(fixtest PRIVATE ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
|
||||||
|
add_executable(fixsingen ${fixsingen-srcs})
|
||||||
|
target_link_libraries(fixsingen PRIVATE libfixmath m)
|
||||||
|
target_include_directories(fixsingen PRIVATE ${CMAKE_SOURCE_DIR})
|
|
@ -9,7 +9,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <fix16.h>
|
#include <libfixmath/fix16.h>
|
||||||
|
|
||||||
// You can change the input datatype and intermediate scaling here.
|
// You can change the input datatype and intermediate scaling here.
|
||||||
// By default, the output is divided by the transform length to get a normalized FFT.
|
// By default, the output is divided by the transform length to get a normalized FFT.
|
||||||
|
|
|
@ -1,25 +1,28 @@
|
||||||
#include "hiclock.h"
|
#include "hiclock.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#if defined(__WIN32) || defined(__WIN64)
|
#if defined(__WIN32) || defined(__WIN64)
|
||||||
LONGLONG HICLOCKS_PER_SEC = 0;
|
LONGLONG HICLOCKS_PER_SEC = 0;
|
||||||
|
|
||||||
void hiclock_init() {
|
void hiclock_init()
|
||||||
LARGE_INTEGER freq;
|
{
|
||||||
QueryPerformanceFrequency(&freq);
|
LARGE_INTEGER freq;
|
||||||
HICLOCKS_PER_SEC = freq.QuadPart;
|
QueryPerformanceFrequency(&freq);
|
||||||
|
HICLOCKS_PER_SEC = freq.QuadPart;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
hiclock_t hiclock() {
|
hiclock_t hiclock()
|
||||||
#if defined(__unix__)
|
{
|
||||||
timeval clocks;
|
#if defined(__unix__)
|
||||||
gettimeofday(&clocks, NULL);
|
struct timeval clocks;
|
||||||
return ((uint64_t)clocks.tv_sec * 1000000ULL) + clocks.tv_usec;
|
gettimeofday(&clocks, NULL);
|
||||||
#elif defined(__WIN32) || defined(__WIN64)
|
return ((uint64_t)clocks.tv_sec * 1000000ULL) + clocks.tv_usec;
|
||||||
LARGE_INTEGER clocks;
|
#elif defined(__WIN32) || defined(__WIN64)
|
||||||
QueryPerformanceCounter(&clocks);
|
LARGE_INTEGER clocks;
|
||||||
return clocks.QuadPart;
|
QueryPerformanceCounter(&clocks);
|
||||||
#else
|
return clocks.QuadPart;
|
||||||
return clock();
|
#else
|
||||||
#endif
|
return clock();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
140
fixtest/main.c
140
fixtest/main.c
|
@ -1,87 +1,101 @@
|
||||||
|
#include "hiclock.h"
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <libfixmath/fixmath.h>
|
||||||
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#include <libfixmath/fixmath.h>
|
#define EXP
|
||||||
|
//#define ATAN
|
||||||
|
//#define SIN
|
||||||
|
//#define SQRT
|
||||||
|
|
||||||
#include "hiclock.h"
|
#ifdef EXP
|
||||||
|
#define fix_func fix16_exp
|
||||||
|
#define fix_func_str "fix16_exp"
|
||||||
|
#define flt_func expf
|
||||||
|
#define flt_func_str "expf"
|
||||||
|
#endif
|
||||||
|
|
||||||
//#define fix_func fix16_exp
|
#ifdef ATAN
|
||||||
//#define fix_func_str "fix16_exp"
|
#define fix_func fix16_atan
|
||||||
//#define flt_func expf
|
#define fix_func_str "fix16_atan"
|
||||||
//#define flt_func_str "expf"
|
#define flt_func atanf
|
||||||
|
#define flt_func_str "atanf"
|
||||||
|
#endif
|
||||||
|
|
||||||
//#define fix_func fix16_atan
|
#ifdef SIN
|
||||||
//#define fix_func_str "fix16_atan"
|
#define fix_func fix16_sin
|
||||||
//#define flt_func atanf
|
|
||||||
//#define flt_func_str "atanf"
|
|
||||||
|
|
||||||
#define fix_func fix16_sin
|
|
||||||
#define fix_func_str "fix16_sin"
|
#define fix_func_str "fix16_sin"
|
||||||
#define flt_func sinf
|
#define flt_func sinf
|
||||||
#define flt_func_str "sinf"
|
#define flt_func_str "sinf"
|
||||||
|
#endif
|
||||||
|
|
||||||
//#define fix_func fix16_sqrt
|
#ifdef SQRT
|
||||||
//#define fix_func_str "fix16_sqrt"
|
#define fix_func fix16_sqrt
|
||||||
//#define flt_func sqrtf
|
#define fix_func_str "fix16_sqrt"
|
||||||
//#define flt_func_str "sqrtf"
|
#define flt_func sqrtf
|
||||||
|
#define flt_func_str "sqrtf"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
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 args = (1 << 8);
|
||||||
uintptr_t iter = (1 << 8);
|
uintptr_t iter = (1 << 8);
|
||||||
uintptr_t pass = (1 << 8);
|
uintptr_t pass = (1 << 8);
|
||||||
|
|
||||||
uintptr_t i;
|
uintptr_t i;
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
hiclock_t fix_duration = 0;
|
hiclock_t fix_duration = 0;
|
||||||
hiclock_t flt_duration = 0;
|
hiclock_t flt_duration = 0;
|
||||||
fix16_t fix_error = 0;
|
fix16_t fix_error = 0;
|
||||||
|
|
||||||
uintptr_t k;
|
uintptr_t k;
|
||||||
for(k = 0; k < pass; k++) {
|
for (k = 0; k < pass; k++)
|
||||||
fix16_t fix_args[args];
|
{
|
||||||
for(i = 0; i < args; i++)
|
fix16_t fix_args[args];
|
||||||
fix_args[i] = (rand() ^ (rand() << 16));
|
for (i = 0; i < args; i++) fix_args[i] = (rand() ^ (rand() << 16));
|
||||||
fix16_t fix_result[args];
|
fix16_t fix_result[args];
|
||||||
hiclock_t fix_start = hiclock();
|
hiclock_t fix_start = hiclock();
|
||||||
for(i = 0; i < iter; i++) {
|
for (i = 0; i < iter; i++)
|
||||||
uintptr_t j;
|
{
|
||||||
for(j = 0; j < args; j++)
|
uintptr_t j;
|
||||||
fix_result[j] = fix_func(fix_args[j]);
|
for (j = 0; j < args; j++) fix_result[j] = fix_func(fix_args[j]);
|
||||||
}
|
}
|
||||||
hiclock_t fix_end = hiclock();
|
hiclock_t fix_end = hiclock();
|
||||||
|
|
||||||
float flt_args[args];
|
float flt_args[args];
|
||||||
for(i = 0; i < args; i++)
|
for (i = 0; i < args; i++) flt_args[i] = fix16_to_float(fix_args[i]);
|
||||||
flt_args[i] = fix16_to_float(fix_args[i]);
|
float flt_result[args];
|
||||||
float flt_result[args];
|
hiclock_t flt_start = hiclock();
|
||||||
hiclock_t flt_start = hiclock();
|
for (i = 0; i < iter; i++)
|
||||||
for(i = 0; i < iter; i++) {
|
{
|
||||||
uintptr_t j;
|
uintptr_t j;
|
||||||
for(j = 0; j < args; j++)
|
for (j = 0; j < args; j++) flt_result[j] = flt_func(flt_args[j]);
|
||||||
flt_result[j] = flt_func(flt_args[j]);
|
}
|
||||||
}
|
hiclock_t flt_end = hiclock();
|
||||||
hiclock_t flt_end = hiclock();
|
|
||||||
|
|
||||||
for(i = 0; i < args; i++)
|
for (i = 0; i < args; i++)
|
||||||
fix_error += abs(fix16_from_float(flt_result[i]) - fix_result[i]);
|
fix_error += abs(fix16_from_float(flt_result[i]) - fix_result[i]);
|
||||||
flt_duration += (flt_end - flt_start);
|
flt_duration += (flt_end - flt_start);
|
||||||
fix_duration += (fix_end - fix_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", flt_func_str,
|
||||||
printf("%16s: %08"PRIuHICLOCK" @ %"PRIu32"Hz\n", fix_func_str, fix_duration, HICLOCKS_PER_SEC);
|
flt_duration, HICLOCKS_PER_SEC);
|
||||||
printf(" Difference: %08"PRIiHICLOCK" (% 3.2f%%)\n", (flt_duration - fix_duration), ((fix_duration * 100.0) / flt_duration));
|
printf("%16s: %08" PRIuHICLOCK " @ %" PRIu32 "Hz\n", fix_func_str,
|
||||||
printf(" Error: %f%%\n", ((fix16_to_dbl(fix_error) * 100.0) / (args * pass)));
|
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;
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue