Enum Class IntCarryOpGen

java.lang.Object
java.lang.Enum<IntCarryOpGen>
ghidra.pcode.emu.jit.gen.op.IntCarryOpGen
All Implemented Interfaces:
BinOpGen<JitIntCarryOp>, IntPredBinOpGen<JitIntCarryOp>, OpGen<JitIntCarryOp>, Serializable, Comparable<IntCarryOpGen>, Constable

public enum IntCarryOpGen extends Enum<IntCarryOpGen> implements IntPredBinOpGen<JitIntCarryOp>
The generator for a int_carry.

This uses the integer predicate operator generator. First we have to consider which strategy we are going to use. If the p-code type is strictly smaller than its host JVM type, we can simply add the two operands and examine the next bit up. This is accomplished by emitting iadd or ladd, depending on the type, followed by a shift right and a mask.

If the p-code type exactly fits its host JVM type, we still add, but we will need to compare the result to one of the operands. Thus, we emit code to duplicate the left operand. We can then add and invoke Integer.compareUnsigned(int, int) (or similar for longs) to determine whether there was overflow. If there was, then we know the carry bit would have been set. We can spare the conditional flow by just shifting the sign bit into the 1's place.

For multi-precision integers, we invoke the subroutines in IntAddOpGen, but do not store the results, because we only need the carry. When we reach the end, we take advantage of the fact that the final stack result is actually the full 33-bit result for the last leg. We can just shift it the required number of bytes (depending on the type of the input operands) and mask for the desired carry bit.

  • Enum Constant Details

    • GEN

      public static final IntCarryOpGen GEN
      The generator singleton
  • Method Details

    • values

      public static IntCarryOpGen[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static IntCarryOpGen valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • isSigned

      public boolean isSigned()
      Description copied from interface: BinOpGen
      Whether this operator is signed

      In many cases, the operator itself is not affected by the signedness of the operands; however, if size adjustments to the operands are needed, this can determine how those operands are extended.

      Specified by:
      isSigned in interface BinOpGen<JitIntCarryOp>
      Returns:
      true for signed, false if not
    • opForInt

      public <N2 extends Emitter.Next, N1 extends Emitter.Ent<N2, Types.TInt>, N0 extends Emitter.Ent<N1, Types.TInt>> Emitter<Emitter.Ent<N2,Types.TInt>> opForInt(Emitter<N0> em, JitType.IntJitType type)
      Description copied from interface: IntPredBinOpGen
      Emit the JVM bytecode to perform the operator with integer operands on the stack.
      Specified by:
      opForInt in interface IntPredBinOpGen<JitIntCarryOp>
      Type Parameters:
      N2 - the tail of the incoming stack
      N1 - the tail of the incoming stack including the right operand
      N0 - the incoming stack with the right and left operands on top
      Parameters:
      em - the emitter typed with the incoming stack
      type - the p-code type of the operands
      Returns:
      the emitter typed with the resulting stack, i.e., the tail with the result pushed
    • opForLong

      public <N2 extends Emitter.Next, N1 extends Emitter.Ent<N2, Types.TLong>, N0 extends Emitter.Ent<N1, Types.TLong>> Emitter<Emitter.Ent<N2,Types.TInt>> opForLong(Emitter<N0> em, JitType.LongJitType type)
      Description copied from interface: IntPredBinOpGen
      Emit the JVM bytecode to perform the operator with long operands on the stack.
      Specified by:
      opForLong in interface IntPredBinOpGen<JitIntCarryOp>
      Type Parameters:
      N2 - the tail of the incoming stack
      N1 - the tail of the incoming stack including the right operand
      N0 - the incoming stack with the right and left operands on top
      Parameters:
      em - the emitter typed with the incoming stack
      type - the p-code type of the operands
      Returns:
      the emitter typed with the resulting stack, i.e., the tail with the result pushed
    • genRunMpInt

      public <THIS extends JitCompiledPassage> Emitter<Emitter.Ent<Emitter.Bot,Types.TInt>> genRunMpInt(Emitter<Emitter.Bot> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitIntCarryOp op, JitType.MpIntJitType type, Scope scope)
      Description copied from interface: IntPredBinOpGen
      Emit the JVM bytecode to perform the operator with multi-precision operands.
      Specified by:
      genRunMpInt in interface IntPredBinOpGen<JitIntCarryOp>
      Type Parameters:
      THIS - the type of the generated passage
      Parameters:
      em - the emitter typed with the empty stack
      localThis - a handle to the local holding the this reference
      gen - the code generator
      op - the p-code op
      type - the p-code type of the operands
      scope - a scope for generating temporary local storage
      Returns:
      the emitter typed with the resulting stack, i.e., containing only the result