From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by gnuweeb.org (Postfix) with ESMTPS id 89F4F8060F for ; Fri, 5 Aug 2022 09:26:06 +0000 (UTC) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-266-0nSC5lN1Mf6CKuQecZXkzw-1; Fri, 05 Aug 2022 10:26:03 +0100 X-MC-Unique: 0nSC5lN1Mf6CKuQecZXkzw-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Fri, 5 Aug 2022 10:26:02 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.036; Fri, 5 Aug 2022 10:26:02 +0100 From: David Laight To: 'Kanna Scarlet' , Borislav Petkov CC: Thomas Gleixner , Ingo Molnar , "Dave Hansen" , "H. Peter Anvin" , "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 Subject: RE: [PATCH 1/1] x86: Change mov $0, %reg with xor %reg, %reg Thread-Topic: [PATCH 1/1] x86: Change mov $0, %reg with xor %reg, %reg Thread-Index: AQHYqC07pBmJLRD/dU+qGFItY3OGOq2gCd9A Date: Fri, 5 Aug 2022 09:26:02 +0000 Message-ID: <126271e264204581a42b079b51481740@AcuMS.aculab.com> References: <20220804152656.8840-1-knscarlet@gnuweeb.org> <20220804152656.8840-2-knscarlet@gnuweeb.org> <20220804180805.9077-1-knscarlet@gnuweeb.org> In-Reply-To: <20220804180805.9077-1-knscarlet@gnuweeb.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: From: Kanna Scarlet > Sent: 04 August 2022 19:08 >=20 > 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. >=20 > Hello sir Borislav, >=20 > 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 >=20 > "xor (being a recognized zeroing idiom, unlike mov reg, 0) has some > obvious and some subtle advantages: >=20 > 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. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)