From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED4EAC4332F for ; Fri, 16 Dec 2022 06:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229806AbiLPGLY (ORCPT ); Fri, 16 Dec 2022 01:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbiLPGLS (ORCPT ); Fri, 16 Dec 2022 01:11:18 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2189217594 for ; Thu, 15 Dec 2022 22:11:04 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8DxdPD3C5xjCQkGAA--.14137S3; Fri, 16 Dec 2022 14:11:03 +0800 (CST) Received: from [10.130.0.135] (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxf+T3C5xjiTkBAA--.5397S3; Fri, 16 Dec 2022 14:11:03 +0800 (CST) Subject: Re: [PATCH] LoongArch: Correct the definition of is_branch_ins() To: Jinyang He , Huacai Chen , WANG Xuerui References: <1671006659-23859-1-git-send-email-yangtiezhu@loongson.cn> Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org From: Tiezhu Yang Message-ID: Date: Fri, 16 Dec 2022 14:11:03 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID: AQAAf8Cxf+T3C5xjiTkBAA--.5397S3 X-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UJVW8JwCI42IY6I 8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07URa0PUUUUU= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/16/2022 11:18 AM, Jinyang He wrote: > Hi, Tiezhu, > > > On 2022-12-14 16:30, Tiezhu Yang wrote: >> The current definition of is_branch_ins() is not correct, > > But the branch instruction opcode only use the high 6 bits, Yes, I noticed that, the logic result of current code is right, but it seems a little strange (only consider reg1i21_format) at the first glance, the initial aim of this patch is to make it theoretically correct, maybe it is not the best change. I think we can neglect the instruction formats and check the high 6 bits instead, what do you think of the following change? diff --git a/arch/loongarch/include/asm/inst.h b/arch/loongarch/include/asm/inst.h index c00e151..fd31752 100644 --- a/arch/loongarch/include/asm/inst.h +++ b/arch/loongarch/include/asm/inst.h @@ -329,8 +329,8 @@ static inline bool is_pc_ins(union loongarch_instruction *ip) static inline bool is_branch_ins(union loongarch_instruction *ip) { - return ip->reg1i21_format.opcode >= beqz_op && - ip->reg1i21_format.opcode <= bgeu_op; + return ((ip->word >> 26) & 0x3f) >= beqz_op && + ((ip->word >> 26) & 0x3f) <= bgeu_op; } Thanks, Tiezhu