From patchwork Wed Dec 11 19:16:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Musta X-Patchwork-Id: 300305 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B42AB2C0090 for ; Thu, 12 Dec 2013 06:24:53 +1100 (EST) Received: from localhost ([::1]:59822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqpOt-0008IM-43 for incoming@patchwork.ozlabs.org; Wed, 11 Dec 2013 14:24:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44255) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqpIV-0000IT-P5 for qemu-devel@nongnu.org; Wed, 11 Dec 2013 14:18:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VqpIN-0000Ey-0D for qemu-devel@nongnu.org; Wed, 11 Dec 2013 14:18:15 -0500 Received: from mail-yh0-x22b.google.com ([2607:f8b0:4002:c01::22b]:60243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqpIM-0000Et-SO; Wed, 11 Dec 2013 14:18:06 -0500 Received: by mail-yh0-f43.google.com with SMTP id a41so5409266yho.16 for ; Wed, 11 Dec 2013 11:18:06 -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=HCiVDH8EOWiu/XcQZSOzw5tw1sjYRhntARsKjdBSVr8=; b=PW7+27Kr27jBL4hKrjuin+GZ+PiRuGGx2Xc5ngC8hBt2c/Hk9hPAYD6zrpxApFIPAQ TtStuzRoeiFDix3fnyz2KUxAIE+7S9yDt0TaxRnoT526xjijBX7x/eI7EedjOXsNIVya BCkyIZMghbqGdqCqd+FwvKq57M0MspTvKR5XmPWXvo088TnJgCBfl9nQ+hnbK0DVoQ7J HQ1NW4m/8qV9FN1AC75LNQu//f6E8tt/YLwy5YCWlPxvf+ERp3oNnqDFgzPlbgNS9Xqi /fpVIqtomvlVEOPnDSeJDKd1pXhakTmTUhxtPo8WqkY5ow4XhMpopxLZ35n7HjfnyXcA CMYw== X-Received: by 10.236.28.162 with SMTP id g22mr2709007yha.52.1386789486504; Wed, 11 Dec 2013 11:18:06 -0800 (PST) Received: from tmusta-sc.rchland.ibm.com (rchp4.rochester.ibm.com. [129.42.161.36]) by mx.google.com with ESMTPSA id x9sm11764420yhd.13.2013.12.11.11.18.01 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Dec 2013 11:18:05 -0800 (PST) From: Tom Musta To: qemu-devel@nongnu.org Date: Wed, 11 Dec 2013 13:16:31 -0600 Message-Id: <1386789398-5239-12-git-send-email-tommusta@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1386789398-5239-1-git-send-email-tommusta@gmail.com> References: <1386789398-5239-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:4002:c01::22b Cc: Tom Musta , qemu-ppc@nongnu.org Subject: [Qemu-devel] [V2 PATCH 11/18] softfloat: Fix float64_to_uint32 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_uint32 has several flaws: - for numbers between 2**32 and 2**64, the inexact exception flag may get incorrectly set. In this case, only the invalid flag should be set. test pattern: 425F81378DC0CD1F / 0x1.f81378dc0cd1fp+38 - for numbers between 2**63 and 2**64, incorrect results may be produced: test pattern: 43EAAF73F1F0B8BD / 0x1.aaf73f1f0b8bdp+63 This patch re-implements float64_to_uint32 to re-use the float64_to_uint64 routine (instead of float64_to_int64). For the saturation case, the inexact bit is explicitly cleared before raising the invalid flag. Signed-off-by: Tom Musta --- fpu/softfloat.c | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 1003e59..6a8b6f5 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -6578,15 +6578,13 @@ uint_fast16_t float32_to_uint16_round_to_zero(float32 a STATUS_PARAM) uint32 float64_to_uint32( float64 a STATUS_PARAM ) { - int64_t v; + uint64_t v; uint32 res; - v = float64_to_int64(a STATUS_VAR); - if (v < 0) { - res = 0; - float_raise( float_flag_invalid STATUS_VAR); - } else if (v > 0xffffffff) { + v = float64_to_uint64(a STATUS_VAR); + if (v > 0xffffffff) { res = 0xffffffff; + STATUS(float_exception_flags) &= ~float_flag_inexact; float_raise( float_flag_invalid STATUS_VAR); } else { res = v;