From patchwork Wed Feb 16 17:59:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 83383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1B576B7088 for ; Thu, 17 Feb 2011 05:05:21 +1100 (EST) Received: from localhost ([127.0.0.1]:54132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pplkb-0007As-IE for incoming@patchwork.ozlabs.org; Wed, 16 Feb 2011 13:05:17 -0500 Received: from [140.186.70.92] (port=35820 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PplfQ-0004bw-E1 for qemu-devel@nongnu.org; Wed, 16 Feb 2011 13:00:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PplfP-0001UC-F0 for qemu-devel@nongnu.org; Wed, 16 Feb 2011 12:59:56 -0500 Received: from eu1sys200aog115.obsmtp.com ([207.126.144.139]:48626) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PplfP-0001Tw-4S for qemu-devel@nongnu.org; Wed, 16 Feb 2011 12:59:55 -0500 Received: from source ([164.129.1.35]) (using TLSv1) by eu1sys200aob115.postini.com ([207.126.147.11]) with SMTP ID DSNKTVwQmcCHrdhCTHq9vYkmofIc6z7UEm6Z@postini.com; Wed, 16 Feb 2011 17:59:54 UTC Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5BF7932E for ; Wed, 16 Feb 2011 17:59:53 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas6.st.com [10.75.90.73]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D068727A5 for ; Wed, 16 Feb 2011 17:59:52 +0000 (GMT) Received: from localhost.localdomain (164.129.122.40) by webmail-eu.st.com (10.75.90.13) with Microsoft SMTP Server (TLS) id 8.2.234.1; Wed, 16 Feb 2011 18:59:51 +0100 From: To: Date: Wed, 16 Feb 2011 18:59:45 +0100 Message-ID: <1297879186-12670-3-git-send-email-christophe.lyon@st.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1297879186-12670-1-git-send-email-christophe.lyon@st.com> References: <1297879186-12670-1-git-send-email-christophe.lyon@st.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 207.126.144.139 Subject: [Qemu-devel] [PATCH 2/3] target-arm: fix support for vrecpe. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Christophe Lyon Now use the same algorithm as described in the ARM ARM. Signed-off-by: Christophe Lyon --- target-arm/helper.c | 84 +++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 72 insertions(+), 12 deletions(-) diff --git a/target-arm/helper.c b/target-arm/helper.c index 7f63a28..7751d21 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -2687,13 +2687,68 @@ float32 HELPER(rsqrts_f32)(float32 a, float32 b, CPUState *env) /* NEON helpers. */ -/* TODO: The architecture specifies the value that the estimate functions - should return. We return the exact reciprocal/root instead. */ +/* The algorithm that must be used to calculate the estimate + * is specified by the ARM ARM. + */ +static float64 recip_estimate(float64 a, CPUState *env) +{ + float_status *s = &env->vfp.standard_fp_status; + float64 one = int64_to_float64(1, s); + /* q = (int)(a * 512.0) */ + float64 x512 = int64_to_float64(512, s); + float64 q = float64_mul(x512, a, s); + int64_t q_int = float64_to_int64_round_to_zero(q, s); + + /* r = 1.0 / (((double)q + 0.5) / 512.0) */ + q = int64_to_float64(q_int, s); + float64 half = float64_div(one, int64_to_float64(2, s), s); + q = float64_add(q, half, s); + q = float64_div(q, x512, s); + q = float64_div(one, q, s); + + /* s = (int)(256.0 * r + 0.5) */ + float64 x256 = int64_to_float64(256, s); + q = float64_mul(q, x256, s); + q = float64_add(q, half, s); + q_int = float64_to_int64_round_to_zero(q, s); + + /* return (double)s / 256.0 */ + return float64_div(int64_to_float64(q_int, s), x256, s); +} + float32 HELPER(recpe_f32)(float32 a, CPUState *env) { - float_status *s = &env->vfp.fp_status; - float32 one = int32_to_float32(1, s); - return float32_div(one, a, s); + float_status *s = &env->vfp.standard_fp_status; + float64 f64; + uint32_t val32 = float32_val(a); + + int result_exp; + int a_exp = (val32 & 0x7f800000) >> 23; + int sign = val32 & 0x80000000; + + if (float32_is_any_nan(a)) { + return float32_default_nan; + } else if (float32_is_infinity(a)) { + return float32_set_sign(float32_zero, float32_is_neg(a)); + } else if (float32_is_zero_or_denormal(a)) { + float_raise(float_flag_divbyzero, s); + return float32_set_sign(float32_infinity, float32_is_neg(a)); + } else if (a_exp >= 253) { + float_raise(float_flag_underflow, s); + return float32_set_sign(float32_zero, float32_is_neg(a)); + } + + f64 = make_float64((0x3feULL << 52) + | ((int64_t)(val32 & 0x7fffff) << 29)); + + result_exp = 253 - a_exp; + + f64 = recip_estimate(f64, env); + + val32 = sign + | ((result_exp & 0xff) << 23) + | ((float64_val(f64) >> 29) & 0x7fffff); + return make_float32(val32); } float32 HELPER(rsqrte_f32)(float32 a, CPUState *env) @@ -2705,13 +2760,18 @@ float32 HELPER(rsqrte_f32)(float32 a, CPUState *env) uint32_t HELPER(recpe_u32)(uint32_t a, CPUState *env) { - float_status *s = &env->vfp.fp_status; - float32 tmp; - tmp = int32_to_float32(a, s); - tmp = float32_scalbn(tmp, -32, s); - tmp = helper_recpe_f32(tmp, env); - tmp = float32_scalbn(tmp, 31, s); - return float32_to_int32(tmp, s); + float64 f64; + + if ((a & 0x80000000) == 0) { + return 0xffffffff; + } + + f64 = make_float64((0x3feULL << 52) + | ((int64_t)(a & 0x7fffffff) << 21)); + + f64 = recip_estimate (f64, env); + + return 0x80000000 | ((float64_val(f64) >> 21) & 0x7fffffff); } uint32_t HELPER(rsqrte_u32)(uint32_t a, CPUState *env)