views:

105

answers:

0

After working with the ARM instruction set for a bit after heavy X86 work in the past, I'm pondering something for the CIL AOT/JIT compiler I'm working on. My intermediate representation is a fixed-width expansion of the CIL byte code with a couple extra opcodes. Here's an example of a situation that arises in the JIT, and two possible solutions:

Under regular CIL instructions, the add.ovf instruction can be rewritten, allowing the native code generators to be complete without implementing the add.ovf instruction semantics internally. (Assume the top two values on the evaluation stack are int32.)

ldc.i4 0x7FFFFFFF // int.MaxValue
dup 2 // In my intermediate representation, the 'dup' instruction takes the
      // evaluation stack index as an operand. 'dup 0' is the 'dup' instruction
      // as documented in ECMA-335.
sub
dup 1
blt.s +2 // jumps to the 'add' statement - my intermediate representation uses
         // instruction index offsets instead of byte offsets
newobj System.OverflowException::.ctor()
throw
add

However, if I annotate my intermediate representation by adding a condition field alongside the opcodes and their operands, I could do the following:

add
newobj[Overflow] System.OverflowException::.ctor()
throw[Overflow]

I like this representation because it leaves the optimization flexibility in the hands of the native code generator without burdening it with complicated object model semantics - the necessary conditions are readily available in native code. The native code generators for each target are then responsible for honoring the condition field for each instruction. The ARM uses the condition field on each instruction, and the X86 generates (in this case) a JNO instruction before the code it generates for newobj and throw.

My question: The condition codes from the ARM appear to be well-supported across widely varying architectures. As such, I'm thinking about using them directly. Are there other platforms that use condition codes with different meanings that are a super-set of or disjoint from the following conditions?

The condition bits are:

  • Z = Zero
  • C = Carry
  • N = Negative
  • V = Overflow

The conditions are:

  • Always (unconditional, the default)
  • Equal (Z set)
  • NotEqual (Z clear)
  • UnsignedGreaterThanOrEqual (C set)
    • CarrySet is an alias
  • UnsignedLessThan (C clear)
    • CarryClear is an alias
  • Negative (N set)
  • NonNegative (N clear)
  • Overflow (V set)
  • NoOverflow (V clear)
  • UnsignedHigher (C set and Z clear)
  • UnsignedLessThanOrEqual (C clear or Z set)
  • SignedGreaterThanOrEqual (N==V)
  • SignedLessThan (N!=V)
  • SignedGreaterThan (Z clear and N==V)
  • SignedLessThanOrEqual (Z set or N!=V)