diff --git a/src/copapy/generate_stencils.py b/src/copapy/generate_stencils.py index 2714cb3..7a9e239 100644 --- a/src/copapy/generate_stencils.py +++ b/src/copapy/generate_stencils.py @@ -37,11 +37,21 @@ def get_op_code(op: str, type1: str, type2: str, type_out: str) -> str: """ +def get_conv_code(type1: str, type2: str, type_out: str) -> str: + return f""" + void conv_{type1}_{type2}({type1} arg1, {type2} arg2) {{ + asm volatile (".long 0xE1401F0F"); + result_{type_out}_{type2}(({type_out})arg1, arg2); + asm volatile (".long 0xE2401F0F"); + }} + """ + + def get_op_code_float(op: str, type1: str, type2: str) -> str: return f""" void {op}_{type1}_{type2}({type1} arg1, {type2} arg2) {{ asm volatile (".long 0xE1401F0F"); - result_float_{type2}((float)arg1 {op_signs[op]} arg2, arg2); + result_float_{type2}((float)arg1 {op_signs[op]} (float)arg2, arg2); asm volatile (".long 0xE2401F0F"); }} """ @@ -140,7 +150,7 @@ if __name__ == "__main__": t_out = t1 if t1 == t2 else 'float' if op == 'floordiv': code += get_op_code_int('div', t1, t2) - elif op == 'div' and t1 == 'int': + elif op == 'div': code += get_op_code_float(op, t1, t2) else: code += get_op_code(op, t1, t2, t_out) diff --git a/src/coparun/coparun_module.c b/src/coparun/coparun_module.c index a2dd7f2..cb95c31 100644 --- a/src/coparun/coparun_module.c +++ b/src/coparun/coparun_module.c @@ -2,15 +2,6 @@ #include #include "runmem.h" -/* - * coparun(PyObject *self, PyObject *args) - * Accepts a Python `bytes` (or objects supporting the buffer protocol). - * We use the "y#" format in PyArg_ParseTuple which returns a pointer to - * the internal bytes buffer and its length (Py_ssize_t). For safety and - * performance we pass that pointer directly to parse_commands which expects - * a uint8_t* buffer. If parse_commands needs the length, consider - * extending its API to accept a length parameter. - */ static PyObject* coparun(PyObject* self, PyObject* args) { const char *buf; Py_ssize_t buf_len; diff --git a/tests/test_coparun_module.py b/tests/test_coparun_module.py index 5ec360f..11502df 100644 --- a/tests/test_coparun_module.py +++ b/tests/test_coparun_module.py @@ -6,7 +6,7 @@ def function(c1, c2): i1 = c1 * 3.3 + 5 i2 = c2 * 5 + c1 #r1 = i1 + i2 * 55 / 4 - r1 = i1 + i2 * 55 * 4 + r1 = i1 + i2 * 55 / 4 r2 = 4 * i2 + 5 return i1, i2, r1, r2 @@ -30,8 +30,9 @@ def test_compile(): ret_ref = function(4, 2) for test, ref, name in zip(ret, ret_ref, ['i1', 'i2', 'r1', 'r2']): - print('+', name) - assert tg.read_value(test) == approx(ref, 1e-5), name + val = tg.read_value(test) + print('+', name, val, ref) + assert val == approx(ref, 1e-5), name if __name__ == "__main__":