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 15/17] tests/tcg/hexagon: add rounding conv, sffma:lib, and sfinvsqrta
Date: Sat,  5 Sep 2026 11:09:47 -0700	[thread overview]
Message-ID: <20260905180949.1852673-16-brian.cain@oss.qualcomm.com> (raw)
In-Reply-To: <20260905180949.1852673-1-brian.cain@oss.qualcomm.com>

Add round-to-nearest float-to-int conversion tests for the non-:chop variants,
sfmpy:lib with Inf-Inf to verify exception suppression, and sfinvsqrta
with a denormal input.

Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
---
 tests/tcg/hexagon/fpstuff.c | 99 +++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)

diff --git a/tests/tcg/hexagon/fpstuff.c b/tests/tcg/hexagon/fpstuff.c
index 0f28a218d84..9ea79c617d9 100644
--- a/tests/tcg/hexagon/fpstuff.c
+++ b/tests/tcg/hexagon/fpstuff.c
@@ -1017,6 +1017,102 @@ static void check_dfmpyhh(void)
     check64_ne(df_exp(result), 0x7FF0000000000000ULL);
 }
 
+/*
+ * Round-to-nearest float-to-int conversions with normal values.
+ * These test the non-:chop variants which use the USR rounding mode.
+ */
+static void check_conv_rnd(void)
+{
+    uint32_t res32;
+    uint64_t res64;
+
+    /* convert_sf2w(1.5) rounds to nearest-even = 2 */
+    asm(CLEAR_FPSTATUS
+        "%[res] = convert_sf2w(%[val])\n\t"
+        : [res] "=r"(res32)
+        : [val] "r"(0x3fc00000)    /* 1.5f */
+        : "r2", "usr");
+    check32(res32, 2);
+
+    /* convert_sf2d(1.5) = 2 */
+    asm(CLEAR_FPSTATUS
+        "%[res] = convert_sf2d(%[val])\n\t"
+        : [res] "=r"(res64)
+        : [val] "r"(0x3fc00000)    /* 1.5f */
+        : "r2", "usr");
+    check64(res64, 2ULL);
+
+    /* convert_df2w(1.5) = 2 */
+    asm(CLEAR_FPSTATUS
+        "%[res] = convert_df2w(%[val])\n\t"
+        : [res] "=r"(res32)
+        : [val] "r"(0x3FF8000000000000ULL)    /* 1.5 */
+        : "r2", "usr");
+    check32(res32, 2);
+
+    /* convert_df2d(1.5) = 2 */
+    asm(CLEAR_FPSTATUS
+        "%[res] = convert_df2d(%[val])\n\t"
+        : [res] "=r"(res64)
+        : [val] "r"(0x3FF8000000000000ULL)    /* 1.5 */
+        : "r2", "usr");
+    check64(res64, 2ULL);
+}
+
+/*
+ * Test sfmpy:lib with Inf-Inf.
+ *
+ * Rx += sfmpy(Rs, Rt):lib with Rx = -Inf, Rs*Rt -> +Inf
+ * Inf - Inf is invalid, but the :lib variant suppresses the
+ * exception and returns zero.
+ */
+static void check_sffma_lib_inf(void)
+{
+    uint32_t result;
+
+    /* +Inf += sfmpy(+Inf, 1.0):lib -> Inf (no exception, normal) */
+    result = SF_INF;
+    asm(CLEAR_FPSTATUS
+        "%[res] += sfmpy(%[a], %[b]):lib\n\t"
+        : [res] "+r"(result)
+        : [a] "r"(SF_INF), [b] "r"(SF_one)
+        : "r2", "usr");
+    check32(result, SF_INF);
+
+    /*
+     * -Inf += sfmpy(+Inf, 1.0):lib -> Inf - Inf = invalid
+     * The :lib variant should return zero for Inf - Inf.
+     */
+    result = SF_INF | (1u << 31);    /* -Inf */
+    asm(CLEAR_FPSTATUS
+        "%[res] += sfmpy(%[a], %[b]):lib\n\t"
+        : [res] "+r"(result)
+        : [a] "r"(SF_INF), [b] "r"(SF_one)
+        : "r2", "usr");
+    check32(result, 0);
+}
+
+/*
+ * Test sfinvsqrta with a denormal input.
+ */
+static void check_invsqrta_denorm(void)
+{
+    uint32_t result;
+    uint32_t predval;
+    uint32_t exp_bits;
+
+    /* Denormal positive float: 0x00400000 (small denorm) */
+    asm volatile("%[res],p0 = sfinvsqrta(%[val])\n\t"
+                 "%[pred] = p0\n\t"
+                 : [res] "=r"(result), [pred] "=r"(predval)
+                 : [val] "r"(SF_denorm)
+                 : "p0");
+    /* Result should be a valid float (not NaN/zero) */
+    check32_ne(result, 0);
+    exp_bits = (result >> 23) & 0xff;
+    check32_ne(exp_bits, 0xff);  /* not Inf/NaN */
+}
+
 int main()
 {
     check_compare_exception();
@@ -1038,6 +1134,9 @@ int main()
     check_conv_ud2df();
     check_dfmpyfix();
     check_dfmpyhh();
+    check_conv_rnd();
+    check_sffma_lib_inf();
+    check_invsqrta_denorm();
 
     puts(err ? "FAIL" : "PASS");
     return err ? 1 : 0;
-- 
2.34.1


  parent reply	other threads:[~2026-09-05 18:10 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 ` [PATCH 08/17] tests/tcg/hexagon: add cond call, tstbit-jump, and endloop01 tests Brian Cain
2026-09-14 19:44   ` 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 ` Brian Cain [this message]
2026-09-14 21:23   ` [PATCH 15/17] tests/tcg/hexagon: add rounding conv, sffma:lib, and sfinvsqrta 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-16-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.