Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp561947imn; Thu, 28 Jul 2022 08:58:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uEHcxT51N7dicLuMztKbybojCIwd/fE8j5cEuejLQ46lUi5b7vAZ3+Blqh4pH3c5cDbMDU X-Received: by 2002:a05:6402:1f01:b0:43a:239e:e65a with SMTP id b1-20020a0564021f0100b0043a239ee65amr27814801edb.428.1659023930214; Thu, 28 Jul 2022 08:58:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659023930; cv=none; d=google.com; s=arc-20160816; b=bgOxZFOw4n4/U2V4wReumOK9hx62ju+i3Y3zKGY4uhM4K9/N2GZCixPo2/F/2Itsp7 /kv1cIHsf1opN2UyKofGoPb1GQj6banpZ3MfJWzB4Z2zv/kb/kemIfpQ/PR7rV5bLLU+ QHwbMLKwqPOTOmpKA//Z50FX/2sob698YZgIbm3osEJDbl77igr2GGOLV3+wtZM2pZ52 njEkG5Zz8RlluOHhZEqgZNPn2HcTY6jC9nudrdk1vpCR4ApMUTKoAuqRWHHRh/5RTokp rIgL3kjXrY5MsKHwiD9jHEkMo55nRlaCruVtJdP50+6lmNoxc+Ucy71aihDGMq27lGeZ E1Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qcXJ2b1IRRULuK8sjPG/w1yQbfoO0cXAJbpkHsggTJk=; b=qU2SNLYbIo6ynftm/c45F13q9kbVz6OmoB2AJG5L4OhTdSd+le0wuwHmPq4vTi1vea hrsQsEV0Zqr6zVzCfY4+ZysaLFreDyDe4Qugk/0hWTIZGGdCSdT7NT+UOCr5Utnp6azZ yQy0JKqdL6W+3p7gNC3f5pF0Rj2ccEoSWHiONMCxPIbfaV/EzMt+nCwhxHdm3s6UDNGs t0U75yjnoAQ8W5smNvPBvhFom5bevvrNL50N3q4yegQCOcYBlIPm657XGmyZtNzTFEKp 9Lh1Q2Wz6BzixWZ7quP9XtUmi0784npHHjf1iG3e6ns96tCtXTSylpkK8+skZrfRVFLg 85CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f9HytRqr; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g3-20020a056402424300b0043d07d18b15si406804edb.241.2022.07.28.08.58.24; Thu, 28 Jul 2022 08:58:50 -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=@kernel.org header.s=k20201202 header.b=f9HytRqr; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231540AbiG1P0u (ORCPT + 99 others); Thu, 28 Jul 2022 11:26:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231676AbiG1P0l (ORCPT ); Thu, 28 Jul 2022 11:26:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49C985F9B4 for ; Thu, 28 Jul 2022 08:26:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D150961B7C for ; Thu, 28 Jul 2022 15:26:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9827EC433C1; Thu, 28 Jul 2022 15:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659022000; bh=OY1CFZWT7ad7PEe4fFSJDPEcJ11GALMZHQVGZ3Tqumo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=f9HytRqrLmomx4xvTJW+cidOARGraS/srKv4Akng2xTx86OJwLfVXVsQNcUJe/lUx FSRGeGiMnAZZEfv7CZKiUgWdyhmUTnyfQN11WTrQY0Pd2mkEWw7v2IOoNeR7ykcVU1 QxTddwr5DpEWzduPI2YTdW9uizrIMy2GXFZWpIIw7sxnhJpz05suP/6Qvkrqk7kz6p 5wcDu9SGemwnxkdCGm1RztjLoQyZ68jhQHwMMiqtS88KqDpDIOUHsIrk1z4HpFoTht rsCjPt5wg5mRIOXMgH5zQ0WZHCPK3AvzyL/+A3rjLTMR2mrAk0cR0LuasMgPYNrzMb rS9qHXl3UX4hg== Date: Thu, 28 Jul 2022 23:17:38 +0800 From: Jisheng Zhang To: Ard Biesheuvel Cc: Catalin Marinas , Will Deacon , Linux ARM , Linux Kernel Mailing List Subject: Re: [PATCH] arm64: save movk instructions in mov_q when the lower 16|32 bits are all zero Message-ID: References: <20220709084830.3124-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 Thu, Jul 28, 2022 at 10:49:02PM +0800, Jisheng Zhang wrote: > On Wed, Jul 27, 2022 at 08:15:11AM -0700, Ard Biesheuvel wrote: > > On Sat, 9 Jul 2022 at 01:58, Jisheng Zhang wrote: > > > > > > Currently mov_q is used to move a constant into a 64-bit register, > > > when the lower 16 or 32bits of the constant are all zero, the mov_q > > > emits one or two useless movk instructions. If the mov_q macro is used > > > in hot code path, we want to save the movk instructions as much as > > > possible. For example, when CONFIG_ARM64_MTE is 'Y' and > > > CONFIG_KASAN_HW_TAGS is 'N', the following code in __cpu_setup() > > > routine is the pontential optimization target: > > > > > > /* set the TCR_EL1 bits */ > > > mov_q x10, TCR_MTE_FLAGS > > > > > > Before the patch: > > > mov x10, #0x10000000000000 > > > movk x10, #0x40, lsl #32 > > > movk x10, #0x0, lsl #16 > > > movk x10, #0x0 > > > > > > After the patch: > > > mov x10, #0x10000000000000 > > > movk x10, #0x40, lsl #32 > > > > > > Signed-off-by: Jisheng Zhang > > > > This is broken for constants that have 0xffff in the top 16 bits, as > > in that case, we will emit a MOVN/MOVK/MOVK sequence, and omitting the > > MOVKs will set the corresponding field to 0xffff not 0x0. > > Thanks so much for this hint. I think you are right about the 0xffff in > top 16bits case. > the patch breaks below usage case: mov_q x0, 0xffffffff00000000 I think the reason is mov_q starts from high bits, if we change the macro to start from LSB, then that could solve the breakage. But this needs a rewrite of mov_q