Signed-off-by: Richard Henderson <[email protected]>
---
tests/tcg/arm/issue4448.c | 51 +++++++++++++++++++++++++++++++++++++++
tests/tcg/arm/meson.build | 1 +
2 files changed, 52 insertions(+)
create mode 100644 tests/tcg/arm/issue4448.c
diff --git a/tests/tcg/arm/issue4448.c b/tests/tcg/arm/issue4448.c
new file mode 100644
index 00000000000..180ff4029a2
--- /dev/null
+++ b/tests/tcg/arm/issue4448.c
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <assert.h>
+#include <stdint.h>
+
+/* Signed 64-bit product, constant operand first then second. */
+#define SMULL_CONST_LHS(k, x, lo, hi) \
+ __asm__("mov r0, #" #k "\n\tsmull %0, %1, r0, %2" \
+ : "=&r"(lo), "=&r"(hi) : "r"(x) : "r0", "cc")
+
+#define SMULL_CONST_RHS(k, x, lo, hi) \
+ __asm__("mov r0, #" #k "\n\tsmull %0, %1, %2, r0" \
+ : "=&r"(lo), "=&r"(hi) : "r"(x) : "r0", "cc")
+
+/* Unsigned 64-bit product, for contrast: this one is folded correctly. */
+#define UMULL_CONST_LHS(k, x, lo, hi) \
+ __asm__("mov r0, #" #k "\n\tumull %0, %1, r0, %2" \
+ : "=&r"(lo), "=&r"(hi) : "r"(x) : "r0", "cc")
+
+static int64_t s64(int32_t hi, int32_t lo)
+{
+ return ((int64_t)hi << 32) | (uint32_t)lo;
+}
+
+static uint64_t u64(int32_t hi, int32_t lo)
+{
+ return ((uint64_t)(uint32_t)hi << 32) | (uint32_t)lo;
+}
+
+int main(void)
+{
+ static const int32_t values[] = { 1961612, -1479053948, -7, 0 };
+
+ for (unsigned i = 0; i < sizeof(values) / sizeof(values[0]); i++) {
+ int32_t x = values[i];
+ int32_t lo, hi;
+
+ SMULL_CONST_LHS(1, x, lo, hi);
+ assert(x == s64(hi, lo));
+
+ SMULL_CONST_RHS(1, x, lo, hi);
+ assert(x == s64(hi, lo));
+
+ UMULL_CONST_LHS(1, x, lo, hi);
+ assert((uint32_t)x == u64(hi, lo));
+
+ SMULL_CONST_LHS(0, x, lo, hi);
+ assert(0 == u64(hi, lo));
+ }
+ return 0;
+}
diff --git a/tests/tcg/arm/meson.build b/tests/tcg/arm/meson.build
index 1b491cea026..5c2af2189c5 100644
--- a/tests/tcg/arm/meson.build
+++ b/tests/tcg/arm/meson.build
@@ -39,6 +39,7 @@ tests += {
'expected_output': 'fcvt.ref',
},
'pcalign-a32.c': {'cflags': ['-marm']},
+ 'issue4448.c': {},
}
# Vector SHA1
--
2.53.0