[Mono-dev] Arm overflow arithmetic

Rodrigo Kumpera kumpera at gmail.com
Fri Aug 8 18:25:43 EDT 2008


Hey guys,

I just got myself into a roadblock today while fixing overflow arithmetic
under ARM. The issue is that the emitted IR
cannot be properly translated to native code.

The ARM ISA has the oddity that carry/borrow works in the opposite way. Add
with carry do a +1 if the carry bit is set,
but Sub with borrow do a -1 if the carry bit is not set.

Then we have mono_decompose_opcode that use the same condition for both add
and sub:

    case OP_IADD_OVF:
        ins->opcode = OP_IADDCC;
        MONO_EMIT_NEW_COND_EXC (cfg, IOV, "OverflowException");
        break;
    case OP_ISUB_OVF:
        ins->opcode = OP_ISUBCC;
        MONO_EMIT_NEW_COND_EXC (cfg, IOV, "OverflowException");
        break;


I cannot fix that in the arm back-end as it should not reason about previous
instructions.
My idea is to either move the SUB opcodes to arch specific code or add an
#if MONO_ARCH_SUB_INVERTED_CARRY_FLAG.

What do you guys think about this?

Cheers,
Rodrigo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080808/7ccccd14/attachment.html 


More information about the Mono-devel-list mailing list