Skip to content

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesouza committed Mar 5, 2024
1 parent 18da151 commit 4fd59eb
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 90 deletions.
2 changes: 1 addition & 1 deletion osaca/data/create_db_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
sys.exit(1)
2 changes: 1 addition & 1 deletion osaca/data/generate_mov_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
sys.exit(1)
2 changes: 1 addition & 1 deletion osaca/data/model_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,4 @@ def main():


if __name__ == "__main__":
main()
main()
2 changes: 1 addition & 1 deletion osaca/data/pmevo_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,4 @@ def main():


if __name__ == "__main__":
main()
main()
6 changes: 1 addition & 5 deletions osaca/parser/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions osaca/parser/flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
24 changes: 13 additions & 11 deletions osaca/parser/parser_AArch64.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -547,17 +548,18 @@ 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)

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"""
Expand Down
9 changes: 5 additions & 4 deletions osaca/parser/parser_x86att.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion osaca/parser/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def name(self):
@name.setter
def name(self, name):
self._name = name

@property
def width(self):
return self._width
Expand Down
83 changes: 55 additions & 28 deletions osaca/semantics/hw_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -516,7 +543,7 @@ def dump(self, stream=None):
yaml = self._create_yaml_object()
if not stream:
stream = StringIO()

yaml.dump(
{
k: v
Expand All @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions osaca/semantics/kernel_dg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, []
Expand Down
18 changes: 10 additions & 8 deletions tests/test_parser_AArch64.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
24 changes: 13 additions & 11 deletions tests/test_parser_x86att.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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",
)
Expand Down
Loading

0 comments on commit 4fd59eb

Please sign in to comment.