[x264-devel] gas-preprocessor: Support conversion of additional arm instructions into thumb

Martin Storsjö git at videolan.org
Mon May 22 00:01:53 CEST 2017


x264 | branch: master | Martin Storsjö <martin at martin.st> | Fri Mar 24 11:33:41 2017 +0200| [9bffbabfecf0bda066362a1b76b62c5085257e18] | committer: Henrik Gramner

gas-preprocessor: Support conversion of additional arm instructions into thumb

Convert muls into mul+cmp.

Convert "and r0, sp, #xx" into "mov r0, sp", "and r0, r0, #xx".

Convert ldr with a too large shift into add+ldr. This only works in the
special case when the base register is the same as the target for the ldr.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=9bffbabfecf0bda066362a1b76b62c5085257e18
---

 tools/gas-preprocessor.pl | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tools/gas-preprocessor.pl b/tools/gas-preprocessor.pl
index 35d201de..afdfc9e1 100755
--- a/tools/gas-preprocessor.pl
+++ b/tools/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;
     }
 



More information about the x264-devel mailing list