[GASPP] Support converting more instructions to their thumb equivalent

Message ID 20170504113429.91617-1-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö May 4, 2017, 11:34 a.m.
---
These are used for supporting building x264 for windows/arm with
msvc/armasm (currently in the x264 sandbox repo).
---
 gas-preprocessor.pl | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Martin Storsjö Aug. 28, 2017, 10:46 a.m. | #1
On Thu, 4 May 2017, Martin Storsjo wrote:

> ---
> These are used for supporting building x264 for windows/arm with
> msvc/armasm (currently in the x264 sandbox repo).
> ---
> gas-preprocessor.pl | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)

It seems I never got any feedback on this, but this has been merged in 
x264 master for some time already, so I'll push this soon.

// Martin

Patch

diff --git a/gas-preprocessor.pl b/gas-preprocessor.pl
index 35d201d..afdfc9e 100755
--- a/gas-preprocessor.pl
+++ b/gas-preprocessor.pl
@@ -951,6 +951,20 @@  sub handle_serialized_line {
         $line =~ s/stm(?:db|fd)\s+sp!\s*,\s*\{([^,-]+)\}/str $1, [sp, #-4]!/g;
         $line =~ s/ldm(?:ia|fd)?\s+sp!\s*,\s*\{([^,-]+)\}/ldr $1, [sp], #4/g;
 
+        # Convert muls into mul+cmp
+        $line =~ s/muls\s+(\w+),\s*(\w+)\,\s*(\w+)/mul $1, $2, $3\n\tcmp $1, #0/g;
+
+        # Convert "and r0, sp, #xx" into "mov r0, sp", "and r0, r0, #xx"
+        $line =~ s/and\s+(\w+),\s*(sp|r13)\,\s*#(\w+)/mov $1, $2\n\tand $1, $1, #$3/g;
+
+        # Convert "ldr r0, [r0, r1, lsl #6]" where the shift is >3 (which
+        # can't be handled in thumb) into "add r0, r0, r1, lsl #6",
+        # "ldr r0, [r0]", for the special case where the same address is
+        # used as base and target for the ldr.
+        if ($line =~ /(ldr[bh]?)\s+(\w+),\s*\[\2,\s*(\w+),\s*lsl\s*#(\w+)\]/ and $4 > 3) {
+            $line =~ s/(ldr[bh]?)\s+(\w+),\s*\[\2,\s*(\w+),\s*lsl\s*#(\w+)\]/add $2, $2, $3, lsl #$4\n\t$1 $2, [$2]/;
+        }
+
         $line =~ s/\.arm/.thumb/x;
     }