All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Cain <brian.cain@oss.qualcomm.com>
To: qemu-devel@nongnu.org
Cc: "Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Brian Cain" <brian.cain@oss.qualcomm.com>,
	sid.manning@oss.qualcomm.com
Subject: [PATCH 08/17] tests/tcg/hexagon: add cond call, tstbit-jump, and endloop01 tests
Date: Sat,  5 Sep 2026 11:09:40 -0700	[thread overview]
Message-ID: <20260905180949.1852673-9-brian.cain@oss.qualcomm.com> (raw)
In-Reply-To: <20260905180949.1852673-1-brian.cain@oss.qualcomm.com>

Test conditional callr, compound tstbit0-and-jump instructions and
endloop01.  These exercise previously uncovered branch paths in translate.c.

Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
---
 tests/tcg/hexagon/test_cond_branch.c | 162 +++++++++++++++++++++++++++
 tests/tcg/hexagon/meson.build        |   1 +
 2 files changed, 163 insertions(+)
 create mode 100644 tests/tcg/hexagon/test_cond_branch.c

diff --git a/tests/tcg/hexagon/test_cond_branch.c b/tests/tcg/hexagon/test_cond_branch.c
new file mode 100644
index 00000000000..73be8fbb43c
--- /dev/null
+++ b/tests/tcg/hexagon/test_cond_branch.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+/*
+ * Test conditional calls, compound testbit0-and-jump instructions,
+ * and endloop01 (dual hardware loop end).
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+
+int err;
+
+#include "hex_test.h"
+
+/* Target function for conditional calls */
+static int call_target_val;
+
+__attribute__((noinline))
+static void call_target(void)
+{
+    call_target_val = 42;
+}
+
+/*
+ * Test conditional call: if (Pu) callr Rs / if (!Pu) callr Rs
+ */
+static void check_cond_call(void)
+{
+    void (*fn)(void) = call_target;
+
+    /*
+     * callr clobbers all caller-saved registers.
+     * Hexagon caller-saved: r0-r5, r14-r15, r28, p0-p3.
+     */
+
+    /* if (p0) callr Rs -- predicate true */
+    call_target_val = 0;
+    asm volatile("p0 = cmp.eq(%[one], %[one])\n\t"  /* p0 = true */
+                 "if (p0) callr %[fn]\n\t"
+                 :
+                 : [one] "r"(1), [fn] "r"(fn)
+                 : "r0", "r1", "r2", "r3", "r4", "r5",
+                   "r14", "r15", "r28", "r31",
+                   "p0", "p1", "p2", "p3", "memory");
+    check32(call_target_val, 42);
+
+    /* if (!p0) callr Rs -- predicate true, so !p0 is false */
+    call_target_val = 0;
+    asm volatile("p0 = cmp.eq(%[one], %[one])\n\t"  /* p0 = true */
+                 "if (!p0) callr %[fn]\n\t"
+                 :
+                 : [one] "r"(1), [fn] "r"(fn)
+                 : "r0", "r1", "r2", "r3", "r4", "r5",
+                   "r14", "r15", "r28", "r31",
+                   "p0", "p1", "p2", "p3", "memory");
+    check32(call_target_val, 0);
+
+    /* if (!p0) callr Rs -- predicate false, so !p0 is true */
+    call_target_val = 0;
+    asm volatile("p0 = cmp.eq(%[a], %[b])\n\t"  /* p0 = false (1 != 2) */
+                 "if (!p0) callr %[fn]\n\t"
+                 :
+                 : [a] "r"(1), [b] "r"(2), [fn] "r"(fn)
+                 : "r0", "r1", "r2", "r3", "r4", "r5",
+                   "r14", "r15", "r28", "r31",
+                   "p0", "p1", "p2", "p3", "memory");
+    check32(call_target_val, 42);
+}
+
+/*
+ * Test compound testbit0-and-jump.
+ * p0 = tstbit(Rs, #0); if ([!]p0.new) jump:t/nt target
+ */
+static void check_tstbit0_jump(void)
+{
+    uint32_t result;
+
+    /* Rs has bit0 = 1, test "if (p0.new) jump" -> should jump */
+    result = 0;
+    asm volatile(
+        "{\n\t"
+        "    p0 = tstbit(%[val], #0)\n\t"
+        "    if (p0.new) jump:t 1f\n\t"
+        "}\n\t"
+        "%[res] = #0\n\t"
+        "jump 2f\n\t"
+        "1:\n\t"
+        "%[res] = #1\n\t"
+        "2:\n\t"
+        : [res] "=r"(result)
+        : [val] "r"(0x5)  /* bit 0 is set */
+        : "p0");
+    check32(result, 1);
+
+    /* Rs has bit0 = 0, test "if (p0.new) jump" -> should NOT jump */
+    result = 0;
+    asm volatile(
+        "{\n\t"
+        "    p0 = tstbit(%[val], #0)\n\t"
+        "    if (p0.new) jump:t 1f\n\t"
+        "}\n\t"
+        "%[res] = #0\n\t"
+        "jump 2f\n\t"
+        "1:\n\t"
+        "%[res] = #1\n\t"
+        "2:\n\t"
+        : [res] "=r"(result)
+        : [val] "r"(0x4)  /* bit 0 is clear */
+        : "p0");
+    check32(result, 0);
+
+    /* Rs has bit0 = 0, test "if (!p0.new) jump" -> should jump */
+    result = 0;
+    asm volatile(
+        "{\n\t"
+        "    p0 = tstbit(%[val], #0)\n\t"
+        "    if (!p0.new) jump:t 1f\n\t"
+        "}\n\t"
+        "%[res] = #0\n\t"
+        "jump 2f\n\t"
+        "1:\n\t"
+        "%[res] = #1\n\t"
+        "2:\n\t"
+        : [res] "=r"(result)
+        : [val] "r"(0x4)  /* bit 0 is clear */
+        : "p0");
+    check32(result, 1);
+}
+
+/*
+ * Test endloop01: a packet that terminates both loop0 and loop1.
+ * Outer loop runs 3 iterations, inner loop runs 4.
+ */
+static void check_endloop01(void)
+{
+    uint32_t count;
+
+    asm volatile(
+        "%[cnt] = #0\n\t"
+        "loop1(1f, #3)\n\t"    /* outer loop: 3 iterations */
+        "1:\n\t"
+        "loop0(2f, #4)\n\t"    /* inner loop: 4 iterations */
+        "2:\n\t"
+        "{ %[cnt] = add(%[cnt], #1) }:endloop01\n\t"
+        : [cnt] "=r"(count));
+
+    /* 3 outer * 4 inner = 12 total iterations */
+    check32(count, 12);
+}
+
+int main(void)
+{
+    check_cond_call();
+    check_tstbit0_jump();
+    check_endloop01();
+
+    puts(err ? "FAIL" : "PASS");
+    return err ? 1 : 0;
+}
diff --git a/tests/tcg/hexagon/meson.build b/tests/tcg/hexagon/meson.build
index 6c8e26876af..aa176e56883 100644
--- a/tests/tcg/hexagon/meson.build
+++ b/tests/tcg/hexagon/meson.build
@@ -73,6 +73,7 @@ tests += {
   'test_call.S': {'cflags': asmflags},
   'test_clobber.S': {'cflags': asmflags},
   'test_cmp.S': {'cflags': asmflags},
+  'test_cond_branch.c': {'cflags': cflags},
   'test_dotnew.S': {'cflags': asmflags},
   'test_ext.S': {'cflags': asmflags},
   'test_fibonacci.S': {'cflags': asmflags},
-- 
2.34.1


  parent reply	other threads:[~2026-09-05 18:11 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-05 18:09 [PATCH 00/17] hexagon: TCG test coverage + ubsan fixes Brian Cain
2026-09-05 18:09 ` [PATCH 01/17] tests/tcg/hexagon: fix undefined signed left shift in circ.c Brian Cain
2026-09-08 15:54   ` Sid Manning
2026-09-05 18:09 ` [PATCH 02/17] tests/tcg/hexagon: fix undefined signed left shift in brev.c Brian Cain
2026-09-09 14:43   ` Sid Manning
2026-09-05 18:09 ` [PATCH 03/17] tests/tcg/hexagon: fix undefined signed integer overflow in hvx_misc Brian Cain
2026-09-09 14:50   ` Sid Manning
2026-09-05 18:09 ` [PATCH 04/17] tests/tcg/hexagon: fix undefined integer overflow in v69_hvx.c Brian Cain
2026-09-09 14:51   ` Sid Manning
2026-09-05 18:09 ` [PATCH 05/17] tests/tcg/multiarch: suppress UBSan for float-to-int conversions Brian Cain
2026-09-14 19:43   ` Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 06/17] tests/tcg/hexagon: add FP classification, conversion, and fixup tests Brian Cain
2026-09-14 19:43   ` Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 07/17] tests/tcg/hexagon: add bit interleave and convergent rounding tests Brian Cain
2026-09-10 17:54   ` Sid Manning
2026-09-05 18:09 ` Brian Cain [this message]
2026-09-14 19:44   ` [PATCH 08/17] tests/tcg/hexagon: add cond call, tstbit-jump, and endloop01 tests Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 09/17] tests/tcg/hexagon: add dczeroa cache line zero test Brian Cain
2026-09-10 18:14   ` Sid Manning
2026-09-05 18:09 ` [PATCH 10/17] tests/tcg/hexagon: add HVX vwhist tests Brian Cain
2026-09-14 21:21   ` Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 11/17] tests/tcg/hexagon: add sfrecipa edge case tests Brian Cain
2026-09-14 21:22   ` Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 12/17] tests/tcg/hexagon: add dfmpyhh Brian Cain
2026-09-14 21:22   ` Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 13/17] tests/tcg/hexagon: add unconditional store-immediate tests Brian Cain
2026-09-14 21:23   ` Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 14/17] tests/tcg/hexagon: add predicate register transfer test Brian Cain
2026-09-14 21:23   ` Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 15/17] tests/tcg/hexagon: add rounding conv, sffma:lib, and sfinvsqrta Brian Cain
2026-09-14 21:23   ` Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 16/17] tests/tcg/hexagon: add scalar+HVX and masked store tests Brian Cain
2026-09-14 21:24   ` Pierrick Bouvier
2026-09-05 18:09 ` [PATCH 17/17] tests/tcg/hexagon: add decbin MPS test case Brian Cain
2026-09-14 21:24   ` Pierrick Bouvier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260905180949.1852673-9-brian.cain@oss.qualcomm.com \
    --to=brian.cain@oss.qualcomm.com \
    --cc=alex.bennee@linaro.org \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sid.manning@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.