diff --git a/example.py b/example.py index 8e7bb25d..5074fe48 100644 --- a/example.py +++ b/example.py @@ -703,7 +703,7 @@ def __init__(self, var="", arch=Arch_Armv7M, target=Target_CortexM7): def core(self,slothy): slothy.config.variable_size=True - slothy.optimize_loop("start") + slothy.optimize_loop("start", forced_loop_type=Arch_Armv7M.SubsLoop) class Armv7mLoopCmp(Example): def __init__(self, var="", arch=Arch_Armv7M, target=Target_CortexM7): @@ -720,7 +720,7 @@ def __init__(self, var="", arch=Arch_Armv7M, target=Target_CortexM7): def core(self,slothy): slothy.config.variable_size=True slothy.config.outputs = ["r6"] - slothy.optimize_loop("start") + slothy.optimize_loop("start", forced_loop_type=Arch_Armv7M.CmpLoop) class Armv7mLoopVmovCmp(Example): def __init__(self, var="", arch=Arch_Armv7M, target=Target_CortexM7): diff --git a/slothy/core/slothy.py b/slothy/core/slothy.py index d2880ded..501169a3 100644 --- a/slothy/core/slothy.py +++ b/slothy/core/slothy.py @@ -450,7 +450,12 @@ def fusion_loop(self, loop_lbl, forced_loop_type=None, **kwargs): pre , body, post, _, other_data, loop = \ self.arch.Loop.extract(self.source, loop_lbl, forced_loop_type=forced_loop_type) - loop_cnt = other_data['cnt'] + + try: + loop_cnt = other_data['cnt'] + except KeyError: + loop_cnt = Nonee + indentation = AsmHelper.find_indentation(body) body_ssa = SourceLine.read_multiline(loop.start(loop_cnt)) + \ @@ -472,7 +477,11 @@ def optimize_loop(self, loop_lbl, postamble_label=None, forced_loop_type=None): early, body, late, _, other_data, loop = \ self.arch.Loop.extract(self.source, loop_lbl, forced_loop_type=forced_loop_type) - loop_cnt = other_data['cnt'] + + try: + loop_cnt = other_data['cnt'] + except KeyError: + loop_cnt = None # Check if the body has a dominant indentation indentation = AsmHelper.find_indentation(body) diff --git a/slothy/targets/arm_v7m/arch_v7m.py b/slothy/targets/arm_v7m/arch_v7m.py index abac28ac..56e1f4ed 100644 --- a/slothy/targets/arm_v7m/arch_v7m.py +++ b/slothy/targets/arm_v7m/arch_v7m.py @@ -297,6 +297,105 @@ def end(self, other, indentation=0): yield f'{indent}cmp {other["cnt"]}, {other["end"]}' yield f'{indent}bne {lbl_start}' + +class BranchLoop(Loop): + """ + More general loop type that just considers the branch instruction as part of the boundary. + This can help to improve performance as the instructions that belong to handling the loop can be considered by SLOTHY aswell. + + Note: This loop type is still rather experimental. It has a lot of logics inside as it needs to be able to "understand" a variety of different ways to express loops, e.g., how counters get incremented, how registers marking the end of the loop need to be modified in case of software pipelining etc. Currently, this type covers the three other types we offer above, namely `SubsLoop`, `CmpLoop`, and `VmovCmpLoop`. + + For examples, we refer to the classes `SubsLoop`, `CmpLoop`, and `VmovCmpLoop`. + """ + def __init__(self, lbl="lbl", lbl_start="1", lbl_end="2", loop_init="lr") -> None: + super().__init__(lbl_start=lbl_start, lbl_end=lbl_end, loop_init=loop_init) + self.lbl = lbl + self.lbl_regex = r"^\s*(?P