From patchwork Wed Dec 18 20:19:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Musta X-Patchwork-Id: 303036 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EE8BE2C007B for ; Thu, 19 Dec 2013 07:22:09 +1100 (EST) Received: from localhost ([::1]:40472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtNd8-0001nB-Vs for incoming@patchwork.ozlabs.org; Wed, 18 Dec 2013 15:22:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtNbD-0000Q4-TT for qemu-devel@nongnu.org; Wed, 18 Dec 2013 15:20:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtNb5-0003Ph-GV for qemu-devel@nongnu.org; Wed, 18 Dec 2013 15:20:07 -0500 Received: from mail-oa0-x22e.google.com ([2607:f8b0:4003:c02::22e]:54523) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtNb5-0003Oe-9I; Wed, 18 Dec 2013 15:19:59 -0500 Received: by mail-oa0-f46.google.com with SMTP id o6so186578oag.33 for ; Wed, 18 Dec 2013 12:19:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QKOzivK8Dhvt3uvwz+S7oAvyvEiN5eTj881C+WFd/EQ=; b=PmYW5dON92e7ub7jkz3M+D0NSPrVCJo5chpDkYXj9TOCvLl0LhC/yJpTwvSpHzl+Ig ds7D4ROhcJ200i5VcZQDJ1raML5nsiEZjYFKm1oNTXiTY0PvZ+UFgGYNn8f5d/LLsPG9 5wSL+XnQa6GSsJoOtk5lT/cG+ry4rRTW2DWRRY8mN0CZoOo7gTXg+N/y6i7CHvvZof8D fJ1eZtWesZfjoxPnvA+DycJiMZynW0vMb7u/CLdKhozeROpDdOi3MF8Gm5zF4trwpjQy fKsMyHQU+XToAWHTNQDmKMXDuXJ/luJ09TbxU+sOemrNLGFMY5sKpmbO/x4zwWx8USSw /qwg== X-Received: by 10.60.83.17 with SMTP id m17mr16789133oey.62.1387397998771; Wed, 18 Dec 2013 12:19:58 -0800 (PST) Received: from tmusta-sc.rchland.ibm.com (rchp4.rochester.ibm.com. [129.42.161.36]) by mx.google.com with ESMTPSA id h4sm1797915oel.3.2013.12.18.12.19.56 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 18 Dec 2013 12:19:58 -0800 (PST) From: Tom Musta To: qemu-devel@nongnu.org Date: Wed, 18 Dec 2013 14:19:02 -0600 Message-Id: <1387397961-4894-4-git-send-email-tommusta@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1387397961-4894-1-git-send-email-tommusta@gmail.com> References: <1387397961-4894-1-git-send-email-tommusta@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c02::22e Cc: Tom Musta , qemu-ppc@nongnu.org Subject: [Qemu-devel] [V4 PATCH 03/22] softfloat: Fix float64_to_uint64_round_to_zero X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The float64_to_uint64_round_to_zero routine is incorrect. For example, the following test pattern: 46697351FF4AEC29 / 0x1.97351ff4aec29p+103 currently produces 8000000000000000 instead of FFFFFFFFFFFFFFFF. This patch re-implements the routine to temporarily force the rounding mode and use the float64_to_uint64 routine. This contribution can be licensed under either the softfloat-2a or -2b license. Signed-off-by: Tom Musta Reviewed-by: Peter Maydell --- fpu/softfloat.c | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 1ff59d0..1b614ae 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -6675,13 +6675,11 @@ uint64_t float64_to_uint64(float64 a STATUS_PARAM) uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM) { - int64_t v; - - v = float64_val(int64_to_float64(INT64_MIN STATUS_VAR)); - v += float64_val(a); - v = float64_to_int64_round_to_zero(make_float64(v) STATUS_VAR); - - return v - INT64_MIN; + signed char current_rounding_mode = STATUS(float_rounding_mode); + set_float_rounding_mode(float_round_to_zero STATUS_VAR); + int64_t v = float64_to_uint64(a STATUS_VAR); + set_float_rounding_mode(current_rounding_mode STATUS_VAR); + return v; } #define COMPARE(s, nan_exp) \