From patchwork Mon Oct 24 13:44:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Greenhalgh X-Patchwork-Id: 78956 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp2585968qge; Mon, 24 Oct 2016 06:45:46 -0700 (PDT) X-Received: by 10.98.157.218 with SMTP id a87mr29197008pfk.1.1477316746771; Mon, 24 Oct 2016 06:45:46 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d5si15514429pgk.71.2016.10.24.06.45.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Oct 2016 06:45:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439395-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439395-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439395-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; q=dns; s=default; b=GoocZOidEPFz7gMA WYA8Z2KNh3iKbTZ8jWkFCqSSug0O/lQajQHK6YcmjYPfwvm4MLRDAkatHrHQfgLl aW0J6s/t+gHLobv3KLlrMSbv1JP+87MAPz9cEPE4R+RzUWHgT0SXWnDlaYCbXRll avHCNci/mkh+yCt30gUCSsD7q7c= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=default; bh=RJJYupO3Qqt6BcynoR+3Rl uyQWE=; b=BjSFtHoCwj3phLe0iLlBZI9SPsRA+HJry/nzYjFQI3aZloUDWxjgWq I/bXdN0XvjkxzwyMhg1okEpzF40xCk/zYfsk9QtqQywYIB8/ZhUG/Zaf4mene7GV v4Ifqzy3P6+pkHV+uJU2it29YZ3xI5OMXwoolT7NqJHjmZQPAzNwc= Received: (qmail 60070 invoked by alias); 24 Oct 2016 13:45:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 59406 invoked by uid 89); 24 Oct 2016 13:45:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=2269, 0x8000, 2235, adapting X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Oct 2016 13:45:10 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03lp0086.outbound.protection.outlook.com [94.245.120.86]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-94-ADfpiwMROGOUqyP1irnQhA-1; Mon, 24 Oct 2016 14:45:04 +0100 Received: from DB5PR08CA0008.eurprd08.prod.outlook.com (10.163.102.146) by VI1PR08MB0623.eurprd08.prod.outlook.com (10.163.169.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.12; Mon, 24 Oct 2016 13:44:59 +0000 Received: from DB3FFO11FD042.protection.gbl (2a01:111:f400:7e04::107) by DB5PR08CA0008.outlook.office365.com (2a01:111:e400:52c3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12 via Frontend Transport; Mon, 24 Oct 2016 13:44:59 +0000 Received: from nebula.arm.com (217.140.96.140) by DB3FFO11FD042.mail.protection.outlook.com (10.47.217.73) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.669.7 via Frontend Transport; Mon, 24 Oct 2016 13:44:59 +0000 Received: from e107456-lin.cambridge.arm.com (10.1.2.79) by mail.arm.com (10.1.106.66) with Microsoft SMTP Server id 14.3.294.0; Mon, 24 Oct 2016 14:44:57 +0100 From: James Greenhalgh To: CC: , , , , Subject: [Patch 1/4] [libgcc, ARM] Generalise float-to-half conversion function. Date: Mon, 24 Oct 2016 14:44:37 +0100 Message-ID: <1477316680-5094-2-git-send-email-james.greenhalgh@arm.com> In-Reply-To: <1477316680-5094-1-git-send-email-james.greenhalgh@arm.com> References: <1475254617-10825-1-git-send-email-james.greenhalgh@arm.com> <1477316680-5094-1-git-send-email-james.greenhalgh@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:217.140.96.140; IPV:CAL; SCL:-1; CTRY:GB; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(438002)(189002)(199003)(377424004)(626004)(5660300001)(4001150100001)(2476003)(106466001)(356003)(2351001)(76176999)(50986999)(230783001)(19580405001)(229853001)(19580395003)(7846002)(110136003)(26826002)(86362001)(2950100002)(6916009)(77096005)(5890100001)(512874002)(4610100001)(305945005)(2906002)(568964002)(586003)(4326007)(84326002)(189998001)(11100500001)(50226002)(33646002)(6666003)(87936001)(92566002)(104016004)(36756003)(8936002)(8676002)(246002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB0623; H:nebula.arm.com; FPR:; SPF:Pass; PTR:fw-tnat.cambridge.arm.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DB3FFO11FD042; 1:+Sl93yUEjjUFXYXEXj3AjGY7RPwp97sny5odbKX20gpjkq4Ik95dQAubv8NII+8dqMMvS57akTovnvm1ZAySXwcbXkbDzWdSB/wNeSP7TkLd+FbacmCDf1lClwP77X/fnZRqTeDjnZKc8U9oU3zJ/uwt2WWF9/iIrRkDexEjNURBiYe+YqCc5c0gYuZHIrndSUAwy7+M3lRqdSnEDfGgle5hTTkcYGuKyIZmAFc5OsPQYiL3ri/m3iy96Xc4C/Y+WREGqNdd9/RCKYpbcphcqZ1FZHZ7zSQcLTBh2x2dWN12ocrAMW/M94uV2n5F3COGRHHo/lZyf8feTDLPtYHEYlzfsDoBZ6/DqXSTOMKct7KJ9BqRYH5+TxJqcWnS7c78IWlseKhlwoxiDcgkko49hft/4/DujaWOlYdtt7wGrL/AJ6N51bxSuU/e2S7PaV5bqLXfK2bNU7gnlCotZDC5K1aFq4aSvgYeO7CNiKn/y9ia5yKBQtLD2TaYxGLKN7CLl+2j56W0EjPXTzYe8xRZjGuUsdf4VlFc37l6XW4Q+ztosNE3X/HnrTnHDyPDj6z2HXG9aKCi/SWjZSSuxVJgEwPbP0KK/f7g3d5bwnMfsm8= X-MS-Office365-Filtering-Correlation-Id: 5adfc703-a867-4926-3f2e-08d3fc13f2c7 X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0623; 2:sS5m20r6knB9cJrIwu7JxxgdyJawk7k9JiiN1Q3nPbGYQ2GMXgKYmE7AcigZIJaWNh0lb59Qo5F3jlIrDWN49RZV5pM0MLZ45d4fz4kO9LgSXBudb8LKfdpNA4AoCT4oIXTUnFrA/1mbX1RXargxaTB2uaWOh5Q4UZURsvAqYeuupeZcRi7T5K1XWE1Pyf20CwWVkaeT3+GlBDvmHSAfBA==; 3:f8ulJePkw2DAvDAA9VOVM/2ZsQy2m3Q+Vpg6Emr0MuoLLegcNetcTh+6mmsHwGAO3ww9DpwLa5Miz8IzpCM2fY6rWM1yzBbYTZcJfP1D8jsI4xwPBdeUXZjAF7tZko0H+/mGjEMw2M7XHb1CMpUTRX3AD6wm7t9PH/cJCjTogjXaVfGxQckbIWfC4Mtz+LBuOaTNLWLVdOFjRNgh3MKwMfVJZjZxV+s8geurQFSYiRpMMngXE3os9gVclLcHASAZ0ge9h6dIASd+fs79dU8eEl9eRICYZlMum1vkuebHdno= X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:VI1PR08MB0623; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0623; 25:T2RlHVvo8KngS5iewohT6EIUST9fzSAr2hIXvqFolRlhmUybbGAa2Wc61OgmRUuaC+tlYUgxlg6CmfrL9FJhOm8FGAjVMCMFWJfvIRPlWORCAiY6cPxPiXxDpTDuQxzlL7ZFTVMdRnm9mYx/cl6NVfvdrdEn2DWUYkU1k2rQoq2JvFY7js8hgE+rWOyrK5b7R2Y/utb08A0Zefbbeu9dTv4fvTAEvhgz7INmsh3xylZ61uUmt56zeRyvwVvtmRFziipxee/GqEIlawWuEgNg0i4LBQV7hDvWbCh1KV2OQze0LvYX/akeg4bOLzVTkgQ+5erMmMMbWIJKWY4b2lmg9JmZVONpHZOOx2Est0QQfVbAnAxjKaP4wZdybwXd67J7ApCH66xII5NkC6noCyUfc01LOQBbgLhOEKwPbeXnpT+4RCnPWjIeHNLlWGm57guTand8cYM5wEq/obLasBLo+meG0ghsu0PZvDmTV2HMIijhhtJk1Udx9np50FGerHqCpAQ7h9IPMshCSejQJPgNc+nuWKSueAwHVpXVu/z0wmopCo0omG7cdkX98SY5IDoj6mv1VbohTYeF6CipnixZskbgGQqdZ6/dby7bHhh7FmBqfcN5XHZVRxuajPqFukGYwI5hLZhA9ArTB337LwYKdVggHKtJ8+Qx+FUd61Hxvl0AtoZymMKRXguV5KaDxs2rWQm5X+rVVS3gzY4l01uHVNET8pkVtuEJXtJYwK+PVnCIEQhNP7kNMJh1V3n6RUKqMaSWbH4Eyp7bSPkC801BTk5d8qdlCDfSnjybej7JqTtI9TNojFcynuUz0gHKntdN4nBVJL/gEQ9AJ/6aTWVfCR6T+bY4+PBORsKuqQydyH62MclPl+xdzQHhwoXf+SYJHn549wx8313xmtUhQT3g50nxsYGplypw5mg49Apy/aI= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0623; 31:cNV7KkkFggaTLxV/mWXZ2ZFma5yJJLj6YaCXlgzz6g7+MAJIZbkw2KPFZymk44TZBgxeYzqJOo4KhLsl36g73LcD5Q7sWeRLQ9ibyaxoM8uqFu4iuNseAWyPGpQKtR16w8UmtnxyDhEukpQlb90o1+Ebq28j3GGxAuVVR4Mso4IWYibE2+/DHWoACJMVvbzjiOxsLaqeySrIJq1l14GKpoVQKgXmwTRhCO0cHHbiDwtHWpT9k/OrvhPoJnSq51WuHg+sSXOR81o/51HF0VgjexgwkP2NwM+KQqN9TOQ4BxU=; 20:v2oKLkhJCFwcwla3iJFN90tZJ93Ms9FXlrf3cSE70bxW/It/nmwZL3BvOpW3jkAFInKOZImbNdkdFFMUcQ/bRbTk8m9xvOKtvlFatJ7ZcfDGiXSp5y0UoJxbiQO3cRemHo5/dc/QbbWGOofqY263oLOhPRD24QO/z0sjnGnPlbiS4i9N/SP8M4I5zMeMxg1dfxYDoUC5Ig5w9yjR8F6fO1w+IBA6CqX5uhrouwg13RW5FxnArpgE5O6jdif08Phe NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(102415321)(6040176)(601004)(2401047)(13023025)(13013025)(13020025)(13024025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:VI1PR08MB0623; BCL:0; PCL:0; RULEID:; SRVR:VI1PR08MB0623; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0623; 4:SCRMDj1xMKDhQ80WTAxKo8D0cMjZA7VA3VT2/o91/jNENS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CrossTenant-OriginalArrivalTime: 24 Oct 2016 13:44:59.4598 (UTC) X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[217.140.96.140]; Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB0623 X-MC-Unique: ADfpiwMROGOUqyP1irnQhA-1 X-IsSubscribed: yes Hi, I'm adapting this patch from work started by Matthew Wahab. Conversions from double precision floats to the ARM __fp16 are required to round only once. A conversion function for double to __fp16 to support this on soft-fp targets. This and the following patch add this conversion function by reusing the exising float to __fp16 function config/arm/fp16.c:__gnu_f2h_internal. This patch generalizes __gnu_f2h_internal by adding a specification of the source format and reworking the code to make use of it. Initially, only the binary32 format is supported. Bootstrapped on an ARMv8-A machine with no issues, and cross-tested with a reasonable multi-lib range. OK? Thanks, James --- libgcc/ 2016-10-24 James Greenhalgh Matthew Wahab * config/arm/fp16.c (struct format): New. (binary32): New. (__gnu_float2h_internal): New. Body moved from __gnu_f2h_internal and generalize. (_gnu_f2h_internal): Move body to function __gnu_float2h_internal. Call it with binary32. diff --git a/libgcc/config/arm/fp16.c b/libgcc/config/arm/fp16.c index 39c863c..8d02a24 100644 --- a/libgcc/config/arm/fp16.c +++ b/libgcc/config/arm/fp16.c @@ -22,35 +22,69 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ +struct format +{ + /* Number of bits. */ + unsigned long long size; + /* Exponent bias. */ + unsigned long long bias; + /* Exponent width in bits. */ + unsigned long long exponent; + /* Significand precision in explicitly stored bits. */ + unsigned long long significand; +}; + +static const struct format +binary32 = +{ + 32, /* size. */ + 127, /* bias. */ + 8, /* exponent. */ + 23 /* significand. */ +}; + static inline unsigned short -__gnu_f2h_internal(unsigned int a, int ieee) +__gnu_float2h_internal (const struct format* fmt, + unsigned long long a, int ieee) { - unsigned short sign = (a >> 16) & 0x8000; - int aexp = (a >> 23) & 0xff; - unsigned int mantissa = a & 0x007fffff; - unsigned int mask; - unsigned int increment; + unsigned long long point = 1ULL << fmt->significand;; + unsigned short sign = (a >> (fmt->size - 16)) & 0x8000; + int aexp; + unsigned long long mantissa; + unsigned long long mask; + unsigned long long increment; + + /* Get the exponent and mantissa encodings. */ + mantissa = a & (point - 1); + + mask = (1 << fmt->exponent) - 1; + aexp = (a >> fmt->significand) & mask; - if (aexp == 0xff) + /* Infinity, NaN and alternative format special case. */ + if (((unsigned int) aexp) == mask) { if (!ieee) return sign; if (mantissa == 0) return sign | 0x7c00; /* Infinity. */ /* Remaining cases are NaNs. Convert SNaN to QNaN. */ - return sign | 0x7e00 | (mantissa >> 13); + return sign | 0x7e00 | (mantissa >> (fmt->significand - 10)); } + /* Zero. */ if (aexp == 0 && mantissa == 0) return sign; - aexp -= 127; + /* Construct the exponent and mantissa. */ + aexp -= fmt->bias; + + /* Decimal point is immediately after the significand. */ + mantissa |= point; - /* Decimal point between bits 22 and 23. */ - mantissa |= 0x00800000; if (aexp < -14) { - mask = 0x00ffffff; + mask = point | (point - 1); + /* Minimum exponent for half-precision is 2^-24. */ if (aexp >= -25) mask >>= 25 + aexp; } @@ -64,8 +98,8 @@ __gnu_f2h_internal(unsigned int a, int ieee) if ((mantissa & mask) == increment) increment = mantissa & (increment << 1); mantissa += increment; - if (mantissa >= 0x01000000) - { + if (mantissa >= (point << 1)) + { mantissa >>= 1; aexp++; } @@ -93,7 +127,13 @@ __gnu_f2h_internal(unsigned int a, int ieee) /* We leave the leading 1 in the mantissa, and subtract one from the exponent bias to compensate. */ - return sign | (((aexp + 14) << 10) + (mantissa >> 13)); + return sign | (((aexp + 14) << 10) + (mantissa >> (fmt->significand - 10))); +} + +static inline unsigned short +__gnu_f2h_internal (unsigned int a, int ieee) +{ + return __gnu_float2h_internal (&binary32, (unsigned long long) a, ieee); } unsigned int