NumericInstruction

Enum NumericInstruction 

Source
pub enum NumericInstruction {
Show 53 variants I32Constant(i32), I64Constant(i64), F32Constant(f32), F64Constant(f64), CountLeadingZeros(IntegerType), CountTrailingZeros(IntegerType), CountOnes(IntegerType), AbsoluteValue(FloatType), Negate(FloatType), SquareRoot(FloatType), Ceiling(FloatType), Floor(FloatType), Truncate(FloatType), Nearest(FloatType), Add(NumberType), Subtract(NumberType), Multiply(NumberType), DivideInteger(IntegerType, SignExtension), DivideFloat(FloatType), Remainder(IntegerType, SignExtension), And(IntegerType), Or(IntegerType), Xor(IntegerType), ShiftLeft(IntegerType), ShiftRight(IntegerType, SignExtension), RotateLeft(IntegerType), RotateRight(IntegerType), Minimum(FloatType), Maximum(FloatType), CopySign(FloatType), EqualToZero(IntegerType), Equal(NumberType), NotEqual(NumberType), LessThanInteger(IntegerType, SignExtension), LessThanFloat(FloatType), GreaterThanInteger(IntegerType, SignExtension), GreaterThanFloat(FloatType), LessThanOrEqualToInteger(IntegerType, SignExtension), LessThanOrEqualToFloat(FloatType), GreaterThanOrEqualToInteger(IntegerType, SignExtension), GreaterThanOrEqualToFloat(FloatType), ExtendSigned8(IntegerType), ExtendSigned16(IntegerType), ExtendSigned32, Wrap, ExtendWithSignExtension(SignExtension), ConvertAndTruncate(IntegerType, FloatType, SignExtension), ConvertAndTruncateWithSaturation(IntegerType, FloatType, SignExtension), Demote, Promote, Convert(FloatType, IntegerType, SignExtension), ReinterpretFloat(IntegerType), ReinterpretInteger(FloatType),
}
Expand description

Numeric instructions provide basic operations over numeric values of specific type. These operations closely match respective operations available in hardware.

Some integer instructions come in two flavors, where a signedness annotation sx distinguishes whether the operands are to be interpreted as unsigned or signed integers. For the other integer instructions, the use of two’s complement for the signed interpretation means that they behave the same regardless of signedness.

See https://webassembly.github.io/spec/core/syntax/instructions.html#numeric-instructions

§Examples

§Constant

use wasm_ast::{NumericInstruction, Instruction};

assert_eq!(
    Instruction::Numeric(NumericInstruction::I32Constant(42)),
    42i32.into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::I64Constant(42i64)),
    42i64.into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::F32Constant(0.1)),
    0.1f32.into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::F64Constant(0.2)),
    0.2f64.into()
);

§Integer

use wasm_ast::{NumericInstruction, Instruction, IntegerType, SignExtension};

assert_eq!(
    Instruction::Numeric(NumericInstruction::CountLeadingZeros(IntegerType::I32)),
    NumericInstruction::CountLeadingZeros(IntegerType::I32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::CountTrailingZeros(IntegerType::I64)),
    NumericInstruction::CountTrailingZeros(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::CountOnes(IntegerType::I64)),
    NumericInstruction::CountOnes(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::DivideInteger(IntegerType::I64, SignExtension::Unsigned)),
    NumericInstruction::DivideInteger(IntegerType::I64, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Remainder(IntegerType::I64, SignExtension::Unsigned)),
    NumericInstruction::Remainder(IntegerType::I64, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::And(IntegerType::I64)),
    NumericInstruction::And(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Or(IntegerType::I64)),
    NumericInstruction::Or(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Xor(IntegerType::I64)),
    NumericInstruction::Xor(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ShiftLeft(IntegerType::I64)),
    NumericInstruction::ShiftLeft(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ShiftRight(IntegerType::I64, SignExtension::Unsigned)),
    NumericInstruction::ShiftRight(IntegerType::I64, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::RotateLeft(IntegerType::I64)),
    NumericInstruction::RotateLeft(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::RotateRight(IntegerType::I64)),
    NumericInstruction::RotateRight(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::EqualToZero(IntegerType::I64)),
    NumericInstruction::EqualToZero(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::LessThanInteger(IntegerType::I64, SignExtension::Unsigned)),
    NumericInstruction::LessThanInteger(IntegerType::I64, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::GreaterThanInteger(IntegerType::I64, SignExtension::Unsigned)),
    NumericInstruction::GreaterThanInteger(IntegerType::I64, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::LessThanOrEqualToInteger(IntegerType::I64, SignExtension::Unsigned)),
    NumericInstruction::LessThanOrEqualToInteger(IntegerType::I64, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::GreaterThanOrEqualToInteger(IntegerType::I64, SignExtension::Unsigned)),
    NumericInstruction::GreaterThanOrEqualToInteger(IntegerType::I64, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ExtendSigned8(IntegerType::I64)),
    NumericInstruction::ExtendSigned8(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ExtendSigned16(IntegerType::I64)),
    NumericInstruction::ExtendSigned16(IntegerType::I64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ExtendSigned32),
    NumericInstruction::ExtendSigned32.into()
);

§Float

use wasm_ast::{NumericInstruction, Instruction, FloatType};

assert_eq!(
    Instruction::Numeric(NumericInstruction::AbsoluteValue(FloatType::F32)),
    NumericInstruction::AbsoluteValue(FloatType::F32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Negate(FloatType::F64)),
    NumericInstruction::Negate(FloatType::F64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::SquareRoot(FloatType::F64)),
    NumericInstruction::SquareRoot(FloatType::F64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Ceiling(FloatType::F32)),
    NumericInstruction::Ceiling(FloatType::F32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Floor(FloatType::F64)),
    NumericInstruction::Floor(FloatType::F64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Truncate(FloatType::F64)),
    NumericInstruction::Truncate(FloatType::F64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Nearest(FloatType::F64)),
    NumericInstruction::Nearest(FloatType::F64).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::DivideFloat(FloatType::F32)),
    NumericInstruction::DivideFloat(FloatType::F32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Minimum(FloatType::F32)),
    NumericInstruction::Minimum(FloatType::F32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Maximum(FloatType::F32)),
    NumericInstruction::Maximum(FloatType::F32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::CopySign(FloatType::F32)),
    NumericInstruction::CopySign(FloatType::F32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::LessThanFloat(FloatType::F32)),
    NumericInstruction::LessThanFloat(FloatType::F32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::GreaterThanFloat(FloatType::F32)),
    NumericInstruction::GreaterThanFloat(FloatType::F32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::LessThanOrEqualToFloat(FloatType::F32)),
    NumericInstruction::LessThanOrEqualToFloat(FloatType::F32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::GreaterThanOrEqualToFloat(FloatType::F32)),
    NumericInstruction::GreaterThanOrEqualToFloat(FloatType::F32).into()
);

§Number

use wasm_ast::{NumericInstruction, Instruction, NumberType};

assert_eq!(
    Instruction::Numeric(NumericInstruction::Add(NumberType::I32)),
    NumericInstruction::Add(NumberType::I32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Subtract(NumberType::I32)),
    NumericInstruction::Subtract(NumberType::I32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Multiply(NumberType::I32)),
    NumericInstruction::Multiply(NumberType::I32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Equal(NumberType::I32)),
    NumericInstruction::Equal(NumberType::I32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::NotEqual(NumberType::I32)),
    NumericInstruction::NotEqual(NumberType::I32).into()
);

§Convert

use wasm_ast::{NumericInstruction, Instruction, NumberType, SignExtension, IntegerType, FloatType};

assert_eq!(
    Instruction::Numeric(NumericInstruction::Wrap),
    NumericInstruction::Wrap.into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ExtendWithSignExtension(SignExtension::Signed)),
    NumericInstruction::ExtendWithSignExtension(SignExtension::Signed).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ConvertAndTruncate(IntegerType::I32, FloatType::F64, SignExtension::Unsigned)),
    NumericInstruction::ConvertAndTruncate(IntegerType::I32, FloatType::F64, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ConvertAndTruncateWithSaturation(IntegerType::I32, FloatType::F64, SignExtension::Unsigned)),
    NumericInstruction::ConvertAndTruncateWithSaturation(IntegerType::I32, FloatType::F64, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Demote),
    NumericInstruction::Demote.into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Promote),
    NumericInstruction::Promote.into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::Convert(FloatType::F64, IntegerType::I32, SignExtension::Unsigned)),
    NumericInstruction::Convert(FloatType::F64, IntegerType::I32, SignExtension::Unsigned).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ReinterpretFloat(IntegerType::I32)),
    NumericInstruction::ReinterpretFloat(IntegerType::I32).into()
);
assert_eq!(
    Instruction::Numeric(NumericInstruction::ReinterpretInteger(FloatType::F64)),
    NumericInstruction::ReinterpretInteger(FloatType::F64).into()
);

Variants§

§

I32Constant(i32)

i32.const

§

I64Constant(i64)

i64.const

§

F32Constant(f32)

f32.const

§

F64Constant(f64)

f64.const

§

CountLeadingZeros(IntegerType)

inn.clz

§

CountTrailingZeros(IntegerType)

inn.ctz

§

CountOnes(IntegerType)

inn.popcnt

§

AbsoluteValue(FloatType)

fnn.abs

§

Negate(FloatType)

fnn.negate

§

SquareRoot(FloatType)

fnn.sqrt

§

Ceiling(FloatType)

fnn.ceil

§

Floor(FloatType)

fnn.floor

§

Truncate(FloatType)

fnn.trunc

§

Nearest(FloatType)

fnn.nearest

§

Add(NumberType)

xnn.add

§

Subtract(NumberType)

xnn.sub

§

Multiply(NumberType)

xnn.mul

§

DivideInteger(IntegerType, SignExtension)

inn.div_sx

§

DivideFloat(FloatType)

fnn.div

§

Remainder(IntegerType, SignExtension)

inn.rem_sx

§

And(IntegerType)

inn.and

§

Or(IntegerType)

inn.or

§

Xor(IntegerType)

inn.xor

§

ShiftLeft(IntegerType)

inn.shl

§

ShiftRight(IntegerType, SignExtension)

inn.shr_sx

§

RotateLeft(IntegerType)

inn.rotl

§

RotateRight(IntegerType)

inn.rotr

§

Minimum(FloatType)

fnn.min

§

Maximum(FloatType)

fnn.max

§

CopySign(FloatType)

fnn.copysign

§

EqualToZero(IntegerType)

inn.eqz

§

Equal(NumberType)

xnn.eq

§

NotEqual(NumberType)

xnn.ne

§

LessThanInteger(IntegerType, SignExtension)

inn.lt_sx

§

LessThanFloat(FloatType)

fnn.lt

§

GreaterThanInteger(IntegerType, SignExtension)

inn.gt_sx

§

GreaterThanFloat(FloatType)

fnn.gt

§

LessThanOrEqualToInteger(IntegerType, SignExtension)

inn.le_sx

§

LessThanOrEqualToFloat(FloatType)

fnn.le

§

GreaterThanOrEqualToInteger(IntegerType, SignExtension)

inn.ge_sx

§

GreaterThanOrEqualToFloat(FloatType)

fnn.ge

§

ExtendSigned8(IntegerType)

inn.extend8_s

§

ExtendSigned16(IntegerType)

inn.extend16_s

§

ExtendSigned32

i64.extend32_s

§

Wrap

i32.wrap_i64

§

ExtendWithSignExtension(SignExtension)

i64.extend_i32_sx

§

ConvertAndTruncate(IntegerType, FloatType, SignExtension)

inn.trunc_fmm_sx

§

ConvertAndTruncateWithSaturation(IntegerType, FloatType, SignExtension)

inn.trunc_sat_fmm_sx

§

Demote

f32.demote_f64

§

Promote

f64.promote_f32

§

Convert(FloatType, IntegerType, SignExtension)

fnn.convert_imm_sx

§

ReinterpretFloat(IntegerType)

inn.reinterpret_fmm

§

ReinterpretInteger(FloatType)

fnn.reinterpret.imm

Trait Implementations§

Source§

impl Clone for NumericInstruction

Source§

fn clone(&self) -> NumericInstruction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NumericInstruction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<NumericInstruction> for Instruction

Source§

fn from(instruction: NumericInstruction) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for NumericInstruction

Source§

fn eq(&self, other: &NumericInstruction) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for NumericInstruction

Source§

impl StructuralPartialEq for NumericInstruction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.