From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailrelay4-3.pub.mailoutpod1-cph3.one.com (mailrelay4-3.pub.mailoutpod1-cph3.one.com [46.30.212.13]) by sourceware.org (Postfix) with ESMTPS id B840E3857C47 for ; Mon, 17 Aug 2020 14:31:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B840E3857C47 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=carewolf.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux@carewolf.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=carewolf.com; s=20191106; h=content-type:content-transfer-encoding:mime-version:references:in-reply-to: message-id:date:subject:cc:to:from:from; bh=Vs3z8X6OGjn5m9/BhDy6y8GkEPuJMkFItEQNaW2LFHE=; b=CBzyq8wUf1V65nPmK2lQRm7Mpzl+s67uKy7eA2+SsO15zyPm8C2tFDuziRrVy5xP1MdlbrSGFUYCV f4CCsZgSdcvuYPDmETPjpBv2lW6gqYxd+bm6bbb0vpyOQ1fhRbyknstX1rNuLWTYWxVFj+m35MOpGq klcCjXUFxrRkag5WWSXlVQmauoSLp9xoJIThOjjQMzKQBscCzt6AZnj7nPem7xutf90JFOMQtZB0Mp ecAxY79cazBrya0ry4ase2eOFiqfpZYdbGiDjI1ScXTDAyDXihbg8cKQmVnMe2GU9sh7fPn5z+FYlD fDwo15eRt2QYbHTounqpZMOgGu+rFbw== X-HalOne-Cookie: 381e8b907697a91278c2d39b5e4eecf38b5ae398 X-HalOne-ID: 5aba4175-e096-11ea-9b1e-d0431ea8bb10 Received: from twilight.localnet (cable-158-181-75-108.cust.telecolumbus.net [158.181.75.108]) by mailrelay4.pub.mailoutpod1-cph3.one.com (Halon) with ESMTPSA id 5aba4175-e096-11ea-9b1e-d0431ea8bb10; Mon, 17 Aug 2020 14:31:36 +0000 (UTC) From: Allan Sandfeld Jensen To: gcc@gcc.gnu.org Cc: Stefan Kanthak Subject: Re: Peephole optimisation: isWhitespace() Date: Mon, 17 Aug 2020 16:31:35 +0200 Message-ID: <7880964.lOV4Wx5bFT@twilight> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Mon, 17 Aug 2020 14:31:40 -0000 On Freitag, 14. August 2020 18:43:12 CEST Stefan Kanthak wrote: > Hi @ll, > > in his ACM queue article , > Matt Godbolt used the function > > | bool isWhitespace(char c) > | { > | > | return c == ' ' > | > | || c == '\r' > | || c == '\n' > | || c == '\t'; > | > | } > > as an example, for which GCC 9.1 emits the following assembly for AMD64 > > processors (see ): > | xor eax, eax ; result = false > | cmp dil, 32 ; is c > 32 > | ja .L4 ; if so, exit with false > | movabs rax, 4294977024 ; rax = 0x100002600 > | shrx rax, rax, rdi ; rax >>= c > | and eax, 1 ; result = rax & 1 > | > |.L4: > | ret > No it doesn't. As your example shows if you took the time to read it, it is what gcc emit when generating code to run on a _haswell_ architecture. If you remove -march=haswell from the command line you get: xor eax, eax cmp dil, 32 ja .L1 movabs rax, 4294977024 mov ecx, edi shr rax, cl and eax, 1 It uses one mov more, but no shrx. 'Allan