Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E59F606A320 for ; Tue, 1 Dec 2026 23:22:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hcQV7AYp Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYXAk-0001HW-9i; Tue, 01 Dec 2026 18:22:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYXAi-0001Gi-5A for qemu-devel@nongnu.org; Tue, 01 Dec 2026 18:22:04 -0500 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xYXAf-0004fU-Ha for qemu-devel@nongnu.org; Tue, 01 Dec 2026 18:22:03 -0500 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id A53D04544E; Tue, 1 Dec 2026 23:21:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9872C1F0089C; Tue, 1 Dec 2026 23:21:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796167319; bh=KqjvCBPBhNakigpz5mlxrziENHyQa1oZsxV5C9e8vJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hcQV7AYpACNKz7NsZ82XlOBoR+a48PumcY0LO5SiYCObYJSmeF+Xh75zm6yBwoYUt ayGjylXslwaYLJQPYy01cNLW6UjLogYgTYYXYr6D/uuZHNsnB7EEdgC7hlJxyWcdbl bnCYg4JU5iaboAQLtoM5dSv42EzPnxUd0mmbBbTzzR9/Z7WO5lpMjq2w4br9KAljYS UGCCURrxEKFc3xz/vFEEemgW/TvC1y9Yg3nYENRxybKa7S663BP41sqkyHqOCOZ91/ YHm5zHl/BriqyFtEHqc7nDMCjV+Zx57rPyRitiiTOjg5L+Y4W3Lq8b8+tMNCJeBHXq DItXa9wlnopEA== From: Helge Deller To: qemu-devel@nongnu.org Cc: "Kirill A . Korinsky" , Helge Deller Subject: [PULL for 11.2 1/4] target/hppa: Emulate FREM Date: Wed, 2 Dec 2026 00:21:51 +0100 Message-ID: <20261201232154.3178-2-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261201232154.3178-1-deller@kernel.org> References: <20261201232154.3178-1-deller@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=172.234.252.31; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: "Kirill A. Korinsky" 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 Signed-off-by: Helge Deller --- 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