LoongArch: Support referring to FCSRs as $fcsrX
authorFeiyang Chen <chenfeiyang@loongson.cn>
Fri, 16 Jun 2023 03:16:10 +0000 (11:16 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Sun, 25 Jun 2023 07:06:32 +0000 (15:06 +0800)
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 <chenfeiyang@loongson.cn>
gas/config/tc-loongarch.c
gas/testsuite/gas/loongarch/float_op.d
gas/testsuite/gas/loongarch/float_op.s
include/opcode/loongarch.h
opcodes/loongarch-dis.c
opcodes/loongarch-opc.c

index d1c5ce287e4e4f6692cb2a3411cc31ecdf48043c..ba5b626e1ea50bb804b53b8e4102bd8aa359ecde 100644 (file)
@@ -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,18 @@ 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);
+           }
+         break;
+       default:
+         imm = (intptr_t) str_hash_find (f_htab, arg);
+       }
       ip->match_now = 0 < imm;
       ret = imm - 1;
       break;
index cdc41d4db8b25365198898ea20649cafb12e9860..f9d3b89e4a02ce3111d42a8fa061f2d634500212 100644 (file)
@@ -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
index da1a198edee7f091b3a046fc0a5ff7d3651d725c..2e3ec5b8519eb272862adf0157a3bdef0addf69d 100644 (file)
@@ -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
index 004bb6561ef257a0097151f1e2c76a14f7428310..aa2f3fb645d36f6dba51471669efd96c70cf523e 100644 (file)
@@ -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];
index d064d30d55382a49449501d037f36ae7741fd75f..0725270ed340ea0e6ca9f2edbb021c1172f62aea 100644 (file)
@@ -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)
index 573b691c1fdc90610a0e54be87dbfa86e249ff61..e557b23105c1c9c8f8a94741487f63a96d170158 100644 (file)
@@ -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 },