slothy-optimizer / slothy

Assembly super-optimization via constraint solving
https://slothy-optimizer.github.io/slothy/
Other
165 stars 10 forks source link

Allow spaces instead of commas in macro definitions and invocations #62

Closed mkannwischer closed 4 months ago

mkannwischer commented 4 months ago

The GNU as [1] allows macro definitons and invoation to separate arguments by spaces or commas. So far SLOTHY cannot handle spaces in both definitions and invocations. This commit adds that functionality.

Here is some minimal examples for which SLOTHY currently fails:

.macro mx aa bb cc
    add \aa, \bb, \cc
.endm

.macro my aa, bb, cc
    add \aa, \bb, \cc
.endm

start:
mx x3, x1, x2
mx x4  x1  x2
my x5, x1, x2
my x6  x1  x2
end:

The following SLOTHY calls can be used to test:

import logging
import sys
from slothy import Slothy

import slothy.targets.aarch64.aarch64_neon as AArch64_Neon
import slothy.targets.aarch64.cortex_a55 as Target_CortexA55

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

arch = AArch64_Neon
target = Target_CortexA55

slothy = Slothy(arch, target)

slothy.load_source_from_file("sample.s")
slothy.config.outputs=["x3", "x4", "x5", "x6"]

slothy.optimize(start="start", end="end")
slothy.write_source_to_file("opt.s")

[1] https://ftp.gnu.org/old-gnu/Manuals/gas-2.9.1/html_node/as_107.html

mkannwischer commented 4 months ago

~Don't merge this yet. I'm investigating another problem that have been caused by this change.~ All good.