All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL for 11.2 0/4] Hppa fixes patches
@ 2026-12-01 23:21 Helge Deller
  2026-12-01 23:21 ` [PULL for 11.2 1/4] target/hppa: Emulate FREM Helge Deller
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Helge Deller @ 2026-12-01 23:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kirill A . Korinsky, Helge Deller

From: Helge Deller <deller@gmx.de>

The following changes since commit 9751c62358073580cbf330a4df22077a7c6a407c:

  Update version for v11.2.0-rc2 release (2026-11-25 21:39:27 -0800)

are available in the Git repository at:

  https://github.com/hdeller/qemu-hppa.git tags/hppa-fixes-pull-request

for you to fetch changes up to bd107c56027e297358af8a12bf1709472f5a77a4:

  target/hppa: Fix tcg_gen_goto_tb assertion (2026-12-01 22:42:15 +0100)

----------------------------------------------------------------
target/hppa patches

Add the missing FREM asm instruction to fix OpenBSD, and
one fix for goto_tb which prevented boot of some versions
of HP-UX 10.20 on B160L (issue #4835).

----------------------------------------------------------------

Kirill A. Korinsky (4):
  target/hppa: Emulate FREM
  target/hppa: Defer PA7300LC FCNVFF on NaNs
  target/hppa: Defer PA7300LC multiply assists
  target/hppa: Fix tcg_gen_goto_tb assertion

 target/hppa/cpu.h           |   1 +
 target/hppa/fpu_helper.c    | 173 ++++++++++++++++++-
 target/hppa/helper.h        |  12 +-
 target/hppa/insns.decode    |   4 +
 target/hppa/int_helper.c    |   4 +
 target/hppa/translate.c     | 154 +++++++++++++----
 tests/qtest/hppa-fpu-test.c | 330 +++++++++++++++++++++++++++++++++++-
 7 files changed, 639 insertions(+), 39 deletions(-)

-- 
2.54.0



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PULL for 11.2 1/4] target/hppa: Emulate FREM
  2026-12-01 23:21 [PULL for 11.2 0/4] Hppa fixes patches Helge Deller
@ 2026-12-01 23:21 ` Helge Deller
  2026-12-01 23:21 ` [PULL for 11.2 2/4] target/hppa: Defer PA7300LC FCNVFF on NaNs Helge Deller
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2026-12-01 23:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kirill A . Korinsky, Helge Deller

From: "Kirill A. Korinsky" <kirill@korins.ky>

OpenBSD/hppa's libm remainder tests terminate with SIGILL on FREM
because QEMU's HPPA decoder omits class 3 subopcode 4 under both
major opcodes, 0x0c and 0x0e, sending both encodings through
gen_illegal() to raise EXCP_ILL when the FPU is enabled.

Decode both encodings and compute IEEE remainder in single and
double precision with SoftFloat, with qtest coverage for exact
result bits at quotient ties under directed rounding and for the
FPSR invalid operation flag on zero divisors and infinite dividends.

Signed-off-by: Kirill A. Korinsky <kirill@korins.ky>
Signed-off-by: Helge Deller <deller@gmx.de>
---
 target/hppa/fpu_helper.c    |  14 +++++
 target/hppa/helper.h        |   2 +
 target/hppa/insns.decode    |   4 ++
 target/hppa/translate.c     |  10 ++++
 tests/qtest/hppa-fpu-test.c | 105 +++++++++++++++++++++++++++++++++++-
 5 files changed, 134 insertions(+), 1 deletion(-)

diff --git a/target/hppa/fpu_helper.c b/target/hppa/fpu_helper.c
index a0c8c91ee5..f42044cdef 100644
--- a/target/hppa/fpu_helper.c
+++ b/target/hppa/fpu_helper.c
@@ -177,6 +177,13 @@ float32 HELPER(fdiv_s)(CPUHPPAState *env, float32 a, float32 b)
     return ret;
 }
 
+float32 HELPER(frem_s)(CPUHPPAState *env, float32 a, float32 b)
+{
+    float32 ret = float32_rem(a, b, &env->fp_status);
+    update_fr0_op(env, GETPC());
+    return ret;
+}
+
 float64 HELPER(fsqrt_d)(CPUHPPAState *env, float64 arg)
 {
     float64 ret = float64_sqrt(arg, &env->fp_status);
@@ -219,6 +226,13 @@ float64 HELPER(fdiv_d)(CPUHPPAState *env, float64 a, float64 b)
     return ret;
 }
 
+float64 HELPER(frem_d)(CPUHPPAState *env, float64 a, float64 b)
+{
+    float64 ret = float64_rem(a, b, &env->fp_status);
+    update_fr0_op(env, GETPC());
+    return ret;
+}
+
 float64 HELPER(fcnv_s_d)(CPUHPPAState *env, float32 arg)
 {
     float64 ret = float32_to_float64(arg, &env->fp_status);
diff --git a/target/hppa/helper.h b/target/hppa/helper.h
index f6c7e16f0f..b99e298ee8 100644
--- a/target/hppa/helper.h
+++ b/target/hppa/helper.h
@@ -30,6 +30,7 @@ DEF_HELPER_FLAGS_3(fadd_s, TCG_CALL_NO_RWG, f32, env, f32, f32)
 DEF_HELPER_FLAGS_3(fsub_s, TCG_CALL_NO_RWG, f32, env, f32, f32)
 DEF_HELPER_FLAGS_3(fmpy_s, TCG_CALL_NO_RWG, f32, env, f32, f32)
 DEF_HELPER_FLAGS_3(fdiv_s, TCG_CALL_NO_RWG, f32, env, f32, f32)
+DEF_HELPER_FLAGS_3(frem_s, TCG_CALL_NO_RWG, f32, env, f32, f32)
 
 DEF_HELPER_FLAGS_2(fsqrt_d, TCG_CALL_NO_RWG, f64, env, f64)
 DEF_HELPER_FLAGS_2(frnd_d, TCG_CALL_NO_RWG, f64, env, f64)
@@ -37,6 +38,7 @@ DEF_HELPER_FLAGS_3(fadd_d, TCG_CALL_NO_RWG, f64, env, f64, f64)
 DEF_HELPER_FLAGS_3(fsub_d, TCG_CALL_NO_RWG, f64, env, f64, f64)
 DEF_HELPER_FLAGS_3(fmpy_d, TCG_CALL_NO_RWG, f64, env, f64, f64)
 DEF_HELPER_FLAGS_3(fdiv_d, TCG_CALL_NO_RWG, f64, env, f64, f64)
+DEF_HELPER_FLAGS_3(frem_d, TCG_CALL_NO_RWG, f64, env, f64, f64)
 
 DEF_HELPER_FLAGS_2(fcnv_s_d, TCG_CALL_NO_RWG, f64, env, f32)
 DEF_HELPER_FLAGS_2(fcnv_d_s, TCG_CALL_NO_RWG, f32, env, f64)
diff --git a/target/hppa/insns.decode b/target/hppa/insns.decode
index 135f563c88..ebc290d830 100644
--- a/target/hppa/insns.decode
+++ b/target/hppa/insns.decode
@@ -620,21 +620,25 @@ fadd_f          001100 ..... ..... 000 00 ...... .....  @f0c_3
 fsub_f          001100 ..... ..... 001 00 ...... .....  @f0c_3
 fmpy_f          001100 ..... ..... 010 00 ...... .....  @f0c_3
 fdiv_f          001100 ..... ..... 011 00 ...... .....  @f0c_3
+frem_f          001100 ..... ..... 100 00 ...... .....  @f0c_3
 
 fadd_d          001100 ..... ..... 000 01 ...... .....  @f0c_3
 fsub_d          001100 ..... ..... 001 01 ...... .....  @f0c_3
 fmpy_d          001100 ..... ..... 010 01 ...... .....  @f0c_3
 fdiv_d          001100 ..... ..... 011 01 ...... .....  @f0c_3
+frem_d          001100 ..... ..... 100 01 ...... .....  @f0c_3
 
 fadd_f          001110 ..... ..... 000 ..... ... .....  @f0e_f_3
 fsub_f          001110 ..... ..... 001 ..... ... .....  @f0e_f_3
 fmpy_f          001110 ..... ..... 010 ..... ... .....  @f0e_f_3
 fdiv_f          001110 ..... ..... 011 ..... ... .....  @f0e_f_3
+frem_f          001110 ..... ..... 100 ..... ... .....  @f0e_f_3
 
 fadd_d          001110 ..... ..... 000 ..... ... .....  @f0e_d_3
 fsub_d          001110 ..... ..... 001 ..... ... .....  @f0e_d_3
 fmpy_d          001110 ..... ..... 010 ..... ... .....  @f0e_d_3
 fdiv_d          001110 ..... ..... 011 ..... ... .....  @f0e_d_3
+frem_d          001110 ..... ..... 100 ..... ... .....  @f0e_d_3
 
 xmpyu           001110 ..... ..... 010 .0111 .00 t:5    r1=%ra64 r2=%rb64
 
diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index ab3505f9c9..0713112063 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -4498,6 +4498,16 @@ static bool trans_fdiv_d(DisasContext *ctx, arg_fclass3 *a)
     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fdiv_d);
 }
 
+static bool trans_frem_f(DisasContext *ctx, arg_fclass3 *a)
+{
+    return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_frem_s);
+}
+
+static bool trans_frem_d(DisasContext *ctx, arg_fclass3 *a)
+{
+    return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_frem_d);
+}
+
 static bool trans_xmpyu(DisasContext *ctx, arg_xmpyu *a)
 {
     TCGv_i64 x, y;
diff --git a/tests/qtest/hppa-fpu-test.c b/tests/qtest/hppa-fpu-test.c
index af4ff2a162..40e097dbbe 100644
--- a/tests/qtest/hppa-fpu-test.c
+++ b/tests/qtest/hppa-fpu-test.c
@@ -1,5 +1,5 @@
 /*
- * HPPA CCR floating-point enable and lazy context switching tests.
+ * HPPA floating-point instruction and context switching tests.
  *
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
@@ -296,6 +296,104 @@ static void test_lazy(void)
     qtest_quit(qts);
 }
 
+typedef struct FremTest {
+    const char *name;
+    uint32_t instruction;
+    uint64_t dividend;
+    uint64_t divisor;
+    uint64_t result;
+    uint32_t fpsr;
+    uint32_t flags;
+} FremTest;
+
+static const FremTest frem_tests[] = {
+    {
+        .name = "single-tie",
+        .instruction = 0x318d860e, /* frem,sgl fr12,fr13,fr14 */
+        .dividend = 0x40e0000000000000ULL, /* 7.0f */
+        .divisor = 0x4000000000000000ULL, /* 2.0f */
+        .result = 0xbf80000089abcdefULL, /* -1.0f */
+        .fpsr = 0x200, /* round toward zero */
+    },
+    {
+        .name = "double-tie",
+        .instruction = 0x318d8e0e, /* frem,dbl fr12,fr13,fr14 */
+        .dividend = 0x4014000000000000ULL, /* 5.0 */
+        .divisor = 0x4000000000000000ULL, /* 2.0 */
+        .result = 0x3ff0000000000000ULL, /* 1.0 */
+        .fpsr = 0x400, /* round upward */
+    },
+    {
+        .name = "single-extended-subnormal",
+        .instruction = 0x398d96ce, /* frem,sgl fr12R,fr13R,fr14R */
+        .dividend = 0x0000000000000001ULL, /* smallest subnormal */
+        .divisor = 0x000000003f800000ULL, /* 1.0f */
+        .result = 0x0123456700000001ULL,
+        .fpsr = 0x600, /* round downward */
+    },
+    {
+        .name = "double-extended-negative-zero",
+        .instruction = 0x398d8e0e, /* frem,dbl fr12,fr13,fr14 */
+        .dividend = 0xc010000000000000ULL, /* -4.0 */
+        .divisor = 0x4000000000000000ULL, /* 2.0 */
+        .result = 0x8000000000000000ULL, /* -0.0 */
+    },
+    {
+        .name = "single-zero-divisor",
+        .instruction = 0x318d860e,
+        .dividend = 0x3f80000000000000ULL, /* 1.0f */
+        .divisor = 0,
+        .result = 0x7fa0000089abcdefULL, /* quiet NaN */
+        .flags = 0x80000000, /* invalid operation */
+    },
+    {
+        .name = "double-infinite-dividend",
+        .instruction = 0x398d8e0e,
+        .dividend = 0x7ff0000000000000ULL, /* infinity */
+        .divisor = 0x3ff0000000000000ULL, /* 1.0 */
+        .result = 0x7ff4000000000000ULL, /* quiet NaN */
+        .flags = 0x80000000, /* invalid operation */
+    },
+};
+
+static void test_frem(const void *opaque)
+{
+    const FremTest *test = opaque;
+    const uint32_t guest[] = {
+        0x34011000, /* ldi 0x800,r1 */
+        0x01c11840, /* mtctl r1,iva */
+        0x34103000, /* ldi 0x1800,r16 */
+        0x34113200, /* ldi 0x1900,r17 */
+        0x34010180, /* ldi 0xc0,r1 */
+        0x01411840, /* mtctl r1,ccr */
+        0x2e00100c, /* fldd 0(r16),fr12 */
+        0x2e10100d, /* fldd 8(r16),fr13 */
+        0x36100020, /* ldo 16(r16),r16 */
+        0x2e001000, /* fldd 0(r16),fr0 */
+        0x2e10100e, /* fldd 8(r16),fr14 */
+        test->instruction,
+        0x2e10120e, /* fstd fr14,8(r16) */
+        0x2e001200, /* fstd fr0,0(r16) */
+        0x34010002, /* ldi 1,r1 */
+        0x6a210000, /* stw r1,0(r17): completion */
+    };
+    QTestState *qts = start_guest(false);
+    uint32_t end = CODE + sizeof(guest);
+
+    write_words(qts, CODE, guest, G_N_ELEMENTS(guest));
+    qtest_writel(qts, end, branch(end, HALT));
+    qtest_writeq(qts, DATA, test->dividend);
+    qtest_writeq(qts, DATA + 8, test->divisor);
+    qtest_writeq(qts, DATA + 16, (uint64_t)test->fpsr << 32);
+    /* A single-precision write must preserve the other half of FR14. */
+    qtest_writeq(qts, DATA + 24, 0x0123456789abcdefULL);
+
+    run_guest(qts, 1);
+    g_assert_cmphex(qtest_readq(qts, DATA + 24), ==, test->result);
+    g_assert_cmphex(qtest_readl(qts, DATA + 16), ==, test->fpsr | test->flags);
+    qtest_quit(qts);
+}
+
 static const uint32_t fault_guest[] = {
     0x34011000, /* ldi 0x800,r1 */
     0x01c11840, /* mtctl r1,iva */
@@ -362,6 +460,11 @@ int main(int argc, char **argv)
         qtest_add_data_func(name, &fp_tests[i], test_fp);
     }
     qtest_add_func("fpu/lazy-contexts", test_lazy);
+    for (size_t i = 0; i < G_N_ELEMENTS(frem_tests); i++) {
+        g_autofree char *name = g_strdup_printf("fpu/frem/%s", frem_tests[i].name);
+
+        qtest_add_data_func(name, &frem_tests[i], test_frem);
+    }
     for (size_t i = 0; i < G_N_ELEMENTS(fault_tests); i++) {
         g_autofree char *name = g_strdup_printf("fpu/%s", fault_tests[i].name);
 
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL for 11.2 2/4] target/hppa: Defer PA7300LC FCNVFF on NaNs
  2026-12-01 23:21 [PULL for 11.2 0/4] Hppa fixes patches Helge Deller
  2026-12-01 23:21 ` [PULL for 11.2 1/4] target/hppa: Emulate FREM Helge Deller
@ 2026-12-01 23:21 ` Helge Deller
  2026-12-01 23:21 ` [PULL for 11.2 3/4] target/hppa: Defer PA7300LC multiply assists Helge Deller
  2026-12-01 23:21 ` [PULL for 11.2 4/4] target/hppa: Fix tcg_gen_goto_tb assertion Helge Deller
  3 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2026-12-01 23:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kirill A . Korinsky, Helge Deller

From: "Kirill A. Korinsky" <kirill@korins.ky>

QEMU passed PA7300LC FCNVFF NaN operands to SoftFloat, bypassing the
deferred assist exercised by OpenBSD/hppa's fmaxmin_test-11.

For a NaN operand, leave the destination intact, record the
instruction in ER2 and set FPSR.T so the next active floating point
instruction takes assist vector 14 before execution. FSTD FR0 can
save the pending status first, clearing T only after the store
succeeds.

Signed-off-by: Kirill A. Korinsky <kirill@korins.ky>
Signed-off-by: Helge Deller <deller@gmx.de>
---
 target/hppa/cpu.h           |   1 +
 target/hppa/fpu_helper.c    |  47 ++++++++++++--
 target/hppa/helper.h        |   4 +-
 target/hppa/int_helper.c    |   4 ++
 target/hppa/translate.c     |  79 +++++++++++++++++------
 tests/qtest/hppa-fpu-test.c | 121 ++++++++++++++++++++++++++++++++++++
 6 files changed, 228 insertions(+), 28 deletions(-)

diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index 7b708a564b..842964074a 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -97,6 +97,7 @@
 
 /* Emulated hardware TOC button */
 #define EXCP_TOC                 32 /* TOC = Transfer of control (NMI) */
+#define EXCP_ASSIST_DELAYED      33 /* Internal, delivered through vector 14 */
 
 const char *hppa_exception_name(int excp);
 
diff --git a/target/hppa/fpu_helper.c b/target/hppa/fpu_helper.c
index f42044cdef..82ad6da34d 100644
--- a/target/hppa/fpu_helper.c
+++ b/target/hppa/fpu_helper.c
@@ -113,6 +113,10 @@ static void update_fr0_op(CPUHPPAState *env, uintptr_t ra)
         shadow = FIELD_DP32(shadow, FPSR, T, 1);
         /* fill exception register #1, which is lower 32-bits of fr[0] */
 #if !defined(CONFIG_USER_ONLY)
+        if (!hppa_is_pa20(env)) {
+            /* Drop any retained ER2 record before an immediate trap. */
+            env->fr[1] = (uint32_t)env->fr[1];
+        }
         if (hard_exp & (R_FPSR_ENA_O_MASK | R_FPSR_ENA_U_MASK)) {
             /* over- and underflow both set overflow flag only */
             fr1 = FIELD_DP32(fr1, FPSR, C, 1);
@@ -233,18 +237,49 @@ float64 HELPER(frem_d)(CPUHPPAState *env, float64 a, float64 b)
     return ret;
 }
 
-float64 HELPER(fcnv_s_d)(CPUHPPAState *env, float32 arg)
+#ifndef CONFIG_USER_ONLY
+static void defer_fp_unimplemented(CPUHPPAState *env, uint32_t insn)
+{
+    uint32_t code = (insn >> 26) == 0x0c ? 0x09 : 0x0b;
+    uint32_t record = deposit32(insn, 26, 6, code);
+
+    /* PA7300LC records the original operation in exception register 2. */
+    env->fr[1] = deposit64(env->fr[1], 32, 32, record);
+    env->fr0_shadow |= R_FPSR_T_MASK;
+    env->fr[0] = deposit64(env->fr[0], 32, 32, env->fr0_shadow);
+}
+#endif
+
+void HELPER(fcnv_s_d)(CPUHPPAState *env, float32 arg, uint32_t reg, uint32_t insn)
 {
-    float64 ret = float32_to_float64(arg, &env->fp_status);
+    float64 ret;
+
+#ifndef CONFIG_USER_ONLY
+    if (!hppa_is_pa20(env) && float32_is_any_nan(arg)) {
+        defer_fp_unimplemented(env, insn);
+        return;
+    }
+#endif
+    ret = float32_to_float64(arg, &env->fp_status);
     update_fr0_op(env, GETPC());
-    return ret;
+    env->fr[reg] = ret;
 }
 
-float32 HELPER(fcnv_d_s)(CPUHPPAState *env, float64 arg)
+void HELPER(fcnv_d_s)(CPUHPPAState *env, float64 arg, uint32_t reg, uint32_t insn)
 {
-    float32 ret = float64_to_float32(arg, &env->fp_status);
+    float32 ret;
+    unsigned shift = reg & 32 ? 0 : 32;
+
+#ifndef CONFIG_USER_ONLY
+    if (!hppa_is_pa20(env) && float64_is_any_nan(arg)) {
+        defer_fp_unimplemented(env, insn);
+        return;
+    }
+#endif
+    ret = float64_to_float32(arg, &env->fp_status);
     update_fr0_op(env, GETPC());
-    return ret;
+    reg &= 31;
+    env->fr[reg] = deposit64(env->fr[reg], shift, 32, ret);
 }
 
 float32 HELPER(fcnv_w_s)(CPUHPPAState *env, int32_t arg)
diff --git a/target/hppa/helper.h b/target/hppa/helper.h
index b99e298ee8..84937ee73f 100644
--- a/target/hppa/helper.h
+++ b/target/hppa/helper.h
@@ -40,8 +40,8 @@ DEF_HELPER_FLAGS_3(fmpy_d, TCG_CALL_NO_RWG, f64, env, f64, f64)
 DEF_HELPER_FLAGS_3(fdiv_d, TCG_CALL_NO_RWG, f64, env, f64, f64)
 DEF_HELPER_FLAGS_3(frem_d, TCG_CALL_NO_RWG, f64, env, f64, f64)
 
-DEF_HELPER_FLAGS_2(fcnv_s_d, TCG_CALL_NO_RWG, f64, env, f32)
-DEF_HELPER_FLAGS_2(fcnv_d_s, TCG_CALL_NO_RWG, f32, env, f64)
+DEF_HELPER_FLAGS_4(fcnv_s_d, TCG_CALL_NO_RWG, void, env, f32, i32, i32)
+DEF_HELPER_FLAGS_4(fcnv_d_s, TCG_CALL_NO_RWG, void, env, f64, i32, i32)
 
 DEF_HELPER_FLAGS_2(fcnv_w_s, TCG_CALL_NO_RWG, f32, env, s32)
 DEF_HELPER_FLAGS_2(fcnv_dw_s, TCG_CALL_NO_RWG, f32, env, s64)
diff --git a/target/hppa/int_helper.c b/target/hppa/int_helper.c
index da9c7c6457..8a19232062 100644
--- a/target/hppa/int_helper.c
+++ b/target/hppa/int_helper.c
@@ -162,6 +162,7 @@ void hppa_cpu_do_interrupt(CPUState *cs)
         case EXCP_COND:
         case EXCP_PRIV_REG:
         case EXCP_PRIV_OPR:
+        case EXCP_ASSIST_DELAYED:
             /* IIR set via translate.c.  */
             break;
 
@@ -223,6 +224,9 @@ void hppa_cpu_do_interrupt(CPUState *cs)
     }
 
     /* step 7 */
+    if (i == EXCP_ASSIST_DELAYED) {
+        i = EXCP_ASSIST;
+    }
     if (i == EXCP_TOC) {
         hwaddr pdc_toc_addr = FIRMWARE_START;
 
diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index 0713112063..67670768d1 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -1692,13 +1692,32 @@ static bool do_load(DisasContext *ctx, unsigned rt, unsigned rb,
     return nullify_end(ctx);
 }
 
+static void gen_fp_assist_check(DisasContext *ctx)
+{
+#ifndef CONFIG_USER_ONLY
+    if (!ctx->is_pa20) {
+        TCGv_i32 fpsr = tcg_temp_new_i32();
+        DisasDelayException *e = delay_excp(ctx, EXCP_ASSIST_DELAYED);
+
+        tcg_gen_ld_i32(fpsr, tcg_env, offsetof(CPUHPPAState, fr0_shadow));
+        tcg_gen_brcondi_i32(TCG_COND_TSTNE, fpsr, R_FPSR_T_MASK, e->lab);
+    }
+#endif
+}
+
+static void fp_nullify_over(DisasContext *ctx)
+{
+    nullify_over(ctx);
+    gen_fp_assist_check(ctx);
+}
+
 static bool do_floadw(DisasContext *ctx, unsigned rt, unsigned rb,
                       unsigned rx, int scale, int64_t disp,
                       unsigned sp, int modify)
 {
     TCGv_i32 tmp;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
 
     tmp = tcg_temp_new_i32();
     do_load_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_UL);
@@ -1745,7 +1764,7 @@ static bool do_floadd(DisasContext *ctx, unsigned rt, unsigned rb,
 {
     TCGv_i64 tmp;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
 
     tmp = tcg_temp_new_i64();
     do_load_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_UQ);
@@ -1782,7 +1801,7 @@ static bool do_fstorew(DisasContext *ctx, unsigned rt, unsigned rb,
 {
     TCGv_i32 tmp;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
 
     tmp = load_frw_i32(rt);
     do_store_32(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_UL);
@@ -1807,8 +1826,22 @@ static bool do_fstored(DisasContext *ctx, unsigned rt, unsigned rb,
 
     nullify_over(ctx);
 
+    if (rt != 0) {
+        gen_fp_assist_check(ctx);
+    }
     tmp = load_frd(rt);
     do_store_64(ctx, tmp, rb, rx, scale, disp, sp, modify, MO_UQ);
+#ifndef CONFIG_USER_ONLY
+    if (rt == 0 && !ctx->is_pa20) {
+        TCGv_i32 fpsr = tcg_temp_new_i32();
+
+        /* FSTD FR0 saves T in memory and clears it only after the store. */
+        tcg_gen_andi_i64(tmp, tmp, ~((uint64_t)R_FPSR_T_MASK << 32));
+        save_frd(0, tmp);
+        tcg_gen_extrh_i64_i32(fpsr, tmp);
+        tcg_gen_st_i32(fpsr, tcg_env, offsetof(CPUHPPAState, fr0_shadow));
+    }
+#endif
 
     return nullify_end(ctx);
 }
@@ -1827,7 +1860,7 @@ static bool do_fop_wew(DisasContext *ctx, unsigned rt, unsigned ra,
 {
     TCGv_i32 tmp;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
     tmp = load_frw0_i32(ra);
 
     func(tmp, tcg_env, tmp);
@@ -1842,7 +1875,7 @@ static bool do_fop_wed(DisasContext *ctx, unsigned rt, unsigned ra,
     TCGv_i32 dst;
     TCGv_i64 src;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
     src = load_frd(ra);
     dst = tcg_temp_new_i32();
 
@@ -1857,7 +1890,7 @@ static bool do_fop_ded(DisasContext *ctx, unsigned rt, unsigned ra,
 {
     TCGv_i64 tmp;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
     tmp = load_frd0(ra);
 
     func(tmp, tcg_env, tmp);
@@ -1872,7 +1905,7 @@ static bool do_fop_dew(DisasContext *ctx, unsigned rt, unsigned ra,
     TCGv_i32 src;
     TCGv_i64 dst;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
     src = load_frw0_i32(ra);
     dst = tcg_temp_new_i64();
 
@@ -1888,7 +1921,7 @@ static bool do_fop_weww(DisasContext *ctx, unsigned rt,
 {
     TCGv_i32 a, b;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
     a = load_frw0_i32(ra);
     b = load_frw0_i32(rb);
 
@@ -1904,7 +1937,7 @@ static bool do_fop_dedd(DisasContext *ctx, unsigned rt,
 {
     TCGv_i64 a, b;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
     a = load_frd0(ra);
     b = load_frd0(rb);
 
@@ -4133,7 +4166,7 @@ static bool trans_fid_f(DisasContext *ctx, arg_fid_f *a)
         ret = 0x0f080000000000ULL; /* PA7300LC (PCX-L2) */
     }
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
     save_frd(0, tcg_constant_i64(ret));
     return nullify_end(ctx);
 }
@@ -4239,12 +4272,18 @@ static bool trans_fnegabs_d(DisasContext *ctx, arg_fclass01 *a)
 
 static bool trans_fcnv_d_f(DisasContext *ctx, arg_fclass01 *a)
 {
-    return do_fop_wed(ctx, a->t, a->r, gen_helper_fcnv_d_s);
+    fp_nullify_over(ctx);
+    gen_helper_fcnv_d_s(tcg_env, load_frd(a->r), tcg_constant_i32(a->t),
+                       tcg_constant_i32(ctx->insn));
+    return nullify_end(ctx);
 }
 
 static bool trans_fcnv_f_d(DisasContext *ctx, arg_fclass01 *a)
 {
-    return do_fop_dew(ctx, a->t, a->r, gen_helper_fcnv_s_d);
+    fp_nullify_over(ctx);
+    gen_helper_fcnv_s_d(tcg_env, load_frw0_i32(a->r), tcg_constant_i32(a->t),
+                       tcg_constant_i32(ctx->insn));
+    return nullify_end(ctx);
 }
 
 static bool trans_fcnv_w_f(DisasContext *ctx, arg_fclass01 *a)
@@ -4375,7 +4414,7 @@ static bool trans_fcmp_f(DisasContext *ctx, arg_fclass2 *a)
 {
     TCGv_i32 ta, tb, tc, ty;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
 
     ta = load_frw0_i32(a->r1);
     tb = load_frw0_i32(a->r2);
@@ -4392,7 +4431,7 @@ static bool trans_fcmp_d(DisasContext *ctx, arg_fclass2 *a)
     TCGv_i64 ta, tb;
     TCGv_i32 tc, ty;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
 
     ta = load_frd0(a->r1);
     tb = load_frd0(a->r2);
@@ -4412,9 +4451,6 @@ static bool trans_ftest(DisasContext *ctx, arg_ftest *a)
 
     nullify_over(ctx);
 
-    t = tcg_temp_new_i64();
-    tcg_gen_ld32u_i64(t, tcg_env, offsetof(CPUHPPAState, fr0_shadow));
-
     if (a->y == 1) {
         switch (a->c) {
         case 0: /* simple */
@@ -4450,6 +4486,9 @@ static bool trans_ftest(DisasContext *ctx, arg_ftest *a)
         mask = R_FPSR_CA0_MASK >> cbit;
     }
 
+    gen_fp_assist_check(ctx);
+    t = tcg_temp_new_i64();
+    tcg_gen_ld32u_i64(t, tcg_env, offsetof(CPUHPPAState, fr0_shadow));
     ctx->null_cond = cond_make_ti(tc, t, mask);
     return nullify_end(ctx);
 }
@@ -4512,7 +4551,7 @@ static bool trans_xmpyu(DisasContext *ctx, arg_xmpyu *a)
 {
     TCGv_i64 x, y;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
 
     x = load_frw0_i64(a->r1);
     y = load_frw0_i64(a->r2);
@@ -4580,7 +4619,7 @@ static bool trans_fmpyfadd_f(DisasContext *ctx, arg_fmpyfadd_f *a)
 {
     TCGv_i32 x, y, z;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
     x = load_frw0_i32(a->rm1);
     y = load_frw0_i32(a->rm2);
     z = load_frw0_i32(a->ra3);
@@ -4599,7 +4638,7 @@ static bool trans_fmpyfadd_d(DisasContext *ctx, arg_fmpyfadd_d *a)
 {
     TCGv_i64 x, y, z;
 
-    nullify_over(ctx);
+    fp_nullify_over(ctx);
     x = load_frd0(a->rm1);
     y = load_frd0(a->rm2);
     z = load_frd0(a->ra3);
diff --git a/tests/qtest/hppa-fpu-test.c b/tests/qtest/hppa-fpu-test.c
index 40e097dbbe..f49d834e31 100644
--- a/tests/qtest/hppa-fpu-test.c
+++ b/tests/qtest/hppa-fpu-test.c
@@ -394,6 +394,122 @@ static void test_frem(const void *opaque)
     qtest_quit(qts);
 }
 
+typedef struct FcnvTest {
+    const char *name;
+    uint32_t instruction;
+    uint64_t operand;
+    uint64_t result;
+    uint64_t result_mask;
+    uint32_t er2;
+    bool result_first;
+} FcnvTest;
+
+static const FcnvTest fcnv_tests[] = {
+    {
+        .name = "status-first",
+        .instruction = 0x3180220c, /* fcnvff,sgl,dbl fr12,fr12 */
+        .operand = 0x7fa0000012345678ULL,
+        .result = 0x7fa0000000000000ULL,
+        .result_mask = 0xffffffff00000000ULL,
+        .er2 = 0x2580220c,
+    },
+    {
+        .name = "result-first",
+        .instruction = 0x3180220c,
+        .operand = 0x7fa0000012345678ULL,
+        .result = 0x7fa0000000000000ULL,
+        .result_mask = 0xffffffff00000000ULL,
+        .er2 = 0x2580220c,
+        .result_first = true,
+    },
+    {
+        .name = "finite",
+        .instruction = 0x3180220c,
+        .operand = 0x4000000012345678ULL, /* 2.0f in the left half */
+        .result = 0x4000000000000000ULL, /* 2.0 */
+        .result_mask = UINT64_MAX,
+    },
+    {
+        .name = "extended-status-first",
+        .instruction = 0x39800a4c, /* fcnvff,dbl,sgl fr12,fr12R */
+        .operand = 0x7ff4000001234567ULL,
+        .result = 0x7ff4000001234567ULL,
+        .result_mask = UINT64_MAX,
+        .er2 = 0x2d800a4c,
+    },
+    {
+        .name = "extended-finite",
+        .instruction = 0x39800a4c,
+        .operand = 0x4004000000000000ULL, /* 2.5 */
+        .result = 0x4004000040200000ULL, /* 2.5f in the right half */
+        .result_mask = UINT64_MAX,
+    },
+};
+
+static const uint32_t fcnv_save[] = {
+    0x2e101200, /* fstd fr0,8(r16) */
+    0x36100020, /* ldo 16(r16),r16 */
+    0x2e001201, /* fstd fr1,0(r16) */
+    0x2e101200, /* fstd fr0,8(r16) */
+    0x36100020, /* ldo 16(r16),r16 */
+    0x2e00120c, /* fstd fr12,0(r16) */
+};
+
+static void test_fcnv(const void *opaque)
+{
+    const FcnvTest *test = opaque;
+    const uint32_t guest[] = {
+        0x34011000, /* ldi 0x800,r1 */
+        0x01c11840, /* mtctl r1,iva */
+        0x34103000, /* ldi 0x1800,r16 */
+        0x34113200, /* ldi 0x1900,r17 */
+        0x34123050, /* ldi 0x1828,r18 */
+        0x34010180, /* ldi 0xc0,r1 */
+        0x01411840, /* mtctl r1,ccr */
+        0x2e00100c, /* fldd 0(r16),fr12 */
+        test->instruction,
+        0x08002880, /* cmpclr,= r0,r0,r0 */
+        0x2e40120c, /* fstd fr12,0(r18): nullified */
+    };
+    static const uint32_t complete[] = {
+        0x34010002, /* ldi 1,r1 */
+        0x6a210000, /* stw r1,0(r17): completion */
+    };
+    QTestState *qts = start_guest(false);
+    uint32_t pc = CODE + sizeof(guest);
+    uint64_t fr0 = test->er2 ? 0x0000004000000000ULL : 0;
+
+    write_words(qts, CODE, guest, G_N_ELEMENTS(guest));
+    if (test->result_first) {
+        uint32_t vector_branch = 0x800 + 14 * 32 + 4;
+        uint32_t end = ASSIST + sizeof(fcnv_save);
+
+        qtest_writel(qts, pc, 0x2e40120c); /* fstd fr12,0(r18) */
+        pc += 4;
+        qtest_writel(qts, vector_branch, branch(vector_branch, ASSIST));
+        write_words(qts, ASSIST, fcnv_save, G_N_ELEMENTS(fcnv_save));
+        qtest_writel(qts, end, branch(end, UNEXPECTED));
+    }
+    write_words(qts, pc, fcnv_save, G_N_ELEMENTS(fcnv_save));
+    pc += sizeof(fcnv_save);
+    write_words(qts, pc, complete, G_N_ELEMENTS(complete));
+    pc += sizeof(complete);
+    qtest_writel(qts, pc, branch(pc, HALT));
+    qtest_writeq(qts, DATA, test->operand);
+
+    run_guest(qts, test->result_first ? 0x10e : 1);
+    if (test->result_first) {
+        g_assert_cmphex(qtest_readl(qts, RESULT + 8), ==, CODE + sizeof(guest));
+    }
+    g_assert_cmphex(qtest_readq(qts, DATA + 8), ==, fr0);
+    g_assert_cmphex(qtest_readl(qts, DATA + 16), ==, test->er2);
+    g_assert_cmphex(qtest_readq(qts, DATA + 24), ==, 0);
+    g_assert_cmphex(qtest_readq(qts, DATA + 32) & test->result_mask, ==,
+                    test->result);
+    g_assert_cmphex(qtest_readq(qts, DATA + 40), ==, 0);
+    qtest_quit(qts);
+}
+
 static const uint32_t fault_guest[] = {
     0x34011000, /* ldi 0x800,r1 */
     0x01c11840, /* mtctl r1,iva */
@@ -465,6 +581,11 @@ int main(int argc, char **argv)
 
         qtest_add_data_func(name, &frem_tests[i], test_frem);
     }
+    for (size_t i = 0; i < G_N_ELEMENTS(fcnv_tests); i++) {
+        g_autofree char *name = g_strdup_printf("fpu/fcnv/%s", fcnv_tests[i].name);
+
+        qtest_add_data_func(name, &fcnv_tests[i], test_fcnv);
+    }
     for (size_t i = 0; i < G_N_ELEMENTS(fault_tests); i++) {
         g_autofree char *name = g_strdup_printf("fpu/%s", fault_tests[i].name);
 
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL for 11.2 3/4] target/hppa: Defer PA7300LC multiply assists
  2026-12-01 23:21 [PULL for 11.2 0/4] Hppa fixes patches Helge Deller
  2026-12-01 23:21 ` [PULL for 11.2 1/4] target/hppa: Emulate FREM Helge Deller
  2026-12-01 23:21 ` [PULL for 11.2 2/4] target/hppa: Defer PA7300LC FCNVFF on NaNs Helge Deller
@ 2026-12-01 23:21 ` Helge Deller
  2026-12-01 23:21 ` [PULL for 11.2 4/4] target/hppa: Fix tcg_gen_goto_tb assertion Helge Deller
  3 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2026-12-01 23:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kirill A . Korinsky, Helge Deller

From: "Kirill A. Korinsky" <kirill@korins.ky>

With FPSR.D clear, PA7300LC defers FMPY, FMPYADD and FMPYSUB for
certain denormal operands or a result that is tiny after rounding,
including exact results that leave IEEE underflow clear. Detect
tininess through SoftFloat's output flush flag on a scratch status.

Evaluate both components of FMPYADD and FMPYSUB from the original
operands. If either requires an assist, record the instruction in
ER2 and set FPSR.T, preserving both destinations and the FPSR
exception flags.

OpenBSD/hppa's trig_test-3 takes its expected failure path when
tanf encounters the assist, and the full msun regression passes
with the original Makefile.

Signed-off-by: Kirill A. Korinsky <kirill@korins.ky>
Signed-off-by: Helge Deller <deller@gmx.de>
---
 target/hppa/fpu_helper.c    | 116 +++++++++++++++++++++++++++++++++++-
 target/hppa/helper.h        |   6 ++
 target/hppa/translate.c     |  39 ++++++++++++
 tests/qtest/hppa-fpu-test.c | 104 ++++++++++++++++++++++++++++++++
 4 files changed, 264 insertions(+), 1 deletion(-)

diff --git a/target/hppa/fpu_helper.c b/target/hppa/fpu_helper.c
index 82ad6da34d..1255b4999c 100644
--- a/target/hppa/fpu_helper.c
+++ b/target/hppa/fpu_helper.c
@@ -240,7 +240,25 @@ float64 HELPER(frem_d)(CPUHPPAState *env, float64 a, float64 b)
 #ifndef CONFIG_USER_ONLY
 static void defer_fp_unimplemented(CPUHPPAState *env, uint32_t insn)
 {
-    uint32_t code = (insn >> 26) == 0x0c ? 0x09 : 0x0b;
+    uint32_t code;
+
+    switch (insn >> 26) {
+    case 0x06:
+        code = 0x03;
+        break;
+    case 0x26:
+        code = 0x23;
+        break;
+    case 0x0c:
+        code = 0x09;
+        break;
+    case 0x0e:
+        code = 0x0b;
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
     uint32_t record = deposit32(insn, 26, 6, code);
 
     /* PA7300LC records the original operation in exception register 2. */
@@ -248,6 +266,102 @@ static void defer_fp_unimplemented(CPUHPPAState *env, uint32_t insn)
     env->fr0_shadow |= R_FPSR_T_MASK;
     env->fr[0] = deposit64(env->fr[0], 32, 32, env->fr0_shadow);
 }
+
+static float_status pa1_multiply_status(CPUHPPAState *env)
+{
+    float_status status = env->fp_status;
+
+    if (!(env->fr0_shadow & R_FPSR_D_MASK)) {
+        /* Identify tiny results even when IEEE underflow is not raised. */
+        set_flush_to_zero(true, &status);
+        set_float_ftz_detection(float_ftz_after_rounding, &status);
+    }
+    return status;
+}
+
+static bool pa1_multiply_needs_assist(CPUHPPAState *env,
+                                    const float_status *status, bool single,
+                                    bool multiply, uint64_t a, uint64_t b)
+{
+    if (env->fr0_shadow & R_FPSR_D_MASK) {
+        return false;
+    }
+    if (get_float_exception_flags(status) & float_flag_output_denormal_flushed) {
+        return true;
+    }
+
+    uint64_t sign_mask = single ? INT32_MAX : INT64_MAX;
+    uint64_t min_normal = single ? 0x00800000 : 0x0010000000000000ULL;
+    uint64_t infinity = single ? 0x7f800000 : 0x7ff0000000000000ULL;
+
+    a &= sign_mask;
+    b &= sign_mask;
+    return (a != 0 && a < min_normal && b != infinity &&
+            (!multiply || b != 0)) ||
+           (b != 0 && b < min_normal && a != infinity &&
+            (!multiply || a != 0));
+}
+
+static void pa1_multiply_write_result(CPUHPPAState *env, uint32_t reg,
+                                      bool single, uint64_t result,
+                                      const float_status *status, uintptr_t ra)
+{
+    set_float_exception_flags(get_float_exception_flags(status),
+                              &env->fp_status);
+    update_fr0_op(env, ra);
+    if (single) {
+        unsigned shift = reg & 32 ? 0 : 32;
+
+        reg &= 31;
+        env->fr[reg] = deposit64(env->fr[reg], shift, 32, result);
+    } else {
+        env->fr[reg] = result;
+    }
+}
+
+void HELPER(fmpy_pa1)(CPUHPPAState *env, uint64_t a, uint64_t b,
+                      uint32_t reg, uint32_t insn)
+{
+    bool single = !extract32(insn, 11, 1);
+    float_status status = pa1_multiply_status(env);
+    uint64_t product = single ? float32_mul(a, b, &status)
+                              : float64_mul(a, b, &status);
+
+    if (pa1_multiply_needs_assist(env, &status, single, true, a, b)) {
+        defer_fp_unimplemented(env, insn);
+        return;
+    }
+    pa1_multiply_write_result(env, reg, single, product, &status, GETPC());
+}
+
+void HELPER(fmpyadd_pa1)(CPUHPPAState *env, uint64_t m1, uint64_t m2,
+                        uint64_t a1, uint64_t a2, uint32_t regs, uint32_t insn)
+{
+    bool single = extract32(insn, 5, 1);
+    bool subtract = (insn >> 26) == 0x26;
+    float_status multiply_status = pa1_multiply_status(env);
+    float_status add_status = multiply_status;
+    uint64_t product, sum;
+
+    if (single) {
+        product = float32_mul(m1, m2, &multiply_status);
+        sum = subtract ? float32_sub(a1, a2, &add_status)
+                       : float32_add(a1, a2, &add_status);
+    } else {
+        product = float64_mul(m1, m2, &multiply_status);
+        sum = subtract ? float64_sub(a1, a2, &add_status)
+                       : float64_add(a1, a2, &add_status);
+    }
+
+    if (pa1_multiply_needs_assist(env, &multiply_status, single, true, m1, m2) ||
+        pa1_multiply_needs_assist(env, &add_status, single, false, a1, a2)) {
+        defer_fp_unimplemented(env, insn);
+        return;
+    }
+    pa1_multiply_write_result(env, regs & 63, single, product,
+                              &multiply_status, GETPC());
+    pa1_multiply_write_result(env, regs >> 6, single, sum, &add_status, GETPC());
+}
 #endif
 
 void HELPER(fcnv_s_d)(CPUHPPAState *env, float32 arg, uint32_t reg, uint32_t insn)
diff --git a/target/hppa/helper.h b/target/hppa/helper.h
index 84937ee73f..a1d1dfffd8 100644
--- a/target/hppa/helper.h
+++ b/target/hppa/helper.h
@@ -24,6 +24,12 @@ DEF_HELPER_FLAGS_4(probe, TCG_CALL_NO_WG, tl, env, tl, i32, i32)
 
 DEF_HELPER_FLAGS_1(loaded_fr0, TCG_CALL_NO_RWG, void, env)
 
+#ifndef CONFIG_USER_ONLY
+DEF_HELPER_FLAGS_5(fmpy_pa1, TCG_CALL_NO_RWG, void, env, i64, i64, i32, i32)
+DEF_HELPER_FLAGS_7(fmpyadd_pa1, TCG_CALL_NO_RWG, void, env, i64, i64, i64, i64,
+                   i32, i32)
+#endif
+
 DEF_HELPER_FLAGS_2(fsqrt_s, TCG_CALL_NO_RWG, f32, env, f32)
 DEF_HELPER_FLAGS_2(frnd_s, TCG_CALL_NO_RWG, f32, env, f32)
 DEF_HELPER_FLAGS_3(fadd_s, TCG_CALL_NO_RWG, f32, env, f32, f32)
diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index 67670768d1..c8e2b13c8c 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -4519,11 +4519,27 @@ static bool trans_fsub_d(DisasContext *ctx, arg_fclass3 *a)
 
 static bool trans_fmpy_f(DisasContext *ctx, arg_fclass3 *a)
 {
+#ifndef CONFIG_USER_ONLY
+    if (!ctx->is_pa20) {
+        fp_nullify_over(ctx);
+        gen_helper_fmpy_pa1(tcg_env, load_frw0_i64(a->r1), load_frw0_i64(a->r2),
+                            tcg_constant_i32(a->t), tcg_constant_i32(ctx->insn));
+        return nullify_end(ctx);
+    }
+#endif
     return do_fop_weww(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_s);
 }
 
 static bool trans_fmpy_d(DisasContext *ctx, arg_fclass3 *a)
 {
+#ifndef CONFIG_USER_ONLY
+    if (!ctx->is_pa20) {
+        fp_nullify_over(ctx);
+        gen_helper_fmpy_pa1(tcg_env, load_frd0(a->r1), load_frd0(a->r2),
+                            tcg_constant_i32(a->t), tcg_constant_i32(ctx->insn));
+        return nullify_end(ctx);
+    }
+#endif
     return do_fop_dedd(ctx, a->t, a->r1, a->r2, gen_helper_fmpy_d);
 }
 
@@ -4575,6 +4591,18 @@ static bool do_fmpyadd_s(DisasContext *ctx, arg_mpyadd *a, bool is_sub)
     int rm2 = fmpyadd_s_reg(a->rm2);
     int rm1 = fmpyadd_s_reg(a->rm1);
 
+#ifndef CONFIG_USER_ONLY
+    /* A zero addend field in FMPYADD encodes FMPYCFXT on PA7300LC. */
+    if (!ctx->is_pa20 && (is_sub || a->ra != 0)) {
+        fp_nullify_over(ctx);
+        gen_helper_fmpyadd_pa1(tcg_env,
+                              load_frw0_i64(rm1), load_frw0_i64(rm2),
+                              load_frw0_i64(ta), load_frw0_i64(ra),
+                              tcg_constant_i32((ta << 6) | tm),
+                              tcg_constant_i32(ctx->insn));
+        return nullify_end(ctx);
+    }
+#endif
     nullify_over(ctx);
 
     do_fop_weww(ctx, tm, rm1, rm2, gen_helper_fmpy_s);
@@ -4596,6 +4624,17 @@ static bool trans_fmpysub_f(DisasContext *ctx, arg_mpyadd *a)
 
 static bool do_fmpyadd_d(DisasContext *ctx, arg_mpyadd *a, bool is_sub)
 {
+#ifndef CONFIG_USER_ONLY
+    if (!ctx->is_pa20 && (is_sub || a->ra != 0)) {
+        fp_nullify_over(ctx);
+        gen_helper_fmpyadd_pa1(tcg_env,
+                              load_frd0(a->rm1), load_frd0(a->rm2),
+                              load_frd0(a->ta), load_frd0(a->ra),
+                              tcg_constant_i32((a->ta << 6) | a->tm),
+                              tcg_constant_i32(ctx->insn));
+        return nullify_end(ctx);
+    }
+#endif
     nullify_over(ctx);
 
     do_fop_dedd(ctx, a->tm, a->rm1, a->rm2, gen_helper_fmpy_d);
diff --git a/tests/qtest/hppa-fpu-test.c b/tests/qtest/hppa-fpu-test.c
index f49d834e31..7ab28efc8a 100644
--- a/tests/qtest/hppa-fpu-test.c
+++ b/tests/qtest/hppa-fpu-test.c
@@ -510,6 +510,104 @@ static void test_fcnv(const void *opaque)
     qtest_quit(qts);
 }
 
+typedef struct FmpyAssistTest {
+    const char *name;
+    uint32_t instruction;
+    uint32_t er2;
+    uint64_t fr22;
+    uint64_t fr23;
+} FmpyAssistTest;
+
+static const FmpyAssistTest fmpy_assist_tests[] = {
+    {
+        .name = "scalar-tiny",
+        .instruction = 0x33374617, /* fmpy,sgl fr25,fr23,fr23 */
+        .er2 = 0x27374617,
+        .fr22 = 0xb79bae5f8cad057cULL,
+        .fr23 = 0x37d95384fd6b8987ULL,
+    },
+    {
+        .name = "compound-trace",
+        .instruction = 0x19263a26, /* fmpyadd,sgl fr25,fr22,fr22,fr24,fr23 */
+        .er2 = 0x0d263a26,
+        .fr22 = 0xb79bae5f8cad057cULL,
+        .fr23 = 0x004a1020fd6b8987ULL,
+    },
+    {
+        .name = "compound-tiny",
+        .instruction = 0x19263a26,
+        .er2 = 0x0d263a26,
+        .fr22 = 0x380000008cad057cULL, /* Exact subnormal product. */
+        .fr23 = 0x37d95384fd6b8987ULL,
+    },
+    {
+        .name = "double-scalar-tiny",
+        .instruction = 0x33374e17, /* fmpy,dbl fr25,fr23,fr23 */
+        .er2 = 0x27374e17,
+        .fr22 = 0xb79bae5f8cad057cULL,
+        .fr23 = 0x3850000000000000ULL, /* 2^-122. */
+    },
+    {
+        .name = "compound-subtract-tiny",
+        .instruction = 0x99263a26, /* fmpysub,sgl fr25,fr22,fr22,fr24,fr23 */
+        .er2 = 0x8d263a26,
+        .fr22 = 0x380000008cad057cULL,
+        .fr23 = 0x37d95384fd6b8987ULL,
+    },
+    {
+        .name = "compound-denormal",
+        .instruction = 0x19263a26,
+        .er2 = 0x0d263a26,
+        .fr22 = 0x3f8000008cad057cULL, /* Multiply by 1.0f. */
+        .fr23 = 0x004a1020fd6b8987ULL,
+    },
+};
+
+static void test_fmpy_assist(const void *opaque)
+{
+    const FmpyAssistTest *test = opaque;
+    const uint32_t guest[] = {
+        0x34011000, /* ldi 0x800,r1 */
+        0x01c11840, /* mtctl r1,iva */
+        0x34103000, /* ldi 0x1800,r16 */
+        0x34113200, /* ldi 0x1900,r17 */
+        0x34010180, /* ldi 0xc0,r1 */
+        0x01411840, /* mtctl r1,ccr */
+        0x2e001016, /* fldd 0(r16),fr22 */
+        0x2e101017, /* fldd 8(r16),fr23 */
+        0x36100020, /* ldo 16(r16),r16 */
+        0x2e001018, /* fldd 0(r16),fr24 */
+        0x2e101019, /* fldd 8(r16),fr25 */
+        test->instruction,
+        0x2e001200, /* fstd fr0,0(r16) */
+        0x2e101201, /* fstd fr1,8(r16) */
+        0x36100020, /* ldo 16(r16),r16 */
+        0x2e001200, /* fstd fr0,0(r16) */
+        0x2e101216, /* fstd fr22,8(r16) */
+        0x36100020, /* ldo 16(r16),r16 */
+        0x2e001217, /* fstd fr23,0(r16) */
+        0x34010002, /* ldi 1,r1 */
+        0x6a210000, /* stw r1,0(r17): completion */
+    };
+    QTestState *qts = start_guest(false);
+    uint32_t end = CODE + sizeof(guest);
+
+    write_words(qts, CODE, guest, G_N_ELEMENTS(guest));
+    qtest_writel(qts, end, branch(end, HALT));
+    qtest_writeq(qts, DATA, test->fr22);
+    qtest_writeq(qts, DATA + 8, test->fr23);
+    qtest_writeq(qts, DATA + 16, 0x3895c07a1110fe7aULL);
+    qtest_writeq(qts, DATA + 24, 0x07ae7c429facdab0ULL);
+
+    run_guest(qts, 1);
+    g_assert_cmphex(qtest_readq(qts, DATA + 16), ==, 0x0000004000000000ULL);
+    g_assert_cmphex(qtest_readl(qts, DATA + 24), ==, test->er2);
+    g_assert_cmphex(qtest_readq(qts, DATA + 32), ==, 0);
+    g_assert_cmphex(qtest_readq(qts, DATA + 40), ==, test->fr22);
+    g_assert_cmphex(qtest_readq(qts, DATA + 48), ==, test->fr23);
+    qtest_quit(qts);
+}
+
 static const uint32_t fault_guest[] = {
     0x34011000, /* ldi 0x800,r1 */
     0x01c11840, /* mtctl r1,iva */
@@ -586,6 +684,12 @@ int main(int argc, char **argv)
 
         qtest_add_data_func(name, &fcnv_tests[i], test_fcnv);
     }
+    for (size_t i = 0; i < G_N_ELEMENTS(fmpy_assist_tests); i++) {
+        g_autofree char *name = g_strdup_printf("fpu/fmpy-assist/%s",
+                                                fmpy_assist_tests[i].name);
+
+        qtest_add_data_func(name, &fmpy_assist_tests[i], test_fmpy_assist);
+    }
     for (size_t i = 0; i < G_N_ELEMENTS(fault_tests); i++) {
         g_autofree char *name = g_strdup_printf("fpu/%s", fault_tests[i].name);
 
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL for 11.2 4/4] target/hppa: Fix tcg_gen_goto_tb assertion
  2026-12-01 23:21 [PULL for 11.2 0/4] Hppa fixes patches Helge Deller
                   ` (2 preceding siblings ...)
  2026-12-01 23:21 ` [PULL for 11.2 3/4] target/hppa: Defer PA7300LC multiply assists Helge Deller
@ 2026-12-01 23:21 ` Helge Deller
  3 siblings, 0 replies; 5+ messages in thread
From: Helge Deller @ 2026-12-01 23:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kirill A . Korinsky, Helge Deller

From: "Kirill A. Korinsky" <kirill@korins.ky>

On hppa a branch may generate three exits from one block, but qemu has
only two slots; the third exit reused slot 0 and badaboom happened.
Try to assign a unique slot to avoid the problem.

Signed-off-by: Kirill A. Korinsky <kirill@korins.ky>
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4835
Signed-off-by: Helge Deller <deller@gmx.de>
---
 target/hppa/translate.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index c8e2b13c8c..70bc7deabd 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -85,6 +85,7 @@ typedef struct DisasContext {
     uint32_t tb_flags;
     int mmu_idx;
     int privilege;
+    unsigned goto_tb_idx;
     uint32_t psw_xb;
     bool psw_n_nonzero;
     bool psw_b_next;
@@ -791,7 +792,8 @@ static bool gen_illegal(DisasContext *ctx)
 static bool use_goto_tb(DisasContext *ctx, const DisasIAQE *f,
                         const DisasIAQE *b)
 {
-    return (!iaqe_variable(f) &&
+    return (ctx->goto_tb_idx <= TB_EXIT_IDXMAX &&
+            !iaqe_variable(f) &&
             (b == NULL || !iaqe_variable(b)) &&
             translator_use_goto_tb(&ctx->base, ctx->iaoq_first + f->disp));
 }
@@ -808,11 +810,13 @@ static bool use_nullify_skip(DisasContext *ctx)
                 & TARGET_PAGE_MASK) == 0);
 }
 
-static void gen_goto_tb(DisasContext *ctx, int which,
+static void gen_goto_tb(DisasContext *ctx,
                         const DisasIAQE *f, const DisasIAQE *b)
 {
     install_iaq_entries(ctx, f, b);
     if (use_goto_tb(ctx, f, b)) {
+        unsigned which = ctx->goto_tb_idx++;
+
         tcg_gen_goto_tb(which);
         tcg_gen_exit_tb(ctx->base.tb, which);
     } else {
@@ -1960,7 +1964,7 @@ static bool do_dbranch(DisasContext *ctx, int64_t disp,
             if (use_nullify_skip(ctx)) {
                 nullify_set(ctx, 0);
                 store_psw_xb(ctx, 0);
-                gen_goto_tb(ctx, 0, &ctx->iaq_j, NULL);
+                gen_goto_tb(ctx, &ctx->iaq_j, NULL);
                 ctx->base.is_jmp = DISAS_NORETURN;
                 return true;
             }
@@ -1975,17 +1979,17 @@ static bool do_dbranch(DisasContext *ctx, int64_t disp,
         if (is_n && use_nullify_skip(ctx)) {
             nullify_set(ctx, 0);
             store_psw_xb(ctx, 0);
-            gen_goto_tb(ctx, 0, &ctx->iaq_j, NULL);
+            gen_goto_tb(ctx, &ctx->iaq_j, NULL);
         } else {
             nullify_set(ctx, is_n);
             store_psw_xb(ctx, PSW_B);
-            gen_goto_tb(ctx, 0, &ctx->iaq_b, &ctx->iaq_j);
+            gen_goto_tb(ctx, &ctx->iaq_b, &ctx->iaq_j);
         }
         nullify_end(ctx);
 
         nullify_set(ctx, 0);
         store_psw_xb(ctx, 0);
-        gen_goto_tb(ctx, 1, &ctx->iaq_b, NULL);
+        gen_goto_tb(ctx, &ctx->iaq_b, NULL);
         ctx->base.is_jmp = DISAS_NORETURN;
     }
     return true;
@@ -2017,7 +2021,7 @@ static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n,
         nullify_set(ctx, 0);
         store_psw_xb(ctx, 0);
         next = iaqe_incr(&ctx->iaq_b, 4);
-        gen_goto_tb(ctx, 0, &next, NULL);
+        gen_goto_tb(ctx, &next, NULL);
     } else {
         if (!n && ctx->null_lab) {
             gen_set_label(ctx->null_lab);
@@ -2025,7 +2029,7 @@ static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n,
         }
         nullify_set(ctx, n);
         store_psw_xb(ctx, 0);
-        gen_goto_tb(ctx, 0, &ctx->iaq_b, NULL);
+        gen_goto_tb(ctx, &ctx->iaq_b, NULL);
     }
 
     gen_set_label(taken);
@@ -2037,11 +2041,11 @@ static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n,
     if (n && use_nullify_skip(ctx)) {
         nullify_set(ctx, 0);
         store_psw_xb(ctx, 0);
-        gen_goto_tb(ctx, 1, &next, NULL);
+        gen_goto_tb(ctx, &next, NULL);
     } else {
         nullify_set(ctx, n);
         store_psw_xb(ctx, PSW_B);
-        gen_goto_tb(ctx, 1, &ctx->iaq_b, &next);
+        gen_goto_tb(ctx, &ctx->iaq_b, &next);
     }
 
     /* Not taken: the branch itself was nullified.  */
@@ -4970,7 +4974,7 @@ static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
             && (ctx->null_cond.c == TCG_COND_NEVER
                 || ctx->null_cond.c == TCG_COND_ALWAYS)) {
             nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS);
-            gen_goto_tb(ctx, 0, f, b);
+            gen_goto_tb(ctx, f, b);
             break;
         }
         /* FALLTHRU */
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-01 23:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 23:21 [PULL for 11.2 0/4] Hppa fixes patches Helge Deller
2026-12-01 23:21 ` [PULL for 11.2 1/4] target/hppa: Emulate FREM Helge Deller
2026-12-01 23:21 ` [PULL for 11.2 2/4] target/hppa: Defer PA7300LC FCNVFF on NaNs Helge Deller
2026-12-01 23:21 ` [PULL for 11.2 3/4] target/hppa: Defer PA7300LC multiply assists Helge Deller
2026-12-01 23:21 ` [PULL for 11.2 4/4] target/hppa: Fix tcg_gen_goto_tb assertion Helge Deller

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.