From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpout2.vodafonemail.de (smtpout2.vodafonemail.de [145.253.239.133]) by sourceware.org (Postfix) with ESMTPS id 45FB0385740A for ; Sat, 14 Aug 2021 17:12:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 45FB0385740A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nexgo.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nexgo.de Received: from smtp.vodafone.de (smtpa06.fra-mediabeam.com [10.2.0.37]) by smtpout2.vodafonemail.de (Postfix) with ESMTP id 385CD1234A7; Sat, 14 Aug 2021 19:12:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexgo.de; s=vfde-smtpout-mb-15sep; t=1628961140; bh=Ly6vqT5revx8ihNBpYJL3xa4pRNveY5nJ/pZMgemswg=; h=From:To:References:In-Reply-To:Subject:Date; b=nhpgxPC/PY1/k6lW/L2waHljj/qqClONnqRCDDwway/6hg90PT9YBPXkmioEQwo09 tdlpcqMgy+4vNWFJNUtDcpyrdyJoYfViKRiNkCtSMceoM72ZApLzHt+0QJnUwuWtsq 46d5djwVLi4OZI0qBeFfBbm8Jr2qGMvNfF7zpiZg= Received: from H270 (p5b38f1bc.dip0.t-ipconnect.de [91.56.241.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.vodafone.de (Postfix) with ESMTPSA id E914A140182; Sat, 14 Aug 2021 17:12:19 +0000 (UTC) Message-ID: <3E50C50CC3EB49E8B479700FB4BEB243@H270> From: "Stefan Kanthak" To: "GCC Development" , "Gabriel Ravier" References: <452B1115CF904CFF9568638009A16E33@H270> <79331ef3-3ca5-0c17-af2c-e6bbb83b39e2@gmail.com> In-Reply-To: <79331ef3-3ca5-0c17-af2c-e6bbb83b39e2@gmail.com> Subject: Re: 3rd deficiency (was: Superfluous branches due to insufficient flow analysis) Date: Sat, 14 Aug 2021 19:10:08 +0200 Organization: Me, myself & IT MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Windows Mail 6.0.6002.18197 X-MimeOLE: Produced By Microsoft MimeOLE V6.1.7601.24158 X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 1675 X-purgate-ID: 155817::1628961140-00003C24-F6EDC765/0/0 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Aug 2021 17:12:32 -0000 Gabriel Ravier wrote: Independent from the defunct flow analysis in the presence of NaNs, my example demonstrates another minor deficiency: know thy instruction set! See the comments in the assembly below. > On 8/13/21 8:58 PM, Stefan Kanthak wrote: >> Hi, >> >> compile the following naive implementation of nextafter() for AMD64: >> >> JFTR: ignore the aliasing casts, they don't matter here! >> >> $ cat repro.c >> double nextafter(double from, double to) >> { >> if (to != to) >> return to; // to is NAN >> >> if (from != from) >> return from; // from is NAN >> >> if (from == to) // neither from nor to can be NAN here! >> return to; >> >> if (from == 0.0) // dito! >> return to < 0.0 ? -0x1.0p-1074 : 0x1.0p-1074; >> >> unsigned long long ull = *(unsigned long long *) &from; >> >> if ((from < to) == (from < 0.0)) >> ull--; >> else >> ull++; >> >> return *(double *) &ull; >> } >> $ gcc -m64 -o- -O3 -S repro.c >> ... >> nextafter: [...] >> .L4: >> comisd %xmm0, %xmm1 # sets CF if first comparand < second comparand >> movq %xmm0, %rdx >> leaq -1(%rdx), %rax # superfluous >> seta %r8b # sbb %rcx, %rcx >> comisd %xmm0, %xmm2 >> seta %cl # sbb %rax, %rax >> addq $1, %rdx # xor %rcx, %rax >> cmpb %cl, %r8b # or $1, %rax >> cmovne %rdx, %rax # add %rdx, %rax >> movq %rax, %xmm0 Stefan