mirror of https://github.com/Nonannet/copapy.git
write stencil signiture updated
This commit is contained in:
parent
7fc222d593
commit
5d24f249bf
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
set -v
|
||||
python src/copapy/generate_stancils.py
|
||||
python src/copapy/generate_stencils.py
|
||||
mkdir -p src/copapy/obj
|
||||
gcc -c src/copapy/stancils.c -o src/copapy/obj/stancils_x86_64.o
|
||||
gcc -c src/copapy/stencils.c -o src/copapy/obj/stencils_x86_64.o
|
||||
ls -l src/copapy/obj/*.o
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ def _get_c_function_definitions(code: str) -> dict[str, str]:
|
|||
return {r[0]: r[1] for r in ret}
|
||||
|
||||
|
||||
_ccode = pkgutil.get_data(__name__, 'stancils.c')
|
||||
_ccode = pkgutil.get_data(__name__, 'stencils.c')
|
||||
assert _ccode is not None
|
||||
_function_definitions = _get_c_function_definitions(_ccode.decode('utf-8'))
|
||||
|
||||
|
|
@ -238,7 +238,7 @@ def add_read_ops(node_list: list[Node]) -> Generator[tuple[Net | None, Node], No
|
|||
# print('x swap registers')
|
||||
type_list = ['int' if r is None else r.dtype for r in registers]
|
||||
print(type_list)
|
||||
new_node = Op('read_reg' + str(i) + '_' + '_'.join(type_list), [])
|
||||
new_node = Op(f"read_{net.dtype}_reg{i}_" + '_'.join(type_list), [])
|
||||
yield net, new_node
|
||||
registers[i] = net
|
||||
|
||||
|
|
@ -254,11 +254,11 @@ def add_read_ops(node_list: list[Node]) -> Generator[tuple[Net | None, Node], No
|
|||
def add_write_ops(net_node_list: list[tuple[Net | None, Node]], const_list: list[tuple[str, Net, float | int]]) -> Generator[tuple[Net | None, Node], None, None]:
|
||||
"""Add write operation for each new defined net if a read operation is later flowed"""
|
||||
stored_nets = {c[1] for c in const_list}
|
||||
read_back_nets = {net for net, node in net_node_list if node.name.startswith('read_reg')}
|
||||
read_back_nets = {net for net, node in net_node_list if node.name.startswith('read_')}
|
||||
|
||||
for net, node in net_node_list:
|
||||
yield net, node
|
||||
if net and net in read_back_nets and net not in stored_nets:
|
||||
if net and net in read_back_nets and net not in stored_nets:
|
||||
yield (net, Op('write_' + net.dtype, [net]))
|
||||
stored_nets.add(net)
|
||||
|
||||
|
|
@ -277,7 +277,7 @@ def compile_to_instruction_list(end_nodes: Iterable[Node] | Node) -> binw.data_w
|
|||
extended_output_ops = list(add_write_ops(output_ops, const_list))
|
||||
|
||||
|
||||
obj_file: str = 'src/copapy/obj/stancils_x86_64.o'
|
||||
obj_file: str = 'src/copapy/obj/stencils_x86_64.o'
|
||||
elf = pelfy.open_elf_file(obj_file)
|
||||
|
||||
dw = binw.data_writer(elf.byteorder)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,12 @@ def get_op_code(op: str, type1: str, type2: str, type_out: str):
|
|||
}}
|
||||
"""
|
||||
|
||||
def get_result_stubs(type1: str, type2: str):
|
||||
def get_result_stubs1(type1: str):
|
||||
return f"""
|
||||
void result_{type1}({type1} arg1);
|
||||
"""
|
||||
|
||||
def get_result_stubs2(type1: str, type2: str):
|
||||
return f"""
|
||||
void result_{type1}_{type2}({type1} arg1, {type2} arg2);
|
||||
"""
|
||||
|
|
@ -35,12 +40,12 @@ def get_read_reg1_code(type1: str, type2: str, type_out: str):
|
|||
}}
|
||||
"""
|
||||
|
||||
def get_write_code(type1: str, type2: str):
|
||||
def get_write_code(type1: str):
|
||||
return f"""
|
||||
void write_{type1}_{type2}({type1} arg1, {type2} arg2) {{
|
||||
void write_{type1}({type1} arg1) {{
|
||||
asm volatile (".long 0xF17ECAFE");
|
||||
dummy_{type1} = arg1;
|
||||
result_{type1}_{type2}(arg1, arg2);
|
||||
result_{type1}(arg1);
|
||||
asm volatile (".long 0xF27ECAFE");
|
||||
}}
|
||||
"""
|
||||
|
|
@ -59,14 +64,18 @@ if __name__ == "__main__":
|
|||
ops = ['add', 'sub', 'mul', 'div']
|
||||
|
||||
code = """
|
||||
// Auto-generated stancils for copapy
|
||||
// Auto-generated stencils for copapy
|
||||
// Do not edit manually
|
||||
|
||||
volatile int dummy_int = 1337;
|
||||
volatile float dummy_float = 1337;
|
||||
"""
|
||||
|
||||
for t1 in types:
|
||||
code += get_result_stubs1(t1)
|
||||
|
||||
for t1, t2 in permutate(types, types):
|
||||
code += get_result_stubs(t1, t2)
|
||||
code += get_result_stubs2(t1, t2)
|
||||
|
||||
for op, t1, t2 in permutate(ops, types, types):
|
||||
t_out = t1 if t1 == t2 else 'float'
|
||||
|
|
@ -76,8 +85,8 @@ if __name__ == "__main__":
|
|||
code += get_read_reg0_code(t1, t2, t_out)
|
||||
code += get_read_reg1_code(t1, t2, t_out)
|
||||
|
||||
for t1, t2 in permutate(types, types):
|
||||
code += get_write_code(t1, t2)
|
||||
for t1 in types:
|
||||
code += get_write_code(t1)
|
||||
|
||||
with open('src/copapy/stancils.c', 'w') as f:
|
||||
with open('src/copapy/stencils.c', 'w') as f:
|
||||
f.write(code)
|
||||
|
|
@ -1,10 +1,14 @@
|
|||
|
||||
// Auto-generated stancils for copapy
|
||||
// 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);
|
||||
|
|
@ -205,31 +209,17 @@
|
|||
asm volatile (".long 0xF27ECAFE");
|
||||
}
|
||||
|
||||
void write_int_int(int arg1, int arg2) {
|
||||
void write_int(int arg1) {
|
||||
asm volatile (".long 0xF17ECAFE");
|
||||
dummy_int = arg1;
|
||||
result_int_int(arg1, arg2);
|
||||
result_int(arg1);
|
||||
asm volatile (".long 0xF27ECAFE");
|
||||
}
|
||||
|
||||
void write_int_float(int arg1, float arg2) {
|
||||
asm volatile (".long 0xF17ECAFE");
|
||||
dummy_int = arg1;
|
||||
result_int_float(arg1, arg2);
|
||||
asm volatile (".long 0xF27ECAFE");
|
||||
}
|
||||
|
||||
void write_float_int(float arg1, int arg2) {
|
||||
void write_float(float arg1) {
|
||||
asm volatile (".long 0xF17ECAFE");
|
||||
dummy_float = arg1;
|
||||
result_float_int(arg1, arg2);
|
||||
asm volatile (".long 0xF27ECAFE");
|
||||
}
|
||||
|
||||
void write_float_float(float arg1, float arg2) {
|
||||
asm volatile (".long 0xF17ECAFE");
|
||||
dummy_float = arg1;
|
||||
result_float_float(arg1, arg2);
|
||||
result_float(arg1);
|
||||
asm volatile (".long 0xF27ECAFE");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue