예제 #1
0
파일: numeric.py 프로젝트: metazool/py-wasm
def iXX_trunc_usX_fXX_op(config: Configuration) -> None:
    """
    Common logic function for the TRUNC opcodes which convert a float to an
    integer
    """
    instruction = cast(Truncate, config.current_instruction)

    value = config.pop_f32()

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

    if numpy.isnan(value) or numpy.isinf(value):
        raise Trap(f"Truncation is undefined for {value}")
    else:
        trunc_value = int(numpy.trunc(value))

        if instruction.signed:
            s_lower_bound, s_upper_bound = instruction.valtype.signed_bounds
            if trunc_value < s_lower_bound or trunc_value > s_upper_bound:
                raise Trap(
                    f"Truncation is undefined for {value}. Result outside of s32 "
                    "range.")

            result = instruction.valtype.from_signed(
                instruction.valtype.signed_type(trunc_value))
        else:
            u_lower_bound, u_upper_bound = instruction.valtype.bounds
            if trunc_value < u_lower_bound or trunc_value > u_upper_bound:
                raise Trap(
                    f"Truncation is undefined for {value}. Result outside of s32 "
                    "range.")
            result = instruction.valtype.value(trunc_value)

        config.push_operand(result)
예제 #2
0
파일: numeric.py 프로젝트: metazool/py-wasm
def XXX_reinterpret_XXX_op(config: Configuration) -> None:
    """
    Common logic function for the REINTERPRET opcodes
    """
    instruction = cast(Convert, config.current_instruction)

    value = config.pop_f32()

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

    config.push_operand(
        numpy.frombuffer(value.data, instruction.valtype.value)[0])
예제 #3
0
파일: numeric.py 프로젝트: metazool/py-wasm
def f64promote_op(config: Configuration) -> None:
    """
    Logic function for the F64_PROMOTE_F32 opcode
    """
    value = config.pop_f32()

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

    if numpy.isnan(value):
        if _is_negative(value):
            config.push_operand(numpy.float64('-nan'))
        else:
            config.push_operand(numpy.float64('nan'))
    else:
        config.push_operand(numpy.float64(value))