diff --git a/.gitignore b/.gitignore index b03f2fd0..b05be2da 100644 --- a/.gitignore +++ b/.gitignore @@ -53,8 +53,8 @@ win32/*.suo deushax/deushax deushax/editor monsterz/monsterz -test/lol-test -test/lol-bench +test/testsuite +test/benchsuite test/quad test/sandbox tools/make-font diff --git a/test/Makefile.am b/test/Makefile.am index f95a942a..81401890 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,30 +1,34 @@ AM_CPPFLAGS = -I$(top_srcdir)/src -bench: lol-bench$(EXEEXT) - ./lol-bench$(EXEEXT) +bench: benchsuite$(EXEEXT) + ./benchsuite$(EXEEXT) -all-local: quad$(EXEEXT) lol-bench$(EXEEXT) +all-local: quad$(EXEEXT) benchsuite$(EXEEXT) test x$(MAKE_FSELF) = xno || make_fself quad$(EXEEXT) quad.self test x$(MAKE_FSELF) = xno || make_fself sandbox$(EXEEXT) sandbox.self - test x$(MAKE_FSELF) = xno || make_fself lol-bench$(EXEEXT) lol-bench.self - test x$(MAKE_FSELF) = xno || make_fself lol-test$(EXEEXT) lol-test.self + test x$(MAKE_FSELF) = xno || make_fself benchsuite$(EXEEXT) benchsuite.self + test x$(MAKE_FSELF) = xno || make_fself testsuite$(EXEEXT) testsuite.self -CLEANFILES = quad.self sandbox lol-bench.self lol-test.self +CLEANFILES = $(noinst_PROGRAMS:%=%.self) $(noinst_PROGRAMS:%=%.exe) +#quad.self sandbox.self benchsuite.self testsuite.self \ +# quad.exe sandbox.exe benchsuite.exe testsuite.exe -noinst_PROGRAMS = quad sandbox lol-bench lol-test +noinst_PROGRAMS = quad sandbox benchsuite testsuite -TESTS = lol-test +TESTS = testsuite -lol_test_SOURCES = lol-test.cpp matrix.cpp half.cpp trig.cpp build.cpp -lol_test_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ -lol_test_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ -lol_test_DEPENDENCIES = $(top_builddir)/src/liblol.a +testsuite_SOURCES = testsuite.cpp \ + unit/matrix.cpp unit/half.cpp unit/trig.cpp unit/build.cpp +testsuite_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ +testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ +testsuite_DEPENDENCIES = $(top_builddir)/src/liblol.a -lol_bench_SOURCES = lol-bench.cpp -lol_bench_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ -lol_bench_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ -lol_bench_DEPENDENCIES = $(top_builddir)/src/liblol.a +benchsuite_SOURCES = benchsuite.cpp \ + benchmark/matrix.cpp benchmark/half.cpp benchmark/trig.cpp +benchsuite_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ +benchsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ +benchsuite_DEPENDENCIES = $(top_builddir)/src/liblol.a quad_SOURCES = debug/quad.cpp quad_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ diff --git a/test/benchmark/half.cpp b/test/benchmark/half.cpp new file mode 100644 index 00000000..ef01bd72 --- /dev/null +++ b/test/benchmark/half.cpp @@ -0,0 +1,125 @@ +// +// Lol Engine - Benchmark program +// +// Copyright: (c) 2005-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "core.h" + +using namespace std; +using namespace lol; + +static size_t const HALF_TABLE_SIZE = 1024 * 1024; +static size_t const HALF_RUNS = 50; + +void bench_half(int mode) +{ + float result[10] = { 0.0f }; + Timer timer; + + /* Set up tables */ + float *pf = new float[HALF_TABLE_SIZE + 1]; + half *ph = new half[HALF_TABLE_SIZE + 1]; + + for (size_t run = 0; run < HALF_RUNS; run++) + { + switch (mode) + { + case 1: + for (size_t i = 0; i < HALF_TABLE_SIZE + 1; i++) + ph[i] = half::makebits(rand()); + break; + case 2: + for (size_t i = 0; i < HALF_TABLE_SIZE + 1; i++) + ph[i] = RandF(-2.0f, 2.0f); + break; + } + + /* Copy float */ + timer.GetMs(); + for (size_t i = 0; i < HALF_TABLE_SIZE; i++) + pf[i] = pf[i + 1]; + result[0] += timer.GetMs(); + + /* Convert half to float (array) */ + timer.GetMs(); + half::convert(pf, ph, HALF_TABLE_SIZE); + result[1] += timer.GetMs(); + + /* Convert half to float (fast) */ + timer.GetMs(); + for (size_t i = 0; i < HALF_TABLE_SIZE; i++) + pf[i] = (float)ph[i]; + result[2] += timer.GetMs(); + + /* Add a half to every float */ + timer.GetMs(); + for (size_t i = 0; i < HALF_TABLE_SIZE; i++) + pf[i] += ph[i]; + result[3] += timer.GetMs(); + + /* Copy half */ + timer.GetMs(); + for (size_t i = 0; i < HALF_TABLE_SIZE; i++) + ph[i] = ph[i + 1]; + result[4] += timer.GetMs(); + + /* Change sign of every half */ + timer.GetMs(); + for (size_t i = 0; i < HALF_TABLE_SIZE; i++) + ph[i] = -ph[i]; + result[5] += timer.GetMs(); + + /* Convert float to half (array) */ + timer.GetMs(); + half::convert(ph, pf, HALF_TABLE_SIZE); + result[6] += timer.GetMs(); + + /* Convert float to half (fast) */ + timer.GetMs(); + for (size_t i = 0; i < HALF_TABLE_SIZE; i++) + ph[i] = (half)pf[i]; + result[7] += timer.GetMs(); + + /* Convert float to half (accurate) */ + timer.GetMs(); + for (size_t i = 0; i < HALF_TABLE_SIZE; i++) + ph[i] = half::makeaccurate(pf[i]); + result[8] += timer.GetMs(); + + /* Add a float to every half */ + timer.GetMs(); + for (size_t i = 0; i < HALF_TABLE_SIZE; i++) + ph[i] += pf[i]; + result[9] += timer.GetMs(); + } + + delete[] pf; + delete[] ph; + + for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) + result[i] *= 1000000.0f / (HALF_TABLE_SIZE * HALF_RUNS); + + Log::Info(" ns/elem\n"); + Log::Info("float = float %7.3f\n", result[0]); + Log::Info("float = half (array) %7.3f\n", result[1]); + Log::Info("float = half (fast) %7.3f\n", result[2]); + Log::Info("float += half %7.3f\n", result[3]); + Log::Info("half = half %7.3f\n", result[4]); + Log::Info("half = -half %7.3f\n", result[5]); + Log::Info("half = float (array) %7.3f\n", result[6]); + Log::Info("half = float (fast) %7.3f\n", result[7]); + Log::Info("half = float (accurate) %7.3f\n", result[8]); + Log::Info("half += float %7.3f\n", result[9]); +} + diff --git a/test/benchmark/matrix.cpp b/test/benchmark/matrix.cpp new file mode 100644 index 00000000..21a03045 --- /dev/null +++ b/test/benchmark/matrix.cpp @@ -0,0 +1,90 @@ +// +// Lol Engine - Benchmark program +// +// Copyright: (c) 2005-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "core.h" + +using namespace std; +using namespace lol; + +static size_t const MATRIX_TABLE_SIZE = 64 * 1024; +static size_t const MATRIX_RUNS = 100; + +void bench_matrix(int mode) +{ + float result[5] = { 0.0f }; + Timer timer; + + /* Set up tables */ + mat4 *pm = new mat4[MATRIX_TABLE_SIZE + 1]; + float *pf = new float[MATRIX_TABLE_SIZE]; + + for (size_t run = 0; run < MATRIX_RUNS; run++) + { + switch (mode) + { + case 1: + for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) + for (int j = 0; j < 4; j++) + for (int k = 0; k < 4; k++) + pm[i][j][k] = RandF(-2.0f, 2.0f); + break; + } + + /* Copy matrices */ + timer.GetMs(); + for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) + pm[i] = pm[i + 1]; + result[0] += timer.GetMs(); + + /* Determinant */ + timer.GetMs(); + for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) + pf[i] = pm[i].det(); + result[1] += timer.GetMs(); + + /* Multiply matrices */ + timer.GetMs(); + for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) + pm[i] *= pm[i + 1]; + result[2] += timer.GetMs(); + + /* Add matrices */ + timer.GetMs(); + for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) + pm[i] += pm[i + 1]; + result[3] += timer.GetMs(); + + /* Invert matrix */ + timer.GetMs(); + for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) + pm[i] = pm[i].invert(); + result[4] += timer.GetMs(); + } + + delete[] pm; + delete[] pf; + + for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) + result[i] *= 1000000.0f / (MATRIX_TABLE_SIZE * MATRIX_RUNS); + + Log::Info(" ns/elem\n"); + Log::Info("mat4 = mat4 %7.3f\n", result[0]); + Log::Info("float = mat4.det() %7.3f\n", result[1]); + Log::Info("mat4 *= mat4 %7.3f\n", result[2]); + Log::Info("mat4 += mat4 %7.3f\n", result[3]); + Log::Info("mat4 = mat4.invert() %7.3f\n", result[4]); +} + diff --git a/test/benchmark/trig.cpp b/test/benchmark/trig.cpp new file mode 100644 index 00000000..90b7b5e5 --- /dev/null +++ b/test/benchmark/trig.cpp @@ -0,0 +1,197 @@ +// +// Lol Engine - Benchmark program +// +// Copyright: (c) 2005-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef WIN32 +# define _USE_MATH_DEFINES /* for M_PI */ +# define WIN32_LEAN_AND_MEAN +# include +#endif + +#include + +#if defined HAVE_FASTMATH_H +# include +#endif + +#include "core.h" + +using namespace std; +using namespace lol; + +static size_t const TRIG_TABLE_SIZE = 128 * 1024; +static size_t const TRIG_RUNS = 50; + +void bench_trig(int mode) +{ + float result[12] = { 0.0f }; + Timer timer; + + /* Set up tables */ + float *pf = new float[TRIG_TABLE_SIZE]; + float *pf2 = new float[TRIG_TABLE_SIZE]; + float *pf3 = new float[TRIG_TABLE_SIZE]; + + for (size_t run = 0; run < TRIG_RUNS; run++) + { + switch (mode) + { + case 1: + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) + pf[i] = RandF(-1e5f, 1e5f); + break; + case 2: + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) + pf[i] = RandF(-M_PI, M_PI); + break; + case 3: + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) + pf[i] = RandF(-1e-2f, 1e-2f); + break; + } + + /* Sin */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) +#if defined __GNUC__ + pf2[i] = __builtin_sinf(pf[i]); +#else + pf2[i] = sinf(pf[i]); +#endif + result[0] += timer.GetMs(); + + /* Fast sin */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) +#if defined HAVE_FASTMATH_H + pf2[i] = f_sinf(pf[i]); +#else + pf2[i] = sinf(pf[i]); +#endif + result[1] += timer.GetMs(); + + /* Lol sin */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) + pf2[i] = lol_sin(pf[i]); + result[2] += timer.GetMs(); + + /* Cos */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) +#if defined __GNUC__ + pf2[i] = __builtin_cosf(pf[i]); +#else + pf2[i] = cosf(pf[i]); +#endif + result[3] += timer.GetMs(); + + /* Fast cos */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) +#if defined HAVE_FASTMATH_H + pf2[i] = f_cosf(pf[i]); +#else + pf2[i] = cosf(pf[i]); +#endif + result[4] += timer.GetMs(); + + /* Lol cos */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) + pf2[i] = lol_cos(pf[i]); + result[5] += timer.GetMs(); + + /* Sin & cos */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) + { +#if defined __GNUC__ + pf2[i] = __builtin_sinf(pf[i]); + pf3[i] = __builtin_cosf(pf[i]); +#else + pf2[i] = sinf(pf[i]); + pf3[i] = cosf(pf[i]); +#endif + } + result[6] += timer.GetMs(); + + /* Fast sin & cos */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) + { +#if defined HAVE_FASTMATH_H + pf2[i] = f_sinf(pf[i]); + pf3[i] = f_cosf(pf[i]); +#else + pf2[i] = sinf(pf[i]); + pf3[i] = cosf(pf[i]); +#endif + } + result[7] += timer.GetMs(); + + /* Lol sincos */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) + lol_sincos(pf[i], &pf2[i], &pf3[i]); + result[8] += timer.GetMs(); + + /* Tan */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) +#if defined __GNUC__ + pf2[i] = __builtin_tanf(pf[i]); +#else + pf2[i] = tanf(pf[i]); +#endif + result[9] += timer.GetMs(); + + /* Fast tan */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) +#if defined HAVE_FASTMATH_H + pf2[i] = f_tanf(pf[i]); +#else + pf2[i] = tanf(pf[i]); +#endif + result[10] += timer.GetMs(); + + /* Lol tan */ + timer.GetMs(); + for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) + pf2[i] = lol_tan(pf[i]); + result[11] += timer.GetMs(); + } + + delete[] pf; + delete[] pf2; + delete[] pf3; + + for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) + result[i] *= 1000000.0f / (TRIG_TABLE_SIZE * TRIG_RUNS); + + Log::Info(" ns/elem\n"); + Log::Info("float = sinf(float) %7.3f\n", result[0]); + Log::Info("float = f_sinf(float) %7.3f\n", result[1]); + Log::Info("float = lol_sin(float) %7.3f\n", result[2]); + Log::Info("float = cosf(float) %7.3f\n", result[3]); + Log::Info("float = f_cosf(float) %7.3f\n", result[4]); + Log::Info("float = lol_cos(float) %7.3f\n", result[5]); + Log::Info("float = sinf,cosf(float) %7.3f\n", result[6]); + Log::Info("float = f_sinf,f_cosf(float) %7.3f\n", result[7]); + Log::Info("float = lol_sincos(float) %7.3f\n", result[8]); + Log::Info("float = tanf(float) %7.3f\n", result[9]); + Log::Info("float = f_tanf(float) %7.3f\n", result[10]); + Log::Info("float = lol_tanf(float) %7.3f\n", result[11]); +} + diff --git a/test/benchsuite.cpp b/test/benchsuite.cpp new file mode 100644 index 00000000..6d01fb03 --- /dev/null +++ b/test/benchsuite.cpp @@ -0,0 +1,64 @@ +// +// Lol Engine - Benchmark program +// +// Copyright: (c) 2005-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "core.h" + +using namespace std; +using namespace lol; + +void bench_trig(int mode); +void bench_matrix(int mode); +void bench_half(int mode); + +int main(int argc, char **argv) +{ + Log::Info("--------------------------\n"); + Log::Info(" Trigonometry [-1e5, 1e5]\n"); + Log::Info("--------------------------\n"); + bench_trig(1); + + Log::Info("------------------------\n"); + Log::Info(" Trigonometry [-pi, pi]\n"); + Log::Info("------------------------\n"); + bench_trig(2); + + Log::Info("----------------------------\n"); + Log::Info(" Trigonometry [-1e-2, 1e-2]\n"); + Log::Info("----------------------------\n"); + bench_trig(3); + + Log::Info("----------------------------\n"); + Log::Info(" Float matrices [-2.0, 2.0]\n"); + Log::Info("----------------------------\n"); + bench_matrix(1); + + Log::Info("-------------------------------------\n"); + Log::Info(" Half precision floats (random bits)\n"); + Log::Info("-------------------------------------\n"); + bench_half(1); + + Log::Info("-----------------------------------\n"); + Log::Info(" Half precision floats [-2.0, 2.0]\n"); + Log::Info("-----------------------------------\n"); + bench_half(2); + +#if defined _WIN32 + getchar(); +#endif + + return EXIT_SUCCESS; +} + diff --git a/test/lol-bench.cpp b/test/lol-bench.cpp deleted file mode 100644 index 88fbfb1f..00000000 --- a/test/lol-bench.cpp +++ /dev/null @@ -1,414 +0,0 @@ -// -// Lol Engine - Benchmark program -// -// Copyright: (c) 2005-2011 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://sam.zoy.org/projects/COPYING.WTFPL for more details. -// - -#if defined HAVE_CONFIG_H -# include "config.h" -#endif - -#ifdef WIN32 -# define _USE_MATH_DEFINES /* for M_PI */ -# define WIN32_LEAN_AND_MEAN -# include -#endif - -#include - -#if defined HAVE_FASTMATH_H -# include -#endif - -#include "core.h" -#include "loldebug.h" - -using namespace std; -using namespace lol; - -static size_t const TRIG_TABLE_SIZE = 128 * 1024; -static size_t const TRIG_RUNS = 50; - -static size_t const MATRIX_TABLE_SIZE = 64 * 1024; -static size_t const MATRIX_RUNS = 100; - -static size_t const HALF_TABLE_SIZE = 1024 * 1024; -static size_t const HALF_RUNS = 50; - -static void bench_trig(int mode); -static void bench_matrix(int mode); -static void bench_half(int mode); - -int main(int argc, char **argv) -{ - Log::Info("--------------------------\n"); - Log::Info(" Trigonometry [-1e5, 1e5]\n"); - Log::Info("--------------------------\n"); - bench_trig(1); - - Log::Info("------------------------\n"); - Log::Info(" Trigonometry [-pi, pi]\n"); - Log::Info("------------------------\n"); - bench_trig(2); - - Log::Info("----------------------------\n"); - Log::Info(" Trigonometry [-1e-2, 1e-2]\n"); - Log::Info("----------------------------\n"); - bench_trig(3); - - Log::Info("----------------------------\n"); - Log::Info(" Float matrices [-2.0, 2.0]\n"); - Log::Info("----------------------------\n"); - bench_matrix(1); - - Log::Info("-------------------------------------\n"); - Log::Info(" Half precision floats (random bits)\n"); - Log::Info("-------------------------------------\n"); - bench_half(1); - - Log::Info("-----------------------------------\n"); - Log::Info(" Half precision floats [-2.0, 2.0]\n"); - Log::Info("-----------------------------------\n"); - bench_half(2); - -#if defined _WIN32 - getchar(); -#endif - - return EXIT_SUCCESS; -} - -static void bench_trig(int mode) -{ - float result[12] = { 0.0f }; - Timer timer; - - /* Set up tables */ - float *pf = new float[TRIG_TABLE_SIZE]; - float *pf2 = new float[TRIG_TABLE_SIZE]; - float *pf3 = new float[TRIG_TABLE_SIZE]; - - for (size_t run = 0; run < TRIG_RUNS; run++) - { - switch (mode) - { - case 1: - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) - pf[i] = RandF(-1e5f, 1e5f); - break; - case 2: - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) - pf[i] = RandF(-M_PI, M_PI); - break; - case 3: - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) - pf[i] = RandF(-1e-2f, 1e-2f); - break; - } - - /* Sin */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) -#if defined __GNUC__ - pf2[i] = __builtin_sinf(pf[i]); -#else - pf2[i] = sinf(pf[i]); -#endif - result[0] += timer.GetMs(); - - /* Fast sin */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) -#if defined HAVE_FASTMATH_H - pf2[i] = f_sinf(pf[i]); -#else - pf2[i] = sinf(pf[i]); -#endif - result[1] += timer.GetMs(); - - /* Lol sin */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) - pf2[i] = lol_sin(pf[i]); - result[2] += timer.GetMs(); - - /* Cos */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) -#if defined __GNUC__ - pf2[i] = __builtin_cosf(pf[i]); -#else - pf2[i] = cosf(pf[i]); -#endif - result[3] += timer.GetMs(); - - /* Fast cos */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) -#if defined HAVE_FASTMATH_H - pf2[i] = f_cosf(pf[i]); -#else - pf2[i] = cosf(pf[i]); -#endif - result[4] += timer.GetMs(); - - /* Lol cos */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) - pf2[i] = lol_cos(pf[i]); - result[5] += timer.GetMs(); - - /* Sin & cos */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) - { -#if defined __GNUC__ - pf2[i] = __builtin_sinf(pf[i]); - pf3[i] = __builtin_cosf(pf[i]); -#else - pf2[i] = sinf(pf[i]); - pf3[i] = cosf(pf[i]); -#endif - } - result[6] += timer.GetMs(); - - /* Fast sin & cos */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) - { -#if defined HAVE_FASTMATH_H - pf2[i] = f_sinf(pf[i]); - pf3[i] = f_cosf(pf[i]); -#else - pf2[i] = sinf(pf[i]); - pf3[i] = cosf(pf[i]); -#endif - } - result[7] += timer.GetMs(); - - /* Lol sincos */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) - lol_sincos(pf[i], &pf2[i], &pf3[i]); - result[8] += timer.GetMs(); - - /* Tan */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) -#if defined __GNUC__ - pf2[i] = __builtin_tanf(pf[i]); -#else - pf2[i] = tanf(pf[i]); -#endif - result[9] += timer.GetMs(); - - /* Fast tan */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) -#if defined HAVE_FASTMATH_H - pf2[i] = f_tanf(pf[i]); -#else - pf2[i] = tanf(pf[i]); -#endif - result[10] += timer.GetMs(); - - /* Lol tan */ - timer.GetMs(); - for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) - pf2[i] = lol_tan(pf[i]); - result[11] += timer.GetMs(); - } - - delete[] pf; - delete[] pf2; - delete[] pf3; - - for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) - result[i] *= 1000000.0f / (TRIG_TABLE_SIZE * TRIG_RUNS); - - Log::Info(" ns/elem\n"); - Log::Info("float = sinf(float) %7.3f\n", result[0]); - Log::Info("float = f_sinf(float) %7.3f\n", result[1]); - Log::Info("float = lol_sin(float) %7.3f\n", result[2]); - Log::Info("float = cosf(float) %7.3f\n", result[3]); - Log::Info("float = f_cosf(float) %7.3f\n", result[4]); - Log::Info("float = lol_cos(float) %7.3f\n", result[5]); - Log::Info("float = sinf,cosf(float) %7.3f\n", result[6]); - Log::Info("float = f_sinf,f_cosf(float) %7.3f\n", result[7]); - Log::Info("float = lol_sincos(float) %7.3f\n", result[8]); - Log::Info("float = tanf(float) %7.3f\n", result[9]); - Log::Info("float = f_tanf(float) %7.3f\n", result[10]); - Log::Info("float = lol_tanf(float) %7.3f\n", result[11]); -} - -static void bench_matrix(int mode) -{ - float result[5] = { 0.0f }; - Timer timer; - - /* Set up tables */ - mat4 *pm = new mat4[MATRIX_TABLE_SIZE + 1]; - float *pf = new float[MATRIX_TABLE_SIZE]; - - for (size_t run = 0; run < MATRIX_RUNS; run++) - { - switch (mode) - { - case 1: - for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) - for (int j = 0; j < 4; j++) - for (int k = 0; k < 4; k++) - pm[i][j][k] = RandF(-2.0f, 2.0f); - break; - } - - /* Copy matrices */ - timer.GetMs(); - for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) - pm[i] = pm[i + 1]; - result[0] += timer.GetMs(); - - /* Determinant */ - timer.GetMs(); - for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) - pf[i] = pm[i].det(); - result[1] += timer.GetMs(); - - /* Multiply matrices */ - timer.GetMs(); - for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) - pm[i] *= pm[i + 1]; - result[2] += timer.GetMs(); - - /* Add matrices */ - timer.GetMs(); - for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) - pm[i] += pm[i + 1]; - result[3] += timer.GetMs(); - - /* Invert matrix */ - timer.GetMs(); - for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) - pm[i] = pm[i].invert(); - result[4] += timer.GetMs(); - } - - delete[] pm; - delete[] pf; - - for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) - result[i] *= 1000000.0f / (MATRIX_TABLE_SIZE * MATRIX_RUNS); - - Log::Info(" ns/elem\n"); - Log::Info("mat4 = mat4 %7.3f\n", result[0]); - Log::Info("float = mat4.det() %7.3f\n", result[1]); - Log::Info("mat4 *= mat4 %7.3f\n", result[2]); - Log::Info("mat4 += mat4 %7.3f\n", result[3]); - Log::Info("mat4 = mat4.invert() %7.3f\n", result[4]); -} - -static void bench_half(int mode) -{ - float result[10] = { 0.0f }; - Timer timer; - - /* Set up tables */ - float *pf = new float[HALF_TABLE_SIZE + 1]; - half *ph = new half[HALF_TABLE_SIZE + 1]; - - for (size_t run = 0; run < HALF_RUNS; run++) - { - switch (mode) - { - case 1: - for (size_t i = 0; i < HALF_TABLE_SIZE + 1; i++) - ph[i] = half::makebits(rand()); - break; - case 2: - for (size_t i = 0; i < HALF_TABLE_SIZE + 1; i++) - ph[i] = RandF(-2.0f, 2.0f); - break; - } - - /* Copy float */ - timer.GetMs(); - for (size_t i = 0; i < HALF_TABLE_SIZE; i++) - pf[i] = pf[i + 1]; - result[0] += timer.GetMs(); - - /* Convert half to float (array) */ - timer.GetMs(); - half::convert(pf, ph, HALF_TABLE_SIZE); - result[1] += timer.GetMs(); - - /* Convert half to float (fast) */ - timer.GetMs(); - for (size_t i = 0; i < HALF_TABLE_SIZE; i++) - pf[i] = (float)ph[i]; - result[2] += timer.GetMs(); - - /* Add a half to every float */ - timer.GetMs(); - for (size_t i = 0; i < HALF_TABLE_SIZE; i++) - pf[i] += ph[i]; - result[3] += timer.GetMs(); - - /* Copy half */ - timer.GetMs(); - for (size_t i = 0; i < HALF_TABLE_SIZE; i++) - ph[i] = ph[i + 1]; - result[4] += timer.GetMs(); - - /* Change sign of every half */ - timer.GetMs(); - for (size_t i = 0; i < HALF_TABLE_SIZE; i++) - ph[i] = -ph[i]; - result[5] += timer.GetMs(); - - /* Convert float to half (array) */ - timer.GetMs(); - half::convert(ph, pf, HALF_TABLE_SIZE); - result[6] += timer.GetMs(); - - /* Convert float to half (fast) */ - timer.GetMs(); - for (size_t i = 0; i < HALF_TABLE_SIZE; i++) - ph[i] = (half)pf[i]; - result[7] += timer.GetMs(); - - /* Convert float to half (accurate) */ - timer.GetMs(); - for (size_t i = 0; i < HALF_TABLE_SIZE; i++) - ph[i] = half::makeaccurate(pf[i]); - result[8] += timer.GetMs(); - - /* Add a float to every half */ - timer.GetMs(); - for (size_t i = 0; i < HALF_TABLE_SIZE; i++) - ph[i] += pf[i]; - result[9] += timer.GetMs(); - } - - delete[] pf; - delete[] ph; - - for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) - result[i] *= 1000000.0f / (HALF_TABLE_SIZE * HALF_RUNS); - - Log::Info(" ns/elem\n"); - Log::Info("float = float %7.3f\n", result[0]); - Log::Info("float = half (array) %7.3f\n", result[1]); - Log::Info("float = half (fast) %7.3f\n", result[2]); - Log::Info("float += half %7.3f\n", result[3]); - Log::Info("half = half %7.3f\n", result[4]); - Log::Info("half = -half %7.3f\n", result[5]); - Log::Info("half = float (array) %7.3f\n", result[6]); - Log::Info("half = float (fast) %7.3f\n", result[7]); - Log::Info("half = float (accurate) %7.3f\n", result[8]); - Log::Info("half += float %7.3f\n", result[9]); -} - diff --git a/test/lol-test.cpp b/test/testsuite.cpp similarity index 100% rename from test/lol-test.cpp rename to test/testsuite.cpp diff --git a/test/build.cpp b/test/unit/build.cpp similarity index 100% rename from test/build.cpp rename to test/unit/build.cpp diff --git a/test/half.cpp b/test/unit/half.cpp similarity index 100% rename from test/half.cpp rename to test/unit/half.cpp diff --git a/test/matrix.cpp b/test/unit/matrix.cpp similarity index 100% rename from test/matrix.cpp rename to test/unit/matrix.cpp diff --git a/test/trig.cpp b/test/unit/trig.cpp similarity index 100% rename from test/trig.cpp rename to test/unit/trig.cpp