예제 #1
0
파일: numeric.py 프로젝트: metazool/py-wasm
def iwrap64_op(config: Configuration) -> None:
    """
    Logic function for the I32_WRAP_I64 opcode
    """
    value = config.pop_u64()

    if config.enable_logic_fn_logging:
        logger.debug("%s(%s)", config.current_instruction.opcode.text, value)

    config.push_operand(numpy.uint32(value))
예제 #2
0
파일: numeric.py 프로젝트: metazool/py-wasm
def iXX_clz_op(config: Configuration) -> None:
    """
    Common logic function for the integer CLZ opcodes
    """
    instruction = cast(TestOp, config.current_instruction)
    value = config.pop_u64()
    if config.enable_logic_fn_logging:
        logger.debug("%s(%s)", instruction.opcode.text, value)

    bit_size = instruction.valtype.bit_size.value
    if value == 0:
        config.push_operand(instruction.valtype.value(bit_size))
    else:
        config.push_operand(
            instruction.valtype.value(bit_size - int(value).bit_length()))
예제 #3
0
파일: numeric.py 프로젝트: metazool/py-wasm
def iXX_ctz_op(config: Configuration) -> None:
    """
    Common logic function for the integer CTZ opcodes
    """
    instruction = cast(TestOp, config.current_instruction)
    value = config.pop_u64()
    if config.enable_logic_fn_logging:
        logger.debug("%s(%s)", instruction.opcode.text, value)

    if value == 0:
        config.push_operand(
            instruction.valtype.value(instruction.valtype.bit_size.value))
    else:
        as_bin = bin(int(value))
        _, _, zeros = as_bin.rpartition('1')
        config.push_operand(instruction.valtype.value(len(zeros)))
예제 #4
0
파일: numeric.py 프로젝트: metazool/py-wasm
def fXX_convert_usX_iXX_op(config: Configuration) -> None:
    """
    Common logic function for the CONVERT opcodes
    """
    instruction = cast(Convert, config.current_instruction)

    base_value = config.pop_u64()

    if instruction.signed:
        value = instruction.from_valtype.to_signed(base_value)
    else:
        value = base_value

    if config.enable_logic_fn_logging:
        logger.debug("%s(%s)", instruction.opcode.text, value)

    config.push_operand(instruction.valtype.to_float(value))