Skip to content

Commit

Permalink
[ISSUE-51]: some perf test file cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SzigetiJ committed Jan 9, 2024
1 parent d3bf734 commit 8049035
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 89 deletions.
9 changes: 2 additions & 7 deletions tests/performance/add_perf128.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const StandardArgs ARGS_DEFAULT = INIT_FUN2ARGS(
37U,
29U);

// ### Local types
typedef enum {
FUN_ADD = 0,
FUN_ADD_ASGN,
Expand All @@ -26,7 +25,6 @@ typedef enum {
FUN_SUB_TINY
} AdditiveFun;

// ### Constants
const char *funname[]={
"add",
"add_assign",
Expand All @@ -37,9 +35,7 @@ const char *funname[]={
"sub_replace",
"sub_tiny"
};
const unsigned int fun_n = ARRAYSIZE(funname);

// ### Internal functions
static unsigned int exec_function_loop_(unsigned int ai, unsigned int bi, unsigned int fun, const StandardArgs *args, UInt *chkval) {
BigUInt128 a = get_value_by_level(ai, args->levels);
BigUInt128 b = get_value_by_level(bi, args->levels);
Expand Down Expand Up @@ -69,12 +65,11 @@ static unsigned int exec_function_loop_(unsigned int ai, unsigned int bi, unsign
}
}
process_result_v1(procref, chkval);
inc_operands_v1(&a, &b, args->diff_a, args->diff_b);
inc_operands_v1(&a, &b, args->diff[0], args->diff[1]);
}
return args->loops;
}

// ### Main function
int main(int argc, const char *argv[]) {
return fun2_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, fun_n, funname, &exec_function_loop_, 1);
return fun2_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, ARRAYSIZE(funname), funname, &exec_function_loop_, 1);
}
13 changes: 5 additions & 8 deletions tests/performance/div1000_perf128.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,28 @@ typedef enum {
VARIANT_DIV1000_X
} Div1000Variant;

// ### Constants
const char *funname[] = {
"div(x,1000)",
"div1000(x)"
};
const unsigned int fun_n = sizeof(funname) / sizeof(funname[0]);

static unsigned int exec_function_loop_(unsigned int ai, unsigned int fun, const StandardArgs *args, UInt *chkval) {
BigUInt128 a = get_value_by_level(ai, args->levels);
uint32_t loop_cnt;

BigUInt128 bdiv = biguint128_value_of_uint(1000);
BigUInt128 a = get_value_by_level(ai, args->levels);
BigUIntPair128 res;
uint32_t loop_cnt;

for (loop_cnt = 0; loop_cnt < args->loops; ++loop_cnt) {
res = (fun==VARIANT_DIV1000_X)?
biguint128_div1000(&a):
biguint128_div(&a, &bdiv);
process_result_v1(&res.first, &chkval[0]);
process_result_v1(&res.second, &chkval[1]);
biguint128_add_tiny(&a, (UInt)args->diff_a);
process_result_v3(&res.second.dat[0], &chkval[1]);
biguint128_add_tiny(&a, (UInt)args->diff[0]);
}
return loop_cnt;
}

int main(int argc, const char *argv[]) {
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, fun_n, funname, &exec_function_loop_, 2);
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, ARRAYSIZE(funname), funname, &exec_function_loop_, 2);
}
5 changes: 2 additions & 3 deletions tests/performance/div10_perf128.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ typedef enum {
VARIANT_DIV10_X
} Div10Variant;

// ### Constants
const char *funname[] = {
"div(x,10)",
"d1000(m100(x))",
Expand Down Expand Up @@ -53,11 +52,11 @@ static unsigned int exec_function_loop_(unsigned int ai, unsigned int fun, const
}
process_result_v1(procref1, &chkval[0]);
process_result_v3(procref2, &chkval[1]);
biguint128_add_tiny(&a, (UInt) args->diff_a);
biguint128_add_tiny(&a, (UInt) args->diff[0]);
}
return loop_cnt;
}

int main(int argc, const char *argv[]) {
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, sizeof(funname) / sizeof(funname[0]), funname, &exec_function_loop_,2);
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, ARRAYSIZE(funname), funname, &exec_function_loop_,2);
}
10 changes: 2 additions & 8 deletions tests/performance/mul_perf128.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@ const StandardArgs ARGS_DEFAULT = INIT_FUN2ARGS(
37U,
29U);

// ### Local types
typedef enum {
FUN_MUL = 0,
FUN_DMUL,
FUN_DIV
} MultiplicativeFun;

// ### Constants
const char *funname[]={
"mul",
"dmul",
"div"
};
const unsigned int fun_n = ARRAYSIZE(funname);


// ### Internal functions
static unsigned int exec_function_loop_(unsigned int ai, unsigned int bi, unsigned int fun, const StandardArgs *args, UInt *chkval) {
BigUInt128 a = get_value_by_level(ai, args->levels);
BigUInt128 b = get_value_by_level(bi, args->levels);
Expand All @@ -49,12 +44,11 @@ static unsigned int exec_function_loop_(unsigned int ai, unsigned int bi, unsign
}
process_result_v1(procref2, chkval+0);
process_result_v1(procref1, chkval+1);
inc_operands_v1(&a, &b, (UInt) args->diff_a, (UInt) args->diff_b);
inc_operands_v1(&a, &b, (UInt) args->diff[0], (UInt) args->diff[1]);
}
return args->loops;
}

// ### Main function
int main(int argc, const char *argv[]) {
return fun2_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, fun_n, funname, &exec_function_loop_, 2);
return fun2_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, ARRAYSIZE(funname), funname, &exec_function_loop_, 2);
}
8 changes: 2 additions & 6 deletions tests/performance/parse_perf128.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ const unsigned int numwidth[] = {
HEXDIGITS,
DECDIGITS
};
const unsigned int fun_n = ARRAYSIZE(funname);


// ### Internal functions
static unsigned int exec_function_loop_(unsigned int ai, unsigned int fun, const StandardArgs *args, UInt *chkval) {
char str[DECDIGITS];
memset(str, '1', DECDIGITS);
Expand All @@ -59,12 +56,11 @@ static unsigned int exec_function_loop_(unsigned int ai, unsigned int fun, const
res = biguint128_ctor_deccstream(str, str_n);
}
process_result_v1(&res, chkval);
str[i % str_n] = '0' + ((i * args->diff_a) % 10);
str[i % str_n] = '0' + ((i * args->diff[0]) % 10);
}
return args->loops;
}

// ### Main function
int main(int argc, const char *argv[]) {
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, fun_n, funname, &exec_function_loop_, 1);
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, ARRAYSIZE(funname), funname, &exec_function_loop_, 1);
}
28 changes: 11 additions & 17 deletions tests/performance/perf_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

#include "perf_common.h"

static inline bool set_aorb(char sel, unsigned int *store, unsigned int val) {
if (sel<'a' || 'b'<sel) return true;
store[sel-'a']=val;
return false;
}

StandardArgs parse_args(int argc, const char *argv[], const StandardArgs res_init) {
StandardArgs retv = res_init;
int argi = 1;
Expand Down Expand Up @@ -35,24 +41,12 @@ StandardArgs parse_args(int argc, const char *argv[], const StandardArgs res_ini
if (c2==0) {
retv.levels = val;
} else {
if (c2=='a') {
retv.lmask_a = val;
} else if (c2=='b') {
retv.lmask_b = val;
} else {
retv.error |= true;
}
retv.error|=set_aorb(c2, retv.lmask, val);
if (c3) retv.error |= true;
}
break;
case 'd':
if (c2=='a') {
retv.diff_a = val;
} else if (c2=='b') {
retv.diff_b = val;
} else {
retv.error |= true;
}
retv.error|=set_aorb(c2, retv.diff, val);
if (c3) retv.error |= true;
break;
case 'f':
Expand Down Expand Up @@ -145,9 +139,9 @@ int fun2_main(int argc, const char *argv[],
if (check_res) return check_res;

for (unsigned int ai = 0; ai<args.levels; ++ai) {
if ((args.lmask_a & (1<<ai))==0) continue;
if ((args.lmask[0] & (1<<ai))==0) continue;
for (unsigned int bi = 0; bi<args.levels; ++bi) {
if ((args.lmask_b & (1<<bi))==0) continue;
if ((args.lmask[1] & (1<<bi))==0) continue;
fprintf(stderr, "*** Operand levels: a #%u, b #%u ***\n", ai, bi);

for (unsigned int fi = 0; fi < fun_n; ++fi) {
Expand Down Expand Up @@ -178,7 +172,7 @@ int fun1_main(int argc, const char *argv[],
if (check_res) return check_res;

for (unsigned int ai = 0; ai<args.levels; ++ai) {
if ((args.lmask_a & (1<<ai))==0) continue;
if ((args.lmask[0] & (1<<ai))==0) continue;
fprintf(stderr, "*** Operand level: a #%u ***\n", ai);

for (unsigned int fi = 0; fi < fun_n; ++fi) {
Expand Down
10 changes: 4 additions & 6 deletions tests/performance/perf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ typedef struct {
bool error;
bool help;
unsigned char levels;
unsigned int lmask_a;
unsigned int lmask_b;
int diff_a;
int diff_b;
unsigned int lmask[2];
int diff[2];
unsigned int fmask;
unsigned int fexmask;
} StandardArgs;
Expand All @@ -35,8 +33,8 @@ typedef unsigned int (*LoopFunctionN)(unsigned int *xi, unsigned int funidx, con
#define ARGMASK_FEXMASK 128U
#define ARGMASK_ALL 255U

#define INIT_FUN1ARGS(LOOPS,LEVELS,INCA) (StandardArgs){LOOPS, false, false, LEVELS, -1, 0, INCA, 0, -1, 0}
#define INIT_FUN2ARGS(LOOPS,LEVELS,INCA,INCB) (StandardArgs){LOOPS, false, false, LEVELS, -1, -1, INCA, INCB, -1, 0}
#define INIT_FUN1ARGS(LOOPS,LEVELS,INCA) (StandardArgs){LOOPS, false, false, LEVELS, {-1, 0}, {INCA, 0}, -1, 0}
#define INIT_FUN2ARGS(LOOPS,LEVELS,INCA,INCB) (StandardArgs){LOOPS, false, false, LEVELS, {-1, -1}, {INCA, INCB}, -1, 0}
#define ARRAYSIZE(X) (sizeof(X)/sizeof(X[0]))

StandardArgs parse_args(int argc, const char *argv[], const StandardArgs res_init);
Expand Down
23 changes: 0 additions & 23 deletions tests/performance/perf_common128.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
#ifndef _PERF_COMMON_H_
#define _PERF_COMMON_H_

#include <stdio.h>

#include "biguint128.h"

#define UINT_BITS (8U * sizeof(UInt))
#define BIGUINT_BITS 128
#define DEC_BIGUINTLEN ((BIGUINT_BITS / 10 + 1) * 3 + 1) // a good approximation, since 2^10 >~ 10^3

typedef struct {
char *name[3];
BigUInt128 val[3];
} PerfTestInitValues;

static inline PerfTestInitValues get_std_initvalues() {
PerfTestInitValues retv = {
{"low","medium","high"}
};
for (int i = 0; i<3; ++i) {
retv.val[i]=biguint128_ctor_default();
}
biguint128_sbit(&retv.val[1], UINT_BITS * (BIGUINT128_CELLS / 2));
biguint128_sbit(&retv.val[2], UINT_BITS * (BIGUINT128_CELLS - 1));
return retv;
}

static inline BigUInt128 get_value_by_level(unsigned int level, unsigned int max) {
BigUInt128 retv = biguint128_ctor_unit();
Expand Down Expand Up @@ -58,8 +37,6 @@ static inline void process_result_v3(UInt *a, UInt *b) {
*b+=*a;
}

#undef UINT_BITS
#undef BIGUINT_BITS
#undef DEC_BIGUINTLEN
#endif

9 changes: 2 additions & 7 deletions tests/performance/print_perf128.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@ const StandardArgs ARGS_DEFAULT = INIT_FUN1ARGS(
3U,
37U);

// ### Local types
typedef enum {
FUN_PRINT_HEX = 0,
FUN_PRINT_DEC
} PrintFun;

// ### Constants
const char *funname[]={
"print_hex",
"print_dec"
};
const unsigned int fun_n = sizeof(funname) / sizeof(funname[0]);

// ### Internal functions
static unsigned int exec_function_loop_(unsigned int ai, unsigned int fun, const StandardArgs *args, UInt *chkval) {
BigUInt128 a = get_value_by_level(ai, args->levels);
char pbuf[BUFLEN + 1];
Expand All @@ -49,12 +45,11 @@ static unsigned int exec_function_loop_(unsigned int ai, unsigned int fun, const
plen = biguint128_print_dec(&a, pbuf, BUFLEN);
}
process_result_v2(pbuf, plen, chkval);
biguint128_add_tiny(&a, (UInt)args->diff_a);
biguint128_add_tiny(&a, (UInt)args->diff[0]);
}
return args->loops;
}

// ### Main function
int main(int argc, const char *argv[]) {
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, fun_n, funname, &exec_function_loop_, 1);
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, ARRAYSIZE(funname), funname, &exec_function_loop_, 1);
}
6 changes: 2 additions & 4 deletions tests/performance/shift_perf128.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ const char *funname[]={
"shr_assign(x,i)",
"shr_tiny(copy(x),i)"
};
const unsigned int fun_n = ARRAYSIZE(funname);

// ### Internal functions
static unsigned int exec_function_loop_(unsigned int ai, unsigned int fun, const StandardArgs *args, UInt *chkval) {
BigUInt128 a = get_value_by_level(ai, args->levels);
uint32_t loop_cnt;
Expand Down Expand Up @@ -115,12 +113,12 @@ static unsigned int exec_function_loop_(unsigned int ai, unsigned int fun, const
++loop_cnt;
}
}
biguint128_add_tiny(&a, (UInt)args->diff_a);
biguint128_add_tiny(&a, (UInt)args->diff[0]);
}
return loop_cnt;
}

// ### Main function
int main(int argc, const char *argv[]) {
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, fun_n, funname, &exec_function_loop_, 1);
return fun1_main(argc, argv, 128, ARGS_DEFAULT, &LIMITS, ARRAYSIZE(funname), funname, &exec_function_loop_, 1);
}

0 comments on commit 8049035

Please sign in to comment.