From patchwork Fri Jun 16 03:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feiyang Chen X-Patchwork-Id: 108800 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1059685vqr; Thu, 15 Jun 2023 20:16:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4sHWHixpgergqd9eUI1vtCkyPNZROeXTdGDduvaqzDuP9D5Mg5f5CKGqlyfalZTuHBBedo X-Received: by 2002:a17:907:783:b0:982:c8d0:683f with SMTP id xd3-20020a170907078300b00982c8d0683fmr700139ejb.18.1686885400884; Thu, 15 Jun 2023 20:16:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686885400; cv=none; d=google.com; s=arc-20160816; b=gLjqAcbo5HPsiV5OLWoE6TD7KRq+1bNYn0uu6OXa5SL2aHUaV0jNj7u7lSnTBnZjxn SNvRl5mC61hfMQOzDC4Qbsg6OUHScA98Z83OtGEvt7dui+qN4s7rn3oetTDuAGitnBKW 1yBQSd4VUWePKQHkMcfhKMn+CTWT2CDggP5/YJDSvXVOVOpLpOa4nFSzduEs1VMrjrbS UQ861uAZcAgXt9x2DyMXRcKCnBMBTMlrHBLZcu1ReWW6JO0z61HowBtz5n4mK9H/GFAz xm2DbZUtYcLOvNEW1rgvbmJbHbDrhyfUDT6VUNDsjG7MlN761+PtR5qm1+yyMZZgpi9c SMlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dmarc-filter :delivered-to; bh=Ayuy0C7YhoJnbqCHYcmYYBb58O/1XmUCbbty6N4gP3E=; b=P6/KsDcT1u2eIJgeRWjeMp8wN0pMVVVyaGls3W5z8Ik/KuJB9uLkpMhwjHfHz5/+A9 lq2wljvL3BYPsAe897QquOZmEOun8gjyBLqCjC8OSapuyoQ7lZp8s5H5bizx1CsIMr6W pDtrPrvMknDIb+Y9FRSglprUp+LDwCLuJd9TlsDNsN6AA5nWIOTeKQzwt7nRczl8wuO/ pgtOOUnUHDOoIkvSosDgZd9hGH+KG4LhIi9Gk+0XkJdLdqyZr6gXLzydg6UufWOCXmCx YE+6NC7SziIf0wjdp2SurNKW4zNU7cB4MkJTTtsXHW/ESRVPJEd5pVuR+ERmK3suyJeZ BHKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id jx2-20020a170906ca4200b0096f5850803csi3068984ejb.532.2023.06.15.20.16.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 20:16:40 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95D88385C6E6 for ; Fri, 16 Jun 2023 03:16:39 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 5F2EE3857342 for ; Fri, 16 Jun 2023 03:16:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F2EE3857342 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [112.20.112.76]) by gateway (Coremail) with SMTP id _____8AxX+sJ1ItkANAFAA--.12456S3; Fri, 16 Jun 2023 11:16:26 +0800 (CST) Received: from localhost.localdomain (unknown [112.20.112.76]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxluQH1Itkfc4cAA--.16334S2; Fri, 16 Jun 2023 11:16:24 +0800 (CST) From: Feiyang Chen To: liuzhensong@loongson.cn, xuchenghua@loongson.cn, mengqinggang@loongson.cn Cc: Feiyang Chen , i.swmail@xen0n.name, chris.chenfeiyang@gmail.com, chenhuacai@loongson.cn, binutils@sourceware.org Subject: [PATCH v2] LoongArch: Support referring to FCSRs as $fcsrX Date: Fri, 16 Jun 2023 11:16:10 +0800 Message-Id: <20230616031610.3982906-1-chenfeiyang@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxluQH1Itkfc4cAA--.16334S2 X-CM-SenderInfo: hfkh0wphl1t03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj93XoW3AF4fCFyUZw18tryUWr18tFc_yoW3Zr4rpr 9xurn0kr18GrnYv39rK3s0qFyUXw4xWr12v3W3tFyxur4xXw17Xa18GFyvvFn8Kw47WFya qFs5Wa48XF18JFcCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07UNvtZUUUUU= X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768827545880777283?= X-GMAIL-MSGID: =?utf-8?q?1768827545880777283?= Previously, FCSRs were referred to as $rX, which seemed strange. We refer to FCSRs as $fcsrX, which ensures compatibility with LLVM IAS as well. gas/ChangeLog: * config/tc-loongarch.c: (loongarch_fc_normal_name): New definition. (loongarch_fc_numeric_name): New definition. (loongarch_single_float_opcodes): Modify `movgr2fcsr` and `movfcsr2gr`. testsuite/gas/loongarch/float_op.d: Likewise. testsuite/gas/loongarch/float_op.s: Likewise. include/ChangeLog: * opcode/loongarch.h: (loongarch_fc_normal_name): New extern. (loongarch_fc_numeric_name): New extern. opcodes/ChangeLog: * opcodes/loongarch-dis.c (loongarch_after_parse_args): Support referring to FCSRs as $fcsrX. * opcodes/loongarch-opc.c (loongarch_args_parser_can_match_arg_helper): Likewise. Signed-off-by: Feiyang Chen --- gas/config/tc-loongarch.c | 32 +++++++++++++++++++++++++- gas/testsuite/gas/loongarch/float_op.d | 4 ++-- gas/testsuite/gas/loongarch/float_op.s | 4 ++-- include/opcode/loongarch.h | 2 ++ opcodes/loongarch-dis.c | 11 ++++++++- opcodes/loongarch-opc.c | 14 +++++++++-- 6 files changed, 59 insertions(+), 8 deletions(-) diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index c55d4ee234a..0e552c184b7 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -223,6 +223,8 @@ md_parse_option (int c, const char *arg) static struct htab *r_htab = NULL; static struct htab *f_htab = NULL; +static struct htab *fc_htab = NULL; +static struct htab *fcn_htab = NULL; static struct htab *c_htab = NULL; static struct htab *cr_htab = NULL; static struct htab *v_htab = NULL; @@ -286,6 +288,20 @@ loongarch_after_parse_args () str_hash_insert (f_htab, loongarch_f_normal_name[i], (void *) (i + 1), 0); + if (!fc_htab) + fc_htab = str_htab_create (), str_hash_insert (fc_htab, "", 0, 0); + + for (i = 0; i < ARRAY_SIZE (loongarch_fc_normal_name); i++) + str_hash_insert (fc_htab, loongarch_fc_normal_name[i], (void *) (i + 1), + 0); + + if (!fcn_htab) + fcn_htab = str_htab_create (), str_hash_insert (fcn_htab, "", 0, 0); + + for (i = 0; i < ARRAY_SIZE (loongarch_fc_numeric_name); i++) + str_hash_insert (fcn_htab, loongarch_fc_numeric_name[i], (void *) (i + 1), + 0); + if (!c_htab) c_htab = str_htab_create (), str_hash_insert (c_htab, "", 0, 0); @@ -666,7 +682,21 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2, ret = imm - 1; break; case 'f': - imm = (intptr_t) str_hash_find (f_htab, arg); + switch (esc_ch2) + { + case 'c': + imm = (intptr_t) str_hash_find (fc_htab, arg); + if (0 >= imm) + { + imm = (intptr_t) str_hash_find (fcn_htab, arg); + if (0 < imm) + as_warn ("\"$r%ld\" is deprecated, using \"$fcsr%ld\" instead", + imm - 1, imm - 1); + } + break; + default: + imm = (intptr_t) str_hash_find (f_htab, arg); + } ip->match_now = 0 < imm; ret = imm - 1; break; diff --git a/gas/testsuite/gas/loongarch/float_op.d b/gas/testsuite/gas/loongarch/float_op.d index cdc41d4db8b..f9d3b89e4a0 100644 --- a/gas/testsuite/gas/loongarch/float_op.d +++ b/gas/testsuite/gas/loongarch/float_op.d @@ -49,8 +49,8 @@ Disassembly of section .text: [ ]+9c:[ ]+0114b424 [ ]+movfr2gr.s[ ]+[ ]+\$a0, \$fa1 [ ]+a0:[ ]+0114b824 [ ]+movfr2gr.d[ ]+[ ]+\$a0, \$fa1 [ ]+a4:[ ]+0114bc24 [ ]+movfrh2gr.s [ ]+\$a0, \$fa1 -[ ]+a8:[ ]+0114c0a4 [ ]+movgr2fcsr[ ]+[ ]+\$a0, \$a1 -[ ]+ac:[ ]+0114c8a4 [ ]+movfcsr2gr[ ]+[ ]+\$a0, \$a1 +[ ]+a8:[ ]+0114c0a0 [ ]+movgr2fcsr[ ]+[ ]+\$fcsr0, \$a1 +[ ]+ac:[ ]+0114c804 [ ]+movfcsr2gr[ ]+[ ]+\$a0, \$fcsr0 [ ]+b0:[ ]+0114d020 [ ]+movfr2cf[ ]+[ ]+\$fcc0, \$fa1 [ ]+b4:[ ]+0114d4a0 [ ]+movcf2fr[ ]+[ ]+\$fa0, \$fcc5 [ ]+b8:[ ]+0114d8a0 [ ]+movgr2cf[ ]+[ ]+\$fcc0, \$a1 diff --git a/gas/testsuite/gas/loongarch/float_op.s b/gas/testsuite/gas/loongarch/float_op.s index da1a198edee..2e3ec5b8519 100644 --- a/gas/testsuite/gas/loongarch/float_op.s +++ b/gas/testsuite/gas/loongarch/float_op.s @@ -40,8 +40,8 @@ movgr2frh.w $f0,$r5 movfr2gr.s $r4,$f1 movfr2gr.d $r4,$f1 movfrh2gr.s $r4,$f1 -movgr2fcsr $r4,$r5 -movfcsr2gr $r4,$r5 +movgr2fcsr $fcsr0,$r5 +movfcsr2gr $r4,$fcsr0 movfr2cf $fcc0,$f1 movcf2fr $f0,$fcc5 movgr2cf $fcc0,$r5 diff --git a/include/opcode/loongarch.h b/include/opcode/loongarch.h index 004bb6561ef..aa2f3fb645d 100644 --- a/include/opcode/loongarch.h +++ b/include/opcode/loongarch.h @@ -185,6 +185,8 @@ dec2 : [1-9][0-9]? extern const char *const loongarch_f_normal_name[32]; extern const char *const loongarch_f_lp64_name[32]; extern const char *const loongarch_f_lp64_name1[32]; + extern const char *const loongarch_fc_normal_name[4]; + extern const char *const loongarch_fc_numeric_name[4]; extern const char *const loongarch_c_normal_name[8]; extern const char *const loongarch_cr_normal_name[4]; extern const char *const loongarch_v_normal_name[32]; diff --git a/opcodes/loongarch-dis.c b/opcodes/loongarch-dis.c index d064d30d553..0725270ed34 100644 --- a/opcodes/loongarch-dis.c +++ b/opcodes/loongarch-dis.c @@ -61,6 +61,7 @@ get_loongarch_opcode_by_binfmt (insn_t insn) static const char *const *loongarch_r_disname = NULL; static const char *const *loongarch_f_disname = NULL; +static const char *const *loongarch_fc_disname = NULL; static const char *const *loongarch_c_disname = NULL; static const char *const *loongarch_cr_disname = NULL; static const char *const *loongarch_v_disname = NULL; @@ -78,6 +79,7 @@ set_default_loongarch_dis_options (void) loongarch_r_disname = loongarch_r_lp64_name; loongarch_f_disname = loongarch_f_lp64_name; + loongarch_fc_disname = loongarch_fc_normal_name; loongarch_c_disname = loongarch_c_normal_name; loongarch_cr_disname = loongarch_cr_normal_name; loongarch_v_disname = loongarch_v_normal_name; @@ -142,7 +144,14 @@ dis_one_arg (char esc1, char esc2, const char *bit_field, info->fprintf_func (info->stream, "%s", loongarch_r_disname[u_imm]); break; case 'f': - info->fprintf_func (info->stream, "%s", loongarch_f_disname[u_imm]); + switch (esc2) + { + case 'c': + info->fprintf_func (info->stream, "%s", loongarch_fc_disname[u_imm]); + break; + default: + info->fprintf_func (info->stream, "%s", loongarch_f_disname[u_imm]); + } break; case 'c': switch (esc2) diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c index 573b691c1fd..e557b23105c 100644 --- a/opcodes/loongarch-opc.c +++ b/opcodes/loongarch-opc.c @@ -77,6 +77,16 @@ const char *const loongarch_f_lp64_name1[32] = "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", }; +const char *const loongarch_fc_normal_name[4] = +{ + "$fcsr0", "$fcsr1", "$fcsr2", "$fcsr3", +}; + +const char *const loongarch_fc_numeric_name[4] = +{ + "$r0", "$r1", "$r2", "$r3", +}; + const char *const loongarch_c_normal_name[8] = { "$fcc0", "$fcc1", "$fcc2", "$fcc3", "$fcc4", "$fcc5", "$fcc6", "$fcc7", @@ -459,8 +469,8 @@ static struct loongarch_opcode loongarch_single_float_opcodes[] = { 0x0114ac00, 0xfffffc00, "movgr2frh.w", "f0:5,r5:5", 0, 0, 0, 0 }, { 0x0114b400, 0xfffffc00, "movfr2gr.s", "r0:5,f5:5", 0, 0, 0, 0 }, { 0x0114bc00, 0xfffffc00, "movfrh2gr.s", "r0:5,f5:5", 0, 0, 0, 0 }, - { 0x0114c000, 0xfffffc00, "movgr2fcsr", "r0:5,r5:5", 0, 0, 0, 0 }, - { 0x0114c800, 0xfffffc00, "movfcsr2gr", "r0:5,r5:5", 0, 0, 0, 0 }, + { 0x0114c000, 0xfffffc1c, "movgr2fcsr", "fc0:2,r5:5", 0, 0, 0, 0 }, + { 0x0114c800, 0xffffff80, "movfcsr2gr", "r0:5,fc5:2", 0, 0, 0, 0 }, { 0x0114d000, 0xfffffc18, "movfr2cf", "c0:3,f5:5", 0, 0, 0, 0 }, { 0x0114d400, 0xffffff00, "movcf2fr", "f0:5,c5:3", 0, 0, 0, 0 }, { 0x0114d800, 0xfffffc18, "movgr2cf", "c0:3,r5:5", 0, 0, 0, 0 },