From patchwork Tue Dec 31 13:35:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22846 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f197.google.com (mail-qc0-f197.google.com [209.85.216.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B2DF7218CC for ; Tue, 31 Dec 2013 13:36:52 +0000 (UTC) Received: by mail-qc0-f197.google.com with SMTP id r5sf15338732qcx.0 for ; Tue, 31 Dec 2013 05:36:51 -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=RsAFEVIAvuBHO9M7OjLw6BUMA9mG9//hvLF5MS8lKx0=; b=m5vQheg+/Oy6Rld6VlNVKNI/TnlTfBzbBlTjPD+RQwID26Lo5LQ9Yp9mSkiO51HHEX WESyx7Om+4flRvaI8gsAly/kN/K0vrTsGoCVanycmUE6DvUYHuNWe6n6lhM02jJb6JlJ wvudPZ291bjKpS/y34LwwzdMf2vMFWTYYybkjYQIwQD2XwT3JVeqjzggCyRiFRr8gS5r ckvw+ZuMEN7a8GFJhrA2x2AqXsDJTUsdqQgP3jMCfvTFVhOxB4HzAVndM+K5q9nodM9U f/tUh/5eFGTEPOgOCgyW+/JthRr24M6gwEuk/wwuxO0TdbJz5MDtPq/5MsoCpJOvuoLh FcCA== X-Gm-Message-State: ALoCoQltfNbICZ4UqXdKmW2HTBCRp58jBx8Q3WPvB2PdailK32T8usUVkZh3LGLwTuj3gaqlZ8bi X-Received: by 10.58.145.233 with SMTP id sx9mr23364693veb.0.1388497011954; Tue, 31 Dec 2013 05:36:51 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.36.161 with SMTP id r1ls3743129qej.71.gmail; Tue, 31 Dec 2013 05:36:51 -0800 (PST) X-Received: by 10.52.175.162 with SMTP id cb2mr181806vdc.57.1388497011859; Tue, 31 Dec 2013 05:36:51 -0800 (PST) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id c14si2273211veu.142.2013.12.31.05.36.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 31 Dec 2013 05:36:51 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id c14so6577423vea.9 for ; Tue, 31 Dec 2013 05:36:51 -0800 (PST) X-Received: by 10.58.181.71 with SMTP id du7mr1382920vec.25.1388497011755; Tue, 31 Dec 2013 05:36:51 -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 ey3csp664862ved; Tue, 31 Dec 2013 05:36:51 -0800 (PST) X-Received: by 10.180.90.141 with SMTP id bw13mr18903631wib.13.1388497010947; Tue, 31 Dec 2013 05:36:50 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id je18si18745046wic.16.2013.12.31.05.36.49 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 31 Dec 2013 05:36:50 -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-0000wD-MX; 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 09/22] softfloat: Fix float64_to_uint32 Date: Tue, 31 Dec 2013 13:35:45 +0000 Message-Id: <1388496958-3542-10-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.128.178 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 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, we ignore any flags which the conversion routine has set and raise only the invalid flag. This contribution can be licensed under either the softfloat-2a or -2b license. Signed-off-by: Tom Musta Message-id: 1387397961-4894-5-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 8e536ad..6b07ef2 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -6648,19 +6648,18 @@ 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; + int old_exc_flags = get_float_exception_flags(status); - 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; - 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; }