diff options
author | Edgar E. Iglesias <edgar.iglesias@gmail.com> | 2011-01-22 12:39:16 +0100 |
---|---|---|
committer | Edgar E. Iglesias <edgar.iglesias@gmail.com> | 2011-01-22 12:39:16 +0100 |
commit | e0a42ebc0831e3ae18e965cc202b5d6649cc38f2 (patch) | |
tree | 1b2158cd5d44b15e573794edfc47a8d2e9e70986 /target-microblaze/translate.c | |
parent | 7e9e4330080f40a964cfed2b334b5e231e967792 (diff) |
microblaze: Improve subkc
Move code from the helper into the translator. The remaining
helper parts can reuse helper_addkc, making it possible to
remove helper_subkc entirely.
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Diffstat (limited to 'target-microblaze/translate.c')
-rw-r--r-- | target-microblaze/translate.c | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c index 264395b74c..0c5edc3583 100644 --- a/target-microblaze/translate.c +++ b/target-microblaze/translate.c @@ -247,6 +247,7 @@ static void dec_add(DisasContext *dc) static void dec_sub(DisasContext *dc) { unsigned int u, cmp, k, c; + TCGv cf, na; u = dc->imm & 2; k = dc->opcode & 4; @@ -261,24 +262,57 @@ static void dec_sub(DisasContext *dc) else gen_helper_cmp(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); } - } else { - LOG_DIS("sub%s%s r%d, r%d r%d\n", - k ? "k" : "", c ? "c" : "", dc->rd, dc->ra, dc->rb); + return; + } - if (!k || c) { - TCGv t; - t = tcg_temp_new(); - if (dc->rd) - gen_helper_subkc(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)), - tcg_const_tl(k), tcg_const_tl(c)); - else - gen_helper_subkc(t, cpu_R[dc->ra], *(dec_alu_op_b(dc)), - tcg_const_tl(k), tcg_const_tl(c)); - tcg_temp_free(t); - } - else if (dc->rd) + LOG_DIS("sub%s%s r%d, r%d r%d\n", + k ? "k" : "", c ? "c" : "", dc->rd, dc->ra, dc->rb); + + /* Take care of the easy cases first. */ + if (k) { + /* k - keep carry, no need to update MSR. */ + /* If rd == r0, it's a nop. */ + if (dc->rd) { tcg_gen_sub_tl(cpu_R[dc->rd], *(dec_alu_op_b(dc)), cpu_R[dc->ra]); + + if (c) { + /* c - Add carry into the result. */ + cf = tcg_temp_new(); + + read_carry(dc, cf); + tcg_gen_add_tl(cpu_R[dc->rd], cpu_R[dc->rd], cf); + tcg_temp_free(cf); + } + } + return; + } + + /* From now on, we can assume k is zero. So we need to update MSR. */ + /* Extract carry. And complement a into na. */ + cf = tcg_temp_new(); + na = tcg_temp_new(); + if (c) { + read_carry(dc, cf); + } else { + tcg_gen_movi_tl(cf, 1); + } + + /* d = b + ~a + c. carry defaults to 1. */ + tcg_gen_not_tl(na, cpu_R[dc->ra]); + + if (dc->rd) { + TCGv ncf = tcg_temp_new(); + gen_helper_addkc(ncf, na, *(dec_alu_op_b(dc)), cf); + tcg_gen_add_tl(cpu_R[dc->rd], na, *(dec_alu_op_b(dc))); + tcg_gen_add_tl(cpu_R[dc->rd], cpu_R[dc->rd], cf); + write_carry(dc, ncf); + tcg_temp_free(ncf); + } else { + gen_helper_addkc(cf, na, *(dec_alu_op_b(dc)), cf); + write_carry(dc, cf); } + tcg_temp_free(cf); + tcg_temp_free(na); } static void dec_pattern(DisasContext *dc) |