Skip to content

Commit 02a6352

Browse files
committed
RISC-V: remove indirection from register tables
The longest register name is 4 characters (plus a nul one), so using a 4- or 8-byte pointer to get at it is neither space nor time efficient. Embed the names right into the array. For PIE this also reduces the number of base relocations in the final image. To avoid old gcc, when generating 32-bit code, bogusly warning about bounds being exceeded in the code processing Cs/Cw, Ct/Cx, and CD, an adjustment to EXTRACT_BITS() is needed: This macro shouldn't supply a 64-bit value, and it also doesn't need to - all operand fields to date are far more narrow than 32 bits. This in turn allows dropping a number of casts elsewhere.
1 parent a2182c7 commit 02a6352

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

gas/config/tc-riscv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ hash_reg_name (enum reg_class class, const char *name, unsigned n)
951951
}
952952

953953
static void
954-
hash_reg_names (enum reg_class class, const char * const names[], unsigned n)
954+
hash_reg_names (enum reg_class class, const char names[][NRC], unsigned n)
955955
{
956956
unsigned i;
957957

include/opcode/riscv.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static inline unsigned int riscv_insn_length (insn_t insn)
354354

355355
/* Extract the operand given by FIELD from integer INSN. */
356356
#define EXTRACT_OPERAND(FIELD, INSN) \
357-
EXTRACT_BITS ((INSN), OP_MASK_##FIELD, OP_SH_##FIELD)
357+
((unsigned int) EXTRACT_BITS ((INSN), OP_MASK_##FIELD, OP_SH_##FIELD))
358358

359359
/* Extract an unsigned immediate operand on position s with n bits. */
360360
#define EXTRACT_U_IMM(n, s, l) \
@@ -574,14 +574,16 @@ enum riscv_seg_mstate
574574
MAP_INSN, /* Instructions. */
575575
};
576576

577-
extern const char * const riscv_gpr_names_numeric[NGPR];
578-
extern const char * const riscv_gpr_names_abi[NGPR];
579-
extern const char * const riscv_fpr_names_numeric[NFPR];
580-
extern const char * const riscv_fpr_names_abi[NFPR];
577+
#define NRC (4 + 1) /* Max characters in register names, incl nul. */
578+
579+
extern const char riscv_gpr_names_numeric[NGPR][NRC];
580+
extern const char riscv_gpr_names_abi[NGPR][NRC];
581+
extern const char riscv_fpr_names_numeric[NFPR][NRC];
582+
extern const char riscv_fpr_names_abi[NFPR][NRC];
581583
extern const char * const riscv_rm[8];
582584
extern const char * const riscv_pred_succ[16];
583-
extern const char * const riscv_vecr_names_numeric[NVECR];
584-
extern const char * const riscv_vecm_names_numeric[NVECM];
585+
extern const char riscv_vecr_names_numeric[NVECR][NRC];
586+
extern const char riscv_vecm_names_numeric[NVECM][NRC];
585587
extern const char * const riscv_vsew[8];
586588
extern const char * const riscv_vlmul[8];
587589
extern const char * const riscv_vta[2];

opcodes/riscv-dis.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ static enum riscv_seg_mstate last_map_state = MAP_NONE;
6969
static asection *last_map_section = NULL;
7070

7171
/* Register names as used by the disassembler. */
72-
static const char * const *riscv_gpr_names;
73-
static const char * const *riscv_fpr_names;
72+
static const char (*riscv_gpr_names)[NRC];
73+
static const char (*riscv_fpr_names)[NRC];
7474

7575
/* If set, disassemble as most general instruction. */
7676
static bool no_aliases = false;
@@ -502,7 +502,7 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
502502

503503
case 'y':
504504
print (info->stream, dis_style_immediate, "0x%x",
505-
(unsigned)EXTRACT_OPERAND (BS, l));
505+
EXTRACT_OPERAND (BS, l));
506506
break;
507507

508508
case 'z':
@@ -511,12 +511,12 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
511511

512512
case '>':
513513
print (info->stream, dis_style_immediate, "0x%x",
514-
(unsigned)EXTRACT_OPERAND (SHAMT, l));
514+
EXTRACT_OPERAND (SHAMT, l));
515515
break;
516516

517517
case '<':
518518
print (info->stream, dis_style_immediate, "0x%x",
519-
(unsigned)EXTRACT_OPERAND (SHAMTW, l));
519+
EXTRACT_OPERAND (SHAMTW, l));
520520
break;
521521

522522
case 'S':
@@ -577,7 +577,7 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
577577

578578
case 'Y':
579579
print (info->stream, dis_style_immediate, "0x%x",
580-
(unsigned) EXTRACT_OPERAND (RNUM, l));
580+
EXTRACT_OPERAND (RNUM, l));
581581
break;
582582

583583
case 'Z':

opcodes/riscv-opc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,31 @@
2626

2727
/* Register names used by gas and objdump. */
2828

29-
const char * const riscv_gpr_names_numeric[NGPR] =
29+
const char riscv_gpr_names_numeric[NGPR][NRC] =
3030
{
3131
"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
3232
"x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
3333
"x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
3434
"x24", "x25", "x26", "x27", "x28", "x29", "x30", "x31"
3535
};
3636

37-
const char * const riscv_gpr_names_abi[NGPR] =
37+
const char riscv_gpr_names_abi[NGPR][NRC] =
3838
{
3939
"zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2",
4040
"s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5",
4141
"a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
4242
"s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6"
4343
};
4444

45-
const char * const riscv_fpr_names_numeric[NFPR] =
45+
const char riscv_fpr_names_numeric[NFPR][NRC] =
4646
{
4747
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
4848
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
4949
"f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
5050
"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"
5151
};
5252

53-
const char * const riscv_fpr_names_abi[NFPR] =
53+
const char riscv_fpr_names_abi[NFPR][NRC] =
5454
{
5555
"ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7",
5656
"fs0", "fs1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5",
@@ -72,7 +72,7 @@ const char * const riscv_pred_succ[16] =
7272
};
7373

7474
/* RVV registers. */
75-
const char * const riscv_vecr_names_numeric[NVECR] =
75+
const char riscv_vecr_names_numeric[NVECR][NRC] =
7676
{
7777
"v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7878
"v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
@@ -81,7 +81,7 @@ const char * const riscv_vecr_names_numeric[NVECR] =
8181
};
8282

8383
/* RVV mask registers. */
84-
const char * const riscv_vecm_names_numeric[NVECM] =
84+
const char riscv_vecm_names_numeric[NVECM][NRC] =
8585
{
8686
"v0.t"
8787
};

0 commit comments

Comments
 (0)