tcg: Pass the opcode width to target_parse_constraint
This will let us choose how to interpret a given constraint depending on whether the opcode is 32- or 64-bit. Which will let us share more constraint combinations between opcodes. At the same time, change the interface to return the advanced pointer instead of passing it in/out by reference. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <rth@twiddle.net>
This commit is contained in:
parent
f69d277ece
commit
069ea736b5
@ -115,12 +115,10 @@ static inline void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
|||||||
#define TCG_CT_CONST_MONE 0x800
|
#define TCG_CT_CONST_MONE 0x800
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct,
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
const char **pct_str)
|
const char *ct_str, TCGType type)
|
||||||
{
|
{
|
||||||
const char *ct_str = *pct_str;
|
switch (*ct_str++) {
|
||||||
|
|
||||||
switch (ct_str[0]) {
|
|
||||||
case 'r':
|
case 'r':
|
||||||
ct->ct |= TCG_CT_REG;
|
ct->ct |= TCG_CT_REG;
|
||||||
tcg_regset_set32(ct->u.regs, 0, (1ULL << TCG_TARGET_NB_REGS) - 1);
|
tcg_regset_set32(ct->u.regs, 0, (1ULL << TCG_TARGET_NB_REGS) - 1);
|
||||||
@ -150,12 +148,9 @@ static int target_parse_constraint(TCGArgConstraint *ct,
|
|||||||
ct->ct |= TCG_CT_CONST_ZERO;
|
ct->ct |= TCG_CT_CONST_ZERO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return ct_str;
|
||||||
ct_str++;
|
|
||||||
*pct_str = ct_str;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool is_aimm(uint64_t val)
|
static inline bool is_aimm(uint64_t val)
|
||||||
|
@ -114,12 +114,10 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
|||||||
#define TCG_CT_CONST_ZERO 0x800
|
#define TCG_CT_CONST_ZERO 0x800
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
|
const char *ct_str, TCGType type)
|
||||||
{
|
{
|
||||||
const char *ct_str;
|
switch (*ct_str++) {
|
||||||
|
|
||||||
ct_str = *pct_str;
|
|
||||||
switch (ct_str[0]) {
|
|
||||||
case 'I':
|
case 'I':
|
||||||
ct->ct |= TCG_CT_CONST_ARM;
|
ct->ct |= TCG_CT_CONST_ARM;
|
||||||
break;
|
break;
|
||||||
@ -172,12 +170,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
ct_str++;
|
return ct_str;
|
||||||
*pct_str = ct_str;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t rotl(uint32_t val, int n)
|
static inline uint32_t rotl(uint32_t val, int n)
|
||||||
|
@ -166,12 +166,10 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
|
const char *ct_str, TCGType type)
|
||||||
{
|
{
|
||||||
const char *ct_str;
|
switch(*ct_str++) {
|
||||||
|
|
||||||
ct_str = *pct_str;
|
|
||||||
switch(ct_str[0]) {
|
|
||||||
case 'a':
|
case 'a':
|
||||||
ct->ct |= TCG_CT_REG;
|
ct->ct |= TCG_CT_REG;
|
||||||
tcg_regset_set_reg(ct->u.regs, TCG_REG_EAX);
|
tcg_regset_set_reg(ct->u.regs, TCG_REG_EAX);
|
||||||
@ -249,11 +247,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
ct_str++;
|
return ct_str;
|
||||||
*pct_str = ct_str;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test if a constant matches the constraint */
|
/* test if a constant matches the constraint */
|
||||||
|
@ -721,12 +721,10 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
|
const char *ct_str, TCGType type)
|
||||||
{
|
{
|
||||||
const char *ct_str;
|
switch(*ct_str++) {
|
||||||
|
|
||||||
ct_str = *pct_str;
|
|
||||||
switch(ct_str[0]) {
|
|
||||||
case 'r':
|
case 'r':
|
||||||
ct->ct |= TCG_CT_REG;
|
ct->ct |= TCG_CT_REG;
|
||||||
tcg_regset_set(ct->u.regs, 0xffffffffffffffffull);
|
tcg_regset_set(ct->u.regs, 0xffffffffffffffffull);
|
||||||
@ -750,11 +748,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
|||||||
ct->ct |= TCG_CT_CONST_ZERO;
|
ct->ct |= TCG_CT_CONST_ZERO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
ct_str++;
|
return ct_str;
|
||||||
*pct_str = ct_str;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test if a constant matches the constraint */
|
/* test if a constant matches the constraint */
|
||||||
|
@ -186,12 +186,10 @@ static inline bool is_p2m1(tcg_target_long val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
|
const char *ct_str, TCGType type)
|
||||||
{
|
{
|
||||||
const char *ct_str;
|
switch(*ct_str++) {
|
||||||
|
|
||||||
ct_str = *pct_str;
|
|
||||||
switch(ct_str[0]) {
|
|
||||||
case 'r':
|
case 'r':
|
||||||
ct->ct |= TCG_CT_REG;
|
ct->ct |= TCG_CT_REG;
|
||||||
tcg_regset_set(ct->u.regs, 0xffffffff);
|
tcg_regset_set(ct->u.regs, 0xffffffff);
|
||||||
@ -238,11 +236,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
|||||||
ct->ct |= TCG_CT_CONST_ZERO;
|
ct->ct |= TCG_CT_CONST_ZERO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
ct_str++;
|
return ct_str;
|
||||||
*pct_str = ct_str;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test if a constant matches the constraint */
|
/* test if a constant matches the constraint */
|
||||||
|
@ -259,12 +259,10 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
|
const char *ct_str, TCGType type)
|
||||||
{
|
{
|
||||||
const char *ct_str;
|
switch (*ct_str++) {
|
||||||
|
|
||||||
ct_str = *pct_str;
|
|
||||||
switch (ct_str[0]) {
|
|
||||||
case 'A': case 'B': case 'C': case 'D':
|
case 'A': case 'B': case 'C': case 'D':
|
||||||
ct->ct |= TCG_CT_REG;
|
ct->ct |= TCG_CT_REG;
|
||||||
tcg_regset_set_reg(ct->u.regs, 3 + ct_str[0] - 'A');
|
tcg_regset_set_reg(ct->u.regs, 3 + ct_str[0] - 'A');
|
||||||
@ -311,11 +309,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
|||||||
ct->ct |= TCG_CT_CONST_ZERO;
|
ct->ct |= TCG_CT_CONST_ZERO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
ct_str++;
|
return ct_str;
|
||||||
*pct_str = ct_str;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test if a constant matches the constraint */
|
/* test if a constant matches the constraint */
|
||||||
|
@ -359,11 +359,10 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
|
const char *ct_str, TCGType type)
|
||||||
{
|
{
|
||||||
const char *ct_str = *pct_str;
|
switch (*ct_str++) {
|
||||||
|
|
||||||
switch (ct_str[0]) {
|
|
||||||
case 'r': /* all registers */
|
case 'r': /* all registers */
|
||||||
ct->ct |= TCG_CT_REG;
|
ct->ct |= TCG_CT_REG;
|
||||||
tcg_regset_set32(ct->u.regs, 0, 0xffff);
|
tcg_regset_set32(ct->u.regs, 0, 0xffff);
|
||||||
@ -404,12 +403,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
|||||||
ct->ct |= TCG_CT_CONST_ZERO;
|
ct->ct |= TCG_CT_CONST_ZERO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
ct_str++;
|
return ct_str;
|
||||||
*pct_str = ct_str;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Immediates to be used with logical OR. This is an optimization only,
|
/* Immediates to be used with logical OR. This is an optimization only,
|
||||||
|
@ -319,12 +319,10 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
|
const char *ct_str, TCGType type)
|
||||||
{
|
{
|
||||||
const char *ct_str;
|
switch (*ct_str++) {
|
||||||
|
|
||||||
ct_str = *pct_str;
|
|
||||||
switch (ct_str[0]) {
|
|
||||||
case 'r':
|
case 'r':
|
||||||
ct->ct |= TCG_CT_REG;
|
ct->ct |= TCG_CT_REG;
|
||||||
tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
|
tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
|
||||||
@ -360,11 +358,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
|||||||
ct->ct |= TCG_CT_CONST_ZERO;
|
ct->ct |= TCG_CT_CONST_ZERO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
ct_str++;
|
return ct_str;
|
||||||
*pct_str = ct_str;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test if a constant matches the constraint */
|
/* test if a constant matches the constraint */
|
||||||
|
12
tcg/tcg.c
12
tcg/tcg.c
@ -96,7 +96,8 @@ static void tcg_register_jit_int(void *buf, size_t size,
|
|||||||
__attribute__((unused));
|
__attribute__((unused));
|
||||||
|
|
||||||
/* Forward declarations for functions declared and used in tcg-target.inc.c. */
|
/* Forward declarations for functions declared and used in tcg-target.inc.c. */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str);
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
|
const char *ct_str, TCGType type);
|
||||||
static void tcg_out_ld(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg1,
|
static void tcg_out_ld(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg1,
|
||||||
intptr_t arg2);
|
intptr_t arg2);
|
||||||
static void tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg);
|
static void tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg);
|
||||||
@ -1231,7 +1232,8 @@ static void process_op_defs(TCGContext *s)
|
|||||||
for (op = 0; op < NB_OPS; op++) {
|
for (op = 0; op < NB_OPS; op++) {
|
||||||
TCGOpDef *def = &tcg_op_defs[op];
|
TCGOpDef *def = &tcg_op_defs[op];
|
||||||
const TCGTargetOpDef *tdefs;
|
const TCGTargetOpDef *tdefs;
|
||||||
int i, nb_args, ok;
|
TCGType type;
|
||||||
|
int i, nb_args;
|
||||||
|
|
||||||
if (def->flags & TCG_OPF_NOT_PRESENT) {
|
if (def->flags & TCG_OPF_NOT_PRESENT) {
|
||||||
continue;
|
continue;
|
||||||
@ -1246,6 +1248,7 @@ static void process_op_defs(TCGContext *s)
|
|||||||
/* Missing TCGTargetOpDef entry. */
|
/* Missing TCGTargetOpDef entry. */
|
||||||
tcg_debug_assert(tdefs != NULL);
|
tcg_debug_assert(tdefs != NULL);
|
||||||
|
|
||||||
|
type = (def->flags & TCG_OPF_64BIT ? TCG_TYPE_I64 : TCG_TYPE_I32);
|
||||||
for (i = 0; i < nb_args; i++) {
|
for (i = 0; i < nb_args; i++) {
|
||||||
const char *ct_str = tdefs->args_ct_str[i];
|
const char *ct_str = tdefs->args_ct_str[i];
|
||||||
/* Incomplete TCGTargetOpDef entry. */
|
/* Incomplete TCGTargetOpDef entry. */
|
||||||
@ -1279,9 +1282,10 @@ static void process_op_defs(TCGContext *s)
|
|||||||
ct_str++;
|
ct_str++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ok = target_parse_constraint(&def->args_ct[i], &ct_str);
|
ct_str = target_parse_constraint(&def->args_ct[i],
|
||||||
|
ct_str, type);
|
||||||
/* Typo in TCGTargetOpDef constraint. */
|
/* Typo in TCGTargetOpDef constraint. */
|
||||||
tcg_debug_assert(ok == 0);
|
tcg_debug_assert(ct_str != NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,10 +384,10 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Parse target specific constraints. */
|
/* Parse target specific constraints. */
|
||||||
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
static const char *target_parse_constraint(TCGArgConstraint *ct,
|
||||||
|
const char *ct_str, TCGType type)
|
||||||
{
|
{
|
||||||
const char *ct_str = *pct_str;
|
switch (*ct_str++) {
|
||||||
switch (ct_str[0]) {
|
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'L': /* qemu_ld constraint */
|
case 'L': /* qemu_ld constraint */
|
||||||
case 'S': /* qemu_st constraint */
|
case 'S': /* qemu_st constraint */
|
||||||
@ -395,11 +395,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
|
|||||||
tcg_regset_set32(ct->u.regs, 0, BIT(TCG_TARGET_NB_REGS) - 1);
|
tcg_regset_set32(ct->u.regs, 0, BIT(TCG_TARGET_NB_REGS) - 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
ct_str++;
|
return ct_str;
|
||||||
*pct_str = ct_str;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_DEBUG_TCG_INTERPRETER)
|
#if defined(CONFIG_DEBUG_TCG_INTERPRETER)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user