From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by sourceware.org (Postfix) with ESMTPS id A49FF3858D3C for ; Sun, 28 May 2023 06:28:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A49FF3858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-62603efd2e3so12012166d6.1 for ; Sat, 27 May 2023 23:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685255325; x=1687847325; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=dxT/3oBhB+139mZ8Rxt/u6mIUx613vDCYCDAd9NVdmw=; b=rPtGApm+EEzJDsdGco8xHEJLzSijLxUb43821nA7MXPEkU7phTCYASsBE1V57Q9AzU eg6pN0fY91PR0zgX8kd/T4brfF2mWGcO+vGRbymsfF2FLopnu+lpsyQCctzfcVtkGwNu 9DqFceWre0qRSLsd62DJowXuPn+N7UJlAUJhqT+c+1/vvLR+a/Uci5LrKeHM8KI+ZaxN fZu0Y7HI5mYjRpIkeGuUY11L7/9DZ5Nci1oUbCW1t3iE8CAGaSxwV6BhGT/b1IwJFOhv r3tjseQtfUUv7WlhPbkESt7Hdv7y1mgWewWwnWI/czdepI3qZeb5xq/v1fiCvhppncXq W/4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685255325; x=1687847325; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dxT/3oBhB+139mZ8Rxt/u6mIUx613vDCYCDAd9NVdmw=; b=SWxa76hbnjHlYx3WgS9Bi9ngbnlQ8EBB72x9LueYNMIAufXtrWN5KSbwNOLMThFuHV eM53kphOkNloRb6VIbrs0eSoS2dfsj5+j+Ml+oEnMc0PFe/zNCVC/VOWaLy0q+kJTs2+ krnzSK8ezbAGGqlSw8Mk2NRTsV9a9eQJf+mGhDHgvdB7hjxJYt8/eu9isQIy+1syACKv QKxuy6Key/qZ0TiGJWPtRRAS4bS0jbGKN+L9Rb8284iLMgwR9vgb2fywtwv/jYOs1GAb eDV8iLVIVfSeSpOTSmDa3tiiXOugTpKM684gYc8CAn0bqgdOPx6THbN92ofvmglZVqwI eeYA== X-Gm-Message-State: AC+VfDyjrqhPiKR3aAHtXxAf4aRtJX6m8qW1yJqU84h7YFBxY/lsiTyb n5BgxwKWgXDFX88tnXsZyum7ViAB6rU= X-Google-Smtp-Source: ACHHUZ7w8mG2XtAn+F0FC+b4QscSIQ0MJC8EV7g7k3Y+Vx2IVrBGeKy7DLGPATv+XQ89ibVh1FISOg== X-Received: by 2002:a05:6214:d4b:b0:625:aa49:19ea with SMTP id 11-20020a0562140d4b00b00625aa4919eamr7387598qvr.55.1685255325387; Sat, 27 May 2023 23:28:45 -0700 (PDT) Received: from ?IPV6:2602:47:d92c:4400:4846:7012:40d6:e51b? ([2602:47:d92c:4400:4846:7012:40d6:e51b]) by smtp.gmail.com with ESMTPSA id mi3-20020a056214558300b005ef6b124d39sm2583738qvb.5.2023.05.27.23.28.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 27 May 2023 23:28:44 -0700 (PDT) Message-ID: <5a374835-cdf0-3542-8a64-fda3e400c052@gmail.com> Date: Sun, 28 May 2023 02:28:44 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: Another epic optimiser failure Content-Language: en-US To: gcc@gcc.gnu.org References: <2A5397441B7D46C7928856D7AAF5836B@H270> From: Nicholas Vinson In-Reply-To: <2A5397441B7D46C7928856D7AAF5836B@H270> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 5/27/23 17:04, Stefan Kanthak wrote: > --- .c --- > int ispowerof2(unsigned long long argument) { > return __builtin_popcountll(argument) == 1; > } > --- EOF --- > > GCC 13.3 gcc -m32 -march=alderlake -O3 > gcc -m32 -march=sapphirerapids -O3 > gcc -m32 -mpopcnt -mtune=sapphirerapids -O3 > > https://gcc.godbolt.org/z/cToYrrYPq > ispowerof2(unsigned long long): > xor eax, eax # superfluous > xor edx, edx # superfluous > popcnt eax, [esp+4] > popcnt edx, [esp+8] > add eax, edx > cmp eax, 1 -> dec eax > sete al > movzx eax, al # superfluous > ret > > 9 instructions in 28 bytes # 6 instructions in 20 bytes I agree this can be done using 6 instructions, but you cannot do it using the dec instruction. If you use the dec instruction, "movzx eax, al" becomes a required instruction (consider the case when the input is 0) resulting in 7 instructions and 22 bytes.