]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
kvx: gas: fix the detection of negative powers of 2
authorPaul Iannetta <piannetta@kalrayinc.com>
Mon, 4 Sep 2023 13:31:53 +0000 (15:31 +0200)
committerPaul Iannetta <piannetta@kalrayinc.com>
Tue, 20 Feb 2024 11:07:57 +0000 (12:07 +0100)
The detection of negative powers of 2 was wrong and could lead to
well-formed bundles ending up taking more syllables than necessary.

gas/ChangeLog:

* config/kvx-parse.c (get_token_class): Use the signed value.
* testsuite/gas/kvx/np2-detection.d: New test.
* testsuite/gas/kvx/np2-detection.s: New test.

gas/config/kvx-parse.c
gas/testsuite/gas/kvx/np2-detection.d [new file with mode: 0644]
gas/testsuite/gas/kvx/np2-detection.s [new file with mode: 0644]

index 5cfb1fb676c85e6d099c778af3f9efa985dfb04d..0825b1823192b935f1de1181e234b08dab62d64e 100644 (file)
@@ -525,7 +525,7 @@ get_token_class (struct token_s *token, struct token_classes *classes, int insn_
           : strtoull (tok + (tok[0] == '-') + (tok[0] == '+'), NULL, 0));
       int64_t val = uval;
       int64_t pval = val < 0 ? -uval : uval;
-      int neg_power2_p = val < 0 && !(uval & (uval - 1));
+      int neg_power2_p = val < 0 && !(pval & (pval - 1));
       unsigned len = pval ? 8 * sizeof (pval) - __builtin_clzll (pval) : 0;
       while (class[cur].class_id != -1
             && ((unsigned) (class[cur].sz < 0
diff --git a/gas/testsuite/gas/kvx/np2-detection.d b/gas/testsuite/gas/kvx/np2-detection.d
new file mode 100644 (file)
index 0000000..b612277
--- /dev/null
@@ -0,0 +1,14 @@
+#as: -march=kv3-1
+#source: np2-detection.s
+#objdump: -d
+
+.*\/np2-detection.o:     file format elf64-kvx
+
+
+Disassembly of section .text:
+
+0000000000000000 <.text>:
+   0:  00 80 00 e1                                             addd \$r0 = \$r0, -512 \(0xfffffe00\)
+   4:  00 00 00 e0                                             make \$r0 = 0 \(0x0\)
+   8:  c0 ff 00 e0 c0 ff 00 e0 ff ff df 97                     make \$r0 = 9223372034707292159 \(0x7fffffff7fffffff\)
+  14:  ff ff ff 93 ff ff df 9f ff ff ff 1b                     make \$r0 = 9223372034707292159 \(0x7fffffff7fffffff\);;
diff --git a/gas/testsuite/gas/kvx/np2-detection.s b/gas/testsuite/gas/kvx/np2-detection.s
new file mode 100644 (file)
index 0000000..dfc3c26
--- /dev/null
@@ -0,0 +1,5 @@
+       addd $r0 = $r0, -512
+       make $r0 = 0x7fffffff7fffffff
+       make $r0 = 0x7fffffff7fffffff
+       make $r0 = 0
+;;