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
impl Clone for NumericInstruction
Source§fn clone(&self) -> NumericInstruction
fn clone(&self) -> NumericInstruction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more