]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: Fixed precedence of expression operators in instructions
authorLulu Cai <cailulu@loongson.cn>
Mon, 2 Sep 2024 04:05:54 +0000 (12:05 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Mon, 9 Sep 2024 07:11:53 +0000 (15:11 +0800)
The precedence of the operators "+" and "-" in the current loongarch
instruction expression is higher than "<<" and ">>", which is different
from the explanation in the user guide.

We modified the precedence of "<<" and ">>" to be higher than "+" and "-".

gas/config/loongarch-parse.y
gas/testsuite/gas/loongarch/insn_expr.d [new file with mode: 0644]
gas/testsuite/gas/loongarch/insn_expr.s [new file with mode: 0644]

index 63a4fcf0cdab9b63453e84f9ee67c98fd9c146b6..0607248bb419abaf3db9cf305ba36d8d924cc42b 100644 (file)
@@ -368,24 +368,24 @@ multiplicative_expression
        | multiplicative_expression '%' unary_expression {emit_bin ('%');}
        ;
 
-additive_expression
+shift_expression
        : multiplicative_expression
-       | additive_expression '+' multiplicative_expression {emit_bin ('+');}
-       | additive_expression '-' multiplicative_expression {emit_bin ('-');}
+       | shift_expression LEFT_OP multiplicative_expression {emit_bin (LEFT_OP);}
+       | shift_expression RIGHT_OP multiplicative_expression {emit_bin (RIGHT_OP);}
        ;
 
-shift_expression
-       : additive_expression
-       | shift_expression LEFT_OP additive_expression {emit_bin (LEFT_OP);}
-       | shift_expression RIGHT_OP additive_expression {emit_bin (RIGHT_OP);}
+additive_expression
+       : shift_expression
+       | additive_expression '+' shift_expression {emit_bin ('+');}
+       | additive_expression '-' shift_expression {emit_bin ('-');}
        ;
 
 relational_expression
-       : shift_expression
-       | relational_expression '<' shift_expression {emit_bin ('<');}
-       | relational_expression '>' shift_expression {emit_bin ('>');}
-       | relational_expression LE_OP shift_expression {emit_bin (LE_OP);}
-       | relational_expression GE_OP shift_expression {emit_bin (GE_OP);}
+       : additive_expression
+       | relational_expression '<' additive_expression {emit_bin ('<');}
+       | relational_expression '>' additive_expression {emit_bin ('>');}
+       | relational_expression LE_OP additive_expression {emit_bin (LE_OP);}
+       | relational_expression GE_OP additive_expression {emit_bin (GE_OP);}
        ;
 
 equality_expression
diff --git a/gas/testsuite/gas/loongarch/insn_expr.d b/gas/testsuite/gas/loongarch/insn_expr.d
new file mode 100644 (file)
index 0000000..9abc711
--- /dev/null
@@ -0,0 +1,10 @@
+#as:
+#objdump: -d
+
+.*:     file format .*
+
+
+Disassembly of section \.text:
+
+0+ <\.text>:
+   0:  02c00ca4        addi.d          \$a0, \$a1, 3
diff --git a/gas/testsuite/gas/loongarch/insn_expr.s b/gas/testsuite/gas/loongarch/insn_expr.s
new file mode 100644 (file)
index 0000000..3b9ef08
--- /dev/null
@@ -0,0 +1 @@
+addi.d    $a0,$a1,(8 >> 2 + 1)