Skip to content

Commit 80df5c4

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 85f9067 commit 80df5c4

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
@@ -1359,7 +1359,6 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
13591359
case 'j': used_bits |= ENCODE_ITYPE_IMM (-1U); break;
13601360
case 'a': used_bits |= ENCODE_JTYPE_IMM (-1U); break;
13611361
case 'p': used_bits |= ENCODE_BTYPE_IMM (-1U); break;
1362-
case 'f': /* Fall through. */
13631362
case 'q': used_bits |= ENCODE_STYPE_IMM (-1U); break;
13641363
case 'u': used_bits |= ENCODE_UTYPE_IMM (-1U); break;
13651364
case 'z': break; /* Zero immediate. */
@@ -1386,6 +1385,21 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
13861385
goto unknown_validate_operand;
13871386
}
13881387
break;
1388+
case 'W': /* Various operands. */
1389+
switch (*++oparg)
1390+
{
1391+
case 'i':
1392+
switch (*++oparg)
1393+
{
1394+
case 'f': used_bits |= ENCODE_STYPE_IMM (-1U); break;
1395+
default:
1396+
goto unknown_validate_operand;
1397+
}
1398+
break;
1399+
default:
1400+
goto unknown_validate_operand;
1401+
}
1402+
break;
13891403
case 'X': /* Integer immediate. */
13901404
{
13911405
size_t n;
@@ -3401,22 +3415,37 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
34013415
imm_expr->X_op = O_absent;
34023416
continue;
34033417

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

34213450
case 'X': /* Integer immediate. */
34223451
{
@@ -3469,6 +3498,7 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
34693498
}
34703499
}
34713500
break;
3501+
34723502
default:
34733503
unknown_riscv_ip_operand:
34743504
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)