From e526546b1d78a5426a94efce31158679ef4ecec3 Mon Sep 17 00:00:00 2001 From: Amin Abdulrahman Date: Tue, 15 Oct 2024 15:07:39 +0200 Subject: [PATCH] Add Loop parser + examples for armv7m --- example.py | 35 ++++++++ slothy/targets/arm_v7m/arch_v7m.py | 129 ++++++++++------------------- 2 files changed, 77 insertions(+), 87 deletions(-) diff --git a/example.py b/example.py index d7dbd347..1240e9e3 100644 --- a/example.py +++ b/example.py @@ -293,6 +293,39 @@ def __init__(self, var="", arch=AArch64_Neon, target=Target_CortexA55): def core(self,slothy): slothy.config.variable_size=True slothy.optimize_loop("start") + +class Armv7mLoopSubs(Example): + def __init__(self, var="", arch=Arch_Armv7M, target=Target_CortexM7): + name = "loop_subs" + infile = name + + if var != "": + name += f"_{var}" + infile += f"_{var}" + name += f"_{target_label_dict[target]}" + + super().__init__(infile, name, rename=True, arch=arch, target=target) + + def core(self,slothy): + slothy.config.variable_size=True + slothy.optimize_loop("start") + +class Armv7mLoopCmp(Example): + def __init__(self, var="", arch=Arch_Armv7M, target=Target_CortexM7): + name = "loop_cmp" + infile = name + + if var != "": + name += f"_{var}" + infile += f"_{var}" + name += f"_{target_label_dict[target]}" + + super().__init__(infile, name, rename=True, arch=arch, target=target) + + def core(self,slothy): + slothy.config.variable_size=True + slothy.config.outputs = ["r6"] + slothy.optimize_loop("start") class CRT(Example): def __init__(self): @@ -2106,6 +2139,8 @@ def main(): # Loop examples AArch64LoopSubs(), LoopLe(), + Armv7mLoopSubs(), + Armv7mLoopCmp(), CRT(), diff --git a/slothy/targets/arm_v7m/arch_v7m.py b/slothy/targets/arm_v7m/arch_v7m.py index 1dfc4ae6..1abc41b1 100644 --- a/slothy/targets/arm_v7m/arch_v7m.py +++ b/slothy/targets/arm_v7m/arch_v7m.py @@ -5,7 +5,7 @@ from enum import Enum from functools import cache -from slothy.helper import SourceLine +from slothy.helper import SourceLine, Loop from sympy import simplify llvm_mca_arch = "arm" # TODO @@ -126,16 +126,13 @@ def unconditional(lbl): yield f"b {lbl}" -class Loop: - """Helper functions for parsing and writing simple loops in armv7m - - TODO: Generalize; current implementation too specific about shape of loop""" - - def __init__(self, lbl_start="1", lbl_end="2", loop_init="lr"): - self.lbl_start = lbl_start - self.lbl_end = lbl_end - self.loop_init = loop_init - +class CmpLoop(Loop): + 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_regex = r"^\s*(?P