@Nonnull private BuilderInstruction31i newBuilderInstruction31i(@Nonnull Instruction31i instruction) { return new BuilderInstruction31i( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
public static BuilderInstruction buildConstant(int value, int register) { BuilderInstruction result; int bitCount = value == 0 ? 1 : 1 + Integer.numberOfTrailingZeros(Integer.highestOneBit(value)); if (bitCount < 4 && (register & 0xFFFFFFF0) == 0) { result = new BuilderInstruction11n(Opcode.CONST_4, register, value); } else if (bitCount < 16 && (register & 0xFFFFFF00) == 0) { result = new BuilderInstruction21s(Opcode.CONST_16, register, value); } else { result = new BuilderInstruction31i(Opcode.CONST, register, value); } return result; }
public static BuilderInstruction buildConstant(long value, int register) { BuilderInstruction result; int bitCount = Long.SIZE - Long.numberOfLeadingZeros(value); if (bitCount < 16 && (register & 0xFFFFFF00) == 0) { result = new BuilderInstruction21s(Opcode.CONST_WIDE_16, register, (int) value); } else if (bitCount < 32 && (register & 0xFFFFFF00) == 0) { result = new BuilderInstruction31i(Opcode.CONST_WIDE_32, register, (int) value); } else { result = new BuilderInstruction51l(Opcode.CONST_WIDE, register, value); } return result; }
public static BuilderInstruction buildConstant(float value, int register) { if (value % 1 == 0) { // No decimal portion if (value <= Integer.MAX_VALUE) { return buildConstant(((Float) value).intValue(), register); } } int intBits = Float.floatToIntBits(value); String binaryValue = Integer.toBinaryString(intBits); BuilderInstruction constant; if (binaryValue.endsWith(LAST_16_BITS_ZERO)) { constant = new BuilderInstruction21ih(Opcode.CONST_HIGH16, register, intBits); } else { constant = new BuilderInstruction31i(Opcode.CONST, register, intBits); } return constant; }
@Override protected BuilderInstruction getRealInsn0(LabelAssigner assigner) { return new BuilderInstruction31i(opc, (short) getRegA().getNumber(), getLitB()); }
@Test public void withLast16BitsNotZero() { float value = 127.01F; int intBits = Float.floatToIntBits(value); Instruction expected = new BuilderInstruction31i(Opcode.CONST, REGISTER, intBits); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
@Test public void with31BitLiteral() { long value = (long) (Math.pow(2, 31) - 1); Instruction expected = new BuilderInstruction31i(Opcode.CONST_WIDE_32, REGISTER, (int) value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
@Test public void withMinValue() { int value = Integer.MIN_VALUE; Instruction expected = new BuilderInstruction31i(Opcode.CONST, REGISTER, value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); } }
@Test public void with31BitLiteral() { int value = Integer.MAX_VALUE; Instruction expected = new BuilderInstruction31i(Opcode.CONST, REGISTER, value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
@Test public void with16BitLiteral() { int value = 50000; Instruction expected = new BuilderInstruction31i(Opcode.CONST, REGISTER, value); Instruction actual = ConstantBuilder.buildConstant(value, REGISTER); testEquals(expected, actual); }
method_stack.peek().methodBuilder.addInstruction(new BuilderInstruction31i(opcode, regA, litB));
@Nonnull private BuilderInstruction31i newBuilderInstruction31i(@Nonnull Instruction31i instruction) { return new BuilderInstruction31i( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
@Nonnull private BuilderInstruction31i newBuilderInstruction31i(@Nonnull Instruction31i instruction) { return new BuilderInstruction31i( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
@Nonnull private BuilderInstruction31i newBuilderInstruction31i(@Nonnull Instruction31i instruction) { return new BuilderInstruction31i( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
@Nonnull private BuilderInstruction31i newBuilderInstruction31i(@Nonnull Instruction31i instruction) { return new BuilderInstruction31i( instruction.getOpcode(), instruction.getRegisterA(), instruction.getNarrowLiteral()); }
method_stack.peek().methodBuilder.addInstruction(new BuilderInstruction31i(opcode, regA, litB));
method_stack.peek().methodBuilder.addInstruction(new BuilderInstruction31i(opcode, regA, litB));