From 9d74fcc181320ef98dc3e218fbd7da4c6ed04d0d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 4 Jan 2022 17:50:49 +0900 Subject: [PATCH] [gamecode] Add tests for the basic math ops * / % %% + - As a bonus, includes partial tests for a few extra operators. Several things are broken at this stage, but uncommitted code is already working. --- libs/gamecode/test/Makemodule.am | 24 ++++ libs/gamecode/test/main.c | 9 +- libs/gamecode/test/test-double.c | 192 +++++++++++++++++++++++++++++++ libs/gamecode/test/test-float.c | 192 +++++++++++++++++++++++++++++++ libs/gamecode/test/test-int.c | 146 +++++++++++++++++++++++ libs/gamecode/test/test-long.c | 148 ++++++++++++++++++++++++ 6 files changed, 709 insertions(+), 2 deletions(-) create mode 100644 libs/gamecode/test/test-double.c create mode 100644 libs/gamecode/test/test-float.c create mode 100644 libs/gamecode/test/test-int.c create mode 100644 libs/gamecode/test/test-long.c diff --git a/libs/gamecode/test/Makemodule.am b/libs/gamecode/test/Makemodule.am index 191470c74..2df9ef114 100644 --- a/libs/gamecode/test/Makemodule.am +++ b/libs/gamecode/test/Makemodule.am @@ -1,5 +1,9 @@ libs_gamecode_tests = \ + libs/gamecode/test/test-double \ + libs/gamecode/test/test-float \ + libs/gamecode/test/test-int \ libs/gamecode/test/test-load \ + libs/gamecode/test/test-long \ libs/gamecode/test/test-vector \ libs/gamecode/test/test-stack \ libs/gamecode/test/test-store @@ -14,11 +18,31 @@ test_gamecode_libs= \ libs/gamecode/libQFgamecode.la \ libs/util/libQFutil.la +libs_gamecode_test_test_double_SOURCES= \ + libs/gamecode/test/test-double.c +libs_gamecode_test_test_double_LDADD= $(test_gamecode_libs) +libs_gamecode_test_test_double_DEPENDENCIES= $(test_gamecode_libs) + +libs_gamecode_test_test_float_SOURCES= \ + libs/gamecode/test/test-float.c +libs_gamecode_test_test_float_LDADD= $(test_gamecode_libs) +libs_gamecode_test_test_float_DEPENDENCIES= $(test_gamecode_libs) + +libs_gamecode_test_test_int_SOURCES= \ + libs/gamecode/test/test-int.c +libs_gamecode_test_test_int_LDADD= $(test_gamecode_libs) +libs_gamecode_test_test_int_DEPENDENCIES= $(test_gamecode_libs) + libs_gamecode_test_test_load_SOURCES= \ libs/gamecode/test/test-load.c libs_gamecode_test_test_load_LDADD= $(test_gamecode_libs) libs_gamecode_test_test_load_DEPENDENCIES= $(test_gamecode_libs) +libs_gamecode_test_test_long_SOURCES= \ + libs/gamecode/test/test-long.c +libs_gamecode_test_test_long_LDADD= $(test_gamecode_libs) +libs_gamecode_test_test_long_DEPENDENCIES= $(test_gamecode_libs) + libs_gamecode_test_test_stack_SOURCES= \ libs/gamecode/test/test-stack.c libs_gamecode_test_test_stack_LDADD= $(test_gamecode_libs) diff --git a/libs/gamecode/test/main.c b/libs/gamecode/test/main.c index e9256dcec..44e91167e 100644 --- a/libs/gamecode/test/main.c +++ b/libs/gamecode/test/main.c @@ -84,7 +84,7 @@ setup_test (test_t *test) num_globals += test->extra_globals + test->stack_size; test_pr.globals_size = num_globals; - test_pr.pr_globals = malloc (num_globals * sizeof (pr_type_t)); + test_pr.pr_globals = Sys_Alloc (num_globals * sizeof (pr_type_t)); memcpy (test_pr.pr_globals, test->init_globals, test->num_globals * sizeof (pr_type_t)); memset (test_pr.pr_globals + test->num_globals, 0, @@ -99,6 +99,7 @@ setup_test (test_t *test) test_pr.pr_edict_area = test_pr.pr_globals + test->edict_area; } + test_progs.numstatements = test->num_statements + 1; test_pr.pr_statements = malloc ((test->num_statements + 1) * sizeof (dstatement_t)); memcpy (test_pr.pr_statements, test->statements, @@ -139,7 +140,11 @@ run_test (test_t *test) } else { printf ("test #%zd: %s: critical failure\n", test - tests, test->desc); } - free (test_pr.pr_globals); + + pr_uint_t num_globals = test->num_globals; + num_globals += test->extra_globals + test->stack_size; + Sys_Free (test_pr.pr_globals, num_globals * sizeof (pr_type_t)); + free (test_pr.pr_statements); return ret; } diff --git a/libs/gamecode/test/test-double.c b/libs/gamecode/test/test-double.c new file mode 100644 index 000000000..230ba69ee --- /dev/null +++ b/libs/gamecode/test/test-double.c @@ -0,0 +1,192 @@ +#include "head.c" + +#include "QF/mathlib.h" + +#define sq(x) ((x)*(x)) + +static pr_dvec4_t double_binop_init[] = { + { 5, -5, 5, -5}, + { 3, 3, -3, -3}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, +}; + +static pr_dvec4_t double_binop_expect[] = { + { 5, -5, 5, -5}, + { 3, 3, -3, -3}, + { 15, -15, -15, 15}, + { 5.0/3, -5.0/3, -5.0/3, 5.0/3}, + { 2, -2, 2, -2}, + { 2, 1, -1, -2}, + { 8, -2, 2, -8}, + { 2, -8, 8, -2}, +}; + +static dstatement_t double_binop_1_statements[] = { + { OP(0, 0, 0, OP_LEA_A), 8, 0, 64 }, // init index +//loop: + { OP(0, 0, 0, OP_LEA_C), 64, -2, 64 }, // dec index + { OP(0, 0, 0, OP_IFAE_A), 2, 0, 64 }, + { OP(0, 0, 0, OP_BREAK), 0, 0, 0 }, + { OP(0, 0, 0, OP_WITH), 4, 64, 1 }, + { OP(1, 1, 1, OP_MUL_D_1), 0, 8, 16 }, + { OP(1, 1, 1, OP_DIV_D_1), 0, 8, 24 }, + { OP(1, 1, 1, OP_REM_D_1), 0, 8, 32 }, + { OP(1, 1, 1, OP_MOD_D_1), 0, 8, 40 }, + { OP(1, 1, 1, OP_ADD_D_1), 0, 8, 48 }, + { OP(1, 1, 1, OP_SUB_D_1), 0, 8, 56 }, + { OP(1, 1, 1, OP_JUMP_A), -10, 0, 0 }, +}; + +static dstatement_t double_binop_2_statements[] = { + { OP(0, 0, 0, OP_LEA_A), 8, 0, 64 }, // init index +//loop: + { OP(0, 0, 0, OP_LEA_C), 64, -4, 64 }, // dec index + { OP(0, 0, 0, OP_IFAE_A), 2, 0, 64 }, + { OP(0, 0, 0, OP_BREAK), 0, 0, 0 }, + { OP(0, 0, 0, OP_WITH), 4, 64, 1 }, + { OP(1, 1, 1, OP_MUL_D_2), 0, 8, 16 }, + { OP(1, 1, 1, OP_DIV_D_2), 0, 8, 24 }, + { OP(1, 1, 1, OP_REM_D_2), 0, 8, 32 }, + { OP(1, 1, 1, OP_MOD_D_2), 0, 8, 40 }, + { OP(1, 1, 1, OP_ADD_D_2), 0, 8, 48 }, + { OP(1, 1, 1, OP_SUB_D_2), 0, 8, 56 }, + { OP(1, 1, 1, OP_JUMP_A), -10, 0, 0 }, +}; + +static dstatement_t double_binop_3a_statements[] = { + { OP(1, 1, 1, OP_MUL_D_3), 0, 8, 16 }, + { OP(1, 1, 1, OP_MUL_D_1), 6, 14, 22 }, + { OP(1, 1, 1, OP_DIV_D_3), 0, 8, 24 }, + { OP(1, 1, 1, OP_DIV_D_1), 6, 14, 30 }, + { OP(1, 1, 1, OP_REM_D_3), 0, 8, 32 }, + { OP(1, 1, 1, OP_REM_D_1), 6, 14, 38 }, + { OP(1, 1, 1, OP_MOD_D_3), 0, 8, 40 }, + { OP(1, 1, 1, OP_MOD_D_1), 6, 14, 46 }, + { OP(1, 1, 1, OP_ADD_D_3), 0, 8, 48 }, + { OP(1, 1, 1, OP_ADD_D_1), 6, 14, 54 }, + { OP(1, 1, 1, OP_SUB_D_3), 0, 8, 56 }, + { OP(1, 1, 1, OP_SUB_D_1), 6, 14, 62 }, +}; + +static dstatement_t double_binop_3b_statements[] = { + { OP(1, 1, 1, OP_MUL_D_1), 0, 8, 16 }, + { OP(1, 1, 1, OP_MUL_D_3), 2, 10, 18 }, + { OP(1, 1, 1, OP_DIV_D_1), 0, 8, 24 }, + { OP(1, 1, 1, OP_DIV_D_3), 2, 10, 26 }, + { OP(1, 1, 1, OP_REM_D_1), 0, 8, 32 }, + { OP(1, 1, 1, OP_REM_D_3), 2, 10, 34 }, + { OP(1, 1, 1, OP_MOD_D_1), 0, 8, 40 }, + { OP(1, 1, 1, OP_MOD_D_3), 2, 10, 42 }, + { OP(1, 1, 1, OP_ADD_D_1), 0, 8, 48 }, + { OP(1, 1, 1, OP_ADD_D_3), 2, 10, 50 }, + { OP(1, 1, 1, OP_SUB_D_1), 0, 8, 56 }, + { OP(1, 1, 1, OP_SUB_D_3), 2, 10, 58 }, +}; + +static dstatement_t double_binop_4_statements[] = { + { OP(1, 1, 1, OP_MUL_D_4), 0, 8, 16 }, + { OP(1, 1, 1, OP_DIV_D_4), 0, 8, 24 }, + { OP(1, 1, 1, OP_REM_D_4), 0, 8, 32 }, + { OP(1, 1, 1, OP_MOD_D_4), 0, 8, 40 }, + { OP(1, 1, 1, OP_ADD_D_4), 0, 8, 48 }, + { OP(1, 1, 1, OP_SUB_D_4), 0, 8, 56 }, +}; + +static pr_dvec4_t double_cossin_init[] = { + { 1, 2, 3, 4 }, // 0: output + { M_PI/6, 0, 0, 0 }, // 4: x + { 1, 2, 0, 0 }, // 8: f + { 1, 1, 0, 25 }, // 12: f inc and f0 max + { 0, 0, 0, 0 }, // 16: x2 -> [xx, xx] + // { } // 20: xn +}; + +static pr_dvec4_t double_cossin_expect[] = { + { 0.8660254037844386, 0.49999999999999994, 0, 0 }, // 0: output + { M_PI/6, 0, 0, 0 }, // 4: x + { 25, 26, 0, 0 }, // 8: f + { 1, 1, 0, 25 }, // 12: f inc and f0 max + { -sq(M_PI/6), -sq(M_PI/6), 0, 0 }, // 16: x2 -> [xx, xx] +}; + +static dstatement_t double_cossin_statements[] = { + { OP(0, 0, 0, OP_STORE_A_2), 42, 0, 8 }, // init xn -> [?, x] + { OP(0, 0, 0, OP_STORE_A_2), 40, 0, 16 }, // init xn -> [1, x] + { OP(0, 0, 0, OP_SWIZZLE_D), 8,0xc000, 32 }, // init x2 -> [x, x, 0, 0] + { OP(0, 0, 0, OP_MUL_D_2), 32, 32, 32 }, // x2 -> [x*x, x*x, 0, 0] + { OP(0, 0, 0, OP_SWIZZLE_D), 32,0xc3e4, 32 }, // init x2 -> -x2 + { OP(0, 0, 0, OP_SUB_D_4), 0, 0, 0 }, // init acc (output) to 0 +// loop: + { OP(0, 0, 0, OP_ADD_D_2), 0, 40, 0 }, // acc += xn + { OP(0, 0, 0, OP_MUL_D_2), 40, 32, 40 }, // xn *= x2 + { OP(0, 0, 0, OP_DIV_D_2), 40, 16, 40 }, // xn /= f + { OP(0, 0, 0, OP_ADD_D_2), 16, 24, 16 }, // f += inc + { OP(0, 0, 0, OP_DIV_D_2), 40, 16, 40 }, // xn /= f + { OP(0, 0, 0, OP_ADD_D_2), 16, 24, 16 }, // f += inc + { OP(0, 0, 0, OP_LT_D_1), 16, 30, 46 }, // f0 < fmax + { OP(0, 0, 0, OP_IF_A), -7, 0, 46 }, // f0 < fmax +}; + +test_t tests[] = { + { + .desc = "double binop 1", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(double_binop_init,double_binop_expect), + .num_statements = num_statements (double_binop_1_statements), + .statements = double_binop_1_statements, + .init_globals = (pr_int_t *) double_binop_init, + .expect_globals = (pr_int_t *) double_binop_expect, + }, + { + .desc = "double binop 2", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(double_binop_init,double_binop_expect), + .num_statements = num_statements (double_binop_2_statements), + .statements = double_binop_2_statements, + .init_globals = (pr_int_t *) double_binop_init, + .expect_globals = (pr_int_t *) double_binop_expect, + }, + { + .desc = "double binop 3a", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(double_binop_init,double_binop_expect), + .num_statements = num_statements (double_binop_3a_statements), + .statements = double_binop_3a_statements, + .init_globals = (pr_int_t *) double_binop_init, + .expect_globals = (pr_int_t *) double_binop_expect, + }, + { + .desc = "double binop 3b", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(double_binop_init,double_binop_expect), + .num_statements = num_statements (double_binop_3b_statements), + .statements = double_binop_3b_statements, + .init_globals = (pr_int_t *) double_binop_init, + .expect_globals = (pr_int_t *) double_binop_expect, + }, + { + .desc = "double binop 4", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(double_binop_init,double_binop_expect), + .num_statements = num_statements (double_binop_4_statements), + .statements = double_binop_4_statements, + .init_globals = (pr_int_t *) double_binop_init, + .expect_globals = (pr_int_t *) double_binop_expect, + }, + { + .desc = "double cos sin", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(double_cossin_init,double_cossin_expect), + .num_statements = num_statements (double_cossin_statements), + .statements = double_cossin_statements, + .init_globals = (pr_int_t *) double_cossin_init, + .expect_globals = (pr_int_t *) double_cossin_expect, + }, +}; + +#include "main.c" diff --git a/libs/gamecode/test/test-float.c b/libs/gamecode/test/test-float.c new file mode 100644 index 000000000..d974931bb --- /dev/null +++ b/libs/gamecode/test/test-float.c @@ -0,0 +1,192 @@ +#include "head.c" + +#include "QF/mathlib.h" + +#define sq(x) ((float)(x)*(float)(x)) + +static pr_vec4_t float_binop_init[] = { + { 5, -5, 5, -5}, + { 3, 3, -3, -3}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, +}; + +static pr_vec4_t float_binop_expect[] = { + { 5, -5, 5, -5}, + { 3, 3, -3, -3}, + { 15, -15, -15, 15}, + { 1.666666627, -1.666666627, -1.666666627, 1.666666627}, + { 2, -2, 2, -2}, + { 2, 1, -1, -2}, + { 8, -2, 2, -8}, + { 2, -8, 8, -2}, +}; + +static dstatement_t float_binop_1_statements[] = { + { OP(0, 0, 0, OP_LEA_A), 4, 0, 32 }, // init index +//loop: + { OP(0, 0, 0, OP_LEA_C), 32, -1, 32 }, // dec index + { OP(0, 0, 0, OP_IFAE_A), 2, 0, 32 }, + { OP(0, 0, 0, OP_BREAK), 0, 0, 0 }, + { OP(0, 0, 0, OP_WITH), 4, 32, 1 }, + { OP(1, 1, 1, OP_MUL_F_1), 0, 4, 8 }, + { OP(1, 1, 1, OP_DIV_F_1), 0, 4, 12 }, + { OP(1, 1, 1, OP_REM_F_1), 0, 4, 16 }, + { OP(1, 1, 1, OP_MOD_F_1), 0, 4, 20 }, + { OP(1, 1, 1, OP_ADD_F_1), 0, 4, 24 }, + { OP(1, 1, 1, OP_SUB_F_1), 0, 4, 28 }, + { OP(1, 1, 1, OP_JUMP_A), -10, 0, 0 }, +}; + +static dstatement_t float_binop_2_statements[] = { + { OP(0, 0, 0, OP_LEA_A), 4, 0, 32 }, // index +//loop: + { OP(0, 0, 0, OP_LEA_C), 32, -2, 32 }, // dec index + { OP(0, 0, 0, OP_IFAE_A), 2, 0, 32 }, + { OP(0, 0, 0, OP_BREAK), 0, 0, 0 }, + { OP(0, 0, 0, OP_WITH), 4, 32, 1 }, + { OP(1, 1, 1, OP_MUL_F_2), 0, 4, 8 }, + { OP(1, 1, 1, OP_DIV_F_2), 0, 4, 12 }, + { OP(1, 1, 1, OP_REM_F_2), 0, 4, 16 }, + { OP(1, 1, 1, OP_MOD_F_2), 0, 4, 20 }, + { OP(1, 1, 1, OP_ADD_F_2), 0, 4, 24 }, + { OP(1, 1, 1, OP_SUB_F_2), 0, 4, 28 }, + { OP(1, 1, 1, OP_JUMP_A), -10, 0, 0 }, +}; + +static dstatement_t float_binop_3a_statements[] = { + { OP(1, 1, 1, OP_MUL_F_3), 0, 4, 8 }, + { OP(1, 1, 1, OP_MUL_F_1), 3, 7, 11 }, + { OP(1, 1, 1, OP_DIV_F_3), 0, 4, 12 }, + { OP(1, 1, 1, OP_DIV_F_1), 3, 7, 15 }, + { OP(1, 1, 1, OP_REM_F_3), 0, 4, 16 }, + { OP(1, 1, 1, OP_REM_F_1), 3, 7, 19 }, + { OP(1, 1, 1, OP_MOD_F_3), 0, 4, 20 }, + { OP(1, 1, 1, OP_MOD_F_1), 3, 7, 23 }, + { OP(1, 1, 1, OP_ADD_F_3), 0, 4, 24 }, + { OP(1, 1, 1, OP_ADD_F_1), 3, 7, 27 }, + { OP(1, 1, 1, OP_SUB_F_3), 0, 4, 28 }, + { OP(1, 1, 1, OP_SUB_F_1), 3, 7, 31 }, +}; + +static dstatement_t float_binop_3b_statements[] = { + { OP(1, 1, 1, OP_MUL_F_1), 0, 4, 8 }, + { OP(1, 1, 1, OP_MUL_F_3), 1, 5, 9 }, + { OP(1, 1, 1, OP_DIV_F_1), 0, 4, 12 }, + { OP(1, 1, 1, OP_DIV_F_3), 1, 5, 13 }, + { OP(1, 1, 1, OP_REM_F_1), 0, 4, 16 }, + { OP(1, 1, 1, OP_REM_F_3), 1, 5, 17 }, + { OP(1, 1, 1, OP_MOD_F_1), 0, 4, 20 }, + { OP(1, 1, 1, OP_MOD_F_3), 1, 5, 21 }, + { OP(1, 1, 1, OP_ADD_F_1), 0, 4, 24 }, + { OP(1, 1, 1, OP_ADD_F_3), 1, 5, 25 }, + { OP(1, 1, 1, OP_SUB_F_1), 0, 4, 28 }, + { OP(1, 1, 1, OP_SUB_F_3), 1, 5, 29 }, +}; + +static dstatement_t float_binop_4_statements[] = { + { OP(1, 1, 1, OP_MUL_F_4), 0, 4, 8 }, + { OP(1, 1, 1, OP_DIV_F_4), 0, 4, 12 }, + { OP(1, 1, 1, OP_REM_F_4), 0, 4, 16 }, + { OP(1, 1, 1, OP_MOD_F_4), 0, 4, 20 }, + { OP(1, 1, 1, OP_ADD_F_4), 0, 4, 24 }, + { OP(1, 1, 1, OP_SUB_F_4), 0, 4, 28 }, +}; + +static pr_vec4_t float_cossin_init[] = { + { 1, 2, 3, 4 }, // 0: output + { M_PI/6, 0, 0, 0 }, // 4: x + { 1, 2, 0, 0 }, // 8: f + { 1, 1, 0, 25 }, // 12: f inc and f0 max + { 0, 0, 0, 0 }, // 16: x2 -> [xx, xx] + // { } // 20: xn +}; + +static pr_vec4_t float_cossin_expect[] = { + { 0.866025388, 0.5, 0, 0 }, // 0: output + { M_PI/6, 0, 0, 0 }, // 4: x + { 25, 26, 0, 0 }, // 8: f + { 1, 1, 0, 25 }, // 12: f inc and f0 max + { -sq(M_PI/6), -sq(M_PI/6), 0, 0 }, // 16: x2 -> [xx, xx] +}; + +static dstatement_t float_cossin_statements[] = { + { OP(0, 0, 0, OP_STORE_A_1), 21, 0, 4 }, // init xn -> [?, x] + { OP(0, 0, 0, OP_STORE_A_1), 20, 0, 8 }, // init xn -> [1, x] + { OP(0, 0, 0, OP_SWIZZLE_F), 4, 0xc000, 16 },// init x2 -> [x, x, 0, 0] + { OP(0, 0, 0, OP_MUL_F_2), 16, 16, 16 }, // x2 -> [x*x, x*x, 0, 0] + { OP(0, 0, 0, OP_SWIZZLE_F), 16, 0xc3e4, 16 },// init x2 -> -x2 + { OP(0, 0, 0, OP_SUB_F_4), 0, 0, 0 }, // init acc (output) to 0 +// loop: + { OP(0, 0, 0, OP_ADD_F_2), 0, 20, 0 }, // acc += xn + { OP(0, 0, 0, OP_MUL_F_2), 20, 16, 20 }, // xn *= x2 + { OP(0, 0, 0, OP_DIV_F_2), 20, 8, 20 }, // xn /= f + { OP(0, 0, 0, OP_ADD_F_2), 8, 12, 8 }, // f += inc + { OP(0, 0, 0, OP_DIV_F_2), 20, 8, 20 }, // xn /= f + { OP(0, 0, 0, OP_ADD_F_2), 8, 12, 8 }, // f += inc + { OP(0, 0, 0, OP_LT_F_1), 8, 15, 23 }, // f0 < fmax + { OP(0, 0, 0, OP_IF_A), -7, 0, 23 }, // f0 < fmax +}; + +test_t tests[] = { + { + .desc = "float binop 1", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(float_binop_init,float_binop_expect), + .num_statements = num_statements (float_binop_1_statements), + .statements = float_binop_1_statements, + .init_globals = (pr_int_t *) float_binop_init, + .expect_globals = (pr_int_t *) float_binop_expect, + }, + { + .desc = "float binop 2", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(float_binop_init,float_binop_expect), + .num_statements = num_statements (float_binop_2_statements), + .statements = float_binop_2_statements, + .init_globals = (pr_int_t *) float_binop_init, + .expect_globals = (pr_int_t *) float_binop_expect, + }, + { + .desc = "float binop 3a", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(float_binop_init,float_binop_expect), + .num_statements = num_statements (float_binop_3a_statements), + .statements = float_binop_3a_statements, + .init_globals = (pr_int_t *) float_binop_init, + .expect_globals = (pr_int_t *) float_binop_expect, + }, + { + .desc = "float binop 3b", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(float_binop_init,float_binop_expect), + .num_statements = num_statements (float_binop_3b_statements), + .statements = float_binop_3b_statements, + .init_globals = (pr_int_t *) float_binop_init, + .expect_globals = (pr_int_t *) float_binop_expect, + }, + { + .desc = "float binop 4", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(float_binop_init,float_binop_expect), + .num_statements = num_statements (float_binop_4_statements), + .statements = float_binop_4_statements, + .init_globals = (pr_int_t *) float_binop_init, + .expect_globals = (pr_int_t *) float_binop_expect, + }, + { + .desc = "float cos sin", + .extra_globals = 4 * 1, + .num_globals = 4 * num_globals (float_cossin_init, float_cossin_expect), + .num_statements = num_statements (float_cossin_statements), + .statements = float_cossin_statements, + .init_globals = (pr_int_t *) float_cossin_init, + .expect_globals = (pr_int_t *) float_cossin_expect, + }, +}; + +#include "main.c" diff --git a/libs/gamecode/test/test-int.c b/libs/gamecode/test/test-int.c new file mode 100644 index 000000000..08cfe3596 --- /dev/null +++ b/libs/gamecode/test/test-int.c @@ -0,0 +1,146 @@ +#include "head.c" + +#include "QF/mathlib.h" + +static pr_ivec4_t int_binop_init[] = { + { 5, -5, 5, -5}, + { 3, 3, -3, -3}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, +}; + +static pr_ivec4_t int_binop_expect[] = { + { 5, -5, 5, -5}, + { 3, 3, -3, -3}, + { 15, -15, -15, 15}, + { 1, -1, -1, 1}, + { 2, -2, 2, -2}, + { 2, 1, -1, -2}, + { 8, -2, 2, -8}, + { 2, -8, 8, -2}, +}; + +static dstatement_t int_binop_1_statements[] = { + { OP(0, 0, 0, OP_LEA_A), 4, 0, 32 }, // init index +//loop: + { OP(0, 0, 0, OP_LEA_C), 32, -1, 32 }, // dec index + { OP(0, 0, 0, OP_IFAE_A), 2, 0, 32 }, + { OP(0, 0, 0, OP_BREAK), 0, 0, 0 }, + { OP(0, 0, 0, OP_WITH), 4, 32, 1 }, + { OP(1, 1, 1, OP_MUL_I_1), 0, 4, 8 }, + { OP(1, 1, 1, OP_DIV_I_1), 0, 4, 12 }, + { OP(1, 1, 1, OP_REM_I_1), 0, 4, 16 }, + { OP(1, 1, 1, OP_MOD_I_1), 0, 4, 20 }, + { OP(1, 1, 1, OP_ADD_I_1), 0, 4, 24 }, + { OP(1, 1, 1, OP_SUB_I_1), 0, 4, 28 }, + { OP(1, 1, 1, OP_JUMP_A), -10, 0, 0 }, +}; + +static dstatement_t int_binop_2_statements[] = { + { OP(0, 0, 0, OP_LEA_A), 4, 0, 32 }, // index +//loop: + { OP(0, 0, 0, OP_LEA_C), 32, -2, 32 }, // dec index + { OP(0, 0, 0, OP_IFAE_A), 2, 0, 32 }, + { OP(0, 0, 0, OP_BREAK), 0, 0, 0 }, + { OP(0, 0, 0, OP_WITH), 4, 32, 1 }, + { OP(1, 1, 1, OP_MUL_I_2), 0, 4, 8 }, + { OP(1, 1, 1, OP_DIV_I_2), 0, 4, 12 }, + { OP(1, 1, 1, OP_REM_I_2), 0, 4, 16 }, + { OP(1, 1, 1, OP_MOD_I_2), 0, 4, 20 }, + { OP(1, 1, 1, OP_ADD_I_2), 0, 4, 24 }, + { OP(1, 1, 1, OP_SUB_I_2), 0, 4, 28 }, + { OP(1, 1, 1, OP_JUMP_A), -10, 0, 0 }, +}; + +static dstatement_t int_binop_3a_statements[] = { + { OP(1, 1, 1, OP_MUL_I_3), 0, 4, 8 }, + { OP(1, 1, 1, OP_MUL_I_1), 3, 7, 11 }, + { OP(1, 1, 1, OP_DIV_I_3), 0, 4, 12 }, + { OP(1, 1, 1, OP_DIV_I_1), 3, 7, 15 }, + { OP(1, 1, 1, OP_REM_I_3), 0, 4, 16 }, + { OP(1, 1, 1, OP_REM_I_1), 3, 7, 19 }, + { OP(1, 1, 1, OP_MOD_I_3), 0, 4, 20 }, + { OP(1, 1, 1, OP_MOD_I_1), 3, 7, 23 }, + { OP(1, 1, 1, OP_ADD_I_3), 0, 4, 24 }, + { OP(1, 1, 1, OP_ADD_I_1), 3, 7, 27 }, + { OP(1, 1, 1, OP_SUB_I_3), 0, 4, 28 }, + { OP(1, 1, 1, OP_SUB_I_1), 3, 7, 31 }, +}; + +static dstatement_t int_binop_3b_statements[] = { + { OP(1, 1, 1, OP_MUL_I_1), 0, 4, 8 }, + { OP(1, 1, 1, OP_MUL_I_3), 1, 5, 9 }, + { OP(1, 1, 1, OP_DIV_I_1), 0, 4, 12 }, + { OP(1, 1, 1, OP_DIV_I_3), 1, 5, 13 }, + { OP(1, 1, 1, OP_REM_I_1), 0, 4, 16 }, + { OP(1, 1, 1, OP_REM_I_3), 1, 5, 17 }, + { OP(1, 1, 1, OP_MOD_I_1), 0, 4, 20 }, + { OP(1, 1, 1, OP_MOD_I_3), 1, 5, 21 }, + { OP(1, 1, 1, OP_ADD_I_1), 0, 4, 24 }, + { OP(1, 1, 1, OP_ADD_I_3), 1, 5, 25 }, + { OP(1, 1, 1, OP_SUB_I_1), 0, 4, 28 }, + { OP(1, 1, 1, OP_SUB_I_3), 1, 5, 29 }, +}; + +static dstatement_t int_binop_4_statements[] = { + { OP(1, 1, 1, OP_MUL_I_4), 0, 4, 8 }, + { OP(1, 1, 1, OP_DIV_I_4), 0, 4, 12 }, + { OP(1, 1, 1, OP_REM_I_4), 0, 4, 16 }, + { OP(1, 1, 1, OP_MOD_I_4), 0, 4, 20 }, + { OP(1, 1, 1, OP_ADD_I_4), 0, 4, 24 }, + { OP(1, 1, 1, OP_SUB_I_4), 0, 4, 28 }, +}; + +test_t tests[] = { + { + .desc = "int binop 1", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(int_binop_init,int_binop_expect), + .num_statements = num_statements (int_binop_1_statements), + .statements = int_binop_1_statements, + .init_globals = (pr_int_t *) int_binop_init, + .expect_globals = (pr_int_t *) int_binop_expect, + }, + { + .desc = "int binop 2", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(int_binop_init,int_binop_expect), + .num_statements = num_statements (int_binop_2_statements), + .statements = int_binop_2_statements, + .init_globals = (pr_int_t *) int_binop_init, + .expect_globals = (pr_int_t *) int_binop_expect, + }, + { + .desc = "int binop 3a", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(int_binop_init,int_binop_expect), + .num_statements = num_statements (int_binop_3a_statements), + .statements = int_binop_3a_statements, + .init_globals = (pr_int_t *) int_binop_init, + .expect_globals = (pr_int_t *) int_binop_expect, + }, + { + .desc = "int binop 3b", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(int_binop_init,int_binop_expect), + .num_statements = num_statements (int_binop_3b_statements), + .statements = int_binop_3b_statements, + .init_globals = (pr_int_t *) int_binop_init, + .expect_globals = (pr_int_t *) int_binop_expect, + }, + { + .desc = "int binop 4", + .extra_globals = 4 * 1, + .num_globals = 4*num_globals(int_binop_init,int_binop_expect), + .num_statements = num_statements (int_binop_4_statements), + .statements = int_binop_4_statements, + .init_globals = (pr_int_t *) int_binop_init, + .expect_globals = (pr_int_t *) int_binop_expect, + }, +}; + +#include "main.c" diff --git a/libs/gamecode/test/test-long.c b/libs/gamecode/test/test-long.c new file mode 100644 index 000000000..7777b38e0 --- /dev/null +++ b/libs/gamecode/test/test-long.c @@ -0,0 +1,148 @@ +#include "head.c" + +#include "QF/mathlib.h" + +#define sq(x) ((x)*(x)) + +static pr_lvec4_t long_binop_init[] = { + { 5, -5, 5, -5}, + { 3, 3, -3, -3}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0}, +}; + +static pr_lvec4_t long_binop_expect[] = { + { 5, -5, 5, -5}, + { 3, 3, -3, -3}, + { 15, -15, -15, 15}, + { 5.0/3, -5.0/3, -5.0/3, 5.0/3}, + { 2, -2, 2, -2}, + { 2, 1, -1, -2}, + { 8, -2, 2, -8}, + { 2, -8, 8, -2}, +}; + +static dstatement_t long_binop_1_statements[] = { + { OP(0, 0, 0, OP_LEA_A), 8, 0, 64 }, // init index +//loop: + { OP(0, 0, 0, OP_LEA_C), 64, -2, 64 }, // dec index + { OP(0, 0, 0, OP_IFAE_A), 2, 0, 64 }, + { OP(0, 0, 0, OP_BREAK), 0, 0, 0 }, + { OP(0, 0, 0, OP_WITH), 4, 64, 1 }, + { OP(1, 1, 1, OP_MUL_L_1), 0, 8, 16 }, + { OP(1, 1, 1, OP_DIV_L_1), 0, 8, 24 }, + { OP(1, 1, 1, OP_REM_L_1), 0, 8, 32 }, + { OP(1, 1, 1, OP_MOD_L_1), 0, 8, 40 }, + { OP(1, 1, 1, OP_ADD_L_1), 0, 8, 48 }, + { OP(1, 1, 1, OP_SUB_L_1), 0, 8, 56 }, + { OP(1, 1, 1, OP_JUMP_A), -10, 0, 0 }, +}; + +static dstatement_t long_binop_2_statements[] = { + { OP(0, 0, 0, OP_LEA_A), 8, 0, 64 }, // init index +//loop: + { OP(0, 0, 0, OP_LEA_C), 64, -4, 64 }, // dec index + { OP(0, 0, 0, OP_IFAE_A), 2, 0, 64 }, + { OP(0, 0, 0, OP_BREAK), 0, 0, 0 }, + { OP(0, 0, 0, OP_WITH), 4, 64, 1 }, + { OP(1, 1, 1, OP_MUL_L_2), 0, 8, 16 }, + { OP(1, 1, 1, OP_DIV_L_2), 0, 8, 24 }, + { OP(1, 1, 1, OP_REM_L_2), 0, 8, 32 }, + { OP(1, 1, 1, OP_MOD_L_2), 0, 8, 40 }, + { OP(1, 1, 1, OP_ADD_L_2), 0, 8, 48 }, + { OP(1, 1, 1, OP_SUB_L_2), 0, 8, 56 }, + { OP(1, 1, 1, OP_JUMP_A), -10, 0, 0 }, +}; + +static dstatement_t long_binop_3a_statements[] = { + { OP(1, 1, 1, OP_MUL_L_3), 0, 8, 16 }, + { OP(1, 1, 1, OP_MUL_L_1), 6, 14, 22 }, + { OP(1, 1, 1, OP_DIV_L_3), 0, 8, 24 }, + { OP(1, 1, 1, OP_DIV_L_1), 6, 14, 30 }, + { OP(1, 1, 1, OP_REM_L_3), 0, 8, 32 }, + { OP(1, 1, 1, OP_REM_L_1), 6, 14, 38 }, + { OP(1, 1, 1, OP_MOD_L_3), 0, 8, 40 }, + { OP(1, 1, 1, OP_MOD_L_1), 6, 14, 46 }, + { OP(1, 1, 1, OP_ADD_L_3), 0, 8, 48 }, + { OP(1, 1, 1, OP_ADD_L_1), 6, 14, 54 }, + { OP(1, 1, 1, OP_SUB_L_3), 0, 8, 56 }, + { OP(1, 1, 1, OP_SUB_L_1), 6, 14, 62 }, +}; + +static dstatement_t long_binop_3b_statements[] = { + { OP(1, 1, 1, OP_MUL_L_1), 0, 8, 16 }, + { OP(1, 1, 1, OP_MUL_L_3), 2, 10, 18 }, + { OP(1, 1, 1, OP_DIV_L_1), 0, 8, 24 }, + { OP(1, 1, 1, OP_DIV_L_3), 2, 10, 26 }, + { OP(1, 1, 1, OP_REM_L_1), 0, 8, 32 }, + { OP(1, 1, 1, OP_REM_L_3), 2, 10, 34 }, + { OP(1, 1, 1, OP_MOD_L_1), 0, 8, 40 }, + { OP(1, 1, 1, OP_MOD_L_3), 2, 10, 42 }, + { OP(1, 1, 1, OP_ADD_L_1), 0, 8, 48 }, + { OP(1, 1, 1, OP_ADD_L_3), 2, 10, 50 }, + { OP(1, 1, 1, OP_SUB_L_1), 0, 8, 56 }, + { OP(1, 1, 1, OP_SUB_L_3), 2, 10, 58 }, +}; + +static dstatement_t long_binop_4_statements[] = { + { OP(1, 1, 1, OP_MUL_L_4), 0, 8, 16 }, + { OP(1, 1, 1, OP_DIV_L_4), 0, 8, 24 }, + { OP(1, 1, 1, OP_REM_L_4), 0, 8, 32 }, + { OP(1, 1, 1, OP_MOD_L_4), 0, 8, 40 }, + { OP(1, 1, 1, OP_ADD_L_4), 0, 8, 48 }, + { OP(1, 1, 1, OP_SUB_L_4), 0, 8, 56 }, +}; + +test_t tests[] = { + { + .desc = "long binop 1", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(long_binop_init,long_binop_expect), + .num_statements = num_statements (long_binop_1_statements), + .statements = long_binop_1_statements, + .init_globals = (pr_int_t *) long_binop_init, + .expect_globals = (pr_int_t *) long_binop_expect, + }, + { + .desc = "long binop 2", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(long_binop_init,long_binop_expect), + .num_statements = num_statements (long_binop_2_statements), + .statements = long_binop_2_statements, + .init_globals = (pr_int_t *) long_binop_init, + .expect_globals = (pr_int_t *) long_binop_expect, + }, + { + .desc = "long binop 3a", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(long_binop_init,long_binop_expect), + .num_statements = num_statements (long_binop_3a_statements), + .statements = long_binop_3a_statements, + .init_globals = (pr_int_t *) long_binop_init, + .expect_globals = (pr_int_t *) long_binop_expect, + }, + { + .desc = "long binop 3b", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(long_binop_init,long_binop_expect), + .num_statements = num_statements (long_binop_3b_statements), + .statements = long_binop_3b_statements, + .init_globals = (pr_int_t *) long_binop_init, + .expect_globals = (pr_int_t *) long_binop_expect, + }, + { + .desc = "long binop 4", + .extra_globals = 8 * 1, + .num_globals = 8*num_globals(long_binop_init,long_binop_expect), + .num_statements = num_statements (long_binop_4_statements), + .statements = long_binop_4_statements, + .init_globals = (pr_int_t *) long_binop_init, + .expect_globals = (pr_int_t *) long_binop_expect, + }, +}; + +#include "main.c"