diff --git a/osaca/data/create_db_entry.py b/osaca/data/create_db_entry.py index f07a266..c7b61ae 100644 --- a/osaca/data/create_db_entry.py +++ b/osaca/data/create_db_entry.py @@ -177,4 +177,4 @@ def get_description(instruction_form, port_pressure, latency, rhs_comment=None): print(get_description(*sys.argv[1:])) except KeyError: print("Unknown architecture.") - sys.exit(1) \ No newline at end of file + sys.exit(1) diff --git a/osaca/data/generate_mov_entries.py b/osaca/data/generate_mov_entries.py index dd7d336..cdaaf9d 100644 --- a/osaca/data/generate_mov_entries.py +++ b/osaca/data/generate_mov_entries.py @@ -1641,4 +1641,4 @@ def get_description(arch, rhs_comment=None): print(get_description(sys.argv[1], rhs_comment=" ".join(sys.argv))) except KeyError: print("Unknown architecture.") - sys.exit(1) \ No newline at end of file + sys.exit(1) diff --git a/osaca/data/model_importer.py b/osaca/data/model_importer.py index d41ad0d..d10555e 100644 --- a/osaca/data/model_importer.py +++ b/osaca/data/model_importer.py @@ -306,4 +306,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/osaca/data/pmevo_importer.py b/osaca/data/pmevo_importer.py index 8333353..ba8d041 100644 --- a/osaca/data/pmevo_importer.py +++ b/osaca/data/pmevo_importer.py @@ -318,4 +318,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/osaca/parser/directive.py b/osaca/parser/directive.py index 1996e63..fff2616 100644 --- a/osaca/parser/directive.py +++ b/osaca/parser/directive.py @@ -24,13 +24,9 @@ def parameters(self): def parameters(self, parameters): self._parameters = parameters - def __eq__(self, other): if isinstance(other, DirectiveOperand): - return ( - self._name == other._name - and self._parameters == other._parameters - ) + return self._name == other._name and self._parameters == other._parameters elif isinstance(other, dict): return self._name == other["name"] and self._parameters == other["parameters"] return False diff --git a/osaca/parser/flag.py b/osaca/parser/flag.py index 53ce9fc..7edce72 100644 --- a/osaca/parser/flag.py +++ b/osaca/parser/flag.py @@ -17,9 +17,7 @@ def name(self, name): self._name = name def __str__(self): - return ( - f"Flag(name={self._name}, source={self._source}, relocation={self._destination})" - ) + return f"Flag(name={self._name}, source={self._source}, relocation={self._destination})" def __repr__(self): return self.__str__() diff --git a/osaca/parser/parser_AArch64.py b/osaca/parser/parser_AArch64.py index 26eb571..1dce190 100644 --- a/osaca/parser/parser_AArch64.py +++ b/osaca/parser/parser_AArch64.py @@ -392,10 +392,13 @@ def process_operand(self, operand): return operand def process_directive_operand(self, operand): - return DirectiveOperand( - name=operand["name"], - parameters=operand["parameters"], - ), operand["comment"] if "comment" in operand else None + return ( + DirectiveOperand( + name=operand["name"], + parameters=operand["parameters"], + ), + operand["comment"] if "comment" in operand else None, + ) def process_register_operand(self, operand): return RegisterOperand( @@ -524,9 +527,7 @@ def process_immediate(self, immediate): # normal integer value immediate["type"] = "int" # convert hex/bin immediates to dec - new_immediate = ImmediateOperand( - imd_type=immediate["type"], value=immediate["value"] - ) + new_immediate = ImmediateOperand(imd_type=immediate["type"], value=immediate["value"]) new_immediate.value = self.normalize_imd(new_immediate) return new_immediate if "base_immediate" in immediate: @@ -547,9 +548,7 @@ def process_immediate(self, immediate): dict_name = "double" if "exponent" in immediate[dict_name]: immediate["type"] = dict_name - return ImmediateOperand( - imd_type=immediate["type"], value=immediate[immediate["type"]] - ) + return ImmediateOperand(imd_type=immediate["type"], value=immediate[immediate["type"]]) else: # change 'mantissa' key to 'value' return ImmediateOperand(value=immediate[dict_name]["mantissa"], imd_type=dict_name) @@ -557,7 +556,10 @@ def process_immediate(self, immediate): def process_label(self, label): """Post-process label asm line""" # remove duplicated 'name' level due to identifier - return LabelOperand(name=label["name"]["name"]), label["comment"] if self.comment_id in label else None + return ( + LabelOperand(name=label["name"]["name"]), + label["comment"] if self.comment_id in label else None, + ) def process_identifier(self, identifier): """Post-process identifier operand""" diff --git a/osaca/parser/parser_x86att.py b/osaca/parser/parser_x86att.py index 8dc7042..b02d5bf 100644 --- a/osaca/parser/parser_x86att.py +++ b/osaca/parser/parser_x86att.py @@ -317,7 +317,10 @@ def process_register(self, operand): ) def process_directive(self, directive): - directive_new = DirectiveOperand(name=directive["name"], parameters=directive["parameters"] if "parameters" in directive else []) + directive_new = DirectiveOperand( + name=directive["name"], + parameters=directive["parameters"] if "parameters" in directive else [], + ) return directive_new, directive["comment"] if "comment" in directive else None def process_memory_address(self, memory_address): @@ -346,9 +349,7 @@ def process_memory_address(self, memory_address): ) if isinstance(offset, dict) and "identifier" in offset: offset = IdentifierOperand(name=offset["identifier"]["name"]) - new_dict = MemoryOperand( - offset=offset, base=baseOp, index=indexOp, scale=scale - ) + new_dict = MemoryOperand(offset=offset, base=baseOp, index=indexOp, scale=scale) # Add segmentation extension if existing if self.segment_ext in memory_address: new_dict.segment_ext = memory_address[self.segment_ext] diff --git a/osaca/parser/register.py b/osaca/parser/register.py index 2154eb4..23d4778 100644 --- a/osaca/parser/register.py +++ b/osaca/parser/register.py @@ -46,7 +46,7 @@ def name(self): @name.setter def name(self, name): self._name = name - + @property def width(self): return self._width diff --git a/osaca/semantics/hw_model.py b/osaca/semantics/hw_model.py index f72e5be..0a2dd0e 100644 --- a/osaca/semantics/hw_model.py +++ b/osaca/semantics/hw_model.py @@ -136,7 +136,9 @@ def __init__(self, arch=None, path_to_yaml=None, isa=None, lazy=False): uops=iform["uops"] if "uops" in iform else None, port_pressure=iform["port_pressure"] if "port_pressure" in iform else None, operation=iform["operation"] if "operation" in iform else None, - breaks_dependency_on_equal_operands=iform["breaks_dependency_on_equal_operands"] + breaks_dependency_on_equal_operands=iform[ + "breaks_dependency_on_equal_operands" + ] if "breaks_dependency_on_equal_operands" in iform else False, semantic_operands=iform["semantic_operands"] @@ -151,33 +153,36 @@ def __init__(self, arch=None, path_to_yaml=None, isa=None, lazy=False): new_throughputs = [] if "load_throughput" in self._data: for m in self._data["load_throughput"]: - new_throughputs.append(( - MemoryOperand( - base=m["base"], - offset=m["offset"], - scale=m["scale"], - index=m["index"], - dst=m["dst"] if "dst" in m else None, + new_throughputs.append( + ( + MemoryOperand( + base=m["base"], + offset=m["offset"], + scale=m["scale"], + index=m["index"], + dst=m["dst"] if "dst" in m else None, + ), + m["port_pressure"], ) - , m["port_pressure"]) ) self._data["load_throughput"] = new_throughputs new_throughputs = [] if "store_throughput" in self._data: for m in self._data["store_throughput"]: - new_throughputs.append(( - MemoryOperand( - base=m["base"], - offset=m["offset"], - scale=m["scale"], - index=m["index"], + new_throughputs.append( + ( + MemoryOperand( + base=m["base"], + offset=m["offset"], + scale=m["scale"], + index=m["index"], + ), + m["port_pressure"], ) - , m["port_pressure"]) ) self._data["store_throughput"] = new_throughputs - if not lazy: # cache internal representation for future use self._write_in_cache(self._path) @@ -386,12 +391,15 @@ def get_store_latency(self, reg_type): def get_store_throughput(self, memory, src_reg=None): """Return store throughput for a given destination and register type.""" - st_tp = [m for m in self._data["store_throughput"] if self._match_mem_entries(memory, m[0])] + st_tp = [ + m for m in self._data["store_throughput"] if self._match_mem_entries(memory, m[0]) + ] if src_reg is not None: st_tp = [ tp for tp in st_tp - if "src" in tp[0] and self._check_operands(src_reg, RegisterOperand(name=tp[0]["src"])) + if "src" in tp[0] + and self._check_operands(src_reg, RegisterOperand(name=tp[0]["src"])) ] if len(st_tp) > 0: return st_tp.copy() @@ -461,29 +469,48 @@ def get_isa_for_arch(arch): return arch_dict[arch].lower() else: raise ValueError("Unknown architecture {!r}.".format(arch)) - + def class_to_dict(self, op): """Need to convert operand classes to dicts for the dump. Memory operand types may have their index/base/offset as a register operand/""" if isinstance(op, Operand): - dict_op = dict((key.lstrip('_'), value) for key, value in op.__dict__.items() if not callable(value) and not key.startswith('__')) + dict_op = dict( + (key.lstrip("_"), value) + for key, value in op.__dict__.items() + if not callable(value) and not key.startswith("__") + ) if isinstance(op, MemoryOperand): if isinstance(dict_op["index"], Operand): - dict_op["index"] = dict((key.lstrip('_'), value) for key, value in dict_op["index"].__dict__.items() if not callable(value) and not key.startswith('__')) + dict_op["index"] = dict( + (key.lstrip("_"), value) + for key, value in dict_op["index"].__dict__.items() + if not callable(value) and not key.startswith("__") + ) if isinstance(dict_op["offset"], Operand): - dict_op["offset"] = dict((key.lstrip('_'), value) for key, value in dict_op["offset"].__dict__.items() if not callable(value) and not key.startswith('__')) + dict_op["offset"] = dict( + (key.lstrip("_"), value) + for key, value in dict_op["offset"].__dict__.items() + if not callable(value) and not key.startswith("__") + ) if isinstance(dict_op["base"], Operand): - dict_op["base"] = dict((key.lstrip('_'), value) for key, value in dict_op["base"].__dict__.items() if not callable(value) and not key.startswith('__')) + dict_op["base"] = dict( + (key.lstrip("_"), value) + for key, value in dict_op["base"].__dict__.items() + if not callable(value) and not key.startswith("__") + ) return dict_op return op - def dump(self, stream=None): """Dump machine model to stream or return it as a ``str`` if no stream is given.""" # Replace instruction form's port_pressure with styled version for RoundtripDumper formatted_instruction_forms = [] for instruction_form in self._data["instruction_forms"]: if isinstance(instruction_form, InstructionForm): - instruction_form = dict((key.lstrip('_'), value) for key, value in instruction_form.__dict__.items() if not callable(value) and not key.startswith('__')) + instruction_form = dict( + (key.lstrip("_"), value) + for key, value in instruction_form.__dict__.items() + if not callable(value) and not key.startswith("__") + ) if instruction_form["port_pressure"] is not None: cs = ruamel.yaml.comments.CommentedSeq(instruction_form["port_pressure"]) cs.fa.set_flow_style() @@ -516,7 +543,7 @@ def dump(self, stream=None): yaml = self._create_yaml_object() if not stream: stream = StringIO() - + yaml.dump( { k: v @@ -532,7 +559,7 @@ def dump(self, stream=None): }, stream, ) - + yaml.dump({"load_throughput": formatted_load_throughput}, stream) yaml.dump({"store_throughput": formatted_store_throughput}, stream) yaml.dump({"instruction_forms": formatted_instruction_forms}, stream) diff --git a/osaca/semantics/kernel_dg.py b/osaca/semantics/kernel_dg.py index 464a6ef..a061749 100644 --- a/osaca/semantics/kernel_dg.py +++ b/osaca/semantics/kernel_dg.py @@ -300,10 +300,7 @@ def find_depending(self, instruction_form, instructions, flag_dependencies=False # write to register -> abort if self.is_written(dst, instr_form): break - if ( - isinstance(dst, FlagOperand) - and flag_dependencies - ): + if isinstance(dst, FlagOperand) and flag_dependencies: # read of flag if self.is_read(dst, instr_form): yield instr_form, [] diff --git a/tests/test_parser_AArch64.py b/tests/test_parser_AArch64.py index 25a22c1..161ea6a 100755 --- a/tests/test_parser_AArch64.py +++ b/tests/test_parser_AArch64.py @@ -53,25 +53,27 @@ def test_directive_parser(self): self.assertEqual(self._get_directive(self.parser, "\t.text")[0].name, "text") self.assertEqual(len(self._get_directive(self.parser, "\t.text")[0].parameters), 0) self.assertEqual(self._get_directive(self.parser, "\t.align\t16,0x90")[0].name, "align") - self.assertEqual(len(self._get_directive(self.parser, "\t.align\t16,0x90")[0].parameters), 2) + self.assertEqual( + len(self._get_directive(self.parser, "\t.align\t16,0x90")[0].parameters), 2 + ) self.assertEqual( self._get_directive(self.parser, "\t.align\t16,0x90")[0].parameters[1], "0x90" ) self.assertEqual( - self._get_directive(self.parser, " .byte 100,103,144 //IACA START")[0].name, + self._get_directive(self.parser, " .byte 100,103,144 //IACA START")[ + 0 + ].name, "byte", ) self.assertEqual( - self._get_directive( - self.parser, " .byte 100,103,144 //IACA START" - )[0].parameters[2], + self._get_directive(self.parser, " .byte 100,103,144 //IACA START")[ + 0 + ].parameters[2], "144", ) self.assertEqual( " ".join( - self._get_directive( - self.parser, " .byte 100,103,144 //IACA START" - )[1] + self._get_directive(self.parser, " .byte 100,103,144 //IACA START")[1] ), "IACA START", ) diff --git a/tests/test_parser_x86att.py b/tests/test_parser_x86att.py index 820b6c5..72f273f 100755 --- a/tests/test_parser_x86att.py +++ b/tests/test_parser_x86att.py @@ -48,7 +48,9 @@ def test_directive_parser(self): self.assertEqual(self._get_directive(self.parser, "\t.text")[0].name, "text") self.assertEqual(len(self._get_directive(self.parser, "\t.text")[0].parameters), 0) self.assertEqual(self._get_directive(self.parser, "\t.align\t16,0x90")[0].name, "align") - self.assertEqual(len(self._get_directive(self.parser, "\t.align\t16,0x90")[0].parameters), 2) + self.assertEqual( + len(self._get_directive(self.parser, "\t.align\t16,0x90")[0].parameters), 2 + ) self.assertEqual(len(self._get_directive(self.parser, ".text")[0].parameters), 0) self.assertEqual( len(self._get_directive(self.parser, '.file\t1 "path/to/file.c"')[0].parameters), @@ -75,29 +77,29 @@ def test_directive_parser(self): ], ) self.assertEqual( - self._get_directive( - self.parser, "\t.section\t__TEXT,__literal16,16byte_literals" - )[0].parameters, + self._get_directive(self.parser, "\t.section\t__TEXT,__literal16,16byte_literals")[ + 0 + ].parameters, ["__TEXT", "__literal16", "16byte_literals"], ) self.assertEqual( self._get_directive(self.parser, "\t.align\t16,0x90")[0].parameters[1], "0x90" ) self.assertEqual( - self._get_directive(self.parser, " .byte 100,103,144 #IACA START")[0].name, + self._get_directive(self.parser, " .byte 100,103,144 #IACA START")[ + 0 + ].name, "byte", ) self.assertEqual( - self._get_directive( - self.parser, " .byte 100,103,144 #IACA START" - )[0].parameters[2], + self._get_directive(self.parser, " .byte 100,103,144 #IACA START")[ + 0 + ].parameters[2], "144", ) self.assertEqual( " ".join( - self._get_directive( - self.parser, " .byte 100,103,144 #IACA START" - )[1] + self._get_directive(self.parser, " .byte 100,103,144 #IACA START")[1] ), "IACA START", ) diff --git a/tests/test_semantics.py b/tests/test_semantics.py index 62e5881..cc744f4 100755 --- a/tests/test_semantics.py +++ b/tests/test_semantics.py @@ -189,13 +189,11 @@ def test_machine_model_various_functions(self): # test get_store_tp self.assertEqual( test_mm_x86.get_store_throughput( - MemoryOperand( - base=RegisterOperand(name="x"), offset=None, index=None, scale=1 - ) + MemoryOperand(base=RegisterOperand(name="x"), offset=None, index=None, scale=1) )[0][1], [[2, "237"], [2, "4"]], ) - + self.assertEqual( test_mm_x86.get_store_throughput( MemoryOperand( @@ -207,7 +205,7 @@ def test_machine_model_various_functions(self): )[0][1], [[1, "23"], [1, "4"]], ) - + self.assertEqual( test_mm_arm.get_store_throughput( MemoryOperand( @@ -235,9 +233,7 @@ def test_machine_model_various_functions(self): # test get_store_lt self.assertEqual( test_mm_x86.get_store_latency( - MemoryOperand( - base=RegisterOperand(name="x"), offset=None, index=None, scale=1 - ) + MemoryOperand(base=RegisterOperand(name="x"), offset=None, index=None, scale=1) ), 0, ) @@ -259,9 +255,7 @@ def test_machine_model_various_functions(self): # test default load tp self.assertEqual( test_mm_x86.get_load_throughput( - MemoryOperand( - base=RegisterOperand(name="x"), offset=None, index=None, scale=1 - ) + MemoryOperand(base=RegisterOperand(name="x"), offset=None, index=None, scale=1) )[0][1], [[1, "23"], [1, ["2D", "3D"]]], )