diff --git a/stencils/aux_functions.c b/stencils/aux_functions.c index 89a61f9..18e950e 100644 --- a/stencils/aux_functions.c +++ b/stencils/aux_functions.c @@ -41,13 +41,3 @@ float fast_pow_float(float base, float exponent) { u.i = (uint32_t)y; return u.f; } - -int main() { - // Test aux functions - float a = 16.0f; - float sqrt_a = aux_sqrt(a); - float pow_a = fast_pow_float(a, 0.5f); - float sqrt2_a = aux_sqrt2(a); - float g42 = aux_get_42(0.0f); - return 0; -} \ No newline at end of file diff --git a/stencils/generate_stencils.py b/stencils/generate_stencils.py index 1db9238..5500d69 100644 --- a/stencils/generate_stencils.py +++ b/stencils/generate_stencils.py @@ -4,7 +4,9 @@ from pathlib import Path import os op_signs = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/', 'pow': '**', - 'gt': '>', 'eq': '==', 'ge': '>=', 'ne': '!=', 'mod': '%'} + 'gt': '>', 'eq': '==', 'ge': '>=', 'ne': '!=', 'mod': '%', + 'lshift': '<<', 'rshift': '>>', + 'bwand': '&', 'bwor': '|', 'bwxor': '^'} entry_func_prefix = '' stencil_func_prefix = '__attribute__((naked)) ' # Remove callee prolog @@ -15,7 +17,7 @@ includes = ['aux_functions.c', 'trigonometry.c'] def read_files(files: list[str]) -> str: - ret = '' + ret: str = '' script_dir = Path(__file__).parent for file_name in files: file_path = script_dir / file_name @@ -199,6 +201,7 @@ if __name__ == "__main__": # Scalar arithmetic: types = ['int', 'float'] ops = ['add', 'sub', 'mul', 'div', 'floordiv', 'gt', 'ge', 'eq', 'ne', 'pow'] + int_ops = ['bwand', 'bwor', 'bwxor', 'lshift', 'rshift'] for t1 in types: code += get_result_stubs1(t1) @@ -213,8 +216,8 @@ if __name__ == "__main__": code += get_cast(t1, t2, t_out) fnames = ['sqrt', 'sin', 'cos', 'tan', 'get_42'] - for fn, t1, t2 in permutate(fnames, types, types): - code += get_func2(fn, t1, t2) + for fn, t1 in permutate(fnames, types): + code += get_func2(fn, t1, t1) for op, t1, t2 in permutate(ops, types, types): t_out = t1 if t1 == t2 else 'float' @@ -229,6 +232,9 @@ if __name__ == "__main__": else: code += get_op_code(op, t1, t2, t_out) + for op in int_ops: + code += get_op_code(op, 'int', 'int', 'int') + code += get_op_code('mod', 'int', 'int', 'int') for t1, t2, t_out in permutate(types, types, types): diff --git a/stencils/test.c b/stencils/test.c new file mode 100644 index 0000000..38664f8 --- /dev/null +++ b/stencils/test.c @@ -0,0 +1,15 @@ +#include "aux_functions.c" +#include "trigonometry.c" + +int main() { + // Test aux functions + float a = 16.0f; + float sqrt_a = aux_sqrt(a); + float pow_a = fast_pow_float(a, 0.5f); + float div_result = (float)floor_div(-7.0f, 3.0f); + float sin_30 = aux_sin(30.0f); + float cos_60 = aux_cos(60.0f); + float tan_45 = aux_tan(45.0f); + float g42 = aux_get_42(0.0f); + return 0; +} diff --git a/tools/test_stencil_aux.sh b/tools/test_stencil_aux.sh index b4172b8..1bfbf15 100644 --- a/tools/test_stencil_aux.sh +++ b/tools/test_stencil_aux.sh @@ -4,8 +4,8 @@ set -e set -v mkdir -p bin -FILE=aux_functions -SRC=stencils/$FILE.c +FILE=test +SRC="stencils/$FILE.c" DEST=bin OPT=O3