From patchwork Fri Oct 13 16:24:22 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: 115809 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp940487qgn; Fri, 13 Oct 2017 09:48:03 -0700 (PDT) X-Received: by 10.55.104.216 with SMTP id d207mr2859801qkc.142.1507913283432; Fri, 13 Oct 2017 09:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507913283; cv=none; d=google.com; s=arc-20160816; b=loD49myh9H69oCq1Uqd7BJOwNji3oRo8zTO5MwRsYrm6OA843YYzn9ZgQFyV0D9hRL 7z9a7vOSvmkr9xD6bvRriCmInfd5SL+iZtV8ZQJYVScyah/NpOzTZ4XK0OunRrro9C8q 1w7JdCf4qGQWJOkkqgmLcEiNus/FPFwQujxwCr53rxlA5caOSh5QPCxLiV1t6m0xltMC wLEoSn8LwWN5O8gsUfQyh29SlJI619WdsFY2Awh904oU59XY28PFm3TUFRi+FFwIN3XQ jxjiBV3u4WrcxTgOWuuAvPF40EEE7yAwjkC7LuIPxo6zjYscU6nm84mOOKUJ9OBkm7Ah XMGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=xs7O6Zy8N4Lzul7y2734QtKpGG+w/SMd3MT57cbaOYo=; b=y3g4XQtL0nbQ8KFfXSBZQ6KO5WtAyPgrkdabcMF43WyFi5ZK1Q6DONm4mkthzhAffr DFg7UCnCUCs6eRH9rvthXvUQ+t8J1zwLJAeiuprOme6EgH7GyaXkbu8A9D7qkTugDFR/ NeojrQD13bluevzyyo7Ty2t5zHKCEZmGt6ojMS1Bd7MSLTZf1AP+AzxIDpx6PdDi92Th LReNB1OwtHd4pif6tMtHO4rb4jh5kM7ORTZsgRN328Rni/5+EQHSFAJ95kpJk6JY0q1g A4B/nNzKHYA2wdQ85RZM84Fmcp4ink7/IXAeKMaW6+dT2B8RAi4/XuKtQDUR1maQfFpe n+ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eX28waQX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id i48si1171222qta.66.2017.10.13.09.48.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 13 Oct 2017 09:48:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eX28waQX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e337x-0004iI-3U for patch@linaro.org; Fri, 13 Oct 2017 12:48:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e32sg-0000gk-T3 for qemu-devel@nongnu.org; Fri, 13 Oct 2017 12:32:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e32sf-0002P3-CK for qemu-devel@nongnu.org; Fri, 13 Oct 2017 12:32:14 -0400 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:56195) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e32sf-0002OX-4P for qemu-devel@nongnu.org; Fri, 13 Oct 2017 12:32:13 -0400 Received: by mail-wm0-x236.google.com with SMTP id u138so22988456wmu.4 for ; Fri, 13 Oct 2017 09:32:13 -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=xs7O6Zy8N4Lzul7y2734QtKpGG+w/SMd3MT57cbaOYo=; b=eX28waQXsGFHZe6cZFLVAkxQCYakWFFwOrXmSMmesDGIs6NEfXmTWM6bsKdDIeLOJB L6gyqMkSLRJku1tfLCTXiblItZ7U95fnapSBNThJuXxEniAR3xyJ4kFtTrBRDxd3NtfK 26qYhIYQA2Mhg6wICVsDvDi5veAFwCvxyn+R0= 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=xs7O6Zy8N4Lzul7y2734QtKpGG+w/SMd3MT57cbaOYo=; b=oph/hTICMnQfSlvKLZHMhZ6Jh41alcJm62zJBupfPnmtySGZaE9uj3/5iuJ2mqJTcy OCRagG7aAj/zWxZytK5SbIfrhAEX1+nuJqLWOXLzJZdR4mv6IIlgi4vEG/62drVLkvLz xyY4avhoCNWQTygm7zSX69TJNElPCCyCcX2VwKnTDvMtFj54wsJpqni92c1eoDoAkqI1 D2RxdvmCcrd/pNKaz8FBDPJDpkVmLmWde9wUiC5mgNOHDLTagtIH8Zl3V8nfRVLCu4R4 cWBTCY2Fv+Gwf7Pmg0VidB1ChnBU2FhStPEUJMmwZb8EEpyu3cnyqFVJkiZk8G6QKNmf fHBg== X-Gm-Message-State: AMCzsaUmzTdTLRNpxW2QDPsSXO1DE8tU4kGlfGdOIhbSAm9Tt+bmGkiA QCHWwN5S0TsHx1eayh8E6nRBlw== X-Google-Smtp-Source: ABhQp+SQ0lw0eek/HWbRZAGDq4cFoVTutujhlbAMnnJge336GvjCxWUb1yjRDQIkhxwndCYfdueA0g== X-Received: by 10.28.152.5 with SMTP id a5mr2072887wme.131.1507912331987; Fri, 13 Oct 2017 09:32:11 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id p128sm1654630wmb.1.2017.10.13.09.32.01 (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 6AC973E0BFD; Fri, 13 Oct 2017 17:24:39 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: richard.henderson@linaro.org Date: Fri, 13 Oct 2017 17:24:22 +0100 Message-Id: <20171013162438.32458-15-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::236 Subject: [Qemu-devel] [RFC PATCH 14/30] softfloat: 16 bit helpers for shr, clz and rounding and packing 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Half-precision helpers for float16 maths. I didn't bother hand-coding the count leading zeros as we could always fall-back to host-utils if we needed to. Signed-off-by: Alex Bennée --- fpu/softfloat-macros.h | 39 +++++++++++++++++++++++++++++++++++++++ fpu/softfloat.c | 21 +++++++++++++++++++++ 2 files changed, 60 insertions(+) -- 2.14.1 diff --git a/fpu/softfloat-macros.h b/fpu/softfloat-macros.h index 9cc6158cb4..73091a88a8 100644 --- a/fpu/softfloat-macros.h +++ b/fpu/softfloat-macros.h @@ -89,6 +89,31 @@ this code that are retained. # define SOFTFLOAT_GNUC_PREREQ(maj, min) 0 #endif +/*---------------------------------------------------------------------------- +| Shifts `a' right by the number of bits given in `count'. If any nonzero +| bits are shifted off, they are ``jammed'' into the least significant bit of +| the result by setting the least significant bit to 1. The value of `count' +| can be arbitrarily large; in particular, if `count' is greater than 16, the +| result will be either 0 or 1, depending on whether `a' is zero or nonzero. +| The result is stored in the location pointed to by `zPtr'. +*----------------------------------------------------------------------------*/ + +static inline void shift16RightJamming(uint16_t a, int count, uint16_t *zPtr) +{ + uint16_t z; + + if ( count == 0 ) { + z = a; + } + else if ( count < 16 ) { + z = ( a>>count ) | ( ( a<<( ( - count ) & 16 ) ) != 0 ); + } + else { + z = ( a != 0 ); + } + *zPtr = z; + +} /*---------------------------------------------------------------------------- | Shifts `a' right by the number of bits given in `count'. If any nonzero @@ -664,6 +689,20 @@ static uint32_t estimateSqrt32(int aExp, uint32_t a) } +/*---------------------------------------------------------------------------- +| Returns the number of leading 0 bits before the most-significant 1 bit of +| `a'. If `a' is zero, 16 is returned. +*----------------------------------------------------------------------------*/ + +static int8_t countLeadingZeros16( uint16_t a ) +{ + if (a) { + return __builtin_clz(a); + } else { + return 16; + } +} + /*---------------------------------------------------------------------------- | Returns the number of leading 0 bits before the most-significant 1 bit of | `a'. If `a' is zero, 32 is returned. diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 6ab4b39c09..cf7bf6d4f4 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3488,6 +3488,27 @@ static float16 roundAndPackFloat16(flag zSign, int zExp, return packFloat16(zSign, zExp, zSig >> 13); } +/*---------------------------------------------------------------------------- +| Takes an abstract floating-point value having sign `zSign', exponent `zExp', +| and significand `zSig', and returns the proper single-precision floating- +| point value corresponding to the abstract input. This routine is just like +| `roundAndPackFloat32' except that `zSig' does not have to be normalized. +| Bit 15 of `zSig' must be zero, and `zExp' must be 1 less than the ``true'' +| floating-point exponent. +*----------------------------------------------------------------------------*/ + +static float16 + normalizeRoundAndPackFloat16(flag zSign, int zExp, uint16_t zSig, + float_status *status) +{ + int8_t shiftCount; + + shiftCount = countLeadingZeros16( zSig ) - 1; + return roundAndPackFloat16(zSign, zExp - shiftCount, zSig<