def ixor_op(config: Configuration) -> None: """ Common logic function for the integer XOR opcodes """ b, a = config.pop2_u64() if config.enable_logic_fn_logging: logger.debug("%s(%s, %s)", config.current_instruction.opcode.text, a, b) config.push_operand(a ^ b)
def iXX_mul_op(config: Configuration) -> None: """ Common logic function for the integer MUL opcodes """ b, a = config.pop2_u64() if config.enable_logic_fn_logging: logger.debug("%s(%s, %s)", config.current_instruction.opcode.text, a, b) with allow_overflow(): config.push_operand(a * b)
def iXX_shl_op(config: Configuration) -> None: """ Common logic function for the integer SHL opcodes """ instruction = cast(BinOp, config.current_instruction) b, a = config.pop2_u64() if config.enable_logic_fn_logging: logger.debug("%s(%s, %s)", instruction.opcode.text, a, b) shift_amount = int(b % instruction.valtype.bit_size.value) raw_result = int(a) << shift_amount mod = instruction.valtype.mod config.push_operand(instruction.valtype.value(raw_result % mod))
def iremu_op(config: Configuration) -> None: """ Common logic function for the integer REMU opcodes """ b, a = config.pop2_u64() if config.enable_logic_fn_logging: logger.debug("%s(%s, %s)", config.current_instruction.opcode.text, a, b) if b == 0: raise Trap('DIVISION BY ZERO') config.push_operand(a % b)
def iXX_ges_op(config: Configuration) -> None: """ Common logic function for the integer GES opcodes """ instruction = cast(RelOp, config.current_instruction) b, a = config.pop2_u64() b_s = instruction.valtype.to_signed(b) a_s = instruction.valtype.to_signed(a) if config.enable_logic_fn_logging: logger.debug("%s(%s, %s)", instruction.opcode.text, a_s, b_s) if a_s >= b_s: config.push_operand(constants.U32_ONE) else: config.push_operand(constants.U32_ZERO)
def iXX_rotr_op(config: Configuration) -> None: """ Common logic function for the integer ROTR opcodes """ instruction = cast(BinOp, config.current_instruction) b, a = config.pop2_u64() if config.enable_logic_fn_logging: logger.debug("%s(%s, %s)", instruction.opcode.text, a, b) bit_size = instruction.valtype.bit_size.value shift_size = int(b % bit_size) lower = int(a) >> shift_size upper = int(a) << int(bit_size - shift_size) result = (upper | lower) % instruction.valtype.mod config.push_operand(instruction.valtype.value(result))
def iXX_rems_op(config: Configuration) -> None: """ Common logic function for the integer REMS opcodes """ instruction = cast(BinOp, config.current_instruction) b, a = config.pop2_u64() if config.enable_logic_fn_logging: logger.debug("%s(%s, %s)", instruction.opcode.text, a, b) if b == 0: raise Trap('DIVISION BY ZERO') b_s = instruction.valtype.to_signed(b) a_s = instruction.valtype.to_signed(a) raw_result = numpy.abs(a_s) % numpy.abs(b_s) result = -1 * raw_result if a_s < 0 else raw_result config.push_operand(instruction.valtype.value(result))
def iXX_shr_sXX_op(config: Configuration) -> None: """ Common logic function for the integer SHR opcodes """ instruction = cast(BinOp, config.current_instruction) b, a_raw = config.pop2_u64() if instruction.signed: a = int(instruction.valtype.to_signed(a_raw)) else: a = int(a_raw) if config.enable_logic_fn_logging: logger.debug("%s(%s, %s)", instruction.opcode.text, a, b) shift_amount = int(b % instruction.valtype.bit_size.value) if instruction.signed: result = instruction.valtype.from_signed(a >> shift_amount) else: result = instruction.valtype.value(a >> shift_amount) config.push_operand(result)