stencils for bit-wise operations added

This commit is contained in:
Nicolas Kruse 2025-10-30 22:22:43 +01:00
parent 891848d83f
commit 4df7434c6c
4 changed files with 27 additions and 16 deletions

View File

@ -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;
}

View File

@ -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):

15
stencils/test.c Normal file
View File

@ -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;
}

View File

@ -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