[GASPP,4/6] Convert ldr/str/ldrb/strb etc into ldurb, when the offset is negative

Message ID 1508182699-10436-5-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö Oct. 16, 2017, 7:38 p.m.
---
 gas-preprocessor.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Janne Grunau Oct. 18, 2017, 6:52 a.m. | #1
On 2017-10-16 22:38:17 +0300, Martin Storsjö wrote:
> ---
>  gas-preprocessor.pl | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/gas-preprocessor.pl b/gas-preprocessor.pl
> index 552ed0c..b650c39 100755
> --- a/gas-preprocessor.pl
> +++ b/gas-preprocessor.pl
> @@ -1012,6 +1012,19 @@ sub handle_serialized_line {
>              # variant/combination of prfum tested so far, but it can be
>              # left out without any
>              $line =~ s/prfum.*\]//;
> +
> +            # Convert "ldrb w0, [x0, #-1]" into "ldurb w0, [x0, #-1]".
> +            # Don't do this for forms with writeback though.
> +            if ($line =~ /(ld|st)(r[bh]?)\s+(\w+)\s*,\s*\[\s*(\w+)\s*,\s*#([^\]]+)\s*\][^!]/) {
> +              my $instr = $1;
> +              my $suffix = $2;
> +              my $target = $3;
> +              my $base = $4;
> +              my $offset = eval_expr($5);
> +              if ($offset < 0) {
> +                $line =~ s/$instr$suffix/${instr}u$suffix/;
> +              }
> +            }
>          }
>          # armasm is unable to parse &0x - add spacing
>          $line =~ s/&0x/& 0x/g;

patch ok-ish but we should fix the offending code too. ldr? without 
writeback supports only unsigned offsets and gas seems to fix it for us.

Janne
Martin Storsjö Oct. 18, 2017, 7:40 a.m. | #2
On Wed, 18 Oct 2017, Janne Grunau wrote:

> On 2017-10-16 22:38:17 +0300, Martin Storsjö wrote:
>> ---
>>  gas-preprocessor.pl | 13 +++++++++++++
>>  1 file changed, 13 insertions(+)
>> 
>> diff --git a/gas-preprocessor.pl b/gas-preprocessor.pl
>> index 552ed0c..b650c39 100755
>> --- a/gas-preprocessor.pl
>> +++ b/gas-preprocessor.pl
>> @@ -1012,6 +1012,19 @@ sub handle_serialized_line {
>>              # variant/combination of prfum tested so far, but it can be
>>              # left out without any
>>              $line =~ s/prfum.*\]//;
>> +
>> +            # Convert "ldrb w0, [x0, #-1]" into "ldurb w0, [x0, #-1]".
>> +            # Don't do this for forms with writeback though.
>> +            if ($line =~ /(ld|st)(r[bh]?)\s+(\w+)\s*,\s*\[\s*(\w+)\s*,\s*#([^\]]+)\s*\][^!]/) {
>> +              my $instr = $1;
>> +              my $suffix = $2;
>> +              my $target = $3;
>> +              my $base = $4;
>> +              my $offset = eval_expr($5);
>> +              if ($offset < 0) {
>> +                $line =~ s/$instr$suffix/${instr}u$suffix/;
>> +              }
>> +            }
>>          }
>>          # armasm is unable to parse &0x - add spacing
>>          $line =~ s/&0x/& 0x/g;
>
> patch ok-ish but we should fix the offending code too. ldr? without 
> writeback supports only unsigned offsets and gas seems to fix it for us.

Ok, patch sent to x264.

// Martin

Patch

diff --git a/gas-preprocessor.pl b/gas-preprocessor.pl
index 552ed0c..b650c39 100755
--- a/gas-preprocessor.pl
+++ b/gas-preprocessor.pl
@@ -1012,6 +1012,19 @@  sub handle_serialized_line {
             # variant/combination of prfum tested so far, but it can be
             # left out without any
             $line =~ s/prfum.*\]//;
+
+            # Convert "ldrb w0, [x0, #-1]" into "ldurb w0, [x0, #-1]".
+            # Don't do this for forms with writeback though.
+            if ($line =~ /(ld|st)(r[bh]?)\s+(\w+)\s*,\s*\[\s*(\w+)\s*,\s*#([^\]]+)\s*\][^!]/) {
+              my $instr = $1;
+              my $suffix = $2;
+              my $target = $3;
+              my $base = $4;
+              my $offset = eval_expr($5);
+              if ($offset < 0) {
+                $line =~ s/$instr$suffix/${instr}u$suffix/;
+              }
+            }
         }
         # armasm is unable to parse &0x - add spacing
         $line =~ s/&0x/& 0x/g;