Skip to content

Commit c745057

Browse files
committed
RISC-V: Allocate "various" operand type
This commit intends to move operands that require very special handling or operand types that are so minor (e.g. only useful on a few instructions) under "W". I also intend this "W" to be "temporary" operand storage until we can find good two character (or less) operand type. In this commit, prefetch offset operand "f" for 'Zicbop' extension is moved to "Wif" because of its special handling (and allocating single character "f" for this operand type seemed too much). Current expected allocation guideline is as follows: 1. 'W' 2. The most closely related single-letter extension in lowercase (strongly recommended but not mandatory) 3. Identify operand type The author currently plans to allocate following three-character operand types (for operands including instructions from unratified extensions). 1. "Wif" ('Zicbop': fetch offset) 2. "Wfv" (unratified 'Zfa': value operand from FLI.[HSDQ] instructions) 3. "Wfm" / "WfM" 'Zfh', 'F', 'D', 'Q': rounding modes "m" with special handling solely for widening conversion instructions. gas/ChangeLog: * config/tc-riscv.c (validate_riscv_insn, riscv_ip): Move from "f" to "Wif". opcodes/ChangeLog: * riscv-dis.c (print_insn_args): Move from "f" to "Wif". * riscv-opc.c (riscv_opcodes): Reflect new operand type.
1 parent dc20b8f commit c745057

File tree

3 files changed

+71
-25
lines changed

3 files changed

+71
-25
lines changed

gas/config/tc-riscv.c

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,6 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
13601360
case 'j': used_bits |= ENCODE_ITYPE_IMM (-1U); break;
13611361
case 'a': used_bits |= ENCODE_JTYPE_IMM (-1U); break;
13621362
case 'p': used_bits |= ENCODE_BTYPE_IMM (-1U); break;
1363-
case 'f': /* Fall through. */
13641363
case 'q': used_bits |= ENCODE_STYPE_IMM (-1U); break;
13651364
case 'u': used_bits |= ENCODE_UTYPE_IMM (-1U); break;
13661365
case 'z': break; /* Zero immediate. */
@@ -1387,6 +1386,21 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
13871386
goto unknown_validate_operand;
13881387
}
13891388
break;
1389+
case 'W': /* Various operands. */
1390+
switch (*++oparg)
1391+
{
1392+
case 'i':
1393+
switch (*++oparg)
1394+
{
1395+
case 'f': used_bits |= ENCODE_STYPE_IMM (-1U); break;
1396+
default:
1397+
goto unknown_validate_operand;
1398+
}
1399+
break;
1400+
default:
1401+
goto unknown_validate_operand;
1402+
}
1403+
break;
13901404
case 'X': /* Integer immediate. */
13911405
{
13921406
size_t n;
@@ -3402,22 +3416,37 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
34023416
imm_expr->X_op = O_absent;
34033417
continue;
34043418

3405-
case 'f': /* Prefetch offset, pseudo S-type but lower 5-bits zero. */
3406-
if (riscv_handle_implicit_zero_offset (imm_expr, asarg))
3407-
continue;
3408-
my_getExpression (imm_expr, asarg);
3409-
check_absolute_expr (ip, imm_expr, false);
3410-
if (((unsigned) (imm_expr->X_add_number) & 0x1fU)
3411-
|| imm_expr->X_add_number >= (signed) RISCV_IMM_REACH / 2
3412-
|| imm_expr->X_add_number < -(signed) RISCV_IMM_REACH / 2)
3413-
as_bad (_("improper prefetch offset (%ld)"),
3414-
(long) imm_expr->X_add_number);
3415-
ip->insn_opcode |=
3416-
ENCODE_STYPE_IMM ((unsigned) (imm_expr->X_add_number) &
3417-
~ 0x1fU);
3418-
imm_expr->X_op = O_absent;
3419-
asarg = expr_end;
3420-
continue;
3419+
case 'W': /* Various operands. */
3420+
switch (*++oparg)
3421+
{
3422+
case 'i':
3423+
switch (*++oparg)
3424+
{
3425+
case 'f':
3426+
/* Prefetch offset for 'Zicbop' extension.
3427+
pseudo S-type but lower 5-bits zero. */
3428+
if (riscv_handle_implicit_zero_offset (imm_expr, asarg))
3429+
continue;
3430+
my_getExpression (imm_expr, asarg);
3431+
check_absolute_expr (ip, imm_expr, false);
3432+
if (((unsigned) (imm_expr->X_add_number) & 0x1fU)
3433+
|| imm_expr->X_add_number >= RISCV_IMM_REACH / 2
3434+
|| imm_expr->X_add_number < -RISCV_IMM_REACH / 2)
3435+
as_bad (_ ("improper prefetch offset (%ld)"),
3436+
(long) imm_expr->X_add_number);
3437+
ip->insn_opcode |= ENCODE_STYPE_IMM (
3438+
(unsigned) (imm_expr->X_add_number) & ~0x1fU);
3439+
imm_expr->X_op = O_absent;
3440+
asarg = expr_end;
3441+
continue;
3442+
default:
3443+
goto unknown_riscv_ip_operand;
3444+
}
3445+
break;
3446+
default:
3447+
goto unknown_riscv_ip_operand;
3448+
}
3449+
break;
34213450

34223451
case 'X': /* Integer immediate. */
34233452
{
@@ -3470,6 +3499,7 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
34703499
}
34713500
}
34723501
break;
3502+
34733503
default:
34743504
unknown_riscv_ip_operand:
34753505
as_fatal (_("internal: unknown argument type `%s'"),

opcodes/riscv-dis.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,6 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
473473
(int)EXTRACT_STYPE_IMM (l));
474474
break;
475475

476-
case 'f':
477-
print (info->stream, dis_style_address_offset, "%d",
478-
(int)EXTRACT_STYPE_IMM (l));
479-
break;
480-
481476
case 'a':
482477
info->target = EXTRACT_JTYPE_IMM (l) + pc;
483478
(*info->print_address_func) (info->target, info);
@@ -582,6 +577,27 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
582577
print (info->stream, dis_style_immediate, "%d", rs1);
583578
break;
584579

580+
case 'W': /* Various operands. */
581+
{
582+
switch (*++oparg)
583+
{
584+
case 'i':
585+
switch (*++oparg)
586+
{
587+
case 'f':
588+
print (info->stream, dis_style_address_offset, "%d",
589+
(int) EXTRACT_STYPE_IMM (l));
590+
break;
591+
default:
592+
goto undefined_modifier;
593+
}
594+
break;
595+
default:
596+
goto undefined_modifier;
597+
}
598+
}
599+
break;
600+
585601
case 'X': /* Integer immediate. */
586602
{
587603
size_t n;

opcodes/riscv-opc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ const struct riscv_opcode riscv_opcodes[] =
313313
/* name, xlen, isa, operands, match, mask, match_func, pinfo. */
314314

315315
/* Standard hints. */
316-
{"prefetch.i", 0, INSN_CLASS_ZICBOP, "f(s)", MATCH_PREFETCH_I, MASK_PREFETCH_I, match_opcode, 0 },
317-
{"prefetch.r", 0, INSN_CLASS_ZICBOP, "f(s)", MATCH_PREFETCH_R, MASK_PREFETCH_R, match_opcode, 0 },
318-
{"prefetch.w", 0, INSN_CLASS_ZICBOP, "f(s)", MATCH_PREFETCH_W, MASK_PREFETCH_W, match_opcode, 0 },
316+
{"prefetch.i", 0, INSN_CLASS_ZICBOP, "Wif(s)", MATCH_PREFETCH_I, MASK_PREFETCH_I, match_opcode, 0 },
317+
{"prefetch.r", 0, INSN_CLASS_ZICBOP, "Wif(s)", MATCH_PREFETCH_R, MASK_PREFETCH_R, match_opcode, 0 },
318+
{"prefetch.w", 0, INSN_CLASS_ZICBOP, "Wif(s)", MATCH_PREFETCH_W, MASK_PREFETCH_W, match_opcode, 0 },
319319
{"pause", 0, INSN_CLASS_ZIHINTPAUSE, "", MATCH_PAUSE, MASK_PAUSE, match_opcode, 0 },
320320

321321
/* Basic RVI instructions and aliases. */

0 commit comments

Comments
 (0)