Message ID | 1671006659-23859-1-git-send-email-yangtiezhu@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp99930wrn; Wed, 14 Dec 2022 01:12:34 -0800 (PST) X-Google-Smtp-Source: AA0mqf7yFZDuqkddaFTdg4JxxlKU4vdYMRX7XTCa0jtYh1jNir4YXVnCrkg1zv63cNZQ87AgOu7M X-Received: by 2002:a17:907:8d16:b0:7c1:5098:907a with SMTP id tc22-20020a1709078d1600b007c15098907amr16514421ejc.35.1671009154588; Wed, 14 Dec 2022 01:12:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671009154; cv=none; d=google.com; s=arc-20160816; b=x6HG3AU0mLSeMLoGVkU8mXX5nFmVddWPQWWmZaUHp0lJLy8UYss/F584ZNa6Foo7I7 oEDD5mhugsX5/5QTTJ7b3R9+LUM5d9Q9ff87yqXBAVZlRY2RYqMsLCGQBNQvk9di1nRV Y9KfLrpRtLik5/OsMAEUbI1GbVY55xs5ynvdlTZjraZEIalw6UPY78GzCpWGUDyO6Wnx 3jeWNOHxJh9rVdC9m+qts9h82THOn9P88Fv5KK7vyexvjje4j55F+u0kPVAKgba/ZeH+ XunkymPiZTmcvoxLtUAAj0JBrzYhq/OaB4k3nk37H/LrgbADA3sJQA1ZtjeTrcDVNnJ6 pCoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=QkOKv8GfoqcWiavUSCspmiGtV1Zd2ULAwHEcQ5X7Ybg=; b=BbH6HagSiD7lMWAFsG3ewfH20cXp28WG+OCuUUyiOo90Ddp8+M6oSQmVbMQ2OcQZBg zFcrS6aHYZNxWvd4Pereaq/9SCrTmsBCsC16dBGXyuLsJX6n1cf3V9M5rdjwWVDD6OnL L0dzoeUGIMShVoj/ZuP/YghcvOQD6um/q40k6kmyOEX0Ta2BBFEyvoJ7QvliPt4gLKOX bQBDwZT5Rft+e2Oq/S1+Y9gZGvnkCiNdbvKbr90qDgB2GcdOIkpBWpqBg78twRKzlWtj cy6htYSaPWEZ/0Pk1ZIKbs5/MJJcKdG5wikgi7rsEMKPimCPFrtUtn6dgLoH8W35uO08 5eRA== 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 w19-20020a50d793000000b0046c0e8b6cadsi3153532edi.450.2022.12.14.01.12.11; Wed, 14 Dec 2022 01:12:34 -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 S237276AbiLNIbH (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Wed, 14 Dec 2022 03:31:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237502AbiLNIbE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 14 Dec 2022 03:31:04 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D1D0C165A3 for <linux-kernel@vger.kernel.org>; Wed, 14 Dec 2022 00:31:02 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8CxI_DFiZljJ3sFAA--.12983S3; Wed, 14 Dec 2022 16:31:01 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx5VbEiZljUfIuAA--.29325S2; Wed, 14 Dec 2022 16:31:00 +0800 (CST) From: Tiezhu Yang <yangtiezhu@loongson.cn> To: Huacai Chen <chenhuacai@kernel.org>, WANG Xuerui <kernel@xen0n.name> Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] LoongArch: Correct the definition of is_branch_ins() Date: Wed, 14 Dec 2022 16:30:59 +0800 Message-Id: <1671006659-23859-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf8Cx5VbEiZljUfIuAA--.29325S2 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoW7Zr1xJw43Ww1rJFy3JFW3GFg_yoW8GrWDpF Z8ArZ5Gr4kKr93CFs8Ja1kZF1YyrZ3Wr42qF17Kw17ursFqw1Utrn5Gr1FyFnrKa92gr10 qrW3Jr47WF45A3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b7AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW8JVW5JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2 IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4U McvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr 0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8xuctUUUUU== 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752180095533472814?= X-GMAIL-MSGID: =?utf-8?q?1752180095533472814?= |
Series |
LoongArch: Correct the definition of is_branch_ins()
|
|
Commit Message
Tiezhu Yang
Dec. 14, 2022, 8:30 a.m. UTC
The current definition of is_branch_ins() is not correct, it was
first introduced in commit 49aef111e2da ("LoongArch: Add prologue
unwinder support"), in fact, there exist three branch instruction
formats rather than only reg1i21_format.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
arch/loongarch/include/asm/inst.h | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
Comments
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, [1]. That's meaningless because it is the same as the original result. If we care too much about the details of instruction format, we will lose a lot of tricks on LoongArch instruction coding. [1] https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#table-of-instruction-encoding > it was > first introduced in commit 49aef111e2da ("LoongArch: Add prologue > unwinder support"), in fact, there exist three branch instruction > formats rather than only reg1i21_format. > > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > --- > arch/loongarch/include/asm/inst.h | 27 +++++++++++++++++++++++++-- > 1 file changed, 25 insertions(+), 2 deletions(-) > > diff --git a/arch/loongarch/include/asm/inst.h b/arch/loongarch/include/asm/inst.h > index c00e151..42be39be 100644 > --- a/arch/loongarch/include/asm/inst.h > +++ b/arch/loongarch/include/asm/inst.h > @@ -329,8 +329,31 @@ 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; > + switch (ip->reg0i26_format.opcode) { > + case b_op: > + case bl_op: > + return true; > + } > + > + switch (ip->reg1i21_format.opcode) { > + case beqz_op: > + case bnez_op: > + case bceqz_op: > + return true; > + } > + > + switch (ip->reg2i16_format.opcode) { > + case jirl_op: > + case beq_op: > + case bne_op: > + case blt_op: > + case bge_op: > + case bltu_op: > + case bgeu_op: > + return true; > + } > + > + return false; > } > > static inline bool is_ra_save_ins(union loongarch_instruction *ip)
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
On 2022-12-16 14:11, Tiezhu Yang wrote: > > > 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? We defined many instruction format because of variable-width opcode field and parameter field. IMHO if there is no way to solve that problem really, keeping original codes is better. That depends on the maintainers, of course. Thanks, Jinyang > > 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 > > >
diff --git a/arch/loongarch/include/asm/inst.h b/arch/loongarch/include/asm/inst.h index c00e151..42be39be 100644 --- a/arch/loongarch/include/asm/inst.h +++ b/arch/loongarch/include/asm/inst.h @@ -329,8 +329,31 @@ 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; + switch (ip->reg0i26_format.opcode) { + case b_op: + case bl_op: + return true; + } + + switch (ip->reg1i21_format.opcode) { + case beqz_op: + case bnez_op: + case bceqz_op: + return true; + } + + switch (ip->reg2i16_format.opcode) { + case jirl_op: + case beq_op: + case bne_op: + case blt_op: + case bge_op: + case bltu_op: + case bgeu_op: + return true; + } + + return false; } static inline bool is_ra_save_ins(union loongarch_instruction *ip)