mirror of https://github.com/Nonannet/copapy.git
florr division fixed
This commit is contained in:
parent
3118826515
commit
6cbfdfdaf3
|
|
@ -1,291 +0,0 @@
|
||||||
|
|
||||||
// Auto-generated stencils for copapy
|
|
||||||
// Do not edit manually
|
|
||||||
|
|
||||||
volatile int dummy_int = 1337;
|
|
||||||
volatile float dummy_float = 1337;
|
|
||||||
|
|
||||||
void result_int(int arg1);
|
|
||||||
|
|
||||||
void result_float(float arg1);
|
|
||||||
|
|
||||||
void result_int_int(int arg1, int arg2);
|
|
||||||
|
|
||||||
void result_int_float(int arg1, float arg2);
|
|
||||||
|
|
||||||
void result_float_int(float arg1, int arg2);
|
|
||||||
|
|
||||||
void result_float_float(float arg1, float arg2);
|
|
||||||
|
|
||||||
void add_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(arg1 + arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 + arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(arg1 + arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 + arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void sub_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(arg1 - arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void sub_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 - arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void sub_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(arg1 - arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void sub_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 - arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void mul_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(arg1 * arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void mul_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 * arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void mul_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(arg1 * arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void mul_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 * arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void div_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int((float)arg1 / arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void div_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float((float)arg1 / arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void div_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(arg1 / arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void div_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 / arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void gt_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(arg1 > arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void gt_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 > arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void gt_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(arg1 > arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void gt_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 > arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void eq_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(arg1 == arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void eq_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 == arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void eq_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(arg1 == arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void eq_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1 == arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void mod_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(arg1 % arg2, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_int_reg0_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(dummy_int, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_int_reg1_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(arg1, dummy_int);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_float_reg0_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(dummy_float, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_float_reg1_int_int(int arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_float(arg1, dummy_float);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_int_reg0_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_float(dummy_int, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_int_reg1_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(arg1, dummy_int);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_float_reg0_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(dummy_float, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_float_reg1_int_float(int arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_float(arg1, dummy_float);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_int_reg0_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_int(dummy_int, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_int_reg1_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(arg1, dummy_int);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_float_reg0_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(dummy_float, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_float_reg1_float_int(float arg1, int arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1, dummy_float);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_int_reg0_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_int_float(dummy_int, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_int_reg1_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_int(arg1, dummy_int);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_float_reg0_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(dummy_float, arg2);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void read_float_reg1_float_float(float arg1, float arg2) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
result_float_float(arg1, dummy_float);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_int(int arg1) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
dummy_int = arg1;
|
|
||||||
result_int(arg1);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_float(float arg1) {
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
dummy_float = arg1;
|
|
||||||
result_float(arg1);
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
}
|
|
||||||
|
|
||||||
int function_start(){
|
|
||||||
result_int(0); // dummy call instruction before marker gets striped
|
|
||||||
asm volatile (".long 0xE2401F0F");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int function_end(){
|
|
||||||
result_int(0);
|
|
||||||
asm volatile (".long 0xE1401F0F");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@ from typing import Generator
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
op_signs = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/', 'floordiv': '/',
|
op_signs = {'add': '+', 'sub': '-', 'mul': '*', 'div': '/',
|
||||||
'gt': '>', 'eq': '==', 'mod': '%'}
|
'gt': '>', 'eq': '==', 'mod': '%'}
|
||||||
|
|
||||||
entry_func_prefix = ''
|
entry_func_prefix = ''
|
||||||
|
|
@ -11,7 +11,7 @@ stencil_func_prefix = '__attribute__((naked)) ' # Remove collee prolog
|
||||||
def get_function_start() -> str:
|
def get_function_start() -> str:
|
||||||
return f"""
|
return f"""
|
||||||
{entry_func_prefix}int function_start(){{
|
{entry_func_prefix}int function_start(){{
|
||||||
result_int(0); // dummy call instruction before marker gets striped
|
result_int(0); // dummy call instruction: call instruction before marker gets striped
|
||||||
asm volatile (".long 0xE2401F0F");
|
asm volatile (".long 0xE2401F0F");
|
||||||
return 1;
|
return 1;
|
||||||
}}
|
}}
|
||||||
|
|
@ -21,7 +21,7 @@ def get_function_start() -> str:
|
||||||
def get_function_end() -> str:
|
def get_function_end() -> str:
|
||||||
return f"""
|
return f"""
|
||||||
{entry_func_prefix}int function_end(){{
|
{entry_func_prefix}int function_end(){{
|
||||||
result_int(0);
|
result_int(0); // dummy call instruction: call instruction before marker gets striped
|
||||||
asm volatile (".long 0xE1401F0F");
|
asm volatile (".long 0xE1401F0F");
|
||||||
return 1;
|
return 1;
|
||||||
}}
|
}}
|
||||||
|
|
@ -55,10 +55,10 @@ def get_op_code_float(op: str, type1: str, type2: str) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def get_op_code_int(op: str, type1: str, type2: str) -> str:
|
def get_floordiv(op: str, type1: str, type2: str) -> str:
|
||||||
return f"""
|
return f"""
|
||||||
{stencil_func_prefix}void {op}_{type1}_{type2}({type1} arg1, {type2} arg2) {{
|
{stencil_func_prefix}void {op}_{type1}_{type2}({type1} arg1, {type2} arg2) {{
|
||||||
result_int_{type2}((int)(arg1 {op_signs[op]} arg2), arg2);
|
result_int_{type2}(floor_int((float)arg1 / (float)arg2), arg2);
|
||||||
asm volatile (".long 0xE2401F0F");
|
asm volatile (".long 0xE2401F0F");
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
|
|
@ -129,6 +129,13 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
volatile int dummy_int = 1337;
|
volatile int dummy_int = 1337;
|
||||||
volatile float dummy_float = 1337;
|
volatile float dummy_float = 1337;
|
||||||
|
|
||||||
|
float floor_int(float x) {
|
||||||
|
int i = (int)x;
|
||||||
|
if (x < 0 && x != (float)i)
|
||||||
|
i -= 1;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Scalar arithmetic:
|
# Scalar arithmetic:
|
||||||
|
|
@ -144,7 +151,7 @@ if __name__ == "__main__":
|
||||||
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'
|
||||||
if op == 'floordiv':
|
if op == 'floordiv':
|
||||||
code += get_op_code_int('floordiv', t1, t2)
|
code += get_floordiv('floordiv', t1, t2)
|
||||||
elif op == 'div':
|
elif op == 'div':
|
||||||
code += get_op_code_float(op, t1, t2)
|
code += get_op_code_float(op, t1, t2)
|
||||||
elif op == 'gt' or op == 'eq':
|
elif op == 'gt' or op == 'eq':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue