Skip to content

Commit 6f7508d

Browse files
committed
arcv: gas: apex: Add initializer for XS format instructions.
Introduce arcv_apex_setup_xs_insn to configure riscv_opcode entries for APEX XS instructions. The function sets mask, match, and match_func. It assigns operand argument strings based on the VOID flag, ensuring correct handling of XS and variants. Signed-off-by: Luis Silva <luiss@synopsys.com>
1 parent 30b15a6 commit 6f7508d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

include/opcode/riscv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,10 @@ extern unsigned int riscv_get_sp_base (insn_t, unsigned int);
669669

670670
extern void arcv_apex_setup_xd_insn (struct riscv_opcode *, unsigned int,
671671
unsigned int);
672+
extern void arcv_apex_setup_xs_insn (struct riscv_opcode *, unsigned int,
673+
unsigned int);
674+
extern void arcv_apex_setup_xi_insn (struct riscv_opcode *, unsigned int,
675+
unsigned int);
672676

673677
enum apex_flags {
674678
None = 0,
@@ -682,5 +686,6 @@ enum apex_flags {
682686
};
683687

684688
#define APEX_MASK_XD0xFE00407F
689+
#define APEX_MASK_XS0xF0707F
685690

686691
#endif /* _RISCV_H_ */

opcodes/riscv-opc.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,47 @@ arcv_apex_setup_xd_insn (struct riscv_opcode *insn,
419419
}
420420
}
421421

422+
/* Encode sub-opcode into the XS instruction format. */
423+
424+
static uint32_t
425+
arcv_apex_get_match_xs (unsigned char sub_opcode)
426+
{
427+
uint32_t match = 0;
428+
match |= ((uint32_t)(sub_opcode & 0x3C) << 18); /* Bits [5:2] to [23:18]. */
429+
match |= ((uint32_t)(sub_opcode & 0x3) << 13); /* Bits [1:0] to [14:13]. */
430+
match |= 0xb; /* Fixed Custom-0 field. */
431+
match |= 0x1000; /* Set XS fixed bits. */
432+
return match;
433+
}
434+
435+
/* Initialize an APEX instruction in XS format.
436+
Sets mask, match, and operand argument string based on flags.
437+
The VOID flag controls whether the destination operand is included. */
438+
439+
void
440+
arcv_apex_setup_xs_insn (struct riscv_opcode *insn,
441+
unsigned int flags,
442+
unsigned int sub_opcode)
443+
{
444+
insn->mask |= APEX_MASK_XS;
445+
insn->match = arcv_apex_get_match_xs (sub_opcode);
446+
insn->match_func = match_opcode;
447+
448+
/* Select operand pattern based on VOID flag.
449+
Operands: d = dest, s = src1, k = 8-bit immediate. */
450+
switch (flags & (VOID))
451+
{
452+
/* src0, imm only. */
453+
case VOID:
454+
insn->args = "Ms,Mk";
455+
break;
456+
/* dest, src0, imm (default XS form). */
457+
default:
458+
insn->args = "Md,Ms,Mk";
459+
break;
460+
}
461+
}
462+
422463
/* The order of overloaded instructions matters. Label arguments and
423464
register arguments look the same. Instructions that can have either
424465
for arguments must apear in the correct order in this table for the

0 commit comments

Comments
 (0)