From patchwork Tue Dec 31 13:35:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22849 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BCEA4218CC for ; Tue, 31 Dec 2013 13:37:00 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id lf12sf13410627vcb.5 for ; Tue, 31 Dec 2013 05:36:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=24Xua8ZvsmpbbxfL4070+9lirAtGQPX+PYQzcwHj/iA=; b=KQCqxmtWgOGcSWKuDIO188YBnbZ7TimHPWJC/qmfxw9wAX+mNGp8KQy5hsRSZqeQAp LRDbGqnyiPphlIcBeOG8abtJhhwL1OsTKqIqPoovvbUU1o4a2tsUs7VnWLFkZud0lddD noKgRGwxrFLbpFlvGwmpP0iMqCIFvW9diF4InUOa0dhlU/R18qKuPHhxvORg+Fd3/SOR w2183nTol2FXllK9aKieB1xUOVf4oCczC9nAPQFvQ3t9qgyb2U0dRSepXTbBgABcTpQo bmxOSKyHxKN9Yse2DTkH2nBzr8rqfwtFMqZZdpqT0cDLKJlkAex5JZt7u+S8QFqV83WD Yt/g== X-Gm-Message-State: ALoCoQmbvVjPLFqE7YZjTWZWH+1xGYITKsQzEWKReUUm1nk76l2162jC7xjsWZjCdmYfFlEoXVmY X-Received: by 10.58.187.197 with SMTP id fu5mr31298855vec.34.1388497019879; Tue, 31 Dec 2013 05:36:59 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.81.229 with SMTP id d5ls3805148qey.64.gmail; Tue, 31 Dec 2013 05:36:59 -0800 (PST) X-Received: by 10.220.97.69 with SMTP id k5mr235563vcn.45.1388497019796; Tue, 31 Dec 2013 05:36:59 -0800 (PST) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by mx.google.com with ESMTPS id ec16si18611688veb.48.2013.12.31.05.36.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 31 Dec 2013 05:36:59 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.50; Received: by mail-vb0-f50.google.com with SMTP id w18so6407915vbj.9 for ; Tue, 31 Dec 2013 05:36:59 -0800 (PST) X-Received: by 10.220.53.135 with SMTP id m7mr39902121vcg.12.1388497019689; Tue, 31 Dec 2013 05:36:59 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp664871ved; Tue, 31 Dec 2013 05:36:59 -0800 (PST) X-Received: by 10.180.12.3 with SMTP id u3mr34403468wib.27.1388497018900; Tue, 31 Dec 2013 05:36:58 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id r5si12980122wjq.62.2013.12.31.05.36.57 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 31 Dec 2013 05:36:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1VxzUE-0000wJ-O0; Tue, 31 Dec 2013 13:35:58 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Alexander Graf , Michael Matz , Claudio Fontana , Dirk Mueller , Laurent Desnogues , kvmarm@lists.cs.columbia.edu, Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Christoffer Dall , Will Newton , Peter Crosthwaite , Tom Musta , Aurelien Jarno Subject: [PATCH 10/22] softfloat: Fix float64_to_uint32_round_to_zero Date: Tue, 31 Dec 2013 13:35:46 +0000 Message-Id: <1388496958-3542-11-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1388496958-3542-1-git-send-email-peter.maydell@linaro.org> References: <1388496958-3542-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.50 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Tom Musta The float64_to_uint32_round_to_zero routine is incorrect. For example, the following test pattern: 425F81378DC0CD1F / 0x1.f81378dc0cd1fp+38 will erroneously set the inexact flag. This patch re-implements the routine to use the float64_to_uint64_round_to_zero routine. If saturation occurs we ignore any flags set by the conversion function and raise only Invalid. This contribution can be licensed under either the softfloat-2a or -2b license. Signed-off-by: Tom Musta Message-id: 1387397961-4894-6-git-send-email-tommusta@gmail.com Signed-off-by: Peter Maydell --- fpu/softfloat.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 6b07ef2..0eb4a29 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -6665,19 +6665,18 @@ uint32 float64_to_uint32( float64 a STATUS_PARAM ) uint32 float64_to_uint32_round_to_zero( float64 a STATUS_PARAM ) { - int64_t v; + uint64_t v; uint32 res; + int old_exc_flags = get_float_exception_flags(status); - v = float64_to_int64_round_to_zero(a STATUS_VAR); - if (v < 0) { - res = 0; - float_raise( float_flag_invalid STATUS_VAR); - } else if (v > 0xffffffff) { + v = float64_to_uint64_round_to_zero(a STATUS_VAR); + if (v > 0xffffffff) { res = 0xffffffff; - float_raise( float_flag_invalid STATUS_VAR); } else { - res = v; + return v; } + set_float_exception_flags(old_exc_flags, status); + float_raise(float_flag_invalid STATUS_VAR); return res; }