CRIS: Purify some of the flag evaluation helpers.

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6227 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
edgar_igl 2009-01-07 23:38:41 +00:00
parent c1e1a49190
commit 6231868b11
3 changed files with 155 additions and 161 deletions

View File

@ -13,13 +13,13 @@ DEF_HELPER_2(movl_reg_sreg, void, i32, i32)
DEF_HELPER_FLAGS_1(lz, TCG_CALL_PURE, i32, i32); DEF_HELPER_FLAGS_1(lz, TCG_CALL_PURE, i32, i32);
DEF_HELPER_FLAGS_3(btst, TCG_CALL_PURE, i32, i32, i32, i32); DEF_HELPER_FLAGS_3(btst, TCG_CALL_PURE, i32, i32, i32, i32);
DEF_HELPER_0(evaluate_flags_muls, void) DEF_HELPER_FLAGS_3(evaluate_flags_muls, TCG_CALL_PURE, i32, i32, i32, i32)
DEF_HELPER_0(evaluate_flags_mulu, void) DEF_HELPER_FLAGS_3(evaluate_flags_mulu, TCG_CALL_PURE, i32, i32, i32, i32)
DEF_HELPER_0(evaluate_flags_mcp, void) DEF_HELPER_FLAGS_4(evaluate_flags_mcp, TCG_CALL_PURE, i32, i32, i32, i32, i32)
DEF_HELPER_0(evaluate_flags_alu_4, void) DEF_HELPER_FLAGS_4(evaluate_flags_alu_4, TCG_CALL_PURE, i32, i32, i32, i32, i32)
DEF_HELPER_0(evaluate_flags_sub_4, void) DEF_HELPER_FLAGS_4(evaluate_flags_sub_4, TCG_CALL_PURE, i32, i32, i32, i32, i32)
DEF_HELPER_0(evaluate_flags_move_4, void) DEF_HELPER_FLAGS_2(evaluate_flags_move_4, TCG_CALL_PURE, i32, i32, i32)
DEF_HELPER_0(evaluate_flags_move_2, void) DEF_HELPER_FLAGS_2(evaluate_flags_move_2, TCG_CALL_PURE, i32, i32, i32)
DEF_HELPER_0(evaluate_flags, void) DEF_HELPER_0(evaluate_flags, void)
DEF_HELPER_0(top_evaluate_flags, void) DEF_HELPER_0(top_evaluate_flags, void)

View File

@ -275,7 +275,7 @@ uint32_t helper_btst(uint32_t t0, uint32_t t1, uint32_t ccs)
return ccs; return ccs;
} }
static void evaluate_flags_writeback(uint32_t flags) static inline uint32_t evaluate_flags_writeback(uint32_t flags, uint32_t ccs)
{ {
unsigned int x, z, mask; unsigned int x, z, mask;
@ -289,27 +289,19 @@ static void evaluate_flags_writeback(uint32_t flags)
flags &= mask; flags &= mask;
/* all insn clear the x-flag except setf or clrf. */ /* all insn clear the x-flag except setf or clrf. */
env->pregs[PR_CCS] &= ~mask; ccs &= ~mask;
env->pregs[PR_CCS] |= flags; ccs |= flags;
return ccs;
} }
void helper_evaluate_flags_muls(void) uint32_t helper_evaluate_flags_muls(uint32_t ccs, uint32_t res, uint32_t mof)
{ {
uint32_t src;
uint32_t dst;
uint32_t res;
uint32_t flags = 0; uint32_t flags = 0;
int64_t tmp; int64_t tmp;
int32_t mof;
int dneg; int dneg;
src = env->cc_src;
dst = env->cc_dest;
res = env->cc_result;
dneg = ((int32_t)res) < 0; dneg = ((int32_t)res) < 0;
mof = env->pregs[PR_MOF];
tmp = mof; tmp = mof;
tmp <<= 32; tmp <<= 32;
tmp |= res; tmp |= res;
@ -320,23 +312,14 @@ void helper_evaluate_flags_muls(void)
if ((dneg && mof != -1) if ((dneg && mof != -1)
|| (!dneg && mof != 0)) || (!dneg && mof != 0))
flags |= V_FLAG; flags |= V_FLAG;
evaluate_flags_writeback(flags); return evaluate_flags_writeback(flags, ccs);
} }
void helper_evaluate_flags_mulu(void) uint32_t helper_evaluate_flags_mulu(uint32_t ccs, uint32_t res, uint32_t mof)
{ {
uint32_t src;
uint32_t dst;
uint32_t res;
uint32_t flags = 0; uint32_t flags = 0;
uint64_t tmp; uint64_t tmp;
uint32_t mof;
src = env->cc_src;
dst = env->cc_dest;
res = env->cc_result;
mof = env->pregs[PR_MOF];
tmp = mof; tmp = mof;
tmp <<= 32; tmp <<= 32;
tmp |= res; tmp |= res;
@ -347,19 +330,16 @@ void helper_evaluate_flags_mulu(void)
if (mof) if (mof)
flags |= V_FLAG; flags |= V_FLAG;
evaluate_flags_writeback(flags); return evaluate_flags_writeback(flags, ccs);
} }
void helper_evaluate_flags_mcp(void) uint32_t helper_evaluate_flags_mcp(uint32_t ccs,
uint32_t src, uint32_t dst, uint32_t res)
{ {
uint32_t src;
uint32_t dst;
uint32_t res;
uint32_t flags = 0; uint32_t flags = 0;
src = env->cc_src & 0x80000000; src = src & 0x80000000;
dst = env->cc_dest & 0x80000000; dst = dst & 0x80000000;
res = env->cc_result;
if ((res & 0x80000000L) != 0L) if ((res & 0x80000000L) != 0L)
{ {
@ -379,19 +359,16 @@ void helper_evaluate_flags_mcp(void)
flags |= R_FLAG; flags |= R_FLAG;
} }
evaluate_flags_writeback(flags); return evaluate_flags_writeback(flags, ccs);
} }
void helper_evaluate_flags_alu_4(void) uint32_t helper_evaluate_flags_alu_4(uint32_t ccs,
uint32_t src, uint32_t dst, uint32_t res)
{ {
uint32_t src;
uint32_t dst;
uint32_t res;
uint32_t flags = 0; uint32_t flags = 0;
src = env->cc_src & 0x80000000; src = src & 0x80000000;
dst = env->cc_dest & 0x80000000; dst = dst & 0x80000000;
res = env->cc_result;
if ((res & 0x80000000L) != 0L) if ((res & 0x80000000L) != 0L)
{ {
@ -411,19 +388,16 @@ void helper_evaluate_flags_alu_4(void)
flags |= C_FLAG; flags |= C_FLAG;
} }
evaluate_flags_writeback(flags); return evaluate_flags_writeback(flags, ccs);
} }
void helper_evaluate_flags_sub_4(void) uint32_t helper_evaluate_flags_sub_4(uint32_t ccs,
uint32_t src, uint32_t dst, uint32_t res)
{ {
uint32_t src;
uint32_t dst;
uint32_t res;
uint32_t flags = 0; uint32_t flags = 0;
src = (~env->cc_src) & 0x80000000; src = (~src) & 0x80000000;
dst = env->cc_dest & 0x80000000; dst = dst & 0x80000000;
res = env->cc_result;
if ((res & 0x80000000L) != 0L) if ((res & 0x80000000L) != 0L)
{ {
@ -444,47 +418,37 @@ void helper_evaluate_flags_sub_4(void)
} }
flags ^= C_FLAG; flags ^= C_FLAG;
evaluate_flags_writeback(flags); return evaluate_flags_writeback(flags, ccs);
} }
void helper_evaluate_flags_move_4 (void) uint32_t helper_evaluate_flags_move_4(uint32_t ccs, uint32_t res)
{ {
uint32_t res;
uint32_t flags = 0; uint32_t flags = 0;
res = env->cc_result;
if ((int32_t)res < 0) if ((int32_t)res < 0)
flags |= N_FLAG; flags |= N_FLAG;
else if (res == 0L) else if (res == 0L)
flags |= Z_FLAG; flags |= Z_FLAG;
evaluate_flags_writeback(flags); return evaluate_flags_writeback(flags, ccs);
} }
void helper_evaluate_flags_move_2 (void) uint32_t helper_evaluate_flags_move_2(uint32_t ccs, uint32_t res)
{ {
uint32_t src;
uint32_t flags = 0; uint32_t flags = 0;
uint16_t res;
src = env->cc_src;
res = env->cc_result;
if ((int16_t)res < 0L) if ((int16_t)res < 0L)
flags |= N_FLAG; flags |= N_FLAG;
else if (res == 0) else if (res == 0)
flags |= Z_FLAG; flags |= Z_FLAG;
evaluate_flags_writeback(flags); return evaluate_flags_writeback(flags, ccs);
} }
/* TODO: This is expensive. We could split things up and only evaluate part of /* TODO: This is expensive. We could split things up and only evaluate part of
CCR on a need to know basis. For now, we simply re-evaluate everything. */ CCR on a need to know basis. For now, we simply re-evaluate everything. */
void helper_evaluate_flags (void) void helper_evaluate_flags(void)
{ {
uint32_t src; uint32_t src, dst, res;
uint32_t dst;
uint32_t res;
uint32_t flags = 0; uint32_t flags = 0;
src = env->cc_src; src = env->cc_src;
@ -595,11 +559,10 @@ void helper_evaluate_flags (void)
break; break;
} }
if (env->cc_op == CC_OP_SUB if (env->cc_op == CC_OP_SUB || env->cc_op == CC_OP_CMP)
|| env->cc_op == CC_OP_CMP) {
flags ^= C_FLAG; flags ^= C_FLAG;
}
evaluate_flags_writeback(flags); env->pregs[PR_CCS] = evaluate_flags_writeback(flags, env->pregs[PR_CCS]);
} }
void helper_top_evaluate_flags(void) void helper_top_evaluate_flags(void)
@ -607,13 +570,19 @@ void helper_top_evaluate_flags(void)
switch (env->cc_op) switch (env->cc_op)
{ {
case CC_OP_MCP: case CC_OP_MCP:
helper_evaluate_flags_mcp(); env->pregs[PR_CCS] = helper_evaluate_flags_mcp(
env->pregs[PR_CCS], env->cc_src,
env->cc_dest, env->cc_result);
break; break;
case CC_OP_MULS: case CC_OP_MULS:
helper_evaluate_flags_muls(); env->pregs[PR_CCS] = helper_evaluate_flags_muls(
env->pregs[PR_CCS], env->cc_result,
env->pregs[PR_MOF]);
break; break;
case CC_OP_MULU: case CC_OP_MULU:
helper_evaluate_flags_mulu(); env->pregs[PR_CCS] = helper_evaluate_flags_mulu(
env->pregs[PR_CCS], env->cc_result,
env->pregs[PR_MOF]);
break; break;
case CC_OP_MOVE: case CC_OP_MOVE:
case CC_OP_AND: case CC_OP_AND:
@ -622,26 +591,36 @@ void helper_top_evaluate_flags(void)
case CC_OP_ASR: case CC_OP_ASR:
case CC_OP_LSR: case CC_OP_LSR:
case CC_OP_LSL: case CC_OP_LSL:
switch (env->cc_size) switch (env->cc_size)
{ {
case 4: case 4:
helper_evaluate_flags_move_4(); env->pregs[PR_CCS] =
break; helper_evaluate_flags_move_4(
case 2: env->pregs[PR_CCS],
helper_evaluate_flags_move_2(); env->cc_result);
break; break;
default: case 2:
helper_evaluate_flags(); env->pregs[PR_CCS] =
break; helper_evaluate_flags_move_2(
} env->pregs[PR_CCS],
break; env->cc_result);
break;
default:
helper_evaluate_flags();
break;
}
break;
case CC_OP_FLAGS: case CC_OP_FLAGS:
/* live. */ /* live. */
break; break;
case CC_OP_SUB: case CC_OP_SUB:
case CC_OP_CMP: case CC_OP_CMP:
if (env->cc_size == 4) if (env->cc_size == 4)
helper_evaluate_flags_sub_4(); env->pregs[PR_CCS] =
helper_evaluate_flags_sub_4(
env->pregs[PR_CCS],
env->cc_src, env->cc_dest,
env->cc_result);
else else
helper_evaluate_flags(); helper_evaluate_flags();
break; break;
@ -649,12 +628,16 @@ void helper_top_evaluate_flags(void)
{ {
switch (env->cc_size) switch (env->cc_size)
{ {
case 4: case 4:
helper_evaluate_flags_alu_4(); env->pregs[PR_CCS] =
break; helper_evaluate_flags_alu_4(
default: env->pregs[PR_CCS],
helper_evaluate_flags(); env->cc_src, env->cc_dest,
break; env->cc_result);
break;
default:
helper_evaluate_flags();
break;
} }
} }
break; break;

View File

@ -565,74 +565,85 @@ static void cris_flush_cc_state(DisasContext *dc)
static void cris_evaluate_flags(DisasContext *dc) static void cris_evaluate_flags(DisasContext *dc)
{ {
if (!dc->flags_uptodate) { if (dc->flags_uptodate)
cris_flush_cc_state(dc); return;
switch (dc->cc_op) cris_flush_cc_state(dc);
switch (dc->cc_op)
{
case CC_OP_MCP:
gen_helper_evaluate_flags_mcp(cpu_PR[PR_CCS],
cpu_PR[PR_CCS], cc_src,
cc_dest, cc_result);
break;
case CC_OP_MULS:
gen_helper_evaluate_flags_muls(cpu_PR[PR_CCS],
cpu_PR[PR_CCS], cc_result,
cpu_PR[PR_MOF]);
break;
case CC_OP_MULU:
gen_helper_evaluate_flags_mulu(cpu_PR[PR_CCS],
cpu_PR[PR_CCS], cc_result,
cpu_PR[PR_MOF]);
break;
case CC_OP_MOVE:
case CC_OP_AND:
case CC_OP_OR:
case CC_OP_XOR:
case CC_OP_ASR:
case CC_OP_LSR:
case CC_OP_LSL:
switch (dc->cc_size)
{ {
case CC_OP_MCP: case 4:
gen_helper_evaluate_flags_mcp(); gen_helper_evaluate_flags_move_4(cpu_PR[PR_CCS],
break; cpu_PR[PR_CCS], cc_result);
case CC_OP_MULS: break;
gen_helper_evaluate_flags_muls(); case 2:
break; gen_helper_evaluate_flags_move_2(cpu_PR[PR_CCS],
case CC_OP_MULU: cpu_PR[PR_CCS], cc_result);
gen_helper_evaluate_flags_mulu(); break;
break; default:
case CC_OP_MOVE: gen_helper_evaluate_flags();
case CC_OP_AND:
case CC_OP_OR:
case CC_OP_XOR:
case CC_OP_ASR:
case CC_OP_LSR:
case CC_OP_LSL:
switch (dc->cc_size)
{
case 4:
gen_helper_evaluate_flags_move_4();
break;
case 2:
gen_helper_evaluate_flags_move_2();
break;
default:
gen_helper_evaluate_flags();
break;
}
break;
case CC_OP_FLAGS:
/* live. */
break;
case CC_OP_SUB:
case CC_OP_CMP:
if (dc->cc_size == 4)
gen_helper_evaluate_flags_sub_4();
else
gen_helper_evaluate_flags();
break;
default:
switch (dc->cc_size)
{
case 4:
gen_helper_evaluate_flags_alu_4();
break;
default:
gen_helper_evaluate_flags();
break;
}
break; break;
} }
if (dc->flagx_known) { break;
if (dc->flags_x) case CC_OP_FLAGS:
tcg_gen_ori_tl(cpu_PR[PR_CCS], /* live. */
cpu_PR[PR_CCS], X_FLAG); break;
else case CC_OP_SUB:
tcg_gen_andi_tl(cpu_PR[PR_CCS], case CC_OP_CMP:
cpu_PR[PR_CCS], ~X_FLAG); if (dc->cc_size == 4)
} gen_helper_evaluate_flags_sub_4(cpu_PR[PR_CCS],
cpu_PR[PR_CCS], cc_src, cc_dest, cc_result);
else
gen_helper_evaluate_flags();
dc->flags_uptodate = 1; break;
default:
switch (dc->cc_size)
{
case 4:
gen_helper_evaluate_flags_alu_4(cpu_PR[PR_CCS],
cpu_PR[PR_CCS], cc_src, cc_dest, cc_result);
break;
default:
gen_helper_evaluate_flags();
break;
}
break;
} }
if (dc->flagx_known) {
if (dc->flags_x)
tcg_gen_ori_tl(cpu_PR[PR_CCS],
cpu_PR[PR_CCS], X_FLAG);
else
tcg_gen_andi_tl(cpu_PR[PR_CCS],
cpu_PR[PR_CCS], ~X_FLAG);
}
dc->flags_uptodate = 1;
} }
static void cris_cc_mask(DisasContext *dc, unsigned int mask) static void cris_cc_mask(DisasContext *dc, unsigned int mask)