Commit a73c760da2 for qemu.org
commit a73c760da26c91846971bccec1c32a0236572927
Author: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Date: Thu Oct 29 11:18:19 2026 +0100
tests/tcg/mipsel: Test MIPS32R6 BALC
Add a branch group, starting with BALC.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Message-ID: <20261030182546.2508-12-philmd@oss.qualcomm.com>
diff --git a/tests/tcg/mipsel/meson.build b/tests/tcg/mipsel/meson.build
index a7af2f1619..fc27a4f6eb 100644
--- a/tests/tcg/mipsel/meson.build
+++ b/tests/tcg/mipsel/meson.build
@@ -68,6 +68,7 @@ tests = []
tests_mips32r6 = [
'test_mips32r6_bitops.c',
+ 'test_mips32r6_branch.c',
'test_mips32r6_logic.c',
'test_mips32r6_multiply.c',
'test_mips32r6_pcrel.c',
diff --git a/tests/tcg/mipsel/test_mips32r6_branch.c b/tests/tcg/mipsel/test_mips32r6_branch.c
new file mode 100644
index 0000000000..6db2eb6f67
--- /dev/null
+++ b/tests/tcg/mipsel/test_mips32r6_branch.c
@@ -0,0 +1,56 @@
+/*
+ * MIPS32R6 tests: compact branches and jumps instructions
+ *
+ * Author:
+ * Philippe Mathieu-Daudé
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
+
+#include "../include/tap.h"
+
+/*
+ * BALC: branch and link, no delay slot. The callee records $ra and returns;
+ * $ra must be the address of the instruction following BALC (label 2).
+ */
+static int test_balc(void)
+{
+ uint32_t seen, expected;
+
+ __asm__ volatile (
+ ".set push\n\t"
+ ".set noreorder\n\t"
+ "move %0, $zero\n\t"
+ "balc 1f\n\t"
+ "2: bc 3f\n\t"
+ "1: move %0, $ra\n\t"
+ "jrc $ra\n\t"
+ "3: lapc %1, 2b\n\t"
+ ".set pop\n\t"
+ : "=&r" (seen), "=&r" (expected)
+ :
+ : "ra");
+
+ if (seen != expected) {
+ TAP_INFO("BALC: ra 0x%08x expected 0x%08x", seen, expected);
+ }
+ return seen != expected;
+}
+
+static int run(const char *name, int (*test)(void))
+{
+ int ret = test();
+
+ tap_report(!ret, "MIPS32R6 branch %s", name);
+ return ret;
+}
+
+int main(void)
+{
+ TAP_START();
+ run("BALC", test_balc);
+
+ return tap_done();
+}