From patchwork Fri Oct 13 16:24:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 825606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="kaJjjkpT"; dkim-atps=neutral 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 3yDDCs185yz9sxR for ; Sat, 14 Oct 2017 03:47:37 +1100 (AEDT) Received: from localhost ([::1]:51148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e337X-0004Oe-9H for incoming@patchwork.ozlabs.org; Fri, 13 Oct 2017 12:47:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e32se-0000eK-7n for qemu-devel@nongnu.org; Fri, 13 Oct 2017 12:32:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e32sb-0002KJ-CP for qemu-devel@nongnu.org; Fri, 13 Oct 2017 12:32:12 -0400 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:55189) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e32sb-0002JI-5v for qemu-devel@nongnu.org; Fri, 13 Oct 2017 12:32:09 -0400 Received: by mail-wm0-x22e.google.com with SMTP id i124so22849885wmf.3 for ; Fri, 13 Oct 2017 09:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8LOwz6//NJMXAgclJcDnSEFpDscUIyCSbJ44FRUXv0I=; b=kaJjjkpTsqnL3XDMCT83SIIZFlnSpH1ifLZhYoTBmS6XB8hy7XFC75i/dlvqYciSwM NcpEQG2L/2An4Nu4PrPITr1gl5TzmbpFXb4uFvpePvl9aso6oWtxbfFENc9nwytXQTte i+Njeb4/pDgYORrQVRRcecMOJIsbTN+g1QCtg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8LOwz6//NJMXAgclJcDnSEFpDscUIyCSbJ44FRUXv0I=; b=pX1z+LIeI/8Lg/8msACCnahr9/MVkR5QXYSU/hUJ+6DhoJrIO5hDBIGVgN5uclf/XE g/9wicbz60k8e9UecK0P6epMyHSM1rqm6fbtlHHC2rSwtXY5DsPsupfNMyM3BaCFnYhZ g8N4c8gfIUE6Y//Do5Ch6Iw8DxGb7d2fLOWhC7tkEdoJ5xkLqYetkxqlMlsxvxz6I3AS jca7Hlbw7B8AwC1tcXjd6R2a9AEB6+wEXo0v+fevNB2VXJHLAhwRA3CMWxfO/ebmL7xf 3CJPN33u75lPZOYzb1rh3jGa+Dl1aB6Y6KwfgZoagVdHzRxsEwwbfModJ+1JEXF3Sez9 dhqQ== X-Gm-Message-State: AMCzsaWCoNRalia6fz00SDmW2n7JJRI9bAh9Rsntd7kYf4BoTTooH7lC FF12dEPlG+CGeTGlD5azWIuJ/w== X-Google-Smtp-Source: ABhQp+R5Z6aGG93+JUTIkKPBRGxkN2Yfy6flHWHgIAMOCsq4hFAx3zYG6spfRueNDjsUSL+mMhhm6g== X-Received: by 10.28.211.69 with SMTP id k66mr1853452wmg.1.1507912328032; Fri, 13 Oct 2017 09:32:08 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id s123sm723220wmd.29.2017.10.13.09.32.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Oct 2017 09:32:03 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 4353C3E1061; Fri, 13 Oct 2017 17:24:40 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: richard.henderson@linaro.org Date: Fri, 13 Oct 2017 17:24:33 +0100 Message-Id: <20171013162438.32458-26-alex.bennee@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013162438.32458-1-alex.bennee@linaro.org> References: <20171013162438.32458-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22e Subject: [Qemu-devel] [RFC PATCH 25/30] softfloat: float16_round_to_int X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Again a mechanical conversion. Signed-off-by: Alex Bennée --- fpu/softfloat.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ include/fpu/softfloat.h | 1 + 2 files changed, 83 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index f7473f97e3..dc7f5f6d88 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3532,6 +3532,88 @@ static void normalizeFloat16Subnormal(uint32_t aSig, int *zExpPtr, *zExpPtr = 1 - shiftCount; } +/*---------------------------------------------------------------------------- +| Rounds the half-precision floating-point value `a' to an integer, +| and returns the result as a half-precision floating-point value. The +| operation is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ + +float16 float16_round_to_int(float16 a, float_status *status) +{ + flag aSign; + int aExp; + uint16_t lastBitMask, roundBitsMask; + uint16_t z; + a = float16_squash_input_denormal(a, status); + + aExp = extractFloat16Exp( a ); + if ( 0x19 <= aExp ) { + if ( ( aExp == 0x1F ) && extractFloat16Frac( a ) ) { + return propagateFloat16NaN(a, a, status); + } + return a; + } + if ( aExp <= 0xE ) { + if ( (uint16_t) ( float16_val(a)<<1 ) == 0 ) return a; + status->float_exception_flags |= float_flag_inexact; + aSign = extractFloat16Sign( a ); + switch (status->float_rounding_mode) { + case float_round_nearest_even: + if ( ( aExp == 0xE ) && extractFloat16Frac( a ) ) { + return packFloat16( aSign, 0xF, 0 ); + } + break; + case float_round_ties_away: + if (aExp == 0xE) { + return packFloat16(aSign, 0xF, 0); + } + break; + case float_round_down: + return make_float16(aSign ? 0xBC00 : 0); + case float_round_up: + /* -0.0/1.0f */ + return make_float16(aSign ? 0x8000 : 0x3C00); + } + return packFloat16( aSign, 0, 0 ); + } + lastBitMask = 1; + lastBitMask <<= 0x19 - aExp; + roundBitsMask = lastBitMask - 1; + z = float16_val(a); + switch (status->float_rounding_mode) { + case float_round_nearest_even: + z += lastBitMask>>1; + if ((z & roundBitsMask) == 0) { + z &= ~lastBitMask; + } + break; + case float_round_ties_away: + z += lastBitMask >> 1; + break; + case float_round_to_zero: + break; + case float_round_up: + if (!extractFloat16Sign(make_float16(z))) { + z += roundBitsMask; + } + break; + case float_round_down: + if (extractFloat16Sign(make_float16(z))) { + z += roundBitsMask; + } + break; + default: + abort(); + } + z &= ~ roundBitsMask; + if (z != float16_val(a)) { + status->float_exception_flags |= float_flag_inexact; + } + return make_float16(z); + +} + /*---------------------------------------------------------------------------- | Returns the result of adding the absolute values of the half-precision | floating-point values `a' and `b'. If `zSign' is 1, the sum is negated diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index a7435e2a5b..856f67cf12 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -346,6 +346,7 @@ float64 float16_to_float64(float16 a, flag ieee, float_status *status); | Software half-precision operations. *----------------------------------------------------------------------------*/ +float16 float16_round_to_int(float16, float_status *status); float16 float16_add(float16, float16, float_status *status); float16 float16_sub(float16, float16, float_status *status); float16 float16_mul(float16, float16, float_status *status);