From: Taylor Simpson <tsimpson@quicinc.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, tsimpson@quicinc.com,
richard.henderson@linaro.org, f4bug@amsat.org,
zongyuan.li@smartx.com
Subject: [PULL v2 04/12] Hexagon (target/hexagon) properly handle denorm in arch_sf_recip_common
Date: Sat, 12 Mar 2022 12:13:11 -0800 [thread overview]
Message-ID: <20220312201319.29040-5-tsimpson@quicinc.com> (raw)
In-Reply-To: <20220312201319.29040-1-tsimpson@quicinc.com>
The arch_sf_recip_common function was calling float32_getexp which
adjusts for denorm, but the we actually need the raw exponent bits.
This function is called from 3 instructions
sfrecipa
sffixupn
sffixupd
Test cases added to tests/tcg/hexagon/fpstuff.c
Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
Message-Id: <20220210021556.9217-6-tsimpson@quicinc.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
target/hexagon/fma_emu.h | 6 ++++-
target/hexagon/arch.c | 6 ++---
tests/tcg/hexagon/fpstuff.c | 44 ++++++++++++++++++++++++++++++++++---
3 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/target/hexagon/fma_emu.h b/target/hexagon/fma_emu.h
index e3b99a8cf4..91591d6050 100644
--- a/target/hexagon/fma_emu.h
+++ b/target/hexagon/fma_emu.h
@@ -1,5 +1,5 @@
/*
- * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ * Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,6 +24,10 @@ static inline bool is_finite(float64 x)
}
int32_t float64_getexp(float64 f64);
+static inline uint32_t float32_getexp_raw(float32 f32)
+{
+ return extract32(f32, 23, 8);
+}
int32_t float32_getexp(float32 f32);
float32 infinite_float32(uint8_t sign);
float32 internal_fmafx(float32 a, float32 b, float32 c,
diff --git a/target/hexagon/arch.c b/target/hexagon/arch.c
index 68a55b3bd4..da79b41c4d 100644
--- a/target/hexagon/arch.c
+++ b/target/hexagon/arch.c
@@ -1,5 +1,5 @@
/*
- * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ * Copyright(c) 2019-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -298,8 +298,8 @@ int arch_sf_recip_common(float32 *Rs, float32 *Rt, float32 *Rd, int *adjust,
} else {
PeV = 0x00;
/* Basic checks passed */
- n_exp = float32_getexp(RsV);
- d_exp = float32_getexp(RtV);
+ n_exp = float32_getexp_raw(RsV);
+ d_exp = float32_getexp_raw(RtV);
if ((n_exp - d_exp + SF_BIAS) <= SF_MANTBITS) {
/* Near quotient underflow / inexact Q */
PeV = 0x80;
diff --git a/tests/tcg/hexagon/fpstuff.c b/tests/tcg/hexagon/fpstuff.c
index 0dff429f4c..043f18fab3 100644
--- a/tests/tcg/hexagon/fpstuff.c
+++ b/tests/tcg/hexagon/fpstuff.c
@@ -1,5 +1,5 @@
/*
- * Copyright(c) 2020-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
+ * Copyright(c) 2020-2022 Qualcomm Innovation Center, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,6 +38,8 @@ const int SF_NaN_special = 0x7f800001;
const int SF_ANY = 0x3f800000;
const int SF_HEX_NAN = 0xffffffff;
const int SF_small_neg = 0xab98fba8;
+const int SF_denorm = 0x00000001;
+const int SF_random = 0x346001d6;
const long long DF_NaN = 0x7ff8000000000000ULL;
const long long DF_ANY = 0x3f80000000000000ULL;
@@ -250,10 +252,11 @@ static void check_dfminmax(void)
check_fpstatus(usr, FPINVF);
}
-static void check_recip_exception(void)
+static void check_sfrecipa(void)
{
int result;
int usr;
+ int pred;
/*
* Check that sfrecipa doesn't set status bits when
@@ -329,6 +332,17 @@ static void check_recip_exception(void)
: "r2", "p0", "usr");
check32(result, 0x3f800000);
check_fpstatus(usr, 0);
+
+ /*
+ * Check that sfrecipa properly handles denorm
+ */
+ asm (CLEAR_FPSTATUS
+ "%0,p0 = sfrecipa(%2, %3)\n\t"
+ "%1 = p0\n\t"
+ : "=r"(result), "=r"(pred) : "r"(SF_denorm), "r"(SF_random)
+ : "p0", "usr");
+ check32(result, 0x6a920001);
+ check32(pred, 0x80);
}
static void check_canonical_NaN(void)
@@ -455,6 +469,28 @@ static void check_invsqrta(void)
check32(predval, 0x0);
}
+static void check_sffixupn(void)
+{
+ int result;
+
+ /* Check that sffixupn properly deals with denorm */
+ asm volatile("%0 = sffixupn(%1, %2)\n\t"
+ : "=r"(result)
+ : "r"(SF_random), "r"(SF_denorm));
+ check32(result, 0x246001d6);
+}
+
+static void check_sffixupd(void)
+{
+ int result;
+
+ /* Check that sffixupd properly deals with denorm */
+ asm volatile("%0 = sffixupd(%1, %2)\n\t"
+ : "=r"(result)
+ : "r"(SF_denorm), "r"(SF_random));
+ check32(result, 0x146001d6);
+}
+
static void check_float2int_convs()
{
int res32;
@@ -602,9 +638,11 @@ int main()
check_compare_exception();
check_sfminmax();
check_dfminmax();
- check_recip_exception();
+ check_sfrecipa();
check_canonical_NaN();
check_invsqrta();
+ check_sffixupn();
+ check_sffixupd();
check_float2int_convs();
puts(err ? "FAIL" : "PASS");
--
2.17.1
next prev parent reply other threads:[~2022-03-12 20:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-12 20:13 [PULL v2 00/12] Hexagon (target/hexagon) queue Taylor Simpson
2022-03-12 20:13 ` [PULL v2 01/12] Hexagon (target/hexagon) fix bug in circular addressing Taylor Simpson
2022-03-12 20:13 ` [PULL v2 02/12] Hexagon HVX (target/hexagon) fix bug in HVX saturate instructions Taylor Simpson
2022-03-12 20:13 ` [PULL v2 03/12] Hexagon (target/hexagon) properly set FPINVF bit in sfcmp.uo and dfcmp.uo Taylor Simpson
2022-03-12 20:13 ` Taylor Simpson [this message]
2022-03-12 20:13 ` [PULL v2 05/12] Hexagon (target/hexagon) properly handle NaN in dfmin/dfmax/sfmin/sfmax Taylor Simpson
2022-03-12 20:13 ` [PULL v2 06/12] Hexagon (tests/tcg/hexagon) test instructions that might set bits in USR Taylor Simpson
2022-03-12 20:13 ` [PULL v2 07/12] Hexagon (tests/tcg/hexagon) add floating point instructions to usr.c Taylor Simpson
2022-03-12 20:13 ` [PULL v2 08/12] Hexagon (tests/tcg/hexagon) update overflow test Taylor Simpson
2022-03-12 20:13 ` [PULL v2 09/12] Hexagon (tests/tcg/hexagon) fix inline asm in preg_alias.c Taylor Simpson
2022-03-12 20:13 ` [PULL v2 10/12] Hexagon (target/hexagon) fix bug in conv_df2uw_chop Taylor Simpson
2022-03-12 20:13 ` [PULL v2 11/12] Hexagon (target/hexagon) assignment to c4 should wait until packet commit Taylor Simpson
2022-03-12 20:13 ` [PULL v2 12/12] target/hexagon: remove unused variable Taylor Simpson
2022-03-14 13:22 ` [PULL v2 00/12] Hexagon (target/hexagon) queue Peter Maydell
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=20220312201319.29040-5-tsimpson@quicinc.com \
--to=tsimpson@quicinc.com \
--cc=f4bug@amsat.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=zongyuan.li@smartx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).