Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5130515rwb; Mon, 8 Aug 2022 12:44:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR5OmSHyJTo9OOgFDvsjt+MlaoJugjqJ3T/WxNcC3CQnRCnuu5Vag7UawzG8naL225rucKrq X-Received: by 2002:a17:90b:1e0c:b0:1f5:4e52:4866 with SMTP id pg12-20020a17090b1e0c00b001f54e524866mr28109229pjb.230.1659987877672; Mon, 08 Aug 2022 12:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659987877; cv=none; d=google.com; s=arc-20160816; b=XLBcxpb/KUcSyAkLHgkC63D8Uudsjr4jpqo+5IOaOqPh9ETmu/UOAs7SYAisNvX8NI sI3SOzNbAnIEsIsyN8ZoSQ8T7BkJPHHeUa2BiQY+7IpOpWXFrTRpGwMNLNLpWBXqNtcg SvjHanGn7DaE5sjS6VAyiu4w8B0rK28sUI1QSS4MUJgzNMJ8dyWUhwPoS9q6OUbRSFrY 58TOpC2fAD7rf0aIfJleqh8Y+fmwMXXkoxJMSCgqhNA3TYqCwbDwEsQwxUSswLEB1c0O S0Wfl315NPtar2e3HGN7WCQXwhUY5gVwCCsSimee4Iai39Z4cDpvar8x8plc0q7xiGjj AyWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:user-agent :mime-version:date:message-id:dkim-signature:dkim-filter; bh=AnDyp6xDzf+JDZY8vXjlTvzb+vuPwvrQlkUSK9lN8yc=; b=u7cCSjoQSc5/rQEcA2fSUnlaN6lXO4SFlGf8QC0uodZCQxKcjUBg1c2QnbNJSSyNnH 8Sc9ujMfDQ0N6/GPFXwaTo/iL5YAy17s1mgZ8CvUHPsBS//gPWW9o0kesZSGPo0Q7uMO Ct8VA5gsxmWuVqNhSHY9/4K7o6TKGeFZ4JKrqbaXyaBmU8F7R3MSyuiFdPlulcZMuGJX e6RZHnEc2LTRRNQC09CqD17z6zPJqJVL/0X22n4x5XtCW3QZh6FgOjTe+Lkkk53OIbdi qf27CC68yc4YGXd+eFTgB2Mah1ekK49fessDZIZCd7GGU57LC4Z3Li4r+LHEPNrktk+d dIJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@zytor.com header.s=2022080501 header.b=hKK9UXjv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a63be47000000b00412a9c29e5bsi5139994pgo.702.2022.08.08.12.44.22; Mon, 08 Aug 2022 12:44:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@zytor.com header.s=2022080501 header.b=hKK9UXjv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244184AbiHHTDM (ORCPT + 99 others); Mon, 8 Aug 2022 15:03:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244141AbiHHTDE (ORCPT ); Mon, 8 Aug 2022 15:03:04 -0400 Received: from mail.zytor.com (unknown [IPv6:2607:7c80:54:3::138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAA9D25ED for ; Mon, 8 Aug 2022 12:03:03 -0700 (PDT) Received: from [IPV6:2601:646:8600:40c0:425:cd56:6750:e1bf] ([IPv6:2601:646:8600:40c0:425:cd56:6750:e1bf]) (authenticated bits=0) by mail.zytor.com (8.17.1/8.17.1) with ESMTPSA id 278Ixgc9011401 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Mon, 8 Aug 2022 11:59:42 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 278Ixgc9011401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2022080501; t=1659985183; bh=AnDyp6xDzf+JDZY8vXjlTvzb+vuPwvrQlkUSK9lN8yc=; h=Date:From:Subject:To:Cc:References:In-Reply-To:From; b=hKK9UXjvCaPIGEdjdqyqVbMpdtZL3Y/wj/rvQw3+sVTl6bsYBJvfZj/tIFx60QpkN pjr1MdAkq6r5WuKttR1ITq93ESJLIK7IBkrLMR5ZeQW2gEjStBw0l2aWSlUGi+HwLZ WvCuu3wEw04npPeq1FmGTwDCJM2yl3n1Rj8wootmvA3Rh3fAeOHcnBb++AQI6OG0g0 Z+kLyRWzFpRXKcetHDPrFh+OEzUzkIR4yG3WZ0CqNrDmJziS4daNchLvoGk5Cd1E9x KFTWzherdWm0BnvHnL/kkRwCcdJTI+e2hkbfP6N5TaY23l3uBVzxlsVWrUZSY7DDhM US0bTG/VUt7/A== Message-ID: Date: Mon, 8 Aug 2022 11:59:37 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 From: "H. Peter Anvin" Subject: Re: [PATCH 1/1] x86: Change mov $0, %reg with xor %reg, %reg To: David Laight , "'Kanna Scarlet'" , Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , Dave Hansen , "x86@kernel.org" , Ard Biesheuvel , Bill Metzenthen , Brijesh Singh , Joerg Roedel , Josh Poimboeuf , "Kirill A. Shutemov" , Mark Rutland , Michael Roth , Peter Zijlstra , Sean Christopherson , Steven Rostedt , Ammar Faizi , GNU/Weeb Mailing List , Linux Kernel Mailing List References: <20220804152656.8840-1-knscarlet@gnuweeb.org> <20220804152656.8840-2-knscarlet@gnuweeb.org> <20220804180805.9077-1-knscarlet@gnuweeb.org> <126271e264204581a42b079b51481740@AcuMS.aculab.com> Content-Language: en-US In-Reply-To: <126271e264204581a42b079b51481740@AcuMS.aculab.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,NICE_REPLY_A,RDNS_NONE,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On August 5, 2022 2:26:02 AM PDT, David Laight wrote: >From: Kanna Scarlet >> Sent: 04 August 2022 19:08 >> >> On 8/4/22 10:53 PM, Borislav Petkov wrote: >> > Bonus points if you find out what other advantage >> > >> > XOR reg,reg >> > >> > has when it comes to clearing integer registers. >> >> Hello sir Borislav, >> >> Thank you for your response. I tried to find out other advantages of >> xor reg,reg on Google and found this: >> https://stackoverflow.com/a/33668295/7275114 >> >> "xor (being a recognized zeroing idiom, unlike mov reg, 0) has some >> obvious and some subtle advantages: >> >> 1. smaller code-size than mov reg,0. (All CPUs) >> 2. avoids partial-register penalties for later code. >> (Intel P6-family and SnB-family). >> 3. doesn't use an execution unit, saving power and freeing up >> execution resources. (Intel SnB-family) >> 4. smaller uop (no immediate data) leaves room in the uop cache-line >> for nearby instructions to borrow if needed. (Intel SnB-family). >> 5. doesn't use up entries in the physical register file. (Intel >> SnB-family (and P4) at least, possibly AMD as well since they use >> a similar PRF design instead of keeping register state in the ROB >> like Intel P6-family microarchitectures.)" > >You missed one, and an additional change: > >Use "xor %rax,%rax" instead of "xor %eax,%eax" to save >the 'reg' prefix. > > David > >- >Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK >Registration No: 1397386 (Wales) > > You mean the other way around...