There's no particular reason why R_PC needs to be 64; if you change it
to 32, you can simplify this.
I believe this is in fact needed, see [1] page 18 (section 2, Register
file), quote:
"
The Nios II architecture supports a flat register file, consisting of
thirty-two 32-bit general-purpose integer
registers, and up to thirty-two 32-bit control registers. The
architecture supports supervisor and user
modes that allow system code to protect the control registers from
errant applications.
"
So the CPU supports 32 general purpose regs (R_ZERO..R_RA), then up-to
32 Control registers (CR_STATUS..CR_MPUACC) and then the PC .
Since divide-by-zero is undefined, this can be done with
TCGv t0 = tcg_const_tl(0);
tcg_gen_setcond_tl(TCG_COND_EQ, t0, dc->cpu_R[instr->b], t0);
tcg_gen_or_tl(t0, t0, dc->cpu_R[instr->b]);
tcg_gen_divu_tl(dc->cpu_R[instr->c], dc->cpu_R[instr->a], t0);
tcg_temp_free_tl(t0);
Just so I get it completely, isn't this handled somehow by the
tcg_gen_divu_tl() itself ?