Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp830307rwb; Thu, 4 Aug 2022 11:40:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR6w1vKHhNQpP7EPt5Ncd9muEsJZDsgDbwMmosfKI2oc54jm3/ZTYmoOMeyd1k4vIoWpFOcv X-Received: by 2002:a05:6402:27d3:b0:43e:5490:27ca with SMTP id c19-20020a05640227d300b0043e549027camr3424631ede.307.1659638420827; Thu, 04 Aug 2022 11:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659638420; cv=none; d=google.com; s=arc-20160816; b=Xv6X8Act7QxPifViJkO9H+5vWvatn3ZbdQDJBKsISUCSEx84kQAxRmLlqfEMKn9+B7 W8o6xBOZREFYFaZWFXdt5JVcdQQ0oEJ7PHN0iPIJLkWItVRu+rrWOOhn8msjLU41jA1m 55n7OlAeVy1jdfHDTStHY+/HQLbunfXXcub+N476XVNn1McWwNVlGtPPiO5XkCBiD6r4 8GbAN+jdUv75cqdkAUASvS2bt9os5vwEir0XQ3J4QmOM29jwmeC7XZl50wGwvV/b9mfx +jGP/VG9T/2jw9OohYHxzjgxeV1KGqUCjFz3LUyhVs48999cLRylIWKkP44VzBhWHvZT uLYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/z0b/VTOrahWIcIK1Ng0NTOzpOkGt9szuFiigYXHP/4=; b=yh3iJiKR5S0tZQuxrATZlzQuagrc3D+TAntlsaGyrMWLJ4UpVwMgcFlk0KsqYVp4RK QejQ/xwXb88cfCdnHoGHX1p+TNtGVTlIHH8ot661d1l+Z387+dVqrjq0GF3eYrLFEU4J 9uQnKYpKTiA/hbmTYSJFxJK703OOlsF9d0GbGJ3+qakTsfH70JqRX+ey9cf/coKe3/71 RsoGvZGMilk69xccDK9ijYIMdbPfF+EkmKW8Ag4nryJUCKFeB0DC28ZlHaGEOM25K9qq L4fvI2pcKc8UU+C4b8bVSx4tCp/NgS/1DdoaavOw096K+JstjbmBeXU0EOvN36vcNtCH uJQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=L1K+rKOx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qq17-20020a17090720d100b0072f1f3ec581si1527791ejb.264.2022.08.04.11.39.53; Thu, 04 Aug 2022 11:40:20 -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=pass header.i=@gnuweeb.org header.s=default header.b=L1K+rKOx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gnuweeb.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239553AbiHDSIk (ORCPT + 99 others); Thu, 4 Aug 2022 14:08:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238488AbiHDSIg (ORCPT ); Thu, 4 Aug 2022 14:08:36 -0400 Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAF036BD76 for ; Thu, 4 Aug 2022 11:08:32 -0700 (PDT) Received: from linux.gnuweeb.org (linux.gnuweeb.org [172.17.0.3]) by gnuweeb.org (Postfix) with ESMTPSA id A77767E295; Thu, 4 Aug 2022 18:08:31 +0000 (UTC) X-GW-Data: lPqxHiMPbJw1wb7CM9QUryAGzr0yq5atzVDdxTR0iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1659636511; bh=YbhOBwc9/fp+EJUtdTULgx+1f0UukDq/9CZZosXIem4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1K+rKOx0REOkMQ1ct49BhB4CWXEZ87ETTTY0zL9cJGGLIpDqxUKiJ0Lp+b1t5ggJ 2ugK2izB0QZ3wTeYCt2vNTtOBFv3Jj9KDHmW3ftnoj5rSHC5WVpvFqrHACoOrGkNO3 5skAyHsOXfsSsFBEU7cCbuS3jYDgwFQVIxczQHrppiYWT74cYxSQUBJHBCiv2P9U+5 yzZus2Vt7pTv/Vzhazz/y2oOZnfGivis4rFsn7npbOxRBPZJAAw+IXTN99+DD7hcpl ih49IV+jf3ycjkz9sHevaLYAyzVFm9QzS952r5qL7K85/8+JJVOxOrGGI04pmq8+9V wq5E9Lw9aoUOA== From: Kanna Scarlet To: Borislav Petkov Cc: Kanna Scarlet , 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 Date: Thu, 4 Aug 2022 18:08:05 +0000 Message-Id: <20220804180805.9077-1-knscarlet@gnuweeb.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: <20220804152656.8840-1-knscarlet@gnuweeb.org> <20220804152656.8840-2-knscarlet@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham 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 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.)" Should I add all in the explanation sir? I will send v2 revision tomorrow. We also find more files to patch with this command: grep -rE "mov.?\s+\\$\\0\s*," arch/x86 it shows many immediate zero moves to 64-bit register in file arch/x86/crypto/curve25519-x86_64.c, but the next instruction may depend on the previous %rflags value, we are afraid to change this because xor touches %rflags. We will try to change it to movl $0, %r32 to reduce the code size. Example cmovc needs %rflags " adcx %1, %%r11;" " movq %%r11, 24(%2);" /* Step 3: Fold the carry bit back in; guaranteed not to carry at this point */ " mov $0, %%rax;" " cmovc %%rdx, %%rax;" Thanks. Regards, -- Kanna Scarlet