mirror of https://github.com/Nonannet/copapy.git
stencils for bit-wise operations added
This commit is contained in:
parent
891848d83f
commit
4df7434c6c
|
|
@ -41,13 +41,3 @@ float fast_pow_float(float base, float exponent) {
|
||||||
u.i = (uint32_t)y;
|
u.i = (uint32_t)y;
|
||||||
return u.f;
|
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;
|
|
||||||
}
|
|
||||||
|
|
@ -4,7 +4,9 @@ from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
|
||||||
op_signs = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/', 'pow': '**',
|
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 = ''
|
entry_func_prefix = ''
|
||||||
stencil_func_prefix = '__attribute__((naked)) ' # Remove callee prolog
|
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:
|
def read_files(files: list[str]) -> str:
|
||||||
ret = ''
|
ret: str = ''
|
||||||
script_dir = Path(__file__).parent
|
script_dir = Path(__file__).parent
|
||||||
for file_name in files:
|
for file_name in files:
|
||||||
file_path = script_dir / file_name
|
file_path = script_dir / file_name
|
||||||
|
|
@ -199,6 +201,7 @@ if __name__ == "__main__":
|
||||||
# Scalar arithmetic:
|
# Scalar arithmetic:
|
||||||
types = ['int', 'float']
|
types = ['int', 'float']
|
||||||
ops = ['add', 'sub', 'mul', 'div', 'floordiv', 'gt', 'ge', 'eq', 'ne', 'pow']
|
ops = ['add', 'sub', 'mul', 'div', 'floordiv', 'gt', 'ge', 'eq', 'ne', 'pow']
|
||||||
|
int_ops = ['bwand', 'bwor', 'bwxor', 'lshift', 'rshift']
|
||||||
|
|
||||||
for t1 in types:
|
for t1 in types:
|
||||||
code += get_result_stubs1(t1)
|
code += get_result_stubs1(t1)
|
||||||
|
|
@ -213,8 +216,8 @@ if __name__ == "__main__":
|
||||||
code += get_cast(t1, t2, t_out)
|
code += get_cast(t1, t2, t_out)
|
||||||
|
|
||||||
fnames = ['sqrt', 'sin', 'cos', 'tan', 'get_42']
|
fnames = ['sqrt', 'sin', 'cos', 'tan', 'get_42']
|
||||||
for fn, t1, t2 in permutate(fnames, types, types):
|
for fn, t1 in permutate(fnames, types):
|
||||||
code += get_func2(fn, t1, t2)
|
code += get_func2(fn, t1, t1)
|
||||||
|
|
||||||
for op, t1, t2 in permutate(ops, types, types):
|
for op, t1, t2 in permutate(ops, types, types):
|
||||||
t_out = t1 if t1 == t2 else 'float'
|
t_out = t1 if t1 == t2 else 'float'
|
||||||
|
|
@ -229,6 +232,9 @@ if __name__ == "__main__":
|
||||||
else:
|
else:
|
||||||
code += get_op_code(op, t1, t2, t_out)
|
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')
|
code += get_op_code('mod', 'int', 'int', 'int')
|
||||||
|
|
||||||
for t1, t2, t_out in permutate(types, types, types):
|
for t1, t2, t_out in permutate(types, types, types):
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -4,8 +4,8 @@ set -e
|
||||||
set -v
|
set -v
|
||||||
|
|
||||||
mkdir -p bin
|
mkdir -p bin
|
||||||
FILE=aux_functions
|
FILE=test
|
||||||
SRC=stencils/$FILE.c
|
SRC="stencils/$FILE.c"
|
||||||
DEST=bin
|
DEST=bin
|
||||||
OPT=O3
|
OPT=O3
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue