Skip to content

Commit 6de11ff

Browse files
author
Nelson Chu
committed
RISC-V: Clarify the naming rules of vendor operands.
The vendor operands should be named starting with `X', and preferably the second letter (or multiple following letters) is enough to differentiate them from other vendors. Therefore, added letter `t' after `X' for t-head operands, to differentiate from future different vendor's operands. bfd/ * elfxx-riscv.c (riscv_supported_vendor_x_ext): Removed the vendor document link since it should already be recorded in the gas/doc/c-riscv.texi. gas/ * config/tc-riscv.c (validate_riscv_insn): Added `t' after `X' for t-head operands. Minor updates for indents and comments. (riscv_ip): Likewise. * doc/c-riscv.texi: Minor updates. opcodes/ * riscv-dis.c (print_insn_args): Added `t' after `X' for t-head operands. Minor updates for indents and comments. * riscv-opc.c (riscv_opcode): Likewise.
1 parent 5e9091d commit 6de11ff

File tree

5 files changed

+250
-233
lines changed

5 files changed

+250
-233
lines changed

bfd/elfxx-riscv.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,6 @@ static struct riscv_supported_ext riscv_supported_vendor_x_ext[] =
13631363
{"xtheadmemidx", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
13641364
{"xtheadmempair", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
13651365
{"xtheadsync", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
1366-
/* XVentanaCondOps: https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf */
13671366
{"xventanacondops", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
13681367
{NULL, 0, 0, 0, 0}
13691368
};

gas/config/tc-riscv.c

Lines changed: 97 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,23 +1400,23 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
14001400
case 'F': /* Funct for .insn directive. */
14011401
switch (*++oparg)
14021402
{
1403-
case '7': USE_BITS (OP_MASK_FUNCT7, OP_SH_FUNCT7); break;
1404-
case '3': USE_BITS (OP_MASK_FUNCT3, OP_SH_FUNCT3); break;
1405-
case '2': USE_BITS (OP_MASK_FUNCT2, OP_SH_FUNCT2); break;
1406-
default:
1407-
goto unknown_validate_operand;
1403+
case '7': USE_BITS (OP_MASK_FUNCT7, OP_SH_FUNCT7); break;
1404+
case '3': USE_BITS (OP_MASK_FUNCT3, OP_SH_FUNCT3); break;
1405+
case '2': USE_BITS (OP_MASK_FUNCT2, OP_SH_FUNCT2); break;
1406+
default:
1407+
goto unknown_validate_operand;
14081408
}
14091409
break;
14101410
case 'O': /* Opcode for .insn directive. */
14111411
switch (*++oparg)
14121412
{
1413-
case '4': USE_BITS (OP_MASK_OP, OP_SH_OP); break;
1414-
case '2': USE_BITS (OP_MASK_OP2, OP_SH_OP2); break;
1415-
default:
1416-
goto unknown_validate_operand;
1413+
case '4': USE_BITS (OP_MASK_OP, OP_SH_OP); break;
1414+
case '2': USE_BITS (OP_MASK_OP2, OP_SH_OP2); break;
1415+
default:
1416+
goto unknown_validate_operand;
14171417
}
14181418
break;
1419-
case 'W': /* Various operands. */
1419+
case 'W': /* Various operands for standard z extensions. */
14201420
switch (*++oparg)
14211421
{
14221422
case 'i':
@@ -1451,33 +1451,39 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
14511451
goto unknown_validate_operand;
14521452
}
14531453
break;
1454-
case 'X': /* Integer immediate. */
1455-
{
1456-
size_t n;
1457-
size_t s;
1458-
1459-
switch (*++oparg)
1454+
case 'X': /* Vendor-specific operands. */
1455+
switch (*++oparg)
1456+
{
1457+
case 't': /* Vendor-specific (T-head) operands. */
14601458
{
1461-
case 'l': /* Literal. */
1462-
oparg += strcspn(oparg, ",") - 1;
1463-
break;
1464-
case 's': /* 'XsN@S' ... N-bit signed immediate at bit S. */
1465-
goto use_imm;
1466-
case 'u': /* 'XuN@S' ... N-bit unsigned immediate at bit S. */
1467-
goto use_imm;
1468-
use_imm:
1469-
n = strtol (oparg + 1, (char **)&oparg, 10);
1470-
if (*oparg != '@')
1459+
size_t n;
1460+
size_t s;
1461+
switch (*++oparg)
1462+
{
1463+
case 'l': /* Integer immediate, literal. */
1464+
oparg += strcspn(oparg, ",") - 1;
1465+
break;
1466+
case 's': /* Integer immediate, 'XtsN@S' ... N-bit signed immediate at bit S. */
1467+
goto use_imm;
1468+
case 'u': /* Integer immediate, 'XtuN@S' ... N-bit unsigned immediate at bit S. */
1469+
goto use_imm;
1470+
use_imm:
1471+
n = strtol (oparg + 1, (char **)&oparg, 10);
1472+
if (*oparg != '@')
1473+
goto unknown_validate_operand;
1474+
s = strtol (oparg + 1, (char **)&oparg, 10);
1475+
oparg--;
1476+
1477+
USE_IMM (n, s);
1478+
break;
1479+
default:
14711480
goto unknown_validate_operand;
1472-
s = strtol (oparg + 1, (char **)&oparg, 10);
1473-
oparg--;
1474-
1475-
USE_IMM (n, s);
1476-
break;
1477-
default:
1478-
goto unknown_validate_operand;
1481+
}
14791482
}
1480-
}
1483+
break;
1484+
default:
1485+
goto unknown_validate_operand;
1486+
}
14811487
break;
14821488
default:
14831489
unknown_validate_operand:
@@ -3489,7 +3495,7 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
34893495
imm_expr->X_op = O_absent;
34903496
continue;
34913497

3492-
case 'W': /* Various operands. */
3498+
case 'W': /* Various operands for standard z extensions. */
34933499
switch (*++oparg)
34943500
{
34953501
case 'i':
@@ -3516,6 +3522,7 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
35163522
goto unknown_riscv_ip_operand;
35173523
}
35183524
break;
3525+
35193526
case 'f':
35203527
switch (*++oparg)
35213528
{
@@ -3559,7 +3566,6 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
35593566
break;
35603567
ip->insn_opcode |= ENCODE_ZCB_HALFWORD_UIMM (imm_expr->X_add_number);
35613568
goto rvc_imm_done;
3562-
35633569
case 'b': /* Immediate field for c.lbu/c.sb. */
35643570
/* Handle cases, such as c.lbu rd', (rs1'). */
35653571
if (riscv_handle_implicit_zero_offset (imm_expr, asarg))
@@ -3570,7 +3576,6 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
35703576
break;
35713577
ip->insn_opcode |= ENCODE_ZCB_BYTE_UIMM (imm_expr->X_add_number);
35723578
goto rvc_imm_done;
3573-
35743579
case 'f': /* Operand for matching immediate 255. */
35753580
if (my_getSmallExpression (imm_expr, imm_reloc, asarg, p)
35763581
|| imm_expr->X_op != O_constant
@@ -3581,66 +3586,73 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
35813586
asarg = expr_parse_end;
35823587
imm_expr->X_op = O_absent;
35833588
continue;
3584-
35853589
default:
35863590
goto unknown_riscv_ip_operand;
35873591
}
35883592
break;
3593+
35893594
default:
35903595
goto unknown_riscv_ip_operand;
35913596
}
35923597
break;
35933598

3594-
case 'X': /* Integer immediate. */
3595-
{
3596-
size_t n;
3597-
size_t s;
3598-
bool sign;
3599-
3600-
switch (*++oparg)
3599+
case 'X': /* Vendor-specific operands. */
3600+
switch (*++oparg)
3601+
{
3602+
case 't': /* Vendor-specific (T-head) operands. */
36013603
{
3602-
case 'l': /* Literal. */
3603-
n = strcspn (++oparg, ",");
3604-
if (strncmp (oparg, asarg, n))
3605-
as_bad (_("unexpected literal (%s)"), asarg);
3606-
oparg += n - 1;
3607-
asarg += n;
3608-
continue;
3609-
case 's': /* 'XsN@S' ... N-bit signed immediate at bit S. */
3610-
sign = true;
3611-
goto parse_imm;
3612-
case 'u': /* 'XuN@S' ... N-bit unsigned immediate at bit S. */
3613-
sign = false;
3614-
goto parse_imm;
3615-
parse_imm:
3616-
n = strtol (oparg + 1, (char **)&oparg, 10);
3617-
if (*oparg != '@')
3604+
size_t n;
3605+
size_t s;
3606+
bool sign;
3607+
switch (*++oparg)
3608+
{
3609+
case 'l': /* Integer immediate, literal. */
3610+
n = strcspn (++oparg, ",");
3611+
if (strncmp (oparg, asarg, n))
3612+
as_bad (_("unexpected literal (%s)"), asarg);
3613+
oparg += n - 1;
3614+
asarg += n;
3615+
continue;
3616+
case 's': /* Integer immediate, 'XsN@S' ... N-bit signed immediate at bit S. */
3617+
sign = true;
3618+
goto parse_imm;
3619+
case 'u': /* Integer immediate, 'XuN@S' ... N-bit unsigned immediate at bit S. */
3620+
sign = false;
3621+
goto parse_imm;
3622+
parse_imm:
3623+
n = strtol (oparg + 1, (char **)&oparg, 10);
3624+
if (*oparg != '@')
3625+
goto unknown_riscv_ip_operand;
3626+
s = strtol (oparg + 1, (char **)&oparg, 10);
3627+
oparg--;
3628+
3629+
my_getExpression (imm_expr, asarg);
3630+
check_absolute_expr (ip, imm_expr, false);
3631+
if (!sign)
3632+
{
3633+
if (!VALIDATE_U_IMM (imm_expr->X_add_number, n))
3634+
as_bad (_("improper immediate value (%"PRIu64")"),
3635+
imm_expr->X_add_number);
3636+
}
3637+
else
3638+
{
3639+
if (!VALIDATE_S_IMM (imm_expr->X_add_number, n))
3640+
as_bad (_("improper immediate value (%"PRIi64")"),
3641+
imm_expr->X_add_number);
3642+
}
3643+
INSERT_IMM (n, s, *ip, imm_expr->X_add_number);
3644+
imm_expr->X_op = O_absent;
3645+
asarg = expr_parse_end;
3646+
continue;
3647+
default:
36183648
goto unknown_riscv_ip_operand;
3619-
s = strtol (oparg + 1, (char **)&oparg, 10);
3620-
oparg--;
3621-
3622-
my_getExpression (imm_expr, asarg);
3623-
check_absolute_expr (ip, imm_expr, false);
3624-
if (!sign)
3625-
{
3626-
if (!VALIDATE_U_IMM (imm_expr->X_add_number, n))
3627-
as_bad (_("improper immediate value (%"PRIu64")"),
3628-
imm_expr->X_add_number);
3629-
}
3630-
else
3631-
{
3632-
if (!VALIDATE_S_IMM (imm_expr->X_add_number, n))
3633-
as_bad (_("improper immediate value (%"PRIi64")"),
3634-
imm_expr->X_add_number);
3635-
}
3636-
INSERT_IMM (n, s, *ip, imm_expr->X_add_number);
3637-
imm_expr->X_op = O_absent;
3638-
asarg = expr_parse_end;
3639-
continue;
3640-
default:
3641-
goto unknown_riscv_ip_operand;
3649+
}
36423650
}
3643-
}
3651+
break;
3652+
3653+
default:
3654+
goto unknown_riscv_ip_operand;
3655+
}
36443656
break;
36453657

36463658
default:

gas/doc/c-riscv.texi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,12 @@ It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/rel
804804
The XTheadSync extension provides instructions for multi-processor synchronization.
805805

806806
It is documented in @url{https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.0.0/xthead-2022-09-05-2.0.0.pdf}.
807+
807808
@item XVentanaCondOps
808809
XVentanaCondOps extension provides instructions for branchless
809810
sequences that perform conditional arithmetic, conditional
810811
bitwise-logic, and conditional select operations.
811812

812-
It is documented at @url{https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf}.
813+
It is documented in @url{https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf}.
813814

814815
@end table

0 commit comments

Comments
 (0)