Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2628874rwb; Sun, 15 Jan 2023 19:22:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXtdURBeIYTfn7T6IG3uPnl3PfV5BNlWeR3NWhORsehMu9EbH9cZs9kH+WWNrDrAIbMJA9gy X-Received: by 2002:a17:902:bc86:b0:192:721d:6f0a with SMTP id bb6-20020a170902bc8600b00192721d6f0amr68859502plb.60.1673839377487; Sun, 15 Jan 2023 19:22:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673839377; cv=none; d=google.com; s=arc-20160816; b=pwJrFWKWLfC/OWcA3RvH+YuZ+CVZVFw3wVvZxuQUbl2Y+wBdt+BzrtnxgqHMxrzJ6m /u+oeKCiOvm5vZBrFgw3QYkMYqPNkhYnhATMP3lOELb4vj72rR9uNeDIBw7v8VmIyTa+ qMy+o1NHb/fLdz3wjS3Km1IV/TkDDTlpHLo+sGsJ6FJTHQKcss2R+wbjQjk/jxGpdm9H +IWLZB4hFOuwJ6Ftbd0cnNo77Sfk4Ol6FBKo+Nz/WdlkynTb4tFnoG35Lx7SzuE9B+uY 67HY6VnErDAfiXUxTIArePMFd73nyOZVFej0hKVxXEyidWWS4OARv9G7yRoACnoLAlDZ jyHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SbCH20sz0cskV3Pd95ad2xbLmtAM7kTX4/RrF4HSD9Y=; b=l2NFEhMqO+jJpa0SohpMWnY+nKYN7nc6FL1xldwHrGD3S2qQuzHkhKN+Ll+3947Mlp LSiyvsp2uwEZtdNv2gzajqEHcN9/7b079jczD2b7/1/kNt3P4GfhvN4URionjZ35vRDD 3bqUAP/oOq8b9YnQrUIfluSLx/w0pv04XUyPLSd2ulrr55vTCcRuv+a5jGViu49diiTx cvyuoQEnqryZZwnMAu9Ffg0hM4PtI9WRU0jq8RE7io/is5S9YlR7V2UbO2a2ZddLzWYh SyzRPDuQ3gi0jrtbrrM2cnmRW3cU7PvdJfr2/nuiKHiDueLqbra98shyHe8Otz3E42/u pEjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HVVvza9Z; 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 m3-20020a170902db0300b001929883dd95si23256825plx.70.2023.01.15.19.22.51; Sun, 15 Jan 2023 19:22:57 -0800 (PST) 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=HVVvza9Z; 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 S231799AbjAPDST (ORCPT + 52 others); Sun, 15 Jan 2023 22:18:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231586AbjAPDSO (ORCPT ); Sun, 15 Jan 2023 22:18:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D4EE76A3 for ; Sun, 15 Jan 2023 19:18:14 -0800 (PST) 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 AE74660E08 for ; Mon, 16 Jan 2023 03:18:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21CAFC433D2 for ; Mon, 16 Jan 2023 03:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673839093; bh=xN0nB9m8Mlu0zwKCceXo+pC9SAQhuK5iA+VXSdLnQs8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=HVVvza9ZGJjkt7sEzxGmzuTLqg2RZGgzD8Tze/iheITECJkV/S7NTDVP69amQFcFC /fcSVKAlc9Gi8QoJ3DqLRPfEcfYrIv9ffeCSSAOXyqZmF1tpukkiCMD0SLHBkSuZmp xO1jIMsoG2R2UrL6bFVM1kOsP28bPF/T6XSz2ChjDBaWNlSedO/+J35NXEN2fekFHw O1eW5Ifd5kIKW7sayhbQtyIGsJ5vTygrp+pzYBOl/8uspmWvUX0KT6idqbM/OFvVE/ mINqOD13F4ol7uVPGeiXkvAzCTRIR1HwKXeADVisTilaWA6Q3n1JIL03MP6ROLB0fe SPlhpSLtl0tQA== Received: by mail-ej1-f47.google.com with SMTP id vm8so65013253ejc.2 for ; Sun, 15 Jan 2023 19:18:13 -0800 (PST) X-Gm-Message-State: AFqh2kqUzsA18uMeHOqYAPGAXwEVC8Gse8OJUq420xCkRElDs6B5XjIv 9tXLLkKnCC+eZLZexkt4mKCh9+bUoKj5+yoAM4M= X-Received: by 2002:a17:906:5616:b0:852:132b:2d7e with SMTP id f22-20020a170906561600b00852132b2d7emr2248742ejq.224.1673839091387; Sun, 15 Jan 2023 19:18:11 -0800 (PST) MIME-Version: 1.0 References: <1673688444-24251-1-git-send-email-yangtiezhu@loongson.cn> <1673688444-24251-7-git-send-email-yangtiezhu@loongson.cn> In-Reply-To: <1673688444-24251-7-git-send-email-yangtiezhu@loongson.cn> From: Huacai Chen Date: Mon, 16 Jan 2023 11:18:02 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v11 6/6] LoongArch: Use common function sign_extend64() To: Tiezhu Yang Cc: WANG Xuerui , Masami Hiramatsu , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 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 I queued this patch, but others need more reviews. Huacai On Sat, Jan 14, 2023 at 5:27 PM Tiezhu Yang wrote: > > There exists a common function sign_extend64() to sign extend a 64-bit > value using specified bit as sign-bit in include/linux/bitops.h, it is > more efficient, let us use it and remove the arch-specific sign_extend() > under arch/loongarch. > > Suggested-by: Jinyang He > Signed-off-by: Tiezhu Yang > --- > arch/loongarch/include/asm/inst.h | 8 -------- > arch/loongarch/kernel/alternative.c | 6 +++--- > 2 files changed, 3 insertions(+), 11 deletions(-) > > diff --git a/arch/loongarch/include/asm/inst.h b/arch/loongarch/include/asm/inst.h > index e0771d2..ba18ce8 100644 > --- a/arch/loongarch/include/asm/inst.h > +++ b/arch/loongarch/include/asm/inst.h > @@ -397,14 +397,6 @@ static inline bool unsigned_imm_check(unsigned long val, unsigned int bit) > return val < (1UL << bit); > } > > -static inline unsigned long sign_extend(unsigned long val, unsigned int idx) > -{ > - if (!is_imm_negative(val, idx + 1)) > - return ((1UL << idx) - 1) & val; > - else > - return ~((1UL << idx) - 1) | val; > -} > - > #define DEF_EMIT_REG0I26_FORMAT(NAME, OP) \ > static inline void emit_##NAME(union loongarch_instruction *insn, \ > int offset) \ > diff --git a/arch/loongarch/kernel/alternative.c b/arch/loongarch/kernel/alternative.c > index c5aebea..4ad1384 100644 > --- a/arch/loongarch/kernel/alternative.c > +++ b/arch/loongarch/kernel/alternative.c > @@ -74,7 +74,7 @@ static void __init_or_module recompute_jump(union loongarch_instruction *buf, > switch (src->reg0i26_format.opcode) { > case b_op: > case bl_op: > - jump_addr = cur_pc + sign_extend((si_h << 16 | si_l) << 2, 27); > + jump_addr = cur_pc + sign_extend64((si_h << 16 | si_l) << 2, 27); > if (in_alt_jump(jump_addr, start, end)) > return; > offset = jump_addr - pc; > @@ -93,7 +93,7 @@ static void __init_or_module recompute_jump(union loongarch_instruction *buf, > fallthrough; > case beqz_op: > case bnez_op: > - jump_addr = cur_pc + sign_extend((si_h << 16 | si_l) << 2, 22); > + jump_addr = cur_pc + sign_extend64((si_h << 16 | si_l) << 2, 22); > if (in_alt_jump(jump_addr, start, end)) > return; > offset = jump_addr - pc; > @@ -112,7 +112,7 @@ static void __init_or_module recompute_jump(union loongarch_instruction *buf, > case bge_op: > case bltu_op: > case bgeu_op: > - jump_addr = cur_pc + sign_extend(si << 2, 17); > + jump_addr = cur_pc + sign_extend64(si << 2, 17); > if (in_alt_jump(jump_addr, start, end)) > return; > offset = jump_addr - pc; > -- > 2.1.0 >