From patchwork Sat Jan 14 09:27:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 43735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp205889wrn; Sat, 14 Jan 2023 01:31:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXvVKskBEttiHBaYyYSpVNvvdVud8n2g8aIN53zt+aqm+mP3zCVeKB147gPiMQfGup6GwSwc X-Received: by 2002:a17:90b:3941:b0:227:4d5:6d67 with SMTP id oe1-20020a17090b394100b0022704d56d67mr25023246pjb.24.1673688710016; Sat, 14 Jan 2023 01:31:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673688709; cv=none; d=google.com; s=arc-20160816; b=XGkNkIV8nnUlj30Jldk9Vy9Luj7wTz3McfvqQIsvrqJGWt0oI9ghAJ+W2h7/j/Ae/x IJP5Mnzfe8WFMgfi738+Nco9MTJPtAaDlcbCkbB9NiTtmH3RNaPTtq/F1tGLC//IUgpw ohGPx9RqtYerZhOQtmdNuJyteAsuVTF/OE4R29K6dDrGbfrbxh1QtabksmkPCBGB1Eje cI7GEPUFdAnFBJpF+HrxYhmqZsq2YSAU7qEW+85BxYFquEQOmKyifXeaG7u6zUXG1GQH treYmhhmbLLQQrIsYMZxN/bbs2NCg/oVd7ECmJLfPPzpP7icKYiqmMNC5Oyj1HSqLoQX XK3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=i1h5a9GcsSL5x7TOO0iyy3NqkbfbJAsGrJqhJg/HWLM=; b=vv+SC9oe70+HypSKymqkBBLwtjtMRYLCgyvQYCCj/C12xjRjJWO7tJnkzuN10EyJCv s1UGTG1kZG/EmUQnMiZzkCiz2gvqIOP74/Jmu7caxfJQhBxxdrulnWST4Ubut76pZa7R G0i6vIYmpn0gE49BmyWYGnFPfa2UHQm9nxyBVVNmo8LPjnd6AKYV6fDtf9W9gCjmP8KO 4wGjfL+eWccDpFuf2OSiMQFAiLxtVVz3X4FosphB4q6aOGqtxjKPR+WXB9T5jZGLlgV5 tyiumuB3yKRXE+eSoLmaaEtbLXNfafCCD09nvwwSVCHdRb4hT0iLZ7lFErKTPsD3oY/j WT6g== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pj5-20020a17090b4f4500b00226613377a2si23873226pjb.167.2023.01.14.01.31.38; Sat, 14 Jan 2023 01:31:49 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbjANJ2X (ORCPT + 99 others); Sat, 14 Jan 2023 04:28:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229822AbjANJ1k (ORCPT ); Sat, 14 Jan 2023 04:27:40 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 312555BAB for ; Sat, 14 Jan 2023 01:27:38 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8BxrOqJdcJjg50BAA--.5130S3; Sat, 14 Jan 2023 17:27:37 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bxb+SBdcJjcVYZAA--.11667S8; Sat, 14 Jan 2023 17:27:36 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , WANG Xuerui , Masami Hiramatsu Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v11 6/6] LoongArch: Use common function sign_extend64() Date: Sat, 14 Jan 2023 17:27:24 +0800 Message-Id: <1673688444-24251-7-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1673688444-24251-1-git-send-email-yangtiezhu@loongson.cn> References: <1673688444-24251-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf8Bxb+SBdcJjcVYZAA--.11667S8 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoW7CrW7WF4UtryDWryUKw4rXwb_yoW5JF4kpr ZFyFykJFs8GF1Duryqy3s8XrWrWrn3Cr4aq3W3Kr1I9FWaqr129r18JrWqvF1kt3y0vFW0 gFWfXw1Yva1UA3DanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b28YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2 IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE14v26r4j6F4U McvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr 0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jOdb8UUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754989812507199961?= X-GMAIL-MSGID: =?utf-8?q?1754989812507199961?= 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;