From patchwork Thu Oct 27 11:27:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 79645 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp565203qge; Thu, 27 Oct 2016 04:29:01 -0700 (PDT) X-Received: by 10.98.72.86 with SMTP id v83mr13493174pfa.148.1477567741073; Thu, 27 Oct 2016 04:29:01 -0700 (PDT) Return-Path: Received: from sourceware.org ([209.132.180.131]) by mx.google.com with ESMTPS id fa6si3744884pab.214.2016.10.27.04.29.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Oct 2016 04:29:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439711-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-439711-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439711-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:content-type:mime-version; q=dns; s=default; b=qBuRuwkjPWUn1yx/pfKgCeCccP5aNh9EneLH4l220WfB/eTolU ZLLLu57lodPLilFj6/rWA/0o0a7Sm9RWLq8RyfGjZesU2yoTDFvYrKGY7QINYiLm 5JvWw3GeiFddhtSo45Es6b9e5EUY5FWFF/r7lzb79Biiw/ms5zLUQy70E= 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:content-type:mime-version; s= default; bh=H3r0YR8QOcpoR6pi9Ev2BFq3Zo8=; b=f8iZ01/22IkAiZrrtUab YHuBlbO/eomRRMSar9QCpXsVG8EoNj7bCVMcx8F/VXRM+AhMNd17b+dgGomXpP3A quZmgzzpgSu+53Z5ZZ59kJK1hmpjANzbfiAQ/eKOeSWBcCFbMCeXgP7hQl8R89kJ lz5JroSpvQahaE5e1SAHBOE= Received: (qmail 108889 invoked by alias); 27 Oct 2016 11:28:20 -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 108860 invoked by uid 89); 27 Oct 2016 11:28:19 -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, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:U*ian, bsr, BSR, precautionary X-HELO: COL004-OMC1S16.hotmail.com Received: from Unknown (HELO COL004-OMC1S16.hotmail.com) (65.55.34.26) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Oct 2016 11:28:09 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com ([65.55.34.7]) by COL004-OMC1S16.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Thu, 27 Oct 2016 04:28:01 -0700 Received: from VE1EUR03FT058.eop-EUR03.prod.protection.outlook.com (10.152.18.51) by VE1EUR03HT199.eop-EUR03.prod.protection.outlook.com (10.152.19.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.5; Thu, 27 Oct 2016 11:28:00 +0000 Received: from HE1PR0701MB2169.eurprd07.prod.outlook.com (10.152.18.56) by VE1EUR03FT058.mail.protection.outlook.com (10.152.19.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.5 via Frontend Transport; Thu, 27 Oct 2016 11:28:00 +0000 Received: from HE1PR0701MB2169.eurprd07.prod.outlook.com ([10.168.36.18]) by HE1PR0701MB2169.eurprd07.prod.outlook.com ([10.168.36.18]) with mapi id 15.01.0679.015; Thu, 27 Oct 2016 11:27:59 +0000 From: Bernd Edlinger To: GCC Patches CC: Ian Lance Taylor Subject: [PATCH, LIBGCC] Avoid count_leading_zeros with undefined result (PR 78067) Date: Thu, 27 Oct 2016 11:27:59 +0000 Message-ID: authentication-results: airs.com; dkim=none (message not signed) header.d=none; airs.com; dmarc=none action=none header.from=hotmail.de; x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [Tvzhh/lVwRM6R9NMFhB1YspfcJcBSTNN] x-eopattributedmessage: 0 x-microsoft-exchange-diagnostics: 1; VE1EUR03HT199; 6:X8Kepa7Jw5ojyYnJkS0hNOdF4DjhID5LeepBu+S/WtQfxgzxtP4mwNA3giRC6OlCzC9PJhh5rAIoBSF7EQWOHU0VDnbqip5lJQUh5LYOKBOgyfn4dt3YfXj58mUboeZGm8oaihZoofTsGlcg94ownTStSSCgpO672o6sUcIdpNZdi/FGfKubEz2KCOrh3EsEjjrAV7/vpwDdMRg+oFWFqFL9e55A7wDJAlwAgkd6n4BYWmVBJE9koCj8ZIRZHGYjmr9bGsugL3l/aKH+Kw+bNmIxPTU2DtROV+0K5RLem4Jw2m/r5uqjgd+kmrmcd8J1; 5:SlEZYkmGZPX4/wkqoJD0OeA88aoD4oNk1Gs6cT40ZpxS93KKhADzz9q3smjDgI+YDYhLSo/vxgoU/lED3Dq1RqwhlyoblG15v4FiYrCo6g+A/v/ZQ2T5zTk8SNVBIAf4H0LZaFtLXGGu7slFhdbJPA==; 24:doP3rL6dVz5LDZJmLG/qpFaDtcUZ1Ctvgjpd+76whyd3rnAHBMWGGqavQk4SQ+J2p/YdL4zhQ9grUhqX0iVfJzAzv2gzqKbgMe3+5ttsGb4=; 7:vV+ozHYSuDDXz0ZtGxKlVJU3KyiMLw8HCdvC/uSQJVhdRlCSbNFsRevbRVfe7WIHq99swmMJHWHyVtLZAkpUXV5zrWd11bAQPPtvsErXxl2cqKzpRXzsissauHiFNnZN+zfMtEI27U+UkxvrBhtHrHKXvUidxquSZxUwsPTmY0ZFmuzUL1QcQVShTWF86M2De/+iAbm3NRk7G8UVqoD0si8R3cihJsGA/NYQw+Nbbw5oHuQHsTLhNDYE6Vunz0WmTraYIwakfpt6dSf2NeBq2qlt49CpH7Te0xn9eoBYAUHqai5sh4/UgNltsgd6HSXuvoL762gh9qRLU8Sp3XtHSStR4qwYCst1WkMRugM/CDk= x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(10019020)(98900003); DIR:OUT; SFP:1102; SCL:1; SRVR:VE1EUR03HT199; H:HE1PR0701MB2169.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: 4f24f5d2-c8ef-4da4-5494-08d3fe5c4ea2 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(1601124038)(1603103081)(1601125047); SRVR:VE1EUR03HT199; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(432015012)(102415321)(82015046); SRVR:VE1EUR03HT199; BCL:0; PCL:0; RULEID:; SRVR:VE1EUR03HT199; x-forefront-prvs: 0108A997B2 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Oct 2016 11:27:59.5856 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT199 Hi, by code reading I became aware that libgcc can call count_leading_zeros in certain cases which can give undefined results. This happens on signed int128 -> float or double conversions, when the int128 is in the range INT64_MAX+1 to UINT64_MAX. On x86_64, there is (more or less by chance) no visible effect, because a "BSR esi, esi" instruction is used, which leaves the esi register unchanged, thus the result is only off by one, but that may change at any time. This precautionary patch uses COUNT_LEADING_ZEROS_0 to check what the result of count_leading_zeros(0) will be, and avoids that call if the result is not W_TYPE_SIZE. Bootstrapped and reg-tested on x86_64-pc-linux-gnu. Is it OK for trunk? Thanks Bernd. 2016-10-27 Bernd Edlinger PR libgcc/78067 * libgcc2.c (__floatdisf, __floatdidf): Avoid undefined results from count_leading_zeros. Index: libgcc2.c =================================================================== --- libgcc2.c (revision 241400) +++ libgcc2.c (working copy) @@ -1643,6 +1643,11 @@ hi = -(UWtype) hi; UWtype count, shift; +#if !defined (COUNT_LEADING_ZEROS_0) || COUNT_LEADING_ZEROS_0 != W_TYPE_SIZE + if (hi == 0) + count = W_TYPE_SIZE; + else +#endif count_leading_zeros (count, hi); /* No leading bits means u == minimum. */