Trait cranelift_codegen::ir::InstBuilder
source · pub trait InstBuilder<'f>: InstBuilderBase<'f> {
Show 235 methods
fn jump(self, block: Block, args: &[Value]) -> Inst { ... }
fn brz(self, c: Value, block: Block, args: &[Value]) -> Inst { ... }
fn brnz(self, c: Value, block: Block, args: &[Value]) -> Inst { ... }
fn br_table(self, x: Value, block: Block, JT: JumpTable) -> Inst { ... }
fn debugtrap(self) -> Inst { ... }
fn trap<T1: Into<TrapCode>>(self, code: T1) -> Inst { ... }
fn trapz<T1: Into<TrapCode>>(self, c: Value, code: T1) -> Inst { ... }
fn resumable_trap<T1: Into<TrapCode>>(self, code: T1) -> Inst { ... }
fn trapnz<T1: Into<TrapCode>>(self, c: Value, code: T1) -> Inst { ... }
fn resumable_trapnz<T1: Into<TrapCode>>(self, c: Value, code: T1) -> Inst { ... }
fn return_(self, rvals: &[Value]) -> Inst { ... }
fn call(self, FN: FuncRef, args: &[Value]) -> Inst { ... }
fn call_indirect(self, SIG: SigRef, callee: Value, args: &[Value]) -> Inst { ... }
fn func_addr(self, iAddr: Type, FN: FuncRef) -> Value { ... }
fn splat(self, TxN: Type, x: Value) -> Value { ... }
fn swizzle(self, TxN: Type, x: Value, y: Value) -> Value { ... }
fn insertlane<T1: Into<Uimm8>>(self, x: Value, y: Value, Idx: T1) -> Value { ... }
fn extractlane<T1: Into<Uimm8>>(self, x: Value, Idx: T1) -> Value { ... }
fn smin(self, x: Value, y: Value) -> Value { ... }
fn umin(self, x: Value, y: Value) -> Value { ... }
fn smax(self, x: Value, y: Value) -> Value { ... }
fn umax(self, x: Value, y: Value) -> Value { ... }
fn avg_round(self, x: Value, y: Value) -> Value { ... }
fn uadd_sat(self, x: Value, y: Value) -> Value { ... }
fn sadd_sat(self, x: Value, y: Value) -> Value { ... }
fn usub_sat(self, x: Value, y: Value) -> Value { ... }
fn ssub_sat(self, x: Value, y: Value) -> Value { ... }
fn load<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
Mem: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn store<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst { ... }
fn uload8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt8: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn sload8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt8: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn istore8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst { ... }
fn uload16<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt16: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn sload16<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt16: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn istore16<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst { ... }
fn uload32<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn sload32<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn istore32<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst { ... }
fn uload8x8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn sload8x8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn uload16x4<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn sload16x4<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn uload32x2<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn sload32x2<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value { ... }
fn stack_load<T1: Into<Offset32>>(
self,
Mem: Type,
SS: StackSlot,
Offset: T1
) -> Value { ... }
fn stack_store<T1: Into<Offset32>>(
self,
x: Value,
SS: StackSlot,
Offset: T1
) -> Inst { ... }
fn stack_addr<T1: Into<Offset32>>(
self,
iAddr: Type,
SS: StackSlot,
Offset: T1
) -> Value { ... }
fn dynamic_stack_load(self, Mem: Type, DSS: DynamicStackSlot) -> Value { ... }
fn dynamic_stack_store(self, x: Value, DSS: DynamicStackSlot) -> Inst { ... }
fn dynamic_stack_addr(self, iAddr: Type, DSS: DynamicStackSlot) -> Value { ... }
fn global_value(self, Mem: Type, GV: GlobalValue) -> Value { ... }
fn symbol_value(self, Mem: Type, GV: GlobalValue) -> Value { ... }
fn tls_value(self, Mem: Type, GV: GlobalValue) -> Value { ... }
fn heap_addr<T1: Into<Uimm32>, T2: Into<Uimm8>>(
self,
iAddr: Type,
H: Heap,
index: Value,
Offset: T1,
Size: T2
) -> Value { ... }
fn heap_load<T1: Into<HeapImm>>(
self,
Mem: Type,
heap_imm: T1,
index: Value
) -> Value { ... }
fn heap_store<T1: Into<HeapImm>>(
self,
heap_imm: T1,
index: Value,
a: Value
) -> Inst { ... }
fn get_pinned_reg(self, iAddr: Type) -> Value { ... }
fn set_pinned_reg(self, addr: Value) -> Inst { ... }
fn get_frame_pointer(self, iAddr: Type) -> Value { ... }
fn get_stack_pointer(self, iAddr: Type) -> Value { ... }
fn get_return_address(self, iAddr: Type) -> Value { ... }
fn table_addr<T1: Into<Offset32>>(
self,
iAddr: Type,
T: Table,
p: Value,
Offset: T1
) -> Value { ... }
fn iconst<T1: Into<Imm64>>(self, NarrowInt: Type, N: T1) -> Value { ... }
fn f32const<T1: Into<Ieee32>>(self, N: T1) -> Value { ... }
fn f64const<T1: Into<Ieee64>>(self, N: T1) -> Value { ... }
fn vconst<T1: Into<Constant>>(self, TxN: Type, N: T1) -> Value { ... }
fn shuffle<T1: Into<Immediate>>(self, a: Value, b: Value, mask: T1) -> Value { ... }
fn null(self, Ref: Type) -> Value { ... }
fn nop(self) -> Inst { ... }
fn select(self, c: Value, x: Value, y: Value) -> Value { ... }
fn select_spectre_guard(self, c: Value, x: Value, y: Value) -> Value { ... }
fn bitselect(self, c: Value, x: Value, y: Value) -> Value { ... }
fn vsplit(self, x: Value) -> (Value, Value) { ... }
fn vconcat(self, x: Value, y: Value) -> Value { ... }
fn vselect(self, c: Value, x: Value, y: Value) -> Value { ... }
fn vany_true(self, a: Value) -> Value { ... }
fn vall_true(self, a: Value) -> Value { ... }
fn vhigh_bits(self, Int: Type, a: Value) -> Value { ... }
fn icmp<T1: Into<IntCC>>(self, Cond: T1, x: Value, y: Value) -> Value { ... }
fn icmp_imm<T1: Into<IntCC>, T2: Into<Imm64>>(
self,
Cond: T1,
x: Value,
Y: T2
) -> Value { ... }
fn ifcmp(self, x: Value, y: Value) -> Value { ... }
fn ifcmp_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn iadd(self, x: Value, y: Value) -> Value { ... }
fn isub(self, x: Value, y: Value) -> Value { ... }
fn ineg(self, x: Value) -> Value { ... }
fn iabs(self, x: Value) -> Value { ... }
fn imul(self, x: Value, y: Value) -> Value { ... }
fn umulhi(self, x: Value, y: Value) -> Value { ... }
fn smulhi(self, x: Value, y: Value) -> Value { ... }
fn sqmul_round_sat(self, x: Value, y: Value) -> Value { ... }
fn udiv(self, x: Value, y: Value) -> Value { ... }
fn sdiv(self, x: Value, y: Value) -> Value { ... }
fn urem(self, x: Value, y: Value) -> Value { ... }
fn srem(self, x: Value, y: Value) -> Value { ... }
fn iadd_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn imul_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn udiv_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn sdiv_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn urem_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn srem_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn irsub_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn iadd_cin(self, x: Value, y: Value, c_in: Value) -> Value { ... }
fn iadd_ifcin(self, x: Value, y: Value, c_in: Value) -> Value { ... }
fn iadd_cout(self, x: Value, y: Value) -> (Value, Value) { ... }
fn iadd_ifcout(self, x: Value, y: Value) -> (Value, Value) { ... }
fn iadd_carry(self, x: Value, y: Value, c_in: Value) -> (Value, Value) { ... }
fn iadd_ifcarry(self, x: Value, y: Value, c_in: Value) -> (Value, Value) { ... }
fn uadd_overflow_trap<T1: Into<TrapCode>>(
self,
x: Value,
y: Value,
code: T1
) -> Value { ... }
fn isub_bin(self, x: Value, y: Value, b_in: Value) -> Value { ... }
fn isub_ifbin(self, x: Value, y: Value, b_in: Value) -> Value { ... }
fn isub_bout(self, x: Value, y: Value) -> (Value, Value) { ... }
fn isub_ifbout(self, x: Value, y: Value) -> (Value, Value) { ... }
fn isub_borrow(self, x: Value, y: Value, b_in: Value) -> (Value, Value) { ... }
fn isub_ifborrow(self, x: Value, y: Value, b_in: Value) -> (Value, Value) { ... }
fn band(self, x: Value, y: Value) -> Value { ... }
fn bor(self, x: Value, y: Value) -> Value { ... }
fn bxor(self, x: Value, y: Value) -> Value { ... }
fn bnot(self, x: Value) -> Value { ... }
fn band_not(self, x: Value, y: Value) -> Value { ... }
fn bor_not(self, x: Value, y: Value) -> Value { ... }
fn bxor_not(self, x: Value, y: Value) -> Value { ... }
fn band_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn bor_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn bxor_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn rotl(self, x: Value, y: Value) -> Value { ... }
fn rotr(self, x: Value, y: Value) -> Value { ... }
fn rotl_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn rotr_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn ishl(self, x: Value, y: Value) -> Value { ... }
fn ushr(self, x: Value, y: Value) -> Value { ... }
fn sshr(self, x: Value, y: Value) -> Value { ... }
fn ishl_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn ushr_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn sshr_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value { ... }
fn bitrev(self, x: Value) -> Value { ... }
fn clz(self, x: Value) -> Value { ... }
fn cls(self, x: Value) -> Value { ... }
fn ctz(self, x: Value) -> Value { ... }
fn bswap(self, x: Value) -> Value { ... }
fn popcnt(self, x: Value) -> Value { ... }
fn fcmp<T1: Into<FloatCC>>(self, Cond: T1, x: Value, y: Value) -> Value { ... }
fn ffcmp(self, x: Value, y: Value) -> Value { ... }
fn fadd(self, x: Value, y: Value) -> Value { ... }
fn fsub(self, x: Value, y: Value) -> Value { ... }
fn fmul(self, x: Value, y: Value) -> Value { ... }
fn fdiv(self, x: Value, y: Value) -> Value { ... }
fn sqrt(self, x: Value) -> Value { ... }
fn fma(self, x: Value, y: Value, z: Value) -> Value { ... }
fn fneg(self, x: Value) -> Value { ... }
fn fabs(self, x: Value) -> Value { ... }
fn fcopysign(self, x: Value, y: Value) -> Value { ... }
fn fmin(self, x: Value, y: Value) -> Value { ... }
fn fmin_pseudo(self, x: Value, y: Value) -> Value { ... }
fn fmax(self, x: Value, y: Value) -> Value { ... }
fn fmax_pseudo(self, x: Value, y: Value) -> Value { ... }
fn ceil(self, x: Value) -> Value { ... }
fn floor(self, x: Value) -> Value { ... }
fn trunc(self, x: Value) -> Value { ... }
fn nearest(self, x: Value) -> Value { ... }
fn is_null(self, x: Value) -> Value { ... }
fn is_invalid(self, x: Value) -> Value { ... }
fn bitcast<T1: Into<MemFlags>>(
self,
MemTo: Type,
MemFlags: T1,
x: Value
) -> Value { ... }
fn scalar_to_vector(self, TxN: Type, s: Value) -> Value { ... }
fn bmask(self, IntTo: Type, x: Value) -> Value { ... }
fn ireduce(self, IntTo: Type, x: Value) -> Value { ... }
fn snarrow(self, x: Value, y: Value) -> Value { ... }
fn unarrow(self, x: Value, y: Value) -> Value { ... }
fn uunarrow(self, x: Value, y: Value) -> Value { ... }
fn swiden_low(self, x: Value) -> Value { ... }
fn swiden_high(self, x: Value) -> Value { ... }
fn uwiden_low(self, x: Value) -> Value { ... }
fn uwiden_high(self, x: Value) -> Value { ... }
fn iadd_pairwise(self, x: Value, y: Value) -> Value { ... }
fn widening_pairwise_dot_product_s(self, x: Value, y: Value) -> Value { ... }
fn uextend(self, IntTo: Type, x: Value) -> Value { ... }
fn sextend(self, IntTo: Type, x: Value) -> Value { ... }
fn fpromote(self, FloatTo: Type, x: Value) -> Value { ... }
fn fdemote(self, FloatTo: Type, x: Value) -> Value { ... }
fn fvdemote(self, x: Value) -> Value { ... }
fn fvpromote_low(self, a: Value) -> Value { ... }
fn fcvt_to_uint(self, IntTo: Type, x: Value) -> Value { ... }
fn fcvt_to_sint(self, IntTo: Type, x: Value) -> Value { ... }
fn fcvt_to_uint_sat(self, IntTo: Type, x: Value) -> Value { ... }
fn fcvt_to_sint_sat(self, IntTo: Type, x: Value) -> Value { ... }
fn fcvt_from_uint(self, FloatTo: Type, x: Value) -> Value { ... }
fn fcvt_from_sint(self, FloatTo: Type, x: Value) -> Value { ... }
fn fcvt_low_from_sint(self, FloatTo: Type, x: Value) -> Value { ... }
fn isplit(self, x: Value) -> (Value, Value) { ... }
fn iconcat(self, lo: Value, hi: Value) -> Value { ... }
fn atomic_rmw<T1: Into<MemFlags>, T2: Into<AtomicRmwOp>>(
self,
AtomicMem: Type,
MemFlags: T1,
AtomicRmwOp: T2,
p: Value,
x: Value
) -> Value { ... }
fn atomic_cas<T1: Into<MemFlags>>(
self,
MemFlags: T1,
p: Value,
e: Value,
x: Value
) -> Value { ... }
fn atomic_load<T1: Into<MemFlags>>(
self,
AtomicMem: Type,
MemFlags: T1,
p: Value
) -> Value { ... }
fn atomic_store<T1: Into<MemFlags>>(
self,
MemFlags: T1,
x: Value,
p: Value
) -> Inst { ... }
fn fence(self) -> Inst { ... }
fn extract_vector<T1: Into<Uimm8>>(self, x: Value, y: T1) -> Value { ... }
fn AtomicCas(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
arg0: Value,
arg1: Value,
arg2: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn AtomicRmw(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
op: AtomicRmwOp,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Binary(
self,
opcode: Opcode,
ctrl_typevar: Type,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn BinaryImm64(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Imm64,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn BinaryImm8(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Uimm8,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Branch(
self,
opcode: Opcode,
ctrl_typevar: Type,
destination: Block,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn BranchTable(
self,
opcode: Opcode,
ctrl_typevar: Type,
destination: Block,
table: JumpTable,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Call(
self,
opcode: Opcode,
ctrl_typevar: Type,
func_ref: FuncRef,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn CallIndirect(
self,
opcode: Opcode,
ctrl_typevar: Type,
sig_ref: SigRef,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn CondTrap(
self,
opcode: Opcode,
ctrl_typevar: Type,
code: TrapCode,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn DynamicStackLoad(
self,
opcode: Opcode,
ctrl_typevar: Type,
dynamic_stack_slot: DynamicStackSlot
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn DynamicStackStore(
self,
opcode: Opcode,
ctrl_typevar: Type,
dynamic_stack_slot: DynamicStackSlot,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn FloatCompare(
self,
opcode: Opcode,
ctrl_typevar: Type,
cond: FloatCC,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn FuncAddr(
self,
opcode: Opcode,
ctrl_typevar: Type,
func_ref: FuncRef
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn HeapAddr(
self,
opcode: Opcode,
ctrl_typevar: Type,
heap: Heap,
offset: Uimm32,
size: Uimm8,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn HeapLoad(
self,
opcode: Opcode,
ctrl_typevar: Type,
heap_imm: HeapImm,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn HeapStore(
self,
opcode: Opcode,
ctrl_typevar: Type,
heap_imm: HeapImm,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn IntAddTrap(
self,
opcode: Opcode,
ctrl_typevar: Type,
code: TrapCode,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn IntCompare(
self,
opcode: Opcode,
ctrl_typevar: Type,
cond: IntCC,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn IntCompareImm(
self,
opcode: Opcode,
ctrl_typevar: Type,
cond: IntCC,
imm: Imm64,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Jump(
self,
opcode: Opcode,
ctrl_typevar: Type,
destination: Block,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Load(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
offset: Offset32,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn LoadNoOffset(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn MultiAry(
self,
opcode: Opcode,
ctrl_typevar: Type,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn NullAry(
self,
opcode: Opcode,
ctrl_typevar: Type
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Shuffle(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Immediate,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn StackLoad(
self,
opcode: Opcode,
ctrl_typevar: Type,
stack_slot: StackSlot,
offset: Offset32
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn StackStore(
self,
opcode: Opcode,
ctrl_typevar: Type,
stack_slot: StackSlot,
offset: Offset32,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Store(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
offset: Offset32,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn StoreNoOffset(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn TableAddr(
self,
opcode: Opcode,
ctrl_typevar: Type,
table: Table,
offset: Offset32,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Ternary(
self,
opcode: Opcode,
ctrl_typevar: Type,
arg0: Value,
arg1: Value,
arg2: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn TernaryImm8(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Uimm8,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Trap(
self,
opcode: Opcode,
ctrl_typevar: Type,
code: TrapCode
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn Unary(
self,
opcode: Opcode,
ctrl_typevar: Type,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn UnaryConst(
self,
opcode: Opcode,
ctrl_typevar: Type,
constant_handle: Constant
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn UnaryGlobalValue(
self,
opcode: Opcode,
ctrl_typevar: Type,
global_value: GlobalValue
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn UnaryIeee32(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Ieee32
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn UnaryIeee64(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Ieee64
) -> (Inst, &'f mut DataFlowGraph) { ... }
fn UnaryImm(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Imm64
) -> (Inst, &'f mut DataFlowGraph) { ... }
}Expand description
Convenience methods for building instructions.
The InstBuilder trait has one method per instruction opcode for
conveniently constructing the instruction with minimum arguments.
Polymorphic instructions infer their result types from the input
arguments when possible. In some cases, an explicit ctrl_typevar
argument is required.
The opcode methods return the new instruction’s result values, or
the Inst itself for instructions that don’t have any results.
There is also a method per instruction format. These methods all
return an Inst.
Provided Methods§
sourcefn jump(self, block: Block, args: &[Value]) -> Inst
fn jump(self, block: Block, args: &[Value]) -> Inst
Jump.
Unconditionally jump to a basic block, passing the specified block arguments. The number and types of arguments must match the destination block.
Inputs:
- block: Destination basic block
- args: block arguments
Examples found in repository?
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
fn create_pre_header(
header: Block,
func: &mut Function,
cfg: &mut ControlFlowGraph,
domtree: &DominatorTree,
) -> Block {
let pool = &mut ListPool::<Value>::new();
let header_args_values = func.dfg.block_params(header).to_vec();
let header_args_types: Vec<Type> = header_args_values
.into_iter()
.map(|val| func.dfg.value_type(val))
.collect();
let pre_header = func.dfg.make_block();
let mut pre_header_args_value: EntityList<Value> = EntityList::new();
for typ in header_args_types {
pre_header_args_value.push(func.dfg.append_block_param(pre_header, typ), pool);
}
for BlockPredecessor {
inst: last_inst, ..
} in cfg.pred_iter(header)
{
// We only follow normal edges (not the back edges)
if !domtree.dominates(header, last_inst, &func.layout) {
func.rewrite_branch_destination(last_inst, header, pre_header);
}
}
// Inserts the pre-header at the right place in the layout.
let mut pos = FuncCursor::new(func).at_top(header);
pos.insert_block(pre_header);
pos.next_inst();
pos.ins().jump(header, pre_header_args_value.as_slice(pool));
pre_header
}More examples
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
fn expand_cond_trap(
inst: ir::Inst,
func: &mut ir::Function,
cfg: &mut ControlFlowGraph,
opcode: ir::Opcode,
arg: ir::Value,
code: ir::TrapCode,
) {
trace!(
"expanding conditional trap: {:?}: {}",
inst,
func.dfg.display_inst(inst)
);
// Parse the instruction.
let trapz = match opcode {
ir::Opcode::Trapz => true,
ir::Opcode::Trapnz | ir::Opcode::ResumableTrapnz => false,
_ => panic!("Expected cond trap: {}", func.dfg.display_inst(inst)),
};
// Split the block after `inst`:
//
// trapnz arg
// ..
//
// Becomes:
//
// brz arg, new_block_resume
// jump new_block_trap
//
// new_block_trap:
// trap
//
// new_block_resume:
// ..
let old_block = func.layout.pp_block(inst);
let new_block_trap = func.dfg.make_block();
let new_block_resume = func.dfg.make_block();
// Trapping is a rare event, mark the trapping block as cold.
func.layout.set_cold(new_block_trap);
// Replace trap instruction by the inverted condition.
if trapz {
func.dfg.replace(inst).brnz(arg, new_block_resume, &[]);
} else {
func.dfg.replace(inst).brz(arg, new_block_resume, &[]);
}
// Add jump instruction after the inverted branch.
let mut pos = FuncCursor::new(func).after_inst(inst);
pos.use_srcloc(inst);
pos.ins().jump(new_block_trap, &[]);
// Insert the new label and the unconditional trap terminator.
pos.insert_block(new_block_trap);
match opcode {
ir::Opcode::Trapz | ir::Opcode::Trapnz => {
pos.ins().trap(code);
}
ir::Opcode::ResumableTrapnz => {
pos.ins().resumable_trap(code);
pos.ins().jump(new_block_resume, &[]);
}
_ => unreachable!(),
}
// Insert the new label and resume the execution when the trap fails.
pos.insert_block(new_block_resume);
// Finally update the CFG.
cfg.recompute_block(pos.func, old_block);
cfg.recompute_block(pos.func, new_block_resume);
cfg.recompute_block(pos.func, new_block_trap);
}479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, block: Block, inst: Inst) {
let (term_inst, term_inst_args, term_dest, cond_inst, cond_inst_args, cond_dest, kind) =
match pos.func.dfg[inst] {
InstructionData::Jump {
opcode: Opcode::Jump,
destination,
ref args,
} => {
let next_block = if let Some(next_block) = pos.func.layout.next_block(block) {
next_block
} else {
return;
};
if destination == next_block {
return;
}
let prev_inst = if let Some(prev_inst) = pos.func.layout.prev_inst(inst) {
prev_inst
} else {
return;
};
let prev_inst_data = &pos.func.dfg[prev_inst];
if let Some(prev_dest) = prev_inst_data.branch_destination() {
if prev_dest != next_block {
return;
}
} else {
return;
}
match prev_inst_data {
InstructionData::Branch {
opcode,
args: ref prev_args,
destination: cond_dest,
} => {
let cond_arg = {
let args = pos.func.dfg.inst_args(prev_inst);
args[0]
};
let kind = match opcode {
Opcode::Brz => BranchOrderKind::BrzToBrnz(cond_arg),
Opcode::Brnz => BranchOrderKind::BrnzToBrz(cond_arg),
_ => panic!("unexpected opcode"),
};
(
inst,
args.clone(),
destination,
prev_inst,
prev_args.clone(),
*cond_dest,
kind,
)
}
_ => return,
}
}
_ => return,
};
let cond_args = cond_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec();
let term_args = term_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec();
match kind {
BranchOrderKind::BrnzToBrz(cond_arg) => {
pos.func
.dfg
.replace(term_inst)
.jump(cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(cond_inst)
.brz(cond_arg, term_dest, &term_args);
}
BranchOrderKind::BrzToBrnz(cond_arg) => {
pos.func
.dfg
.replace(term_inst)
.jump(cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(cond_inst)
.brnz(cond_arg, term_dest, &term_args);
}
}
cfg.recompute_block(pos.func, block);
}sourcefn brz(self, c: Value, block: Block, args: &[Value]) -> Inst
fn brz(self, c: Value, block: Block, args: &[Value]) -> Inst
Branch when zero.
Take the branch when c = 0.
Inputs:
- c: Controlling value to test
- block: Destination basic block
- args: block arguments
Examples found in repository?
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
fn expand_cond_trap(
inst: ir::Inst,
func: &mut ir::Function,
cfg: &mut ControlFlowGraph,
opcode: ir::Opcode,
arg: ir::Value,
code: ir::TrapCode,
) {
trace!(
"expanding conditional trap: {:?}: {}",
inst,
func.dfg.display_inst(inst)
);
// Parse the instruction.
let trapz = match opcode {
ir::Opcode::Trapz => true,
ir::Opcode::Trapnz | ir::Opcode::ResumableTrapnz => false,
_ => panic!("Expected cond trap: {}", func.dfg.display_inst(inst)),
};
// Split the block after `inst`:
//
// trapnz arg
// ..
//
// Becomes:
//
// brz arg, new_block_resume
// jump new_block_trap
//
// new_block_trap:
// trap
//
// new_block_resume:
// ..
let old_block = func.layout.pp_block(inst);
let new_block_trap = func.dfg.make_block();
let new_block_resume = func.dfg.make_block();
// Trapping is a rare event, mark the trapping block as cold.
func.layout.set_cold(new_block_trap);
// Replace trap instruction by the inverted condition.
if trapz {
func.dfg.replace(inst).brnz(arg, new_block_resume, &[]);
} else {
func.dfg.replace(inst).brz(arg, new_block_resume, &[]);
}
// Add jump instruction after the inverted branch.
let mut pos = FuncCursor::new(func).after_inst(inst);
pos.use_srcloc(inst);
pos.ins().jump(new_block_trap, &[]);
// Insert the new label and the unconditional trap terminator.
pos.insert_block(new_block_trap);
match opcode {
ir::Opcode::Trapz | ir::Opcode::Trapnz => {
pos.ins().trap(code);
}
ir::Opcode::ResumableTrapnz => {
pos.ins().resumable_trap(code);
pos.ins().jump(new_block_resume, &[]);
}
_ => unreachable!(),
}
// Insert the new label and resume the execution when the trap fails.
pos.insert_block(new_block_resume);
// Finally update the CFG.
cfg.recompute_block(pos.func, old_block);
cfg.recompute_block(pos.func, new_block_resume);
cfg.recompute_block(pos.func, new_block_trap);
}More examples
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, block: Block, inst: Inst) {
let (term_inst, term_inst_args, term_dest, cond_inst, cond_inst_args, cond_dest, kind) =
match pos.func.dfg[inst] {
InstructionData::Jump {
opcode: Opcode::Jump,
destination,
ref args,
} => {
let next_block = if let Some(next_block) = pos.func.layout.next_block(block) {
next_block
} else {
return;
};
if destination == next_block {
return;
}
let prev_inst = if let Some(prev_inst) = pos.func.layout.prev_inst(inst) {
prev_inst
} else {
return;
};
let prev_inst_data = &pos.func.dfg[prev_inst];
if let Some(prev_dest) = prev_inst_data.branch_destination() {
if prev_dest != next_block {
return;
}
} else {
return;
}
match prev_inst_data {
InstructionData::Branch {
opcode,
args: ref prev_args,
destination: cond_dest,
} => {
let cond_arg = {
let args = pos.func.dfg.inst_args(prev_inst);
args[0]
};
let kind = match opcode {
Opcode::Brz => BranchOrderKind::BrzToBrnz(cond_arg),
Opcode::Brnz => BranchOrderKind::BrnzToBrz(cond_arg),
_ => panic!("unexpected opcode"),
};
(
inst,
args.clone(),
destination,
prev_inst,
prev_args.clone(),
*cond_dest,
kind,
)
}
_ => return,
}
}
_ => return,
};
let cond_args = cond_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec();
let term_args = term_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec();
match kind {
BranchOrderKind::BrnzToBrz(cond_arg) => {
pos.func
.dfg
.replace(term_inst)
.jump(cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(cond_inst)
.brz(cond_arg, term_dest, &term_args);
}
BranchOrderKind::BrzToBrnz(cond_arg) => {
pos.func
.dfg
.replace(term_inst)
.jump(cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(cond_inst)
.brnz(cond_arg, term_dest, &term_args);
}
}
cfg.recompute_block(pos.func, block);
}sourcefn brnz(self, c: Value, block: Block, args: &[Value]) -> Inst
fn brnz(self, c: Value, block: Block, args: &[Value]) -> Inst
Branch when non-zero.
Take the branch when c != 0.
Inputs:
- c: Controlling value to test
- block: Destination basic block
- args: block arguments
Examples found in repository?
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
fn expand_cond_trap(
inst: ir::Inst,
func: &mut ir::Function,
cfg: &mut ControlFlowGraph,
opcode: ir::Opcode,
arg: ir::Value,
code: ir::TrapCode,
) {
trace!(
"expanding conditional trap: {:?}: {}",
inst,
func.dfg.display_inst(inst)
);
// Parse the instruction.
let trapz = match opcode {
ir::Opcode::Trapz => true,
ir::Opcode::Trapnz | ir::Opcode::ResumableTrapnz => false,
_ => panic!("Expected cond trap: {}", func.dfg.display_inst(inst)),
};
// Split the block after `inst`:
//
// trapnz arg
// ..
//
// Becomes:
//
// brz arg, new_block_resume
// jump new_block_trap
//
// new_block_trap:
// trap
//
// new_block_resume:
// ..
let old_block = func.layout.pp_block(inst);
let new_block_trap = func.dfg.make_block();
let new_block_resume = func.dfg.make_block();
// Trapping is a rare event, mark the trapping block as cold.
func.layout.set_cold(new_block_trap);
// Replace trap instruction by the inverted condition.
if trapz {
func.dfg.replace(inst).brnz(arg, new_block_resume, &[]);
} else {
func.dfg.replace(inst).brz(arg, new_block_resume, &[]);
}
// Add jump instruction after the inverted branch.
let mut pos = FuncCursor::new(func).after_inst(inst);
pos.use_srcloc(inst);
pos.ins().jump(new_block_trap, &[]);
// Insert the new label and the unconditional trap terminator.
pos.insert_block(new_block_trap);
match opcode {
ir::Opcode::Trapz | ir::Opcode::Trapnz => {
pos.ins().trap(code);
}
ir::Opcode::ResumableTrapnz => {
pos.ins().resumable_trap(code);
pos.ins().jump(new_block_resume, &[]);
}
_ => unreachable!(),
}
// Insert the new label and resume the execution when the trap fails.
pos.insert_block(new_block_resume);
// Finally update the CFG.
cfg.recompute_block(pos.func, old_block);
cfg.recompute_block(pos.func, new_block_resume);
cfg.recompute_block(pos.func, new_block_trap);
}More examples
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, block: Block, inst: Inst) {
let (term_inst, term_inst_args, term_dest, cond_inst, cond_inst_args, cond_dest, kind) =
match pos.func.dfg[inst] {
InstructionData::Jump {
opcode: Opcode::Jump,
destination,
ref args,
} => {
let next_block = if let Some(next_block) = pos.func.layout.next_block(block) {
next_block
} else {
return;
};
if destination == next_block {
return;
}
let prev_inst = if let Some(prev_inst) = pos.func.layout.prev_inst(inst) {
prev_inst
} else {
return;
};
let prev_inst_data = &pos.func.dfg[prev_inst];
if let Some(prev_dest) = prev_inst_data.branch_destination() {
if prev_dest != next_block {
return;
}
} else {
return;
}
match prev_inst_data {
InstructionData::Branch {
opcode,
args: ref prev_args,
destination: cond_dest,
} => {
let cond_arg = {
let args = pos.func.dfg.inst_args(prev_inst);
args[0]
};
let kind = match opcode {
Opcode::Brz => BranchOrderKind::BrzToBrnz(cond_arg),
Opcode::Brnz => BranchOrderKind::BrnzToBrz(cond_arg),
_ => panic!("unexpected opcode"),
};
(
inst,
args.clone(),
destination,
prev_inst,
prev_args.clone(),
*cond_dest,
kind,
)
}
_ => return,
}
}
_ => return,
};
let cond_args = cond_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec();
let term_args = term_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec();
match kind {
BranchOrderKind::BrnzToBrz(cond_arg) => {
pos.func
.dfg
.replace(term_inst)
.jump(cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(cond_inst)
.brz(cond_arg, term_dest, &term_args);
}
BranchOrderKind::BrzToBrnz(cond_arg) => {
pos.func
.dfg
.replace(term_inst)
.jump(cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(cond_inst)
.brnz(cond_arg, term_dest, &term_args);
}
}
cfg.recompute_block(pos.func, block);
}sourcefn br_table(self, x: Value, block: Block, JT: JumpTable) -> Inst
fn br_table(self, x: Value, block: Block, JT: JumpTable) -> Inst
Indirect branch via jump table.
Use x as an unsigned index into the jump table JT. If a jump
table entry is found, branch to the corresponding block. If no entry was
found or the index is out-of-bounds, branch to the given default block.
Note that this branch instruction can’t pass arguments to the targeted blocks. Split critical edges as needed to work around this.
Do not confuse this with “tables” in WebAssembly. br_table is for
jump tables with destinations within the current function only – think
of a match in Rust or a switch in C. If you want to call a
function in a dynamic library, that will typically use
call_indirect.
Inputs:
- x: i32 index into jump table
- block: Destination basic block
- JT: A jump table.
sourcefn trap<T1: Into<TrapCode>>(self, code: T1) -> Inst
fn trap<T1: Into<TrapCode>>(self, code: T1) -> Inst
Terminate execution unconditionally.
Inputs:
- code: A trap reason code.
Examples found in repository?
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
fn expand_cond_trap(
inst: ir::Inst,
func: &mut ir::Function,
cfg: &mut ControlFlowGraph,
opcode: ir::Opcode,
arg: ir::Value,
code: ir::TrapCode,
) {
trace!(
"expanding conditional trap: {:?}: {}",
inst,
func.dfg.display_inst(inst)
);
// Parse the instruction.
let trapz = match opcode {
ir::Opcode::Trapz => true,
ir::Opcode::Trapnz | ir::Opcode::ResumableTrapnz => false,
_ => panic!("Expected cond trap: {}", func.dfg.display_inst(inst)),
};
// Split the block after `inst`:
//
// trapnz arg
// ..
//
// Becomes:
//
// brz arg, new_block_resume
// jump new_block_trap
//
// new_block_trap:
// trap
//
// new_block_resume:
// ..
let old_block = func.layout.pp_block(inst);
let new_block_trap = func.dfg.make_block();
let new_block_resume = func.dfg.make_block();
// Trapping is a rare event, mark the trapping block as cold.
func.layout.set_cold(new_block_trap);
// Replace trap instruction by the inverted condition.
if trapz {
func.dfg.replace(inst).brnz(arg, new_block_resume, &[]);
} else {
func.dfg.replace(inst).brz(arg, new_block_resume, &[]);
}
// Add jump instruction after the inverted branch.
let mut pos = FuncCursor::new(func).after_inst(inst);
pos.use_srcloc(inst);
pos.ins().jump(new_block_trap, &[]);
// Insert the new label and the unconditional trap terminator.
pos.insert_block(new_block_trap);
match opcode {
ir::Opcode::Trapz | ir::Opcode::Trapnz => {
pos.ins().trap(code);
}
ir::Opcode::ResumableTrapnz => {
pos.ins().resumable_trap(code);
pos.ins().jump(new_block_resume, &[]);
}
_ => unreachable!(),
}
// Insert the new label and resume the execution when the trap fails.
pos.insert_block(new_block_resume);
// Finally update the CFG.
cfg.recompute_block(pos.func, old_block);
cfg.recompute_block(pos.func, new_block_resume);
cfg.recompute_block(pos.func, new_block_trap);
}More examples
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
fn bounds_check_and_compute_addr(
pos: &mut FuncCursor,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap: ir::Heap,
// Dynamic operand indexing into the heap.
index: ir::Value,
// Static immediate added to the index.
offset: u32,
// Static size of the heap access.
access_size: u8,
) -> ir::Value {
let pointer_type = isa.pointer_type();
let spectre = isa.flags().enable_heap_access_spectre_mitigation();
let offset_and_size = offset_plus_size(offset, access_size);
let ir::HeapData {
base: _,
min_size,
offset_guard_size: guard_size,
style,
index_type,
} = pos.func.heaps[heap].clone();
let index = cast_index_to_pointer_ty(index, index_type, pointer_type, pos);
// We need to emit code that will trap (or compute an address that will trap
// when accessed) if
//
// index + offset + access_size > bound
//
// or if the `index + offset + access_size` addition overflows.
//
// Note that we ultimately want a 64-bit integer (we only target 64-bit
// architectures at the moment) and that `offset` is a `u32` and
// `access_size` is a `u8`. This means that we can add the latter together
// as `u64`s without fear of overflow, and we only have to be concerned with
// whether adding in `index` will overflow.
//
// Finally, the following right-hand sides of the matches do have a little
// bit of duplicated code across them, but I think writing it this way is
// worth it for readability and seeing very clearly each of our cases for
// different bounds checks and optimizations of those bounds checks. It is
// intentionally written in a straightforward case-matching style that will
// hopefully make it easy to port to ISLE one day.
match style {
// ====== Dynamic Memories ======
//
// 1. First special case for when `offset + access_size == 1`:
//
// index + 1 > bound
// ==> index >= bound
//
// 1.a. When Spectre mitigations are enabled, avoid duplicating
// bounds checks between the mitigations and the regular bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThanOrEqual,
lhs: index,
rhs: bound,
}),
)
}
// 1.b. Emit explicit `index >= bound` bounds checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 2. Second special case for when `offset + access_size <= min_size`.
//
// We know that `bound >= min_size`, so we can do the following
// comparison, without fear of the right-hand side wrapping around:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// 2.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 2.b. Emit explicit `index > bound - (offset + access_size)` bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, index, adjusted_bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for dynamic memories:
//
// index + offset + access_size > bound
//
// And we have to handle the overflow case in the left-hand side.
//
// 3.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if spectre => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: adjusted_index,
rhs: bound,
}),
)
}
// 3.b. Emit an explicit `index + offset + access_size > bound`
// check.
ir::HeapStyle::Dynamic { bound_gv } => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, adjusted_index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// ====== Static Memories ======
//
// With static memories we know the size of the heap bound at compile
// time.
//
// 1. First special case: trap immediately if `offset + access_size >
// bound`, since we will end up being out-of-bounds regardless of the
// given `index`.
ir::HeapStyle::Static { bound } if offset_and_size > bound.into() => {
pos.ins().trap(ir::TrapCode::HeapOutOfBounds);
// Split the block, as the trap is a terminator instruction.
let curr_block = pos.current_block().expect("Cursor is not in a block");
let new_block = pos.func.dfg.make_block();
pos.insert_block(new_block);
cfg.recompute_block(pos.func, curr_block);
cfg.recompute_block(pos.func, new_block);
let null = pos.ins().iconst(pointer_type, 0);
return null;
}
// 2. Second special case for when we can completely omit explicit
// bounds checks for 32-bit static memories.
//
// First, let's rewrite our comparison to move all of the constants
// to one side:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// We know the subtraction on the right-hand side won't wrap because
// we didn't hit the first special case.
//
// Additionally, we add our guard pages (if any) to the right-hand
// side, since we can rely on the virtual memory subsystem at runtime
// to catch out-of-bound accesses within the range `bound .. bound +
// guard_size`. So now we are dealing with
//
// index > bound + guard_size - (offset + access_size)
//
// Note that `bound + guard_size` cannot overflow for
// correctly-configured heaps, as otherwise the heap wouldn't fit in
// a 64-bit memory space.
//
// The complement of our should-this-trap comparison expression is
// the should-this-not-trap comparison expression:
//
// index <= bound + guard_size - (offset + access_size)
//
// If we know the right-hand side is greater than or equal to
// `u32::MAX`, then
//
// index <= u32::MAX <= bound + guard_size - (offset + access_size)
//
// This expression is always true when the heap is indexed with
// 32-bit integers because `index` cannot be larger than
// `u32::MAX`. This means that `index` is always either in bounds or
// within the guard page region, neither of which require emitting an
// explicit bounds check.
ir::HeapStyle::Static { bound }
if index_type == ir::types::I32
&& u64::from(u32::MAX)
<= u64::from(bound) + u64::from(guard_size) - offset_and_size =>
{
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for static memories.
//
// We have to explicitly test whether
//
// index > bound - (offset + access_size)
//
// and trap if so.
//
// Since we have to emit explicit bounds checks, we might as well be
// precise, not rely on the virtual memory subsystem at all, and not
// factor in the guard pages here.
//
// 3.a. Dedupe the Spectre mitigation and the explicit bounds check.
ir::HeapStyle::Static { bound } if spectre => {
// NB: this subtraction cannot wrap because we didn't hit the first
// special case.
let adjusted_bound = u64::from(bound) - offset_and_size;
let adjusted_bound = pos.ins().iconst(pointer_type, adjusted_bound as i64);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 3.b. Emit the explicit `index > bound - (offset + access_size)`
// check.
ir::HeapStyle::Static { bound } => {
// See comment in 3.a. above.
let adjusted_bound = u64::from(bound) - offset_and_size;
let oob = pos
.ins()
.icmp_imm(IntCC::UnsignedGreaterThan, index, adjusted_bound as i64);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
}
}sourcefn trapz<T1: Into<TrapCode>>(self, c: Value, code: T1) -> Inst
fn trapz<T1: Into<TrapCode>>(self, c: Value, code: T1) -> Inst
Trap when zero.
if c is non-zero, execution continues at the following instruction.
Inputs:
- c: Controlling value to test
- code: A trap reason code.
sourcefn resumable_trap<T1: Into<TrapCode>>(self, code: T1) -> Inst
fn resumable_trap<T1: Into<TrapCode>>(self, code: T1) -> Inst
A resumable trap.
This instruction allows non-conditional traps to be used as non-terminal instructions.
Inputs:
- code: A trap reason code.
Examples found in repository?
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
fn expand_cond_trap(
inst: ir::Inst,
func: &mut ir::Function,
cfg: &mut ControlFlowGraph,
opcode: ir::Opcode,
arg: ir::Value,
code: ir::TrapCode,
) {
trace!(
"expanding conditional trap: {:?}: {}",
inst,
func.dfg.display_inst(inst)
);
// Parse the instruction.
let trapz = match opcode {
ir::Opcode::Trapz => true,
ir::Opcode::Trapnz | ir::Opcode::ResumableTrapnz => false,
_ => panic!("Expected cond trap: {}", func.dfg.display_inst(inst)),
};
// Split the block after `inst`:
//
// trapnz arg
// ..
//
// Becomes:
//
// brz arg, new_block_resume
// jump new_block_trap
//
// new_block_trap:
// trap
//
// new_block_resume:
// ..
let old_block = func.layout.pp_block(inst);
let new_block_trap = func.dfg.make_block();
let new_block_resume = func.dfg.make_block();
// Trapping is a rare event, mark the trapping block as cold.
func.layout.set_cold(new_block_trap);
// Replace trap instruction by the inverted condition.
if trapz {
func.dfg.replace(inst).brnz(arg, new_block_resume, &[]);
} else {
func.dfg.replace(inst).brz(arg, new_block_resume, &[]);
}
// Add jump instruction after the inverted branch.
let mut pos = FuncCursor::new(func).after_inst(inst);
pos.use_srcloc(inst);
pos.ins().jump(new_block_trap, &[]);
// Insert the new label and the unconditional trap terminator.
pos.insert_block(new_block_trap);
match opcode {
ir::Opcode::Trapz | ir::Opcode::Trapnz => {
pos.ins().trap(code);
}
ir::Opcode::ResumableTrapnz => {
pos.ins().resumable_trap(code);
pos.ins().jump(new_block_resume, &[]);
}
_ => unreachable!(),
}
// Insert the new label and resume the execution when the trap fails.
pos.insert_block(new_block_resume);
// Finally update the CFG.
cfg.recompute_block(pos.func, old_block);
cfg.recompute_block(pos.func, new_block_resume);
cfg.recompute_block(pos.func, new_block_trap);
}sourcefn trapnz<T1: Into<TrapCode>>(self, c: Value, code: T1) -> Inst
fn trapnz<T1: Into<TrapCode>>(self, c: Value, code: T1) -> Inst
Trap when non-zero.
If c is zero, execution continues at the following instruction.
Inputs:
- c: Controlling value to test
- code: A trap reason code.
Examples found in repository?
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
pub fn expand_table_addr(
isa: &dyn TargetIsa,
inst: ir::Inst,
func: &mut ir::Function,
table: ir::Table,
index: ir::Value,
element_offset: Offset32,
) {
let bound_gv = func.tables[table].bound_gv;
let index_ty = func.dfg.value_type(index);
let addr_ty = func.dfg.value_type(func.dfg.first_result(inst));
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Start with the bounds check. Trap if `index + 1 > bound`.
let bound = pos.ins().global_value(index_ty, bound_gv);
// `index > bound - 1` is the same as `index >= bound`.
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::TableOutOfBounds);
// If Spectre mitigations are enabled, we will use a comparison to
// short-circuit the computed table element address to the start
// of the table on the misspeculation path when out-of-bounds.
let spectre_oob_cmp = if isa.flags().enable_table_access_spectre_mitigation() {
Some((index, bound))
} else {
None
};
compute_addr(
inst,
table,
addr_ty,
index,
index_ty,
element_offset,
pos.func,
spectre_oob_cmp,
);
}More examples
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
fn bounds_check_and_compute_addr(
pos: &mut FuncCursor,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap: ir::Heap,
// Dynamic operand indexing into the heap.
index: ir::Value,
// Static immediate added to the index.
offset: u32,
// Static size of the heap access.
access_size: u8,
) -> ir::Value {
let pointer_type = isa.pointer_type();
let spectre = isa.flags().enable_heap_access_spectre_mitigation();
let offset_and_size = offset_plus_size(offset, access_size);
let ir::HeapData {
base: _,
min_size,
offset_guard_size: guard_size,
style,
index_type,
} = pos.func.heaps[heap].clone();
let index = cast_index_to_pointer_ty(index, index_type, pointer_type, pos);
// We need to emit code that will trap (or compute an address that will trap
// when accessed) if
//
// index + offset + access_size > bound
//
// or if the `index + offset + access_size` addition overflows.
//
// Note that we ultimately want a 64-bit integer (we only target 64-bit
// architectures at the moment) and that `offset` is a `u32` and
// `access_size` is a `u8`. This means that we can add the latter together
// as `u64`s without fear of overflow, and we only have to be concerned with
// whether adding in `index` will overflow.
//
// Finally, the following right-hand sides of the matches do have a little
// bit of duplicated code across them, but I think writing it this way is
// worth it for readability and seeing very clearly each of our cases for
// different bounds checks and optimizations of those bounds checks. It is
// intentionally written in a straightforward case-matching style that will
// hopefully make it easy to port to ISLE one day.
match style {
// ====== Dynamic Memories ======
//
// 1. First special case for when `offset + access_size == 1`:
//
// index + 1 > bound
// ==> index >= bound
//
// 1.a. When Spectre mitigations are enabled, avoid duplicating
// bounds checks between the mitigations and the regular bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThanOrEqual,
lhs: index,
rhs: bound,
}),
)
}
// 1.b. Emit explicit `index >= bound` bounds checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 2. Second special case for when `offset + access_size <= min_size`.
//
// We know that `bound >= min_size`, so we can do the following
// comparison, without fear of the right-hand side wrapping around:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// 2.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 2.b. Emit explicit `index > bound - (offset + access_size)` bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, index, adjusted_bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for dynamic memories:
//
// index + offset + access_size > bound
//
// And we have to handle the overflow case in the left-hand side.
//
// 3.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if spectre => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: adjusted_index,
rhs: bound,
}),
)
}
// 3.b. Emit an explicit `index + offset + access_size > bound`
// check.
ir::HeapStyle::Dynamic { bound_gv } => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, adjusted_index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// ====== Static Memories ======
//
// With static memories we know the size of the heap bound at compile
// time.
//
// 1. First special case: trap immediately if `offset + access_size >
// bound`, since we will end up being out-of-bounds regardless of the
// given `index`.
ir::HeapStyle::Static { bound } if offset_and_size > bound.into() => {
pos.ins().trap(ir::TrapCode::HeapOutOfBounds);
// Split the block, as the trap is a terminator instruction.
let curr_block = pos.current_block().expect("Cursor is not in a block");
let new_block = pos.func.dfg.make_block();
pos.insert_block(new_block);
cfg.recompute_block(pos.func, curr_block);
cfg.recompute_block(pos.func, new_block);
let null = pos.ins().iconst(pointer_type, 0);
return null;
}
// 2. Second special case for when we can completely omit explicit
// bounds checks for 32-bit static memories.
//
// First, let's rewrite our comparison to move all of the constants
// to one side:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// We know the subtraction on the right-hand side won't wrap because
// we didn't hit the first special case.
//
// Additionally, we add our guard pages (if any) to the right-hand
// side, since we can rely on the virtual memory subsystem at runtime
// to catch out-of-bound accesses within the range `bound .. bound +
// guard_size`. So now we are dealing with
//
// index > bound + guard_size - (offset + access_size)
//
// Note that `bound + guard_size` cannot overflow for
// correctly-configured heaps, as otherwise the heap wouldn't fit in
// a 64-bit memory space.
//
// The complement of our should-this-trap comparison expression is
// the should-this-not-trap comparison expression:
//
// index <= bound + guard_size - (offset + access_size)
//
// If we know the right-hand side is greater than or equal to
// `u32::MAX`, then
//
// index <= u32::MAX <= bound + guard_size - (offset + access_size)
//
// This expression is always true when the heap is indexed with
// 32-bit integers because `index` cannot be larger than
// `u32::MAX`. This means that `index` is always either in bounds or
// within the guard page region, neither of which require emitting an
// explicit bounds check.
ir::HeapStyle::Static { bound }
if index_type == ir::types::I32
&& u64::from(u32::MAX)
<= u64::from(bound) + u64::from(guard_size) - offset_and_size =>
{
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for static memories.
//
// We have to explicitly test whether
//
// index > bound - (offset + access_size)
//
// and trap if so.
//
// Since we have to emit explicit bounds checks, we might as well be
// precise, not rely on the virtual memory subsystem at all, and not
// factor in the guard pages here.
//
// 3.a. Dedupe the Spectre mitigation and the explicit bounds check.
ir::HeapStyle::Static { bound } if spectre => {
// NB: this subtraction cannot wrap because we didn't hit the first
// special case.
let adjusted_bound = u64::from(bound) - offset_and_size;
let adjusted_bound = pos.ins().iconst(pointer_type, adjusted_bound as i64);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 3.b. Emit the explicit `index > bound - (offset + access_size)`
// check.
ir::HeapStyle::Static { bound } => {
// See comment in 3.a. above.
let adjusted_bound = u64::from(bound) - offset_and_size;
let oob = pos
.ins()
.icmp_imm(IntCC::UnsignedGreaterThan, index, adjusted_bound as i64);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
}
}sourcefn resumable_trapnz<T1: Into<TrapCode>>(self, c: Value, code: T1) -> Inst
fn resumable_trapnz<T1: Into<TrapCode>>(self, c: Value, code: T1) -> Inst
A resumable trap to be called when the passed condition is non-zero.
If c is zero, execution continues at the following instruction.
Inputs:
- c: Controlling value to test
- code: A trap reason code.
sourcefn return_(self, rvals: &[Value]) -> Inst
fn return_(self, rvals: &[Value]) -> Inst
Return from the function.
Unconditionally transfer control to the calling function, passing the provided return values. The list of return values must match the function signature’s return types.
Inputs:
- rvals: return values
sourcefn call(self, FN: FuncRef, args: &[Value]) -> Inst
fn call(self, FN: FuncRef, args: &[Value]) -> Inst
Direct function call.
Call a function which has been declared in the preamble. The argument types must match the function’s signature.
Inputs:
- FN: function to call, declared by
function - args: call arguments
Outputs:
- rvals: return values
sourcefn call_indirect(self, SIG: SigRef, callee: Value, args: &[Value]) -> Inst
fn call_indirect(self, SIG: SigRef, callee: Value, args: &[Value]) -> Inst
Indirect function call.
Call the function pointed to by callee with the given arguments. The
called function must match the specified signature.
Note that this is different from WebAssembly’s call_indirect; the
callee is a native address, rather than a table index. For WebAssembly,
table_addr and load are used to obtain a native address
from a table.
Inputs:
- SIG: function signature
- callee: address of function to call
- args: call arguments
Outputs:
- rvals: return values
sourcefn func_addr(self, iAddr: Type, FN: FuncRef) -> Value
fn func_addr(self, iAddr: Type, FN: FuncRef) -> Value
Get the address of a function.
Compute the absolute address of a function declared in the preamble.
The returned address can be used as a callee argument to
call_indirect. This is also a method for calling functions that
are too far away to be addressable by a direct call
instruction.
Inputs:
- iAddr (controlling type variable): An integer address type
- FN: function to call, declared by
function
Outputs:
- addr: An integer address type
sourcefn splat(self, TxN: Type, x: Value) -> Value
fn splat(self, TxN: Type, x: Value) -> Value
Vector splat.
Return a vector whose lanes are all x.
Inputs:
- TxN (controlling type variable): A SIMD vector type
- x: Value to splat to all lanes
Outputs:
- a: A SIMD vector type
Examples found in repository?
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn add_nan_canon_seq(pos: &mut FuncCursor, inst: Inst) {
// Select the instruction result, result type. Replace the instruction
// result and step forward before inserting the canonicalization sequence.
let val = pos.func.dfg.first_result(inst);
let val_type = pos.func.dfg.value_type(val);
let new_res = pos.func.dfg.replace_result(val, val_type);
let _next_inst = pos.next_inst().expect("block missing terminator!");
// Insert a comparison instruction, to check if `inst_res` is NaN. Select
// the canonical NaN value if `val` is NaN, assign the result to `inst`.
let is_nan = pos.ins().fcmp(FloatCC::NotEqual, new_res, new_res);
let scalar_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.select(is_nan, canon_nan, new_res);
};
let vector_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.vselect(is_nan, canon_nan, new_res);
};
match val_type {
types::F32 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F64 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F32X4 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
let canon_nan = pos.ins().splat(types::F32X4, canon_nan);
vector_select(pos, canon_nan);
}
types::F64X2 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
let canon_nan = pos.ins().splat(types::F64X2, canon_nan);
vector_select(pos, canon_nan);
}
_ => {
// Panic if the type given was not an IEEE floating point type.
panic!("Could not canonicalize NaN: Unexpected result type found.");
}
}
pos.prev_inst(); // Step backwards so the pass does not skip instructions.
}sourcefn swizzle(self, TxN: Type, x: Value, y: Value) -> Value
fn swizzle(self, TxN: Type, x: Value, y: Value) -> Value
Vector swizzle.
Returns a new vector with byte-width lanes selected from the lanes of the first input
vector x specified in the second input vector s. The indices i in range
[0, 15] select the i-th element of x. For indices outside of the range the
resulting lane is 0. Note that this operates on byte-width lanes.
Inputs:
- TxN (controlling type variable): A SIMD vector type
- x: Vector to modify by re-arranging lanes
- y: Mask for re-arranging lanes
Outputs:
- a: A SIMD vector type
sourcefn insertlane<T1: Into<Uimm8>>(self, x: Value, y: Value, Idx: T1) -> Value
fn insertlane<T1: Into<Uimm8>>(self, x: Value, y: Value, Idx: T1) -> Value
Insert y as lane Idx in x.
The lane index, Idx, is an immediate value, not an SSA value. It
must indicate a valid lane index for the type of x.
Inputs:
- x: The vector to modify
- y: New lane value
- Idx: Lane index
Outputs:
- a: A SIMD vector type
sourcefn extractlane<T1: Into<Uimm8>>(self, x: Value, Idx: T1) -> Value
fn extractlane<T1: Into<Uimm8>>(self, x: Value, Idx: T1) -> Value
Extract lane Idx from x.
The lane index, Idx, is an immediate value, not an SSA value. It
must indicate a valid lane index for the type of x. Note that the upper bits of a
may or may not be zeroed depending on the ISA but the type system should prevent using
a as anything other than the extracted value.
Inputs:
- x: A SIMD vector type
- Idx: Lane index
Outputs:
- a:
sourcefn smin(self, x: Value, y: Value) -> Value
fn smin(self, x: Value, y: Value) -> Value
Signed integer minimum.
Inputs:
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
sourcefn umin(self, x: Value, y: Value) -> Value
fn umin(self, x: Value, y: Value) -> Value
Unsigned integer minimum.
Inputs:
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
sourcefn smax(self, x: Value, y: Value) -> Value
fn smax(self, x: Value, y: Value) -> Value
Signed integer maximum.
Inputs:
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
sourcefn umax(self, x: Value, y: Value) -> Value
fn umax(self, x: Value, y: Value) -> Value
Unsigned integer maximum.
Inputs:
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
sourcefn avg_round(self, x: Value, y: Value) -> Value
fn avg_round(self, x: Value, y: Value) -> Value
Unsigned average with rounding: a := (x + y + 1) // 2
The addition does not lose any information (such as from overflow).
Inputs:
- x: A SIMD vector type containing integers
- y: A SIMD vector type containing integers
Outputs:
- a: A SIMD vector type containing integers
sourcefn uadd_sat(self, x: Value, y: Value) -> Value
fn uadd_sat(self, x: Value, y: Value) -> Value
Add with unsigned saturation.
This is similar to iadd but the operands are interpreted as unsigned integers and their
summed result, instead of wrapping, will be saturated to the highest unsigned integer for
the controlling type (e.g. 0xFF for i8).
Inputs:
- x: A SIMD vector type containing integers
- y: A SIMD vector type containing integers
Outputs:
- a: A SIMD vector type containing integers
sourcefn sadd_sat(self, x: Value, y: Value) -> Value
fn sadd_sat(self, x: Value, y: Value) -> Value
Add with signed saturation.
This is similar to iadd but the operands are interpreted as signed integers and their
summed result, instead of wrapping, will be saturated to the lowest or highest
signed integer for the controlling type (e.g. 0x80 or 0x7F for i8). For example,
since an sadd_sat.i8 of 0x70 and 0x70 is greater than 0x7F, the result will be
clamped to 0x7F.
Inputs:
- x: A SIMD vector type containing integers
- y: A SIMD vector type containing integers
Outputs:
- a: A SIMD vector type containing integers
sourcefn usub_sat(self, x: Value, y: Value) -> Value
fn usub_sat(self, x: Value, y: Value) -> Value
Subtract with unsigned saturation.
This is similar to isub but the operands are interpreted as unsigned integers and their
difference, instead of wrapping, will be saturated to the lowest unsigned integer for
the controlling type (e.g. 0x00 for i8).
Inputs:
- x: A SIMD vector type containing integers
- y: A SIMD vector type containing integers
Outputs:
- a: A SIMD vector type containing integers
sourcefn ssub_sat(self, x: Value, y: Value) -> Value
fn ssub_sat(self, x: Value, y: Value) -> Value
Subtract with signed saturation.
This is similar to isub but the operands are interpreted as signed integers and their
difference, instead of wrapping, will be saturated to the lowest or highest
signed integer for the controlling type (e.g. 0x80 or 0x7F for i8).
Inputs:
- x: A SIMD vector type containing integers
- y: A SIMD vector type containing integers
Outputs:
- a: A SIMD vector type containing integers
sourcefn load<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
Mem: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn load<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
Mem: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load from memory at p + Offset.
This is a polymorphic instruction that can load any value type which has a memory representation.
Inputs:
- Mem (controlling type variable): Any type that can be stored in memory
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: Value loaded
Examples found in repository?
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
pub fn expand_heap_load(
inst: ir::Inst,
func: &mut ir::Function,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap_imm: ir::HeapImm,
index: ir::Value,
) {
let HeapImmData {
flags,
heap,
offset,
} = func.dfg.heap_imms[heap_imm];
let result_ty = func.dfg.ctrl_typevar(inst);
let access_size = result_ty.bytes();
let access_size = u8::try_from(access_size).unwrap();
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
let addr =
bounds_check_and_compute_addr(&mut pos, cfg, isa, heap, index, offset.into(), access_size);
pos.func
.dfg
.replace(inst)
.load(result_ty, flags, addr, Offset32::new(0));
}More examples
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
fn load_addr(
inst: ir::Inst,
func: &mut ir::Function,
base: ir::GlobalValue,
offset: ir::immediates::Offset32,
global_type: ir::Type,
readonly: bool,
isa: &dyn TargetIsa,
) {
// We need to load a pointer from the `base` global value, so insert a new `global_value`
// instruction. This depends on the iterative legalization loop. Note that the IR verifier
// detects any cycles in the `load` globals.
let ptr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Get the value for the base. For tidiness, expand VMContext here so that we avoid
// `vmctx_addr` which creates an otherwise unneeded value alias.
let base_addr = if let ir::GlobalValueData::VMContext = pos.func.global_values[base] {
pos.func
.special_param(ir::ArgumentPurpose::VMContext)
.expect("Missing vmctx parameter")
} else {
pos.ins().global_value(ptr_ty, base)
};
// Global-value loads are always notrap and aligned. They may be readonly.
let mut mflags = ir::MemFlags::trusted();
if readonly {
mflags.set_readonly();
}
// Perform the load.
pos.func
.dfg
.replace(inst)
.load(global_type, mflags, base_addr, offset);
}49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn store<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst
fn store<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst
Store x to memory at p + Offset.
This is a polymorphic instruction that can store any value type with a memory representation.
Inputs:
- MemFlags: Memory operation flags
- x: Value to be stored
- p: An integer address type
- Offset: Byte offset from base address
Examples found in repository?
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
pub fn expand_heap_store(
inst: ir::Inst,
func: &mut ir::Function,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap_imm: ir::HeapImm,
index: ir::Value,
value: ir::Value,
) {
let HeapImmData {
flags,
heap,
offset,
} = func.dfg.heap_imms[heap_imm];
let store_ty = func.dfg.value_type(value);
let access_size = u8::try_from(store_ty.bytes()).unwrap();
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
let addr =
bounds_check_and_compute_addr(&mut pos, cfg, isa, heap, index, offset.into(), access_size);
pos.func
.dfg
.replace(inst)
.store(flags, value, addr, Offset32::new(0));
}More examples
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn uload8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt8: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn uload8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt8: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load 8 bits from memory at p + Offset and zero-extend.
This is equivalent to load.i8 followed by uextend.
Inputs:
- iExt8 (controlling type variable): An integer type with more than 8 bits
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: An integer type with more than 8 bits
sourcefn sload8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt8: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn sload8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt8: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load 8 bits from memory at p + Offset and sign-extend.
This is equivalent to load.i8 followed by sextend.
Inputs:
- iExt8 (controlling type variable): An integer type with more than 8 bits
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: An integer type with more than 8 bits
sourcefn istore8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst
fn istore8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst
Store the low 8 bits of x to memory at p + Offset.
This is equivalent to ireduce.i8 followed by store.i8.
Inputs:
- MemFlags: Memory operation flags
- x: An integer type with more than 8 bits
- p: An integer address type
- Offset: Byte offset from base address
sourcefn uload16<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt16: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn uload16<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt16: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load 16 bits from memory at p + Offset and zero-extend.
This is equivalent to load.i16 followed by uextend.
Inputs:
- iExt16 (controlling type variable): An integer type with more than 16 bits
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: An integer type with more than 16 bits
sourcefn sload16<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt16: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn sload16<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
iExt16: Type,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load 16 bits from memory at p + Offset and sign-extend.
This is equivalent to load.i16 followed by sextend.
Inputs:
- iExt16 (controlling type variable): An integer type with more than 16 bits
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: An integer type with more than 16 bits
sourcefn istore16<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst
fn istore16<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst
Store the low 16 bits of x to memory at p + Offset.
This is equivalent to ireduce.i16 followed by store.i16.
Inputs:
- MemFlags: Memory operation flags
- x: An integer type with more than 16 bits
- p: An integer address type
- Offset: Byte offset from base address
sourcefn uload32<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn uload32<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load 32 bits from memory at p + Offset and zero-extend.
This is equivalent to load.i32 followed by uextend.
Inputs:
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: An integer type with more than 32 bits
sourcefn sload32<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn sload32<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load 32 bits from memory at p + Offset and sign-extend.
This is equivalent to load.i32 followed by sextend.
Inputs:
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: An integer type with more than 32 bits
sourcefn istore32<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst
fn istore32<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
x: Value,
p: Value,
Offset: T2
) -> Inst
Store the low 32 bits of x to memory at p + Offset.
This is equivalent to ireduce.i32 followed by store.i32.
Inputs:
- MemFlags: Memory operation flags
- x: An integer type with more than 32 bits
- p: An integer address type
- Offset: Byte offset from base address
sourcefn uload8x8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn uload8x8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load an 8x8 vector (64 bits) from memory at p + Offset and zero-extend into an i16x8
vector.
Inputs:
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: Value loaded
sourcefn sload8x8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn sload8x8<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load an 8x8 vector (64 bits) from memory at p + Offset and sign-extend into an i16x8
vector.
Inputs:
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: Value loaded
sourcefn uload16x4<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn uload16x4<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load a 16x4 vector (64 bits) from memory at p + Offset and zero-extend into an i32x4
vector.
Inputs:
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: Value loaded
sourcefn sload16x4<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn sload16x4<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load a 16x4 vector (64 bits) from memory at p + Offset and sign-extend into an i32x4
vector.
Inputs:
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: Value loaded
sourcefn uload32x2<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn uload32x2<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load an 32x2 vector (64 bits) from memory at p + Offset and zero-extend into an i64x2
vector.
Inputs:
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: Value loaded
sourcefn sload32x2<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
fn sload32x2<T1: Into<MemFlags>, T2: Into<Offset32>>(
self,
MemFlags: T1,
p: Value,
Offset: T2
) -> Value
Load a 32x2 vector (64 bits) from memory at p + Offset and sign-extend into an i64x2
vector.
Inputs:
- MemFlags: Memory operation flags
- p: An integer address type
- Offset: Byte offset from base address
Outputs:
- a: Value loaded
sourcefn stack_load<T1: Into<Offset32>>(
self,
Mem: Type,
SS: StackSlot,
Offset: T1
) -> Value
fn stack_load<T1: Into<Offset32>>(
self,
Mem: Type,
SS: StackSlot,
Offset: T1
) -> Value
Load a value from a stack slot at the constant offset.
This is a polymorphic instruction that can load any value type which has a memory representation.
The offset is an immediate constant, not an SSA value. The memory
access cannot go out of bounds, i.e.
sizeof(a) + Offset <= sizeof(SS).
Inputs:
- Mem (controlling type variable): Any type that can be stored in memory
- SS: A stack slot
- Offset: In-bounds offset into stack slot
Outputs:
- a: Value loaded
sourcefn stack_store<T1: Into<Offset32>>(
self,
x: Value,
SS: StackSlot,
Offset: T1
) -> Inst
fn stack_store<T1: Into<Offset32>>(
self,
x: Value,
SS: StackSlot,
Offset: T1
) -> Inst
Store a value to a stack slot at a constant offset.
This is a polymorphic instruction that can store any value type with a memory representation.
The offset is an immediate constant, not an SSA value. The memory
access cannot go out of bounds, i.e.
sizeof(a) + Offset <= sizeof(SS).
Inputs:
- x: Value to be stored
- SS: A stack slot
- Offset: In-bounds offset into stack slot
sourcefn stack_addr<T1: Into<Offset32>>(
self,
iAddr: Type,
SS: StackSlot,
Offset: T1
) -> Value
fn stack_addr<T1: Into<Offset32>>(
self,
iAddr: Type,
SS: StackSlot,
Offset: T1
) -> Value
Get the address of a stack slot.
Compute the absolute address of a byte in a stack slot. The offset must
refer to a byte inside the stack slot:
0 <= Offset < sizeof(SS).
Inputs:
- iAddr (controlling type variable): An integer address type
- SS: A stack slot
- Offset: In-bounds offset into stack slot
Outputs:
- addr: An integer address type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn dynamic_stack_load(self, Mem: Type, DSS: DynamicStackSlot) -> Value
fn dynamic_stack_load(self, Mem: Type, DSS: DynamicStackSlot) -> Value
Load a value from a dynamic stack slot.
This is a polymorphic instruction that can load any value type which has a memory representation.
Inputs:
- Mem (controlling type variable): Any type that can be stored in memory
- DSS: A dynamic stack slot
Outputs:
- a: Value loaded
sourcefn dynamic_stack_store(self, x: Value, DSS: DynamicStackSlot) -> Inst
fn dynamic_stack_store(self, x: Value, DSS: DynamicStackSlot) -> Inst
Store a value to a dynamic stack slot.
This is a polymorphic instruction that can store any dynamic value type with a memory representation.
Inputs:
- x: Value to be stored
- DSS: A dynamic stack slot
sourcefn dynamic_stack_addr(self, iAddr: Type, DSS: DynamicStackSlot) -> Value
fn dynamic_stack_addr(self, iAddr: Type, DSS: DynamicStackSlot) -> Value
Get the address of a dynamic stack slot.
Compute the absolute address of the first byte of a dynamic stack slot.
Inputs:
- iAddr (controlling type variable): An integer address type
- DSS: A dynamic stack slot
Outputs:
- addr: An integer address type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn global_value(self, Mem: Type, GV: GlobalValue) -> Value
fn global_value(self, Mem: Type, GV: GlobalValue) -> Value
Compute the value of global GV.
Inputs:
- Mem (controlling type variable): Any type that can be stored in memory
- GV: A global value.
Outputs:
- a: Value loaded
Examples found in repository?
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
fn iadd_imm_addr(
inst: ir::Inst,
func: &mut ir::Function,
base: ir::GlobalValue,
offset: i64,
global_type: ir::Type,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
// Get the value for the lhs. For tidiness, expand VMContext here so that we avoid
// `vmctx_addr` which creates an otherwise unneeded value alias.
let lhs = if let ir::GlobalValueData::VMContext = pos.func.global_values[base] {
pos.func
.special_param(ir::ArgumentPurpose::VMContext)
.expect("Missing vmctx parameter")
} else {
pos.ins().global_value(global_type, base)
};
// Simply replace the `global_value` instruction with an `iadd_imm`, reusing the result value.
pos.func.dfg.replace(inst).iadd_imm(lhs, offset);
}
/// Expand a `global_value` instruction for a load global.
fn load_addr(
inst: ir::Inst,
func: &mut ir::Function,
base: ir::GlobalValue,
offset: ir::immediates::Offset32,
global_type: ir::Type,
readonly: bool,
isa: &dyn TargetIsa,
) {
// We need to load a pointer from the `base` global value, so insert a new `global_value`
// instruction. This depends on the iterative legalization loop. Note that the IR verifier
// detects any cycles in the `load` globals.
let ptr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Get the value for the base. For tidiness, expand VMContext here so that we avoid
// `vmctx_addr` which creates an otherwise unneeded value alias.
let base_addr = if let ir::GlobalValueData::VMContext = pos.func.global_values[base] {
pos.func
.special_param(ir::ArgumentPurpose::VMContext)
.expect("Missing vmctx parameter")
} else {
pos.ins().global_value(ptr_ty, base)
};
// Global-value loads are always notrap and aligned. They may be readonly.
let mut mflags = ir::MemFlags::trusted();
if readonly {
mflags.set_readonly();
}
// Perform the load.
pos.func
.dfg
.replace(inst)
.load(global_type, mflags, base_addr, offset);
}More examples
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
pub fn expand_table_addr(
isa: &dyn TargetIsa,
inst: ir::Inst,
func: &mut ir::Function,
table: ir::Table,
index: ir::Value,
element_offset: Offset32,
) {
let bound_gv = func.tables[table].bound_gv;
let index_ty = func.dfg.value_type(index);
let addr_ty = func.dfg.value_type(func.dfg.first_result(inst));
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Start with the bounds check. Trap if `index + 1 > bound`.
let bound = pos.ins().global_value(index_ty, bound_gv);
// `index > bound - 1` is the same as `index >= bound`.
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::TableOutOfBounds);
// If Spectre mitigations are enabled, we will use a comparison to
// short-circuit the computed table element address to the start
// of the table on the misspeculation path when out-of-bounds.
let spectre_oob_cmp = if isa.flags().enable_table_access_spectre_mitigation() {
Some((index, bound))
} else {
None
};
compute_addr(
inst,
table,
addr_ty,
index,
index_ty,
element_offset,
pos.func,
spectre_oob_cmp,
);
}
/// Emit code for the base address computation of a `table_addr` instruction.
fn compute_addr(
inst: ir::Inst,
table: ir::Table,
addr_ty: ir::Type,
mut index: ir::Value,
index_ty: ir::Type,
element_offset: Offset32,
func: &mut ir::Function,
spectre_oob_cmp: Option<(ir::Value, ir::Value)>,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Convert `index` to `addr_ty`.
if index_ty != addr_ty {
index = pos.ins().uextend(addr_ty, index);
}
// Add the table base address base
let base_gv = pos.func.tables[table].base_gv;
let base = pos.ins().global_value(addr_ty, base_gv);
let element_size = pos.func.tables[table].element_size;
let mut offset;
let element_size: u64 = element_size.into();
if element_size == 1 {
offset = index;
} else if element_size.is_power_of_two() {
offset = pos
.ins()
.ishl_imm(index, i64::from(element_size.trailing_zeros()));
} else {
offset = pos.ins().imul_imm(index, element_size as i64);
}
let element_addr = if element_offset == Offset32::new(0) {
pos.ins().iadd(base, offset)
} else {
let imm: i64 = element_offset.into();
offset = pos.ins().iadd(base, offset);
pos.ins().iadd_imm(offset, imm)
};
let element_addr = if let Some((index, bound)) = spectre_oob_cmp {
let cond = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
// If out-of-bounds, choose the table base on the misspeculation path.
pos.ins().select_spectre_guard(cond, base, element_addr)
} else {
element_addr
};
let new_inst = pos.func.dfg.value_def(element_addr).inst().unwrap();
pos.func.dfg.replace_with_aliases(inst, new_inst);
pos.remove_inst();
}104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
fn bounds_check_and_compute_addr(
pos: &mut FuncCursor,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap: ir::Heap,
// Dynamic operand indexing into the heap.
index: ir::Value,
// Static immediate added to the index.
offset: u32,
// Static size of the heap access.
access_size: u8,
) -> ir::Value {
let pointer_type = isa.pointer_type();
let spectre = isa.flags().enable_heap_access_spectre_mitigation();
let offset_and_size = offset_plus_size(offset, access_size);
let ir::HeapData {
base: _,
min_size,
offset_guard_size: guard_size,
style,
index_type,
} = pos.func.heaps[heap].clone();
let index = cast_index_to_pointer_ty(index, index_type, pointer_type, pos);
// We need to emit code that will trap (or compute an address that will trap
// when accessed) if
//
// index + offset + access_size > bound
//
// or if the `index + offset + access_size` addition overflows.
//
// Note that we ultimately want a 64-bit integer (we only target 64-bit
// architectures at the moment) and that `offset` is a `u32` and
// `access_size` is a `u8`. This means that we can add the latter together
// as `u64`s without fear of overflow, and we only have to be concerned with
// whether adding in `index` will overflow.
//
// Finally, the following right-hand sides of the matches do have a little
// bit of duplicated code across them, but I think writing it this way is
// worth it for readability and seeing very clearly each of our cases for
// different bounds checks and optimizations of those bounds checks. It is
// intentionally written in a straightforward case-matching style that will
// hopefully make it easy to port to ISLE one day.
match style {
// ====== Dynamic Memories ======
//
// 1. First special case for when `offset + access_size == 1`:
//
// index + 1 > bound
// ==> index >= bound
//
// 1.a. When Spectre mitigations are enabled, avoid duplicating
// bounds checks between the mitigations and the regular bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThanOrEqual,
lhs: index,
rhs: bound,
}),
)
}
// 1.b. Emit explicit `index >= bound` bounds checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 2. Second special case for when `offset + access_size <= min_size`.
//
// We know that `bound >= min_size`, so we can do the following
// comparison, without fear of the right-hand side wrapping around:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// 2.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 2.b. Emit explicit `index > bound - (offset + access_size)` bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, index, adjusted_bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for dynamic memories:
//
// index + offset + access_size > bound
//
// And we have to handle the overflow case in the left-hand side.
//
// 3.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if spectre => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: adjusted_index,
rhs: bound,
}),
)
}
// 3.b. Emit an explicit `index + offset + access_size > bound`
// check.
ir::HeapStyle::Dynamic { bound_gv } => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, adjusted_index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// ====== Static Memories ======
//
// With static memories we know the size of the heap bound at compile
// time.
//
// 1. First special case: trap immediately if `offset + access_size >
// bound`, since we will end up being out-of-bounds regardless of the
// given `index`.
ir::HeapStyle::Static { bound } if offset_and_size > bound.into() => {
pos.ins().trap(ir::TrapCode::HeapOutOfBounds);
// Split the block, as the trap is a terminator instruction.
let curr_block = pos.current_block().expect("Cursor is not in a block");
let new_block = pos.func.dfg.make_block();
pos.insert_block(new_block);
cfg.recompute_block(pos.func, curr_block);
cfg.recompute_block(pos.func, new_block);
let null = pos.ins().iconst(pointer_type, 0);
return null;
}
// 2. Second special case for when we can completely omit explicit
// bounds checks for 32-bit static memories.
//
// First, let's rewrite our comparison to move all of the constants
// to one side:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// We know the subtraction on the right-hand side won't wrap because
// we didn't hit the first special case.
//
// Additionally, we add our guard pages (if any) to the right-hand
// side, since we can rely on the virtual memory subsystem at runtime
// to catch out-of-bound accesses within the range `bound .. bound +
// guard_size`. So now we are dealing with
//
// index > bound + guard_size - (offset + access_size)
//
// Note that `bound + guard_size` cannot overflow for
// correctly-configured heaps, as otherwise the heap wouldn't fit in
// a 64-bit memory space.
//
// The complement of our should-this-trap comparison expression is
// the should-this-not-trap comparison expression:
//
// index <= bound + guard_size - (offset + access_size)
//
// If we know the right-hand side is greater than or equal to
// `u32::MAX`, then
//
// index <= u32::MAX <= bound + guard_size - (offset + access_size)
//
// This expression is always true when the heap is indexed with
// 32-bit integers because `index` cannot be larger than
// `u32::MAX`. This means that `index` is always either in bounds or
// within the guard page region, neither of which require emitting an
// explicit bounds check.
ir::HeapStyle::Static { bound }
if index_type == ir::types::I32
&& u64::from(u32::MAX)
<= u64::from(bound) + u64::from(guard_size) - offset_and_size =>
{
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for static memories.
//
// We have to explicitly test whether
//
// index > bound - (offset + access_size)
//
// and trap if so.
//
// Since we have to emit explicit bounds checks, we might as well be
// precise, not rely on the virtual memory subsystem at all, and not
// factor in the guard pages here.
//
// 3.a. Dedupe the Spectre mitigation and the explicit bounds check.
ir::HeapStyle::Static { bound } if spectre => {
// NB: this subtraction cannot wrap because we didn't hit the first
// special case.
let adjusted_bound = u64::from(bound) - offset_and_size;
let adjusted_bound = pos.ins().iconst(pointer_type, adjusted_bound as i64);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 3.b. Emit the explicit `index > bound - (offset + access_size)`
// check.
ir::HeapStyle::Static { bound } => {
// See comment in 3.a. above.
let adjusted_bound = u64::from(bound) - offset_and_size;
let oob = pos
.ins()
.icmp_imm(IntCC::UnsignedGreaterThan, index, adjusted_bound as i64);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
}
}
fn cast_index_to_pointer_ty(
index: ir::Value,
index_ty: ir::Type,
pointer_ty: ir::Type,
pos: &mut FuncCursor,
) -> ir::Value {
if index_ty == pointer_ty {
return index;
}
// Note that using 64-bit heaps on a 32-bit host is not currently supported,
// would require at least a bounds check here to ensure that the truncation
// from 64-to-32 bits doesn't lose any upper bits. For now though we're
// mostly interested in the 32-bit-heaps-on-64-bit-hosts cast.
assert!(index_ty.bits() < pointer_ty.bits());
// Convert `index` to `addr_ty`.
let extended_index = pos.ins().uextend(pointer_ty, index);
// Add debug value-label alias so that debuginfo can name the extended
// value as the address
let loc = pos.srcloc();
let loc = RelSourceLoc::from_base_offset(pos.func.params.base_srcloc(), loc);
pos.func
.stencil
.dfg
.add_value_label_alias(extended_index, loc, index);
extended_index
}
struct SpectreOobComparison {
cc: IntCC,
lhs: ir::Value,
rhs: ir::Value,
}
/// Emit code for the base address computation of a `heap_addr` instruction,
/// without any bounds checks (other than optional Spectre mitigations).
fn compute_addr(
isa: &dyn TargetIsa,
pos: &mut FuncCursor,
heap: ir::Heap,
addr_ty: ir::Type,
index: ir::Value,
offset: u32,
// If we are performing Spectre mitigation with conditional selects, the
// values to compare and the condition code that indicates an out-of bounds
// condition; on this condition, the conditional move will choose a
// speculatively safe address (a zero / null pointer) instead.
spectre_oob_comparison: Option<SpectreOobComparison>,
) -> ir::Value {
debug_assert_eq!(pos.func.dfg.value_type(index), addr_ty);
// Add the heap base address base
let base = if isa.flags().enable_pinned_reg() && isa.flags().use_pinned_reg_as_heap_base() {
let base = pos.ins().get_pinned_reg(isa.pointer_type());
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
} else {
let base_gv = pos.func.heaps[heap].base;
let base = pos.ins().global_value(addr_ty, base_gv);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
};
if let Some(SpectreOobComparison { cc, lhs, rhs }) = spectre_oob_comparison {
let final_base = pos.ins().iadd(base, index);
// NB: The addition of the offset immediate must happen *before* the
// `select_spectre_guard`. If it happens after, then we potentially are
// letting speculative execution read the whole first 4GiB of memory.
let final_addr = if offset == 0 {
final_base
} else {
let final_addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_addr)
);
final_addr
};
let zero = pos.ins().iconst(addr_ty, 0);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(zero));
let cmp = pos.ins().icmp(cc, lhs, rhs);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(cmp));
let value = pos.ins().select_spectre_guard(cmp, zero, final_addr);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(value));
value
} else if offset == 0 {
let addr = pos.ins().iadd(base, index);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
} else {
let final_base = pos.ins().iadd(base, index);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_base)
);
let addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
}
}sourcefn symbol_value(self, Mem: Type, GV: GlobalValue) -> Value
fn symbol_value(self, Mem: Type, GV: GlobalValue) -> Value
Compute the value of global GV, which is a symbolic value.
Inputs:
- Mem (controlling type variable): Any type that can be stored in memory
- GV: A global value.
Outputs:
- a: Value loaded
Examples found in repository?
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
fn symbol(
inst: ir::Inst,
func: &mut ir::Function,
gv: ir::GlobalValue,
isa: &dyn TargetIsa,
tls: bool,
) {
let ptr_ty = isa.pointer_type();
if tls {
func.dfg.replace(inst).tls_value(ptr_ty, gv);
} else {
func.dfg.replace(inst).symbol_value(ptr_ty, gv);
}
}sourcefn tls_value(self, Mem: Type, GV: GlobalValue) -> Value
fn tls_value(self, Mem: Type, GV: GlobalValue) -> Value
Compute the value of global GV, which is a TLS (thread local storage) value.
Inputs:
- Mem (controlling type variable): Any type that can be stored in memory
- GV: A global value.
Outputs:
- a: Value loaded
Examples found in repository?
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
fn symbol(
inst: ir::Inst,
func: &mut ir::Function,
gv: ir::GlobalValue,
isa: &dyn TargetIsa,
tls: bool,
) {
let ptr_ty = isa.pointer_type();
if tls {
func.dfg.replace(inst).tls_value(ptr_ty, gv);
} else {
func.dfg.replace(inst).symbol_value(ptr_ty, gv);
}
}sourcefn heap_addr<T1: Into<Uimm32>, T2: Into<Uimm8>>(
self,
iAddr: Type,
H: Heap,
index: Value,
Offset: T1,
Size: T2
) -> Value
fn heap_addr<T1: Into<Uimm32>, T2: Into<Uimm8>>(
self,
iAddr: Type,
H: Heap,
index: Value,
Offset: T1,
Size: T2
) -> Value
Bounds check and compute absolute address of index + Offset in heap memory.
Verify that the range index .. index + Offset + Size is in bounds for the
heap H, and generate an absolute address that is safe to dereference.
-
If
index + Offset + Sizeis less than or equal ot the heap bound, return an absolute address corresponding to a byte offset ofindex + Offsetfrom the heap’s base address. -
If
index + Offset + Sizeis greater than the heap bound, return theNULLpointer or any other address that is guaranteed to generate a trap when accessed.
Inputs:
- iAddr (controlling type variable): An integer address type
- H: A heap.
- index: An unsigned heap offset
- Offset: Static offset immediate in bytes
- Size: Static size immediate in bytes
Outputs:
- addr: An integer address type
sourcefn heap_load<T1: Into<HeapImm>>(
self,
Mem: Type,
heap_imm: T1,
index: Value
) -> Value
fn heap_load<T1: Into<HeapImm>>(
self,
Mem: Type,
heap_imm: T1,
index: Value
) -> Value
Load a value from the given heap at address index + offset,
trapping on out-of-bounds accesses.
Checks that index + offset .. index + offset + sizeof(a) is
within the heap’s bounds, trapping if it is not. Otherwise, when
that range is in bounds, loads the value from the heap.
Traps on index + offset + sizeof(a) overflow.
Inputs:
- Mem (controlling type variable): Any type that can be stored in memory
- heap_imm: Reference to out-of-line heap access immediates
- index: Dynamic index (in bytes) into the heap
Outputs:
- a: The value loaded from the heap
sourcefn heap_store<T1: Into<HeapImm>>(
self,
heap_imm: T1,
index: Value,
a: Value
) -> Inst
fn heap_store<T1: Into<HeapImm>>(
self,
heap_imm: T1,
index: Value,
a: Value
) -> Inst
Store a into the given heap at address index + offset,
trapping on out-of-bounds accesses.
Checks that index + offset .. index + offset + sizeof(a) is
within the heap’s bounds, trapping if it is not. Otherwise, when
that range is in bounds, stores the value into the heap.
Traps on index + offset + sizeof(a) overflow.
Inputs:
- heap_imm: Reference to out-of-line heap access immediates
- index: Dynamic index (in bytes) into the heap
- a: The value stored into the heap
sourcefn get_pinned_reg(self, iAddr: Type) -> Value
fn get_pinned_reg(self, iAddr: Type) -> Value
Gets the content of the pinned register, when it’s enabled.
Inputs:
- iAddr (controlling type variable): An integer address type
Outputs:
- addr: An integer address type
Examples found in repository?
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
fn compute_addr(
isa: &dyn TargetIsa,
pos: &mut FuncCursor,
heap: ir::Heap,
addr_ty: ir::Type,
index: ir::Value,
offset: u32,
// If we are performing Spectre mitigation with conditional selects, the
// values to compare and the condition code that indicates an out-of bounds
// condition; on this condition, the conditional move will choose a
// speculatively safe address (a zero / null pointer) instead.
spectre_oob_comparison: Option<SpectreOobComparison>,
) -> ir::Value {
debug_assert_eq!(pos.func.dfg.value_type(index), addr_ty);
// Add the heap base address base
let base = if isa.flags().enable_pinned_reg() && isa.flags().use_pinned_reg_as_heap_base() {
let base = pos.ins().get_pinned_reg(isa.pointer_type());
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
} else {
let base_gv = pos.func.heaps[heap].base;
let base = pos.ins().global_value(addr_ty, base_gv);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
};
if let Some(SpectreOobComparison { cc, lhs, rhs }) = spectre_oob_comparison {
let final_base = pos.ins().iadd(base, index);
// NB: The addition of the offset immediate must happen *before* the
// `select_spectre_guard`. If it happens after, then we potentially are
// letting speculative execution read the whole first 4GiB of memory.
let final_addr = if offset == 0 {
final_base
} else {
let final_addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_addr)
);
final_addr
};
let zero = pos.ins().iconst(addr_ty, 0);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(zero));
let cmp = pos.ins().icmp(cc, lhs, rhs);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(cmp));
let value = pos.ins().select_spectre_guard(cmp, zero, final_addr);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(value));
value
} else if offset == 0 {
let addr = pos.ins().iadd(base, index);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
} else {
let final_base = pos.ins().iadd(base, index);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_base)
);
let addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
}
}sourcefn set_pinned_reg(self, addr: Value) -> Inst
fn set_pinned_reg(self, addr: Value) -> Inst
Sets the content of the pinned register, when it’s enabled.
Inputs:
- addr: An integer address type
sourcefn get_frame_pointer(self, iAddr: Type) -> Value
fn get_frame_pointer(self, iAddr: Type) -> Value
Get the address in the frame pointer register.
Usage of this instruction requires setting preserve_frame_pointers to true.
Inputs:
- iAddr (controlling type variable): An integer address type
Outputs:
- addr: An integer address type
sourcefn get_stack_pointer(self, iAddr: Type) -> Value
fn get_stack_pointer(self, iAddr: Type) -> Value
Get the address in the stack pointer register.
Inputs:
- iAddr (controlling type variable): An integer address type
Outputs:
- addr: An integer address type
sourcefn get_return_address(self, iAddr: Type) -> Value
fn get_return_address(self, iAddr: Type) -> Value
Get the PC where this function will transfer control to when it returns.
Usage of this instruction requires setting preserve_frame_pointers to true.
Inputs:
- iAddr (controlling type variable): An integer address type
Outputs:
- addr: An integer address type
sourcefn table_addr<T1: Into<Offset32>>(
self,
iAddr: Type,
T: Table,
p: Value,
Offset: T1
) -> Value
fn table_addr<T1: Into<Offset32>>(
self,
iAddr: Type,
T: Table,
p: Value,
Offset: T1
) -> Value
Bounds check and compute absolute address of a table entry.
Verify that the offset p is in bounds for the table T, and generate
an absolute address that is safe to dereference.
Offset must be less than the size of a table element.
- If
pis not greater than the table bound, return an absolute address corresponding to a byte offset ofpfrom the table’s base address. - If
pis greater than the table bound, generate a trap.
Inputs:
- iAddr (controlling type variable): An integer address type
- T: A table.
- p: An unsigned table offset
- Offset: Byte offset from element address
Outputs:
- addr: An integer address type
sourcefn iconst<T1: Into<Imm64>>(self, NarrowInt: Type, N: T1) -> Value
fn iconst<T1: Into<Imm64>>(self, NarrowInt: Type, N: T1) -> Value
Integer constant.
Create a scalar integer SSA value with an immediate constant value, or an integer vector where all the lanes have the same value.
Inputs:
- NarrowInt (controlling type variable): An integer type with lanes type to
i64 - N: A 64-bit immediate integer.
Outputs:
- a: A constant integer scalar or vector value
Examples found in repository?
More examples
32 33 34 35 36 37 38 39 40 41 42 43 44 45
fn imm_const(pos: &mut FuncCursor, arg: Value, imm: Imm64, is_signed: bool) -> Value {
let ty = pos.func.dfg.value_type(arg);
match (ty, is_signed) {
(I128, true) => {
let imm = pos.ins().iconst(I64, imm);
pos.ins().sextend(I128, imm)
}
(I128, false) => {
let imm = pos.ins().iconst(I64, imm);
pos.ins().uextend(I128, imm)
}
_ => pos.ins().iconst(ty.lane_type(), imm),
}
}104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
fn bounds_check_and_compute_addr(
pos: &mut FuncCursor,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap: ir::Heap,
// Dynamic operand indexing into the heap.
index: ir::Value,
// Static immediate added to the index.
offset: u32,
// Static size of the heap access.
access_size: u8,
) -> ir::Value {
let pointer_type = isa.pointer_type();
let spectre = isa.flags().enable_heap_access_spectre_mitigation();
let offset_and_size = offset_plus_size(offset, access_size);
let ir::HeapData {
base: _,
min_size,
offset_guard_size: guard_size,
style,
index_type,
} = pos.func.heaps[heap].clone();
let index = cast_index_to_pointer_ty(index, index_type, pointer_type, pos);
// We need to emit code that will trap (or compute an address that will trap
// when accessed) if
//
// index + offset + access_size > bound
//
// or if the `index + offset + access_size` addition overflows.
//
// Note that we ultimately want a 64-bit integer (we only target 64-bit
// architectures at the moment) and that `offset` is a `u32` and
// `access_size` is a `u8`. This means that we can add the latter together
// as `u64`s without fear of overflow, and we only have to be concerned with
// whether adding in `index` will overflow.
//
// Finally, the following right-hand sides of the matches do have a little
// bit of duplicated code across them, but I think writing it this way is
// worth it for readability and seeing very clearly each of our cases for
// different bounds checks and optimizations of those bounds checks. It is
// intentionally written in a straightforward case-matching style that will
// hopefully make it easy to port to ISLE one day.
match style {
// ====== Dynamic Memories ======
//
// 1. First special case for when `offset + access_size == 1`:
//
// index + 1 > bound
// ==> index >= bound
//
// 1.a. When Spectre mitigations are enabled, avoid duplicating
// bounds checks between the mitigations and the regular bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThanOrEqual,
lhs: index,
rhs: bound,
}),
)
}
// 1.b. Emit explicit `index >= bound` bounds checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 2. Second special case for when `offset + access_size <= min_size`.
//
// We know that `bound >= min_size`, so we can do the following
// comparison, without fear of the right-hand side wrapping around:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// 2.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 2.b. Emit explicit `index > bound - (offset + access_size)` bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, index, adjusted_bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for dynamic memories:
//
// index + offset + access_size > bound
//
// And we have to handle the overflow case in the left-hand side.
//
// 3.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if spectre => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: adjusted_index,
rhs: bound,
}),
)
}
// 3.b. Emit an explicit `index + offset + access_size > bound`
// check.
ir::HeapStyle::Dynamic { bound_gv } => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, adjusted_index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// ====== Static Memories ======
//
// With static memories we know the size of the heap bound at compile
// time.
//
// 1. First special case: trap immediately if `offset + access_size >
// bound`, since we will end up being out-of-bounds regardless of the
// given `index`.
ir::HeapStyle::Static { bound } if offset_and_size > bound.into() => {
pos.ins().trap(ir::TrapCode::HeapOutOfBounds);
// Split the block, as the trap is a terminator instruction.
let curr_block = pos.current_block().expect("Cursor is not in a block");
let new_block = pos.func.dfg.make_block();
pos.insert_block(new_block);
cfg.recompute_block(pos.func, curr_block);
cfg.recompute_block(pos.func, new_block);
let null = pos.ins().iconst(pointer_type, 0);
return null;
}
// 2. Second special case for when we can completely omit explicit
// bounds checks for 32-bit static memories.
//
// First, let's rewrite our comparison to move all of the constants
// to one side:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// We know the subtraction on the right-hand side won't wrap because
// we didn't hit the first special case.
//
// Additionally, we add our guard pages (if any) to the right-hand
// side, since we can rely on the virtual memory subsystem at runtime
// to catch out-of-bound accesses within the range `bound .. bound +
// guard_size`. So now we are dealing with
//
// index > bound + guard_size - (offset + access_size)
//
// Note that `bound + guard_size` cannot overflow for
// correctly-configured heaps, as otherwise the heap wouldn't fit in
// a 64-bit memory space.
//
// The complement of our should-this-trap comparison expression is
// the should-this-not-trap comparison expression:
//
// index <= bound + guard_size - (offset + access_size)
//
// If we know the right-hand side is greater than or equal to
// `u32::MAX`, then
//
// index <= u32::MAX <= bound + guard_size - (offset + access_size)
//
// This expression is always true when the heap is indexed with
// 32-bit integers because `index` cannot be larger than
// `u32::MAX`. This means that `index` is always either in bounds or
// within the guard page region, neither of which require emitting an
// explicit bounds check.
ir::HeapStyle::Static { bound }
if index_type == ir::types::I32
&& u64::from(u32::MAX)
<= u64::from(bound) + u64::from(guard_size) - offset_and_size =>
{
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for static memories.
//
// We have to explicitly test whether
//
// index > bound - (offset + access_size)
//
// and trap if so.
//
// Since we have to emit explicit bounds checks, we might as well be
// precise, not rely on the virtual memory subsystem at all, and not
// factor in the guard pages here.
//
// 3.a. Dedupe the Spectre mitigation and the explicit bounds check.
ir::HeapStyle::Static { bound } if spectre => {
// NB: this subtraction cannot wrap because we didn't hit the first
// special case.
let adjusted_bound = u64::from(bound) - offset_and_size;
let adjusted_bound = pos.ins().iconst(pointer_type, adjusted_bound as i64);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 3.b. Emit the explicit `index > bound - (offset + access_size)`
// check.
ir::HeapStyle::Static { bound } => {
// See comment in 3.a. above.
let adjusted_bound = u64::from(bound) - offset_and_size;
let oob = pos
.ins()
.icmp_imm(IntCC::UnsignedGreaterThan, index, adjusted_bound as i64);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
}
}
fn cast_index_to_pointer_ty(
index: ir::Value,
index_ty: ir::Type,
pointer_ty: ir::Type,
pos: &mut FuncCursor,
) -> ir::Value {
if index_ty == pointer_ty {
return index;
}
// Note that using 64-bit heaps on a 32-bit host is not currently supported,
// would require at least a bounds check here to ensure that the truncation
// from 64-to-32 bits doesn't lose any upper bits. For now though we're
// mostly interested in the 32-bit-heaps-on-64-bit-hosts cast.
assert!(index_ty.bits() < pointer_ty.bits());
// Convert `index` to `addr_ty`.
let extended_index = pos.ins().uextend(pointer_ty, index);
// Add debug value-label alias so that debuginfo can name the extended
// value as the address
let loc = pos.srcloc();
let loc = RelSourceLoc::from_base_offset(pos.func.params.base_srcloc(), loc);
pos.func
.stencil
.dfg
.add_value_label_alias(extended_index, loc, index);
extended_index
}
struct SpectreOobComparison {
cc: IntCC,
lhs: ir::Value,
rhs: ir::Value,
}
/// Emit code for the base address computation of a `heap_addr` instruction,
/// without any bounds checks (other than optional Spectre mitigations).
fn compute_addr(
isa: &dyn TargetIsa,
pos: &mut FuncCursor,
heap: ir::Heap,
addr_ty: ir::Type,
index: ir::Value,
offset: u32,
// If we are performing Spectre mitigation with conditional selects, the
// values to compare and the condition code that indicates an out-of bounds
// condition; on this condition, the conditional move will choose a
// speculatively safe address (a zero / null pointer) instead.
spectre_oob_comparison: Option<SpectreOobComparison>,
) -> ir::Value {
debug_assert_eq!(pos.func.dfg.value_type(index), addr_ty);
// Add the heap base address base
let base = if isa.flags().enable_pinned_reg() && isa.flags().use_pinned_reg_as_heap_base() {
let base = pos.ins().get_pinned_reg(isa.pointer_type());
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
} else {
let base_gv = pos.func.heaps[heap].base;
let base = pos.ins().global_value(addr_ty, base_gv);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
};
if let Some(SpectreOobComparison { cc, lhs, rhs }) = spectre_oob_comparison {
let final_base = pos.ins().iadd(base, index);
// NB: The addition of the offset immediate must happen *before* the
// `select_spectre_guard`. If it happens after, then we potentially are
// letting speculative execution read the whole first 4GiB of memory.
let final_addr = if offset == 0 {
final_base
} else {
let final_addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_addr)
);
final_addr
};
let zero = pos.ins().iconst(addr_ty, 0);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(zero));
let cmp = pos.ins().icmp(cc, lhs, rhs);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(cmp));
let value = pos.ins().select_spectre_guard(cmp, zero, final_addr);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(value));
value
} else if offset == 0 {
let addr = pos.ins().iadd(base, index);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
} else {
let final_base = pos.ins().iadd(base, index);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_base)
);
let addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
}
}164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}
enum BranchOrderKind {
BrzToBrnz(Value),
BrnzToBrz(Value),
}
/// Reorder branches to encourage fallthroughs.
///
/// When a block ends with a conditional branch followed by an unconditional
/// branch, this will reorder them if one of them is branching to the next Block
/// layout-wise. The unconditional jump can then become a fallthrough.
fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, block: Block, inst: Inst) {
let (term_inst, term_inst_args, term_dest, cond_inst, cond_inst_args, cond_dest, kind) =
match pos.func.dfg[inst] {
InstructionData::Jump {
opcode: Opcode::Jump,
destination,
ref args,
} => {
let next_block = if let Some(next_block) = pos.func.layout.next_block(block) {
next_block
} else {
return;
};
if destination == next_block {
return;
}
let prev_inst = if let Some(prev_inst) = pos.func.layout.prev_inst(inst) {
prev_inst
} else {
return;
};
let prev_inst_data = &pos.func.dfg[prev_inst];
if let Some(prev_dest) = prev_inst_data.branch_destination() {
if prev_dest != next_block {
return;
}
} else {
return;
}
match prev_inst_data {
InstructionData::Branch {
opcode,
args: ref prev_args,
destination: cond_dest,
} => {
let cond_arg = {
let args = pos.func.dfg.inst_args(prev_inst);
args[0]
};
let kind = match opcode {
Opcode::Brz => BranchOrderKind::BrzToBrnz(cond_arg),
Opcode::Brnz => BranchOrderKind::BrnzToBrz(cond_arg),
_ => panic!("unexpected opcode"),
};
(
inst,
args.clone(),
destination,
prev_inst,
prev_args.clone(),
*cond_dest,
kind,
)
}
_ => return,
}
}
_ => return,
};
let cond_args = cond_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec();
let term_args = term_inst_args.as_slice(&pos.func.dfg.value_lists).to_vec();
match kind {
BranchOrderKind::BrnzToBrz(cond_arg) => {
pos.func
.dfg
.replace(term_inst)
.jump(cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(cond_inst)
.brz(cond_arg, term_dest, &term_args);
}
BranchOrderKind::BrzToBrnz(cond_arg) => {
pos.func
.dfg
.replace(term_inst)
.jump(cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(cond_inst)
.brnz(cond_arg, term_dest, &term_args);
}
}
cfg.recompute_block(pos.func, block);
}
mod simplify {
use super::*;
use crate::ir::{
dfg::ValueDef,
immediates,
instructions::{Opcode, ValueList},
types::{I16, I32, I8},
};
use std::marker::PhantomData;
pub struct PeepholeOptimizer<'a, 'b> {
phantom: PhantomData<(&'a (), &'b ())>,
}
pub fn peephole_optimizer<'a, 'b>(_: &dyn TargetIsa) -> PeepholeOptimizer<'a, 'b> {
PeepholeOptimizer {
phantom: PhantomData,
}
}
pub fn apply_all<'a, 'b>(
_optimizer: &mut PeepholeOptimizer<'a, 'b>,
pos: &mut FuncCursor<'a>,
inst: Inst,
native_word_width: u32,
) {
simplify(pos, inst, native_word_width);
branch_opt(pos, inst);
}
#[inline]
fn resolve_imm64_value(dfg: &DataFlowGraph, value: Value) -> Option<immediates::Imm64> {
if let ValueDef::Result(candidate_inst, _) = dfg.value_def(value) {
if let InstructionData::UnaryImm {
opcode: Opcode::Iconst,
imm,
} = dfg[candidate_inst]
{
return Some(imm);
}
}
None
}
/// Try to transform [(x << N) >> N] into a (un)signed-extending move.
/// Returns true if the final instruction has been converted to such a move.
fn try_fold_extended_move(
pos: &mut FuncCursor,
inst: Inst,
opcode: Opcode,
arg: Value,
imm: immediates::Imm64,
) -> bool {
if let ValueDef::Result(arg_inst, _) = pos.func.dfg.value_def(arg) {
if let InstructionData::BinaryImm64 {
opcode: Opcode::IshlImm,
arg: prev_arg,
imm: prev_imm,
} = &pos.func.dfg[arg_inst]
{
if imm != *prev_imm {
return false;
}
let dest_ty = pos.func.dfg.ctrl_typevar(inst);
if dest_ty != pos.func.dfg.ctrl_typevar(arg_inst) || !dest_ty.is_int() {
return false;
}
let imm_bits: i64 = imm.into();
let ireduce_ty = match (dest_ty.lane_bits() as i64).wrapping_sub(imm_bits) {
8 => I8,
16 => I16,
32 => I32,
_ => return false,
};
let ireduce_ty = ireduce_ty.by(dest_ty.lane_count()).unwrap();
// This becomes a no-op, since ireduce_ty has a smaller lane width than
// the argument type (also the destination type).
let arg = *prev_arg;
let narrower_arg = pos.ins().ireduce(ireduce_ty, arg);
if opcode == Opcode::UshrImm {
pos.func.dfg.replace(inst).uextend(dest_ty, narrower_arg);
} else {
pos.func.dfg.replace(inst).sextend(dest_ty, narrower_arg);
}
return true;
}
}
false
}
/// Apply basic simplifications.
///
/// This folds constants with arithmetic to form `_imm` instructions, and other minor
/// simplifications.
///
/// Doesn't apply some simplifications if the native word width (in bytes) is smaller than the
/// controlling type's width of the instruction. This would result in an illegal instruction that
/// would likely be expanded back into an instruction on smaller types with the same initial
/// opcode, creating unnecessary churn.
fn simplify(pos: &mut FuncCursor, inst: Inst, native_word_width: u32) {
match pos.func.dfg[inst] {
InstructionData::Binary { opcode, args } => {
if let Some(mut imm) = resolve_imm64_value(&pos.func.dfg, args[1]) {
let new_opcode = match opcode {
Opcode::Iadd => Opcode::IaddImm,
Opcode::Imul => Opcode::ImulImm,
Opcode::Sdiv => Opcode::SdivImm,
Opcode::Udiv => Opcode::UdivImm,
Opcode::Srem => Opcode::SremImm,
Opcode::Urem => Opcode::UremImm,
Opcode::Band => Opcode::BandImm,
Opcode::Bor => Opcode::BorImm,
Opcode::Bxor => Opcode::BxorImm,
Opcode::Rotl => Opcode::RotlImm,
Opcode::Rotr => Opcode::RotrImm,
Opcode::Ishl => Opcode::IshlImm,
Opcode::Ushr => Opcode::UshrImm,
Opcode::Sshr => Opcode::SshrImm,
Opcode::Isub => {
imm = imm.wrapping_neg();
Opcode::IaddImm
}
Opcode::Ifcmp => Opcode::IfcmpImm,
_ => return,
};
let ty = pos.func.dfg.ctrl_typevar(inst);
if ty.bytes() <= native_word_width {
pos.func
.dfg
.replace(inst)
.BinaryImm64(new_opcode, ty, imm, args[0]);
// Repeat for BinaryImm simplification.
simplify(pos, inst, native_word_width);
}
} else if let Some(imm) = resolve_imm64_value(&pos.func.dfg, args[0]) {
let new_opcode = match opcode {
Opcode::Iadd => Opcode::IaddImm,
Opcode::Imul => Opcode::ImulImm,
Opcode::Band => Opcode::BandImm,
Opcode::Bor => Opcode::BorImm,
Opcode::Bxor => Opcode::BxorImm,
Opcode::Isub => Opcode::IrsubImm,
_ => return,
};
let ty = pos.func.dfg.ctrl_typevar(inst);
if ty.bytes() <= native_word_width {
pos.func
.dfg
.replace(inst)
.BinaryImm64(new_opcode, ty, imm, args[1]);
}
}
}
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let ty = pos.func.dfg.ctrl_typevar(inst);
let mut arg = arg;
let mut imm = imm;
match opcode {
Opcode::IaddImm
| Opcode::ImulImm
| Opcode::BorImm
| Opcode::BandImm
| Opcode::BxorImm => {
// Fold binary_op(C2, binary_op(C1, x)) into binary_op(binary_op(C1, C2), x)
if let ValueDef::Result(arg_inst, _) = pos.func.dfg.value_def(arg) {
if let InstructionData::BinaryImm64 {
opcode: prev_opcode,
arg: prev_arg,
imm: prev_imm,
} = &pos.func.dfg[arg_inst]
{
if opcode == *prev_opcode
&& ty == pos.func.dfg.ctrl_typevar(arg_inst)
{
let lhs: i64 = imm.into();
let rhs: i64 = (*prev_imm).into();
let new_imm = match opcode {
Opcode::BorImm => lhs | rhs,
Opcode::BandImm => lhs & rhs,
Opcode::BxorImm => lhs ^ rhs,
Opcode::IaddImm => lhs.wrapping_add(rhs),
Opcode::ImulImm => lhs.wrapping_mul(rhs),
_ => panic!("can't happen"),
};
let new_imm = immediates::Imm64::from(new_imm);
let new_arg = *prev_arg;
pos.func
.dfg
.replace(inst)
.BinaryImm64(opcode, ty, new_imm, new_arg);
imm = new_imm;
arg = new_arg;
}
}
}
}
Opcode::UshrImm | Opcode::SshrImm => {
if pos.func.dfg.ctrl_typevar(inst).bytes() <= native_word_width
&& try_fold_extended_move(pos, inst, opcode, arg, imm)
{
return;
}
}
_ => {}
};
// Replace operations that are no-ops.
match (opcode, imm.into(), ty) {
(Opcode::IaddImm, 0, _)
| (Opcode::ImulImm, 1, _)
| (Opcode::SdivImm, 1, _)
| (Opcode::UdivImm, 1, _)
| (Opcode::BorImm, 0, _)
| (Opcode::BandImm, -1, _)
| (Opcode::BxorImm, 0, _)
| (Opcode::RotlImm, 0, _)
| (Opcode::RotrImm, 0, _)
| (Opcode::IshlImm, 0, _)
| (Opcode::UshrImm, 0, _)
| (Opcode::SshrImm, 0, _) => {
// Alias the result value with the original argument.
replace_single_result_with_alias(&mut pos.func.dfg, inst, arg);
}
(Opcode::ImulImm, 0, ty) | (Opcode::BandImm, 0, ty) if ty != I128 => {
// Replace by zero.
pos.func.dfg.replace(inst).iconst(ty, 0);
}
(Opcode::BorImm, -1, ty) if ty != I128 => {
// Replace by minus one.
pos.func.dfg.replace(inst).iconst(ty, -1);
}
_ => {}
}
}
InstructionData::IntCompare { opcode, cond, args } => {
debug_assert_eq!(opcode, Opcode::Icmp);
if let Some(imm) = resolve_imm64_value(&pos.func.dfg, args[1]) {
if pos.func.dfg.ctrl_typevar(inst).bytes() <= native_word_width {
pos.func.dfg.replace(inst).icmp_imm(cond, args[0], imm);
}
}
}
_ => {}
}
}sourcefn f32const<T1: Into<Ieee32>>(self, N: T1) -> Value
fn f32const<T1: Into<Ieee32>>(self, N: T1) -> Value
Floating point constant.
Create a f32 SSA value with an immediate constant value.
Inputs:
- N: A 32-bit immediate floating point number.
Outputs:
- a: A constant f32 scalar value
Examples found in repository?
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn add_nan_canon_seq(pos: &mut FuncCursor, inst: Inst) {
// Select the instruction result, result type. Replace the instruction
// result and step forward before inserting the canonicalization sequence.
let val = pos.func.dfg.first_result(inst);
let val_type = pos.func.dfg.value_type(val);
let new_res = pos.func.dfg.replace_result(val, val_type);
let _next_inst = pos.next_inst().expect("block missing terminator!");
// Insert a comparison instruction, to check if `inst_res` is NaN. Select
// the canonical NaN value if `val` is NaN, assign the result to `inst`.
let is_nan = pos.ins().fcmp(FloatCC::NotEqual, new_res, new_res);
let scalar_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.select(is_nan, canon_nan, new_res);
};
let vector_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.vselect(is_nan, canon_nan, new_res);
};
match val_type {
types::F32 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F64 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F32X4 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
let canon_nan = pos.ins().splat(types::F32X4, canon_nan);
vector_select(pos, canon_nan);
}
types::F64X2 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
let canon_nan = pos.ins().splat(types::F64X2, canon_nan);
vector_select(pos, canon_nan);
}
_ => {
// Panic if the type given was not an IEEE floating point type.
panic!("Could not canonicalize NaN: Unexpected result type found.");
}
}
pos.prev_inst(); // Step backwards so the pass does not skip instructions.
}sourcefn f64const<T1: Into<Ieee64>>(self, N: T1) -> Value
fn f64const<T1: Into<Ieee64>>(self, N: T1) -> Value
Floating point constant.
Create a f64 SSA value with an immediate constant value.
Inputs:
- N: A 64-bit immediate floating point number.
Outputs:
- a: A constant f64 scalar value
Examples found in repository?
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn add_nan_canon_seq(pos: &mut FuncCursor, inst: Inst) {
// Select the instruction result, result type. Replace the instruction
// result and step forward before inserting the canonicalization sequence.
let val = pos.func.dfg.first_result(inst);
let val_type = pos.func.dfg.value_type(val);
let new_res = pos.func.dfg.replace_result(val, val_type);
let _next_inst = pos.next_inst().expect("block missing terminator!");
// Insert a comparison instruction, to check if `inst_res` is NaN. Select
// the canonical NaN value if `val` is NaN, assign the result to `inst`.
let is_nan = pos.ins().fcmp(FloatCC::NotEqual, new_res, new_res);
let scalar_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.select(is_nan, canon_nan, new_res);
};
let vector_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.vselect(is_nan, canon_nan, new_res);
};
match val_type {
types::F32 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F64 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F32X4 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
let canon_nan = pos.ins().splat(types::F32X4, canon_nan);
vector_select(pos, canon_nan);
}
types::F64X2 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
let canon_nan = pos.ins().splat(types::F64X2, canon_nan);
vector_select(pos, canon_nan);
}
_ => {
// Panic if the type given was not an IEEE floating point type.
panic!("Could not canonicalize NaN: Unexpected result type found.");
}
}
pos.prev_inst(); // Step backwards so the pass does not skip instructions.
}sourcefn vconst<T1: Into<Constant>>(self, TxN: Type, N: T1) -> Value
fn vconst<T1: Into<Constant>>(self, TxN: Type, N: T1) -> Value
SIMD vector constant.
Construct a vector with the given immediate bytes.
Inputs:
- TxN (controlling type variable): A SIMD vector type
- N: The 16 immediate bytes of a 128-bit vector
Outputs:
- a: A constant vector value
sourcefn shuffle<T1: Into<Immediate>>(self, a: Value, b: Value, mask: T1) -> Value
fn shuffle<T1: Into<Immediate>>(self, a: Value, b: Value, mask: T1) -> Value
SIMD vector shuffle.
Shuffle two vectors using the given immediate bytes. For each of the 16 bytes of the immediate, a value i of 0-15 selects the i-th element of the first vector and a value i of 16-31 selects the (i-16)th element of the second vector. Immediate values outside of the 0-31 range place a 0 in the resulting vector lane.
Inputs:
- a: A vector value
- b: A vector value
- mask: The 16 immediate bytes used for selecting the elements to shuffle
Outputs:
- a: A vector value
sourcefn null(self, Ref: Type) -> Value
fn null(self, Ref: Type) -> Value
Null constant value for reference types.
Create a scalar reference SSA value with a constant null value.
Inputs:
- Ref (controlling type variable): A scalar reference type
Outputs:
- a: A constant reference null value
sourcefn nop(self) -> Inst
fn nop(self) -> Inst
Just a dummy instruction.
Note: this doesn’t compile to a machine code nop.
sourcefn select(self, c: Value, x: Value, y: Value) -> Value
fn select(self, c: Value, x: Value, y: Value) -> Value
Conditional select.
This instruction selects whole values. Use vselect for
lane-wise selection.
Inputs:
- c: Controlling value to test
- x: Value to use when
cis true - y: Value to use when
cis false
Outputs:
- a: Any integer, float, or reference scalar or vector type
Examples found in repository?
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn add_nan_canon_seq(pos: &mut FuncCursor, inst: Inst) {
// Select the instruction result, result type. Replace the instruction
// result and step forward before inserting the canonicalization sequence.
let val = pos.func.dfg.first_result(inst);
let val_type = pos.func.dfg.value_type(val);
let new_res = pos.func.dfg.replace_result(val, val_type);
let _next_inst = pos.next_inst().expect("block missing terminator!");
// Insert a comparison instruction, to check if `inst_res` is NaN. Select
// the canonical NaN value if `val` is NaN, assign the result to `inst`.
let is_nan = pos.ins().fcmp(FloatCC::NotEqual, new_res, new_res);
let scalar_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.select(is_nan, canon_nan, new_res);
};
let vector_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.vselect(is_nan, canon_nan, new_res);
};
match val_type {
types::F32 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F64 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F32X4 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
let canon_nan = pos.ins().splat(types::F32X4, canon_nan);
vector_select(pos, canon_nan);
}
types::F64X2 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
let canon_nan = pos.ins().splat(types::F64X2, canon_nan);
vector_select(pos, canon_nan);
}
_ => {
// Panic if the type given was not an IEEE floating point type.
panic!("Could not canonicalize NaN: Unexpected result type found.");
}
}
pos.prev_inst(); // Step backwards so the pass does not skip instructions.
}sourcefn select_spectre_guard(self, c: Value, x: Value, y: Value) -> Value
fn select_spectre_guard(self, c: Value, x: Value, y: Value) -> Value
Conditional select intended for Spectre guards.
This operation is semantically equivalent to a select instruction. However, it is guaranteed to not be removed or otherwise altered by any optimization pass, and is guaranteed to result in a conditional-move instruction, not a branch-based lowering. As such, it is suitable for use when producing Spectre guards. For example, a bounds-check may guard against unsafe speculation past a bounds-check conditional branch by passing the address or index to be accessed through a conditional move, also gated on the same condition. Because no Spectre-vulnerable processors are known to perform speculation on conditional move instructions, this is guaranteed to pick the correct input. If the selected input in case of overflow is a “safe” value, for example a null pointer that causes an exception in the speculative path, this ensures that no Spectre vulnerability will exist.
Inputs:
- c: Controlling value to test
- x: Value to use when
cis true - y: Value to use when
cis false
Outputs:
- a: Any integer, float, or reference scalar or vector type
Examples found in repository?
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
fn compute_addr(
inst: ir::Inst,
table: ir::Table,
addr_ty: ir::Type,
mut index: ir::Value,
index_ty: ir::Type,
element_offset: Offset32,
func: &mut ir::Function,
spectre_oob_cmp: Option<(ir::Value, ir::Value)>,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Convert `index` to `addr_ty`.
if index_ty != addr_ty {
index = pos.ins().uextend(addr_ty, index);
}
// Add the table base address base
let base_gv = pos.func.tables[table].base_gv;
let base = pos.ins().global_value(addr_ty, base_gv);
let element_size = pos.func.tables[table].element_size;
let mut offset;
let element_size: u64 = element_size.into();
if element_size == 1 {
offset = index;
} else if element_size.is_power_of_two() {
offset = pos
.ins()
.ishl_imm(index, i64::from(element_size.trailing_zeros()));
} else {
offset = pos.ins().imul_imm(index, element_size as i64);
}
let element_addr = if element_offset == Offset32::new(0) {
pos.ins().iadd(base, offset)
} else {
let imm: i64 = element_offset.into();
offset = pos.ins().iadd(base, offset);
pos.ins().iadd_imm(offset, imm)
};
let element_addr = if let Some((index, bound)) = spectre_oob_cmp {
let cond = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
// If out-of-bounds, choose the table base on the misspeculation path.
pos.ins().select_spectre_guard(cond, base, element_addr)
} else {
element_addr
};
let new_inst = pos.func.dfg.value_def(element_addr).inst().unwrap();
pos.func.dfg.replace_with_aliases(inst, new_inst);
pos.remove_inst();
}More examples
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
fn compute_addr(
isa: &dyn TargetIsa,
pos: &mut FuncCursor,
heap: ir::Heap,
addr_ty: ir::Type,
index: ir::Value,
offset: u32,
// If we are performing Spectre mitigation with conditional selects, the
// values to compare and the condition code that indicates an out-of bounds
// condition; on this condition, the conditional move will choose a
// speculatively safe address (a zero / null pointer) instead.
spectre_oob_comparison: Option<SpectreOobComparison>,
) -> ir::Value {
debug_assert_eq!(pos.func.dfg.value_type(index), addr_ty);
// Add the heap base address base
let base = if isa.flags().enable_pinned_reg() && isa.flags().use_pinned_reg_as_heap_base() {
let base = pos.ins().get_pinned_reg(isa.pointer_type());
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
} else {
let base_gv = pos.func.heaps[heap].base;
let base = pos.ins().global_value(addr_ty, base_gv);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
};
if let Some(SpectreOobComparison { cc, lhs, rhs }) = spectre_oob_comparison {
let final_base = pos.ins().iadd(base, index);
// NB: The addition of the offset immediate must happen *before* the
// `select_spectre_guard`. If it happens after, then we potentially are
// letting speculative execution read the whole first 4GiB of memory.
let final_addr = if offset == 0 {
final_base
} else {
let final_addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_addr)
);
final_addr
};
let zero = pos.ins().iconst(addr_ty, 0);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(zero));
let cmp = pos.ins().icmp(cc, lhs, rhs);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(cmp));
let value = pos.ins().select_spectre_guard(cmp, zero, final_addr);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(value));
value
} else if offset == 0 {
let addr = pos.ins().iadd(base, index);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
} else {
let final_base = pos.ins().iadd(base, index);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_base)
);
let addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
}
}sourcefn bitselect(self, c: Value, x: Value, y: Value) -> Value
fn bitselect(self, c: Value, x: Value, y: Value) -> Value
Conditional select of bits.
For each bit in c, this instruction selects the corresponding bit from x if the bit
in c is 1 and the corresponding bit from y if the bit in c is 0. See also:
select, vselect.
Inputs:
- c: Controlling value to test
- x: Value to use when
cis true - y: Value to use when
cis false
Outputs:
- a: Any integer, float, or reference scalar or vector type
sourcefn vsplit(self, x: Value) -> (Value, Value)
fn vsplit(self, x: Value) -> (Value, Value)
Split a vector into two halves.
Split the vector x into two separate values, each containing half of
the lanes from x. The result may be two scalars if x only had
two lanes.
Inputs:
- x: Vector to split
Outputs:
- lo: Low-numbered lanes of
x - hi: High-numbered lanes of
x
sourcefn vconcat(self, x: Value, y: Value) -> Value
fn vconcat(self, x: Value, y: Value) -> Value
Vector concatenation.
Return a vector formed by concatenating x and y. The resulting
vector type has twice as many lanes as each of the inputs. The lanes of
x appear as the low-numbered lanes, and the lanes of y become
the high-numbered lanes of a.
It is possible to form a vector by concatenating two scalars.
Inputs:
- x: Low-numbered lanes
- y: High-numbered lanes
Outputs:
- a: Concatenation of
xandy
sourcefn vselect(self, c: Value, x: Value, y: Value) -> Value
fn vselect(self, c: Value, x: Value, y: Value) -> Value
Vector lane select.
Select lanes from x or y controlled by the lanes of the truthy
vector c.
Inputs:
- c: Controlling vector
- x: Value to use where
cis true - y: Value to use where
cis false
Outputs:
- a: A SIMD vector type
Examples found in repository?
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn add_nan_canon_seq(pos: &mut FuncCursor, inst: Inst) {
// Select the instruction result, result type. Replace the instruction
// result and step forward before inserting the canonicalization sequence.
let val = pos.func.dfg.first_result(inst);
let val_type = pos.func.dfg.value_type(val);
let new_res = pos.func.dfg.replace_result(val, val_type);
let _next_inst = pos.next_inst().expect("block missing terminator!");
// Insert a comparison instruction, to check if `inst_res` is NaN. Select
// the canonical NaN value if `val` is NaN, assign the result to `inst`.
let is_nan = pos.ins().fcmp(FloatCC::NotEqual, new_res, new_res);
let scalar_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.select(is_nan, canon_nan, new_res);
};
let vector_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.vselect(is_nan, canon_nan, new_res);
};
match val_type {
types::F32 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F64 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F32X4 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
let canon_nan = pos.ins().splat(types::F32X4, canon_nan);
vector_select(pos, canon_nan);
}
types::F64X2 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
let canon_nan = pos.ins().splat(types::F64X2, canon_nan);
vector_select(pos, canon_nan);
}
_ => {
// Panic if the type given was not an IEEE floating point type.
panic!("Could not canonicalize NaN: Unexpected result type found.");
}
}
pos.prev_inst(); // Step backwards so the pass does not skip instructions.
}sourcefn vany_true(self, a: Value) -> Value
fn vany_true(self, a: Value) -> Value
Reduce a vector to a scalar boolean.
Return a scalar boolean true if any lane in a is non-zero, false otherwise.
Inputs:
- a: A SIMD vector type
Outputs:
- s: An integer type with 8 bits. WARNING: arithmetic on 8bit integers is incomplete
sourcefn vall_true(self, a: Value) -> Value
fn vall_true(self, a: Value) -> Value
Reduce a vector to a scalar boolean.
Return a scalar boolean true if all lanes in i are non-zero, false otherwise.
Inputs:
- a: A SIMD vector type
Outputs:
- s: An integer type with 8 bits. WARNING: arithmetic on 8bit integers is incomplete
sourcefn vhigh_bits(self, Int: Type, a: Value) -> Value
fn vhigh_bits(self, Int: Type, a: Value) -> Value
Reduce a vector to a scalar integer.
Return a scalar integer, consisting of the concatenation of the most significant bit
of each lane of a.
Inputs:
- Int (controlling type variable): A scalar or vector integer type
- a: A SIMD vector type
Outputs:
- x: A scalar or vector integer type
sourcefn icmp<T1: Into<IntCC>>(self, Cond: T1, x: Value, y: Value) -> Value
fn icmp<T1: Into<IntCC>>(self, Cond: T1, x: Value, y: Value) -> Value
Integer comparison.
The condition code determines if the operands are interpreted as signed or unsigned integers.
| Signed | Unsigned | Condition |
|---|---|---|
| eq | eq | Equal |
| ne | ne | Not equal |
| slt | ult | Less than |
| sge | uge | Greater than or equal |
| sgt | ugt | Greater than |
| sle | ule | Less than or equal |
When this instruction compares integer vectors, it returns a vector of lane-wise comparisons.
Inputs:
- Cond: An integer comparison condition code.
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a:
Examples found in repository?
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
pub fn expand_table_addr(
isa: &dyn TargetIsa,
inst: ir::Inst,
func: &mut ir::Function,
table: ir::Table,
index: ir::Value,
element_offset: Offset32,
) {
let bound_gv = func.tables[table].bound_gv;
let index_ty = func.dfg.value_type(index);
let addr_ty = func.dfg.value_type(func.dfg.first_result(inst));
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Start with the bounds check. Trap if `index + 1 > bound`.
let bound = pos.ins().global_value(index_ty, bound_gv);
// `index > bound - 1` is the same as `index >= bound`.
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::TableOutOfBounds);
// If Spectre mitigations are enabled, we will use a comparison to
// short-circuit the computed table element address to the start
// of the table on the misspeculation path when out-of-bounds.
let spectre_oob_cmp = if isa.flags().enable_table_access_spectre_mitigation() {
Some((index, bound))
} else {
None
};
compute_addr(
inst,
table,
addr_ty,
index,
index_ty,
element_offset,
pos.func,
spectre_oob_cmp,
);
}
/// Emit code for the base address computation of a `table_addr` instruction.
fn compute_addr(
inst: ir::Inst,
table: ir::Table,
addr_ty: ir::Type,
mut index: ir::Value,
index_ty: ir::Type,
element_offset: Offset32,
func: &mut ir::Function,
spectre_oob_cmp: Option<(ir::Value, ir::Value)>,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Convert `index` to `addr_ty`.
if index_ty != addr_ty {
index = pos.ins().uextend(addr_ty, index);
}
// Add the table base address base
let base_gv = pos.func.tables[table].base_gv;
let base = pos.ins().global_value(addr_ty, base_gv);
let element_size = pos.func.tables[table].element_size;
let mut offset;
let element_size: u64 = element_size.into();
if element_size == 1 {
offset = index;
} else if element_size.is_power_of_two() {
offset = pos
.ins()
.ishl_imm(index, i64::from(element_size.trailing_zeros()));
} else {
offset = pos.ins().imul_imm(index, element_size as i64);
}
let element_addr = if element_offset == Offset32::new(0) {
pos.ins().iadd(base, offset)
} else {
let imm: i64 = element_offset.into();
offset = pos.ins().iadd(base, offset);
pos.ins().iadd_imm(offset, imm)
};
let element_addr = if let Some((index, bound)) = spectre_oob_cmp {
let cond = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
// If out-of-bounds, choose the table base on the misspeculation path.
pos.ins().select_spectre_guard(cond, base, element_addr)
} else {
element_addr
};
let new_inst = pos.func.dfg.value_def(element_addr).inst().unwrap();
pos.func.dfg.replace_with_aliases(inst, new_inst);
pos.remove_inst();
}More examples
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
fn bounds_check_and_compute_addr(
pos: &mut FuncCursor,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap: ir::Heap,
// Dynamic operand indexing into the heap.
index: ir::Value,
// Static immediate added to the index.
offset: u32,
// Static size of the heap access.
access_size: u8,
) -> ir::Value {
let pointer_type = isa.pointer_type();
let spectre = isa.flags().enable_heap_access_spectre_mitigation();
let offset_and_size = offset_plus_size(offset, access_size);
let ir::HeapData {
base: _,
min_size,
offset_guard_size: guard_size,
style,
index_type,
} = pos.func.heaps[heap].clone();
let index = cast_index_to_pointer_ty(index, index_type, pointer_type, pos);
// We need to emit code that will trap (or compute an address that will trap
// when accessed) if
//
// index + offset + access_size > bound
//
// or if the `index + offset + access_size` addition overflows.
//
// Note that we ultimately want a 64-bit integer (we only target 64-bit
// architectures at the moment) and that `offset` is a `u32` and
// `access_size` is a `u8`. This means that we can add the latter together
// as `u64`s without fear of overflow, and we only have to be concerned with
// whether adding in `index` will overflow.
//
// Finally, the following right-hand sides of the matches do have a little
// bit of duplicated code across them, but I think writing it this way is
// worth it for readability and seeing very clearly each of our cases for
// different bounds checks and optimizations of those bounds checks. It is
// intentionally written in a straightforward case-matching style that will
// hopefully make it easy to port to ISLE one day.
match style {
// ====== Dynamic Memories ======
//
// 1. First special case for when `offset + access_size == 1`:
//
// index + 1 > bound
// ==> index >= bound
//
// 1.a. When Spectre mitigations are enabled, avoid duplicating
// bounds checks between the mitigations and the regular bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThanOrEqual,
lhs: index,
rhs: bound,
}),
)
}
// 1.b. Emit explicit `index >= bound` bounds checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 2. Second special case for when `offset + access_size <= min_size`.
//
// We know that `bound >= min_size`, so we can do the following
// comparison, without fear of the right-hand side wrapping around:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// 2.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 2.b. Emit explicit `index > bound - (offset + access_size)` bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, index, adjusted_bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for dynamic memories:
//
// index + offset + access_size > bound
//
// And we have to handle the overflow case in the left-hand side.
//
// 3.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if spectre => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: adjusted_index,
rhs: bound,
}),
)
}
// 3.b. Emit an explicit `index + offset + access_size > bound`
// check.
ir::HeapStyle::Dynamic { bound_gv } => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, adjusted_index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// ====== Static Memories ======
//
// With static memories we know the size of the heap bound at compile
// time.
//
// 1. First special case: trap immediately if `offset + access_size >
// bound`, since we will end up being out-of-bounds regardless of the
// given `index`.
ir::HeapStyle::Static { bound } if offset_and_size > bound.into() => {
pos.ins().trap(ir::TrapCode::HeapOutOfBounds);
// Split the block, as the trap is a terminator instruction.
let curr_block = pos.current_block().expect("Cursor is not in a block");
let new_block = pos.func.dfg.make_block();
pos.insert_block(new_block);
cfg.recompute_block(pos.func, curr_block);
cfg.recompute_block(pos.func, new_block);
let null = pos.ins().iconst(pointer_type, 0);
return null;
}
// 2. Second special case for when we can completely omit explicit
// bounds checks for 32-bit static memories.
//
// First, let's rewrite our comparison to move all of the constants
// to one side:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// We know the subtraction on the right-hand side won't wrap because
// we didn't hit the first special case.
//
// Additionally, we add our guard pages (if any) to the right-hand
// side, since we can rely on the virtual memory subsystem at runtime
// to catch out-of-bound accesses within the range `bound .. bound +
// guard_size`. So now we are dealing with
//
// index > bound + guard_size - (offset + access_size)
//
// Note that `bound + guard_size` cannot overflow for
// correctly-configured heaps, as otherwise the heap wouldn't fit in
// a 64-bit memory space.
//
// The complement of our should-this-trap comparison expression is
// the should-this-not-trap comparison expression:
//
// index <= bound + guard_size - (offset + access_size)
//
// If we know the right-hand side is greater than or equal to
// `u32::MAX`, then
//
// index <= u32::MAX <= bound + guard_size - (offset + access_size)
//
// This expression is always true when the heap is indexed with
// 32-bit integers because `index` cannot be larger than
// `u32::MAX`. This means that `index` is always either in bounds or
// within the guard page region, neither of which require emitting an
// explicit bounds check.
ir::HeapStyle::Static { bound }
if index_type == ir::types::I32
&& u64::from(u32::MAX)
<= u64::from(bound) + u64::from(guard_size) - offset_and_size =>
{
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for static memories.
//
// We have to explicitly test whether
//
// index > bound - (offset + access_size)
//
// and trap if so.
//
// Since we have to emit explicit bounds checks, we might as well be
// precise, not rely on the virtual memory subsystem at all, and not
// factor in the guard pages here.
//
// 3.a. Dedupe the Spectre mitigation and the explicit bounds check.
ir::HeapStyle::Static { bound } if spectre => {
// NB: this subtraction cannot wrap because we didn't hit the first
// special case.
let adjusted_bound = u64::from(bound) - offset_and_size;
let adjusted_bound = pos.ins().iconst(pointer_type, adjusted_bound as i64);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 3.b. Emit the explicit `index > bound - (offset + access_size)`
// check.
ir::HeapStyle::Static { bound } => {
// See comment in 3.a. above.
let adjusted_bound = u64::from(bound) - offset_and_size;
let oob = pos
.ins()
.icmp_imm(IntCC::UnsignedGreaterThan, index, adjusted_bound as i64);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
}
}
fn cast_index_to_pointer_ty(
index: ir::Value,
index_ty: ir::Type,
pointer_ty: ir::Type,
pos: &mut FuncCursor,
) -> ir::Value {
if index_ty == pointer_ty {
return index;
}
// Note that using 64-bit heaps on a 32-bit host is not currently supported,
// would require at least a bounds check here to ensure that the truncation
// from 64-to-32 bits doesn't lose any upper bits. For now though we're
// mostly interested in the 32-bit-heaps-on-64-bit-hosts cast.
assert!(index_ty.bits() < pointer_ty.bits());
// Convert `index` to `addr_ty`.
let extended_index = pos.ins().uextend(pointer_ty, index);
// Add debug value-label alias so that debuginfo can name the extended
// value as the address
let loc = pos.srcloc();
let loc = RelSourceLoc::from_base_offset(pos.func.params.base_srcloc(), loc);
pos.func
.stencil
.dfg
.add_value_label_alias(extended_index, loc, index);
extended_index
}
struct SpectreOobComparison {
cc: IntCC,
lhs: ir::Value,
rhs: ir::Value,
}
/// Emit code for the base address computation of a `heap_addr` instruction,
/// without any bounds checks (other than optional Spectre mitigations).
fn compute_addr(
isa: &dyn TargetIsa,
pos: &mut FuncCursor,
heap: ir::Heap,
addr_ty: ir::Type,
index: ir::Value,
offset: u32,
// If we are performing Spectre mitigation with conditional selects, the
// values to compare and the condition code that indicates an out-of bounds
// condition; on this condition, the conditional move will choose a
// speculatively safe address (a zero / null pointer) instead.
spectre_oob_comparison: Option<SpectreOobComparison>,
) -> ir::Value {
debug_assert_eq!(pos.func.dfg.value_type(index), addr_ty);
// Add the heap base address base
let base = if isa.flags().enable_pinned_reg() && isa.flags().use_pinned_reg_as_heap_base() {
let base = pos.ins().get_pinned_reg(isa.pointer_type());
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
} else {
let base_gv = pos.func.heaps[heap].base;
let base = pos.ins().global_value(addr_ty, base_gv);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
};
if let Some(SpectreOobComparison { cc, lhs, rhs }) = spectre_oob_comparison {
let final_base = pos.ins().iadd(base, index);
// NB: The addition of the offset immediate must happen *before* the
// `select_spectre_guard`. If it happens after, then we potentially are
// letting speculative execution read the whole first 4GiB of memory.
let final_addr = if offset == 0 {
final_base
} else {
let final_addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_addr)
);
final_addr
};
let zero = pos.ins().iconst(addr_ty, 0);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(zero));
let cmp = pos.ins().icmp(cc, lhs, rhs);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(cmp));
let value = pos.ins().select_spectre_guard(cmp, zero, final_addr);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(value));
value
} else if offset == 0 {
let addr = pos.ins().iadd(base, index);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
} else {
let final_base = pos.ins().iadd(base, index);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_base)
);
let addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
}
}sourcefn icmp_imm<T1: Into<IntCC>, T2: Into<Imm64>>(
self,
Cond: T1,
x: Value,
Y: T2
) -> Value
fn icmp_imm<T1: Into<IntCC>, T2: Into<Imm64>>(
self,
Cond: T1,
x: Value,
Y: T2
) -> Value
Compare scalar integer to a constant.
This is the same as the icmp instruction, except one operand is
a sign extended 64 bit immediate constant.
This instruction can only compare scalars. Use icmp for
lane-wise vector comparisons.
Inputs:
- Cond: An integer comparison condition code.
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: An integer type with 8 bits. WARNING: arithmetic on 8bit integers is incomplete
Examples found in repository?
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
fn simplify(pos: &mut FuncCursor, inst: Inst, native_word_width: u32) {
match pos.func.dfg[inst] {
InstructionData::Binary { opcode, args } => {
if let Some(mut imm) = resolve_imm64_value(&pos.func.dfg, args[1]) {
let new_opcode = match opcode {
Opcode::Iadd => Opcode::IaddImm,
Opcode::Imul => Opcode::ImulImm,
Opcode::Sdiv => Opcode::SdivImm,
Opcode::Udiv => Opcode::UdivImm,
Opcode::Srem => Opcode::SremImm,
Opcode::Urem => Opcode::UremImm,
Opcode::Band => Opcode::BandImm,
Opcode::Bor => Opcode::BorImm,
Opcode::Bxor => Opcode::BxorImm,
Opcode::Rotl => Opcode::RotlImm,
Opcode::Rotr => Opcode::RotrImm,
Opcode::Ishl => Opcode::IshlImm,
Opcode::Ushr => Opcode::UshrImm,
Opcode::Sshr => Opcode::SshrImm,
Opcode::Isub => {
imm = imm.wrapping_neg();
Opcode::IaddImm
}
Opcode::Ifcmp => Opcode::IfcmpImm,
_ => return,
};
let ty = pos.func.dfg.ctrl_typevar(inst);
if ty.bytes() <= native_word_width {
pos.func
.dfg
.replace(inst)
.BinaryImm64(new_opcode, ty, imm, args[0]);
// Repeat for BinaryImm simplification.
simplify(pos, inst, native_word_width);
}
} else if let Some(imm) = resolve_imm64_value(&pos.func.dfg, args[0]) {
let new_opcode = match opcode {
Opcode::Iadd => Opcode::IaddImm,
Opcode::Imul => Opcode::ImulImm,
Opcode::Band => Opcode::BandImm,
Opcode::Bor => Opcode::BorImm,
Opcode::Bxor => Opcode::BxorImm,
Opcode::Isub => Opcode::IrsubImm,
_ => return,
};
let ty = pos.func.dfg.ctrl_typevar(inst);
if ty.bytes() <= native_word_width {
pos.func
.dfg
.replace(inst)
.BinaryImm64(new_opcode, ty, imm, args[1]);
}
}
}
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let ty = pos.func.dfg.ctrl_typevar(inst);
let mut arg = arg;
let mut imm = imm;
match opcode {
Opcode::IaddImm
| Opcode::ImulImm
| Opcode::BorImm
| Opcode::BandImm
| Opcode::BxorImm => {
// Fold binary_op(C2, binary_op(C1, x)) into binary_op(binary_op(C1, C2), x)
if let ValueDef::Result(arg_inst, _) = pos.func.dfg.value_def(arg) {
if let InstructionData::BinaryImm64 {
opcode: prev_opcode,
arg: prev_arg,
imm: prev_imm,
} = &pos.func.dfg[arg_inst]
{
if opcode == *prev_opcode
&& ty == pos.func.dfg.ctrl_typevar(arg_inst)
{
let lhs: i64 = imm.into();
let rhs: i64 = (*prev_imm).into();
let new_imm = match opcode {
Opcode::BorImm => lhs | rhs,
Opcode::BandImm => lhs & rhs,
Opcode::BxorImm => lhs ^ rhs,
Opcode::IaddImm => lhs.wrapping_add(rhs),
Opcode::ImulImm => lhs.wrapping_mul(rhs),
_ => panic!("can't happen"),
};
let new_imm = immediates::Imm64::from(new_imm);
let new_arg = *prev_arg;
pos.func
.dfg
.replace(inst)
.BinaryImm64(opcode, ty, new_imm, new_arg);
imm = new_imm;
arg = new_arg;
}
}
}
}
Opcode::UshrImm | Opcode::SshrImm => {
if pos.func.dfg.ctrl_typevar(inst).bytes() <= native_word_width
&& try_fold_extended_move(pos, inst, opcode, arg, imm)
{
return;
}
}
_ => {}
};
// Replace operations that are no-ops.
match (opcode, imm.into(), ty) {
(Opcode::IaddImm, 0, _)
| (Opcode::ImulImm, 1, _)
| (Opcode::SdivImm, 1, _)
| (Opcode::UdivImm, 1, _)
| (Opcode::BorImm, 0, _)
| (Opcode::BandImm, -1, _)
| (Opcode::BxorImm, 0, _)
| (Opcode::RotlImm, 0, _)
| (Opcode::RotrImm, 0, _)
| (Opcode::IshlImm, 0, _)
| (Opcode::UshrImm, 0, _)
| (Opcode::SshrImm, 0, _) => {
// Alias the result value with the original argument.
replace_single_result_with_alias(&mut pos.func.dfg, inst, arg);
}
(Opcode::ImulImm, 0, ty) | (Opcode::BandImm, 0, ty) if ty != I128 => {
// Replace by zero.
pos.func.dfg.replace(inst).iconst(ty, 0);
}
(Opcode::BorImm, -1, ty) if ty != I128 => {
// Replace by minus one.
pos.func.dfg.replace(inst).iconst(ty, -1);
}
_ => {}
}
}
InstructionData::IntCompare { opcode, cond, args } => {
debug_assert_eq!(opcode, Opcode::Icmp);
if let Some(imm) = resolve_imm64_value(&pos.func.dfg, args[1]) {
if pos.func.dfg.ctrl_typevar(inst).bytes() <= native_word_width {
pos.func.dfg.replace(inst).icmp_imm(cond, args[0], imm);
}
}
}
_ => {}
}
}More examples
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
fn bounds_check_and_compute_addr(
pos: &mut FuncCursor,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap: ir::Heap,
// Dynamic operand indexing into the heap.
index: ir::Value,
// Static immediate added to the index.
offset: u32,
// Static size of the heap access.
access_size: u8,
) -> ir::Value {
let pointer_type = isa.pointer_type();
let spectre = isa.flags().enable_heap_access_spectre_mitigation();
let offset_and_size = offset_plus_size(offset, access_size);
let ir::HeapData {
base: _,
min_size,
offset_guard_size: guard_size,
style,
index_type,
} = pos.func.heaps[heap].clone();
let index = cast_index_to_pointer_ty(index, index_type, pointer_type, pos);
// We need to emit code that will trap (or compute an address that will trap
// when accessed) if
//
// index + offset + access_size > bound
//
// or if the `index + offset + access_size` addition overflows.
//
// Note that we ultimately want a 64-bit integer (we only target 64-bit
// architectures at the moment) and that `offset` is a `u32` and
// `access_size` is a `u8`. This means that we can add the latter together
// as `u64`s without fear of overflow, and we only have to be concerned with
// whether adding in `index` will overflow.
//
// Finally, the following right-hand sides of the matches do have a little
// bit of duplicated code across them, but I think writing it this way is
// worth it for readability and seeing very clearly each of our cases for
// different bounds checks and optimizations of those bounds checks. It is
// intentionally written in a straightforward case-matching style that will
// hopefully make it easy to port to ISLE one day.
match style {
// ====== Dynamic Memories ======
//
// 1. First special case for when `offset + access_size == 1`:
//
// index + 1 > bound
// ==> index >= bound
//
// 1.a. When Spectre mitigations are enabled, avoid duplicating
// bounds checks between the mitigations and the regular bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThanOrEqual,
lhs: index,
rhs: bound,
}),
)
}
// 1.b. Emit explicit `index >= bound` bounds checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 2. Second special case for when `offset + access_size <= min_size`.
//
// We know that `bound >= min_size`, so we can do the following
// comparison, without fear of the right-hand side wrapping around:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// 2.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 2.b. Emit explicit `index > bound - (offset + access_size)` bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, index, adjusted_bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for dynamic memories:
//
// index + offset + access_size > bound
//
// And we have to handle the overflow case in the left-hand side.
//
// 3.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if spectre => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: adjusted_index,
rhs: bound,
}),
)
}
// 3.b. Emit an explicit `index + offset + access_size > bound`
// check.
ir::HeapStyle::Dynamic { bound_gv } => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, adjusted_index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// ====== Static Memories ======
//
// With static memories we know the size of the heap bound at compile
// time.
//
// 1. First special case: trap immediately if `offset + access_size >
// bound`, since we will end up being out-of-bounds regardless of the
// given `index`.
ir::HeapStyle::Static { bound } if offset_and_size > bound.into() => {
pos.ins().trap(ir::TrapCode::HeapOutOfBounds);
// Split the block, as the trap is a terminator instruction.
let curr_block = pos.current_block().expect("Cursor is not in a block");
let new_block = pos.func.dfg.make_block();
pos.insert_block(new_block);
cfg.recompute_block(pos.func, curr_block);
cfg.recompute_block(pos.func, new_block);
let null = pos.ins().iconst(pointer_type, 0);
return null;
}
// 2. Second special case for when we can completely omit explicit
// bounds checks for 32-bit static memories.
//
// First, let's rewrite our comparison to move all of the constants
// to one side:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// We know the subtraction on the right-hand side won't wrap because
// we didn't hit the first special case.
//
// Additionally, we add our guard pages (if any) to the right-hand
// side, since we can rely on the virtual memory subsystem at runtime
// to catch out-of-bound accesses within the range `bound .. bound +
// guard_size`. So now we are dealing with
//
// index > bound + guard_size - (offset + access_size)
//
// Note that `bound + guard_size` cannot overflow for
// correctly-configured heaps, as otherwise the heap wouldn't fit in
// a 64-bit memory space.
//
// The complement of our should-this-trap comparison expression is
// the should-this-not-trap comparison expression:
//
// index <= bound + guard_size - (offset + access_size)
//
// If we know the right-hand side is greater than or equal to
// `u32::MAX`, then
//
// index <= u32::MAX <= bound + guard_size - (offset + access_size)
//
// This expression is always true when the heap is indexed with
// 32-bit integers because `index` cannot be larger than
// `u32::MAX`. This means that `index` is always either in bounds or
// within the guard page region, neither of which require emitting an
// explicit bounds check.
ir::HeapStyle::Static { bound }
if index_type == ir::types::I32
&& u64::from(u32::MAX)
<= u64::from(bound) + u64::from(guard_size) - offset_and_size =>
{
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for static memories.
//
// We have to explicitly test whether
//
// index > bound - (offset + access_size)
//
// and trap if so.
//
// Since we have to emit explicit bounds checks, we might as well be
// precise, not rely on the virtual memory subsystem at all, and not
// factor in the guard pages here.
//
// 3.a. Dedupe the Spectre mitigation and the explicit bounds check.
ir::HeapStyle::Static { bound } if spectre => {
// NB: this subtraction cannot wrap because we didn't hit the first
// special case.
let adjusted_bound = u64::from(bound) - offset_and_size;
let adjusted_bound = pos.ins().iconst(pointer_type, adjusted_bound as i64);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 3.b. Emit the explicit `index > bound - (offset + access_size)`
// check.
ir::HeapStyle::Static { bound } => {
// See comment in 3.a. above.
let adjusted_bound = u64::from(bound) - offset_and_size;
let oob = pos
.ins()
.icmp_imm(IntCC::UnsignedGreaterThan, index, adjusted_bound as i64);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
}
}sourcefn ifcmp(self, x: Value, y: Value) -> Value
fn ifcmp(self, x: Value, y: Value) -> Value
Compare scalar integers and return flags.
Compare two scalar integer values and return integer CPU flags representing the result.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
Outputs:
- f: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn ifcmp_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn ifcmp_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Compare scalar integer to a constant and return flags.
Like icmp_imm, but returns integer CPU flags instead of testing
a specific condition code.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- f: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
sourcefn iadd(self, x: Value, y: Value) -> Value
fn iadd(self, x: Value, y: Value) -> Value
Wrapping integer addition: a := x + y \pmod{2^B}.
This instruction does not depend on the signed/unsigned interpretation of the operands.
Inputs:
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
fn compute_addr(
inst: ir::Inst,
table: ir::Table,
addr_ty: ir::Type,
mut index: ir::Value,
index_ty: ir::Type,
element_offset: Offset32,
func: &mut ir::Function,
spectre_oob_cmp: Option<(ir::Value, ir::Value)>,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Convert `index` to `addr_ty`.
if index_ty != addr_ty {
index = pos.ins().uextend(addr_ty, index);
}
// Add the table base address base
let base_gv = pos.func.tables[table].base_gv;
let base = pos.ins().global_value(addr_ty, base_gv);
let element_size = pos.func.tables[table].element_size;
let mut offset;
let element_size: u64 = element_size.into();
if element_size == 1 {
offset = index;
} else if element_size.is_power_of_two() {
offset = pos
.ins()
.ishl_imm(index, i64::from(element_size.trailing_zeros()));
} else {
offset = pos.ins().imul_imm(index, element_size as i64);
}
let element_addr = if element_offset == Offset32::new(0) {
pos.ins().iadd(base, offset)
} else {
let imm: i64 = element_offset.into();
offset = pos.ins().iadd(base, offset);
pos.ins().iadd_imm(offset, imm)
};
let element_addr = if let Some((index, bound)) = spectre_oob_cmp {
let cond = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
// If out-of-bounds, choose the table base on the misspeculation path.
pos.ins().select_spectre_guard(cond, base, element_addr)
} else {
element_addr
};
let new_inst = pos.func.dfg.value_def(element_addr).inst().unwrap();
pos.func.dfg.replace_with_aliases(inst, new_inst);
pos.remove_inst();
}More examples
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
fn compute_addr(
isa: &dyn TargetIsa,
pos: &mut FuncCursor,
heap: ir::Heap,
addr_ty: ir::Type,
index: ir::Value,
offset: u32,
// If we are performing Spectre mitigation with conditional selects, the
// values to compare and the condition code that indicates an out-of bounds
// condition; on this condition, the conditional move will choose a
// speculatively safe address (a zero / null pointer) instead.
spectre_oob_comparison: Option<SpectreOobComparison>,
) -> ir::Value {
debug_assert_eq!(pos.func.dfg.value_type(index), addr_ty);
// Add the heap base address base
let base = if isa.flags().enable_pinned_reg() && isa.flags().use_pinned_reg_as_heap_base() {
let base = pos.ins().get_pinned_reg(isa.pointer_type());
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
} else {
let base_gv = pos.func.heaps[heap].base;
let base = pos.ins().global_value(addr_ty, base_gv);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
};
if let Some(SpectreOobComparison { cc, lhs, rhs }) = spectre_oob_comparison {
let final_base = pos.ins().iadd(base, index);
// NB: The addition of the offset immediate must happen *before* the
// `select_spectre_guard`. If it happens after, then we potentially are
// letting speculative execution read the whole first 4GiB of memory.
let final_addr = if offset == 0 {
final_base
} else {
let final_addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_addr)
);
final_addr
};
let zero = pos.ins().iconst(addr_ty, 0);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(zero));
let cmp = pos.ins().icmp(cc, lhs, rhs);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(cmp));
let value = pos.ins().select_spectre_guard(cmp, zero, final_addr);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(value));
value
} else if offset == 0 {
let addr = pos.ins().iadd(base, index);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
} else {
let final_base = pos.ins().iadd(base, index);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_base)
);
let addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
}
}49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}sourcefn isub(self, x: Value, y: Value) -> Value
fn isub(self, x: Value, y: Value) -> Value
Wrapping integer subtraction: a := x - y \pmod{2^B}.
This instruction does not depend on the signed/unsigned interpretation of the operands.
Inputs:
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}More examples
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}sourcefn ineg(self, x: Value) -> Value
fn ineg(self, x: Value) -> Value
Integer negation: a := -x \pmod{2^B}.
Inputs:
- x: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
sourcefn iabs(self, x: Value) -> Value
fn iabs(self, x: Value) -> Value
Integer absolute value with wrapping: a := |x|.
Inputs:
- x: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
sourcefn imul(self, x: Value, y: Value) -> Value
fn imul(self, x: Value, y: Value) -> Value
Wrapping integer multiplication: a := x y \pmod{2^B}.
This instruction does not depend on the signed/unsigned interpretation of the operands.
Polymorphic over all integer types (vector and scalar).
Inputs:
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn umulhi(self, x: Value, y: Value) -> Value
fn umulhi(self, x: Value, y: Value) -> Value
Unsigned integer multiplication, producing the high half of a double-length result.
Polymorphic over all integer types (vector and scalar).
Inputs:
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}sourcefn smulhi(self, x: Value, y: Value) -> Value
fn smulhi(self, x: Value, y: Value) -> Value
Signed integer multiplication, producing the high half of a double-length result.
Polymorphic over all integer types (vector and scalar).
Inputs:
- x: A scalar or vector integer type
- y: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}sourcefn sqmul_round_sat(self, x: Value, y: Value) -> Value
fn sqmul_round_sat(self, x: Value, y: Value) -> Value
Fixed-point multiplication of numbers in the QN format, where N + 1
is the number bitwidth:
a := signed_saturate((x * y + 1 << (Q - 1)) >> Q)
Polymorphic over all integer types (scalar and vector) with 16- or 32-bit numbers.
Inputs:
- x: A scalar or vector integer type with 16- or 32-bit numbers
- y: A scalar or vector integer type with 16- or 32-bit numbers
Outputs:
- a: A scalar or vector integer type with 16- or 32-bit numbers
sourcefn udiv(self, x: Value, y: Value) -> Value
fn udiv(self, x: Value, y: Value) -> Value
Unsigned integer division: a := \lfloor {x \over y} \rfloor.
This operation traps if the divisor is zero.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
Outputs:
- a: A scalar integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn sdiv(self, x: Value, y: Value) -> Value
fn sdiv(self, x: Value, y: Value) -> Value
Signed integer division rounded toward zero: a := sign(xy) \lfloor {|x| \over |y|}\rfloor.
This operation traps if the divisor is zero, or if the result is not
representable in B bits two’s complement. This only happens
when x = -2^{B-1}, y = -1.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
Outputs:
- a: A scalar integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn urem(self, x: Value, y: Value) -> Value
fn urem(self, x: Value, y: Value) -> Value
Unsigned integer remainder.
This operation traps if the divisor is zero.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
Outputs:
- a: A scalar integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn srem(self, x: Value, y: Value) -> Value
fn srem(self, x: Value, y: Value) -> Value
Signed integer remainder. The result has the sign of the dividend.
This operation traps if the divisor is zero.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
Outputs:
- a: A scalar integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn iadd_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn iadd_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Add immediate integer.
Same as iadd, but one operand is a sign extended 64 bit immediate constant.
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
Examples found in repository?
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
fn iadd_imm_addr(
inst: ir::Inst,
func: &mut ir::Function,
base: ir::GlobalValue,
offset: i64,
global_type: ir::Type,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
// Get the value for the lhs. For tidiness, expand VMContext here so that we avoid
// `vmctx_addr` which creates an otherwise unneeded value alias.
let lhs = if let ir::GlobalValueData::VMContext = pos.func.global_values[base] {
pos.func
.special_param(ir::ArgumentPurpose::VMContext)
.expect("Missing vmctx parameter")
} else {
pos.ins().global_value(global_type, base)
};
// Simply replace the `global_value` instruction with an `iadd_imm`, reusing the result value.
pos.func.dfg.replace(inst).iadd_imm(lhs, offset);
}More examples
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
fn compute_addr(
inst: ir::Inst,
table: ir::Table,
addr_ty: ir::Type,
mut index: ir::Value,
index_ty: ir::Type,
element_offset: Offset32,
func: &mut ir::Function,
spectre_oob_cmp: Option<(ir::Value, ir::Value)>,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Convert `index` to `addr_ty`.
if index_ty != addr_ty {
index = pos.ins().uextend(addr_ty, index);
}
// Add the table base address base
let base_gv = pos.func.tables[table].base_gv;
let base = pos.ins().global_value(addr_ty, base_gv);
let element_size = pos.func.tables[table].element_size;
let mut offset;
let element_size: u64 = element_size.into();
if element_size == 1 {
offset = index;
} else if element_size.is_power_of_two() {
offset = pos
.ins()
.ishl_imm(index, i64::from(element_size.trailing_zeros()));
} else {
offset = pos.ins().imul_imm(index, element_size as i64);
}
let element_addr = if element_offset == Offset32::new(0) {
pos.ins().iadd(base, offset)
} else {
let imm: i64 = element_offset.into();
offset = pos.ins().iadd(base, offset);
pos.ins().iadd_imm(offset, imm)
};
let element_addr = if let Some((index, bound)) = spectre_oob_cmp {
let cond = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
// If out-of-bounds, choose the table base on the misspeculation path.
pos.ins().select_spectre_guard(cond, base, element_addr)
} else {
element_addr
};
let new_inst = pos.func.dfg.value_def(element_addr).inst().unwrap();
pos.func.dfg.replace_with_aliases(inst, new_inst);
pos.remove_inst();
}104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
fn bounds_check_and_compute_addr(
pos: &mut FuncCursor,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap: ir::Heap,
// Dynamic operand indexing into the heap.
index: ir::Value,
// Static immediate added to the index.
offset: u32,
// Static size of the heap access.
access_size: u8,
) -> ir::Value {
let pointer_type = isa.pointer_type();
let spectre = isa.flags().enable_heap_access_spectre_mitigation();
let offset_and_size = offset_plus_size(offset, access_size);
let ir::HeapData {
base: _,
min_size,
offset_guard_size: guard_size,
style,
index_type,
} = pos.func.heaps[heap].clone();
let index = cast_index_to_pointer_ty(index, index_type, pointer_type, pos);
// We need to emit code that will trap (or compute an address that will trap
// when accessed) if
//
// index + offset + access_size > bound
//
// or if the `index + offset + access_size` addition overflows.
//
// Note that we ultimately want a 64-bit integer (we only target 64-bit
// architectures at the moment) and that `offset` is a `u32` and
// `access_size` is a `u8`. This means that we can add the latter together
// as `u64`s without fear of overflow, and we only have to be concerned with
// whether adding in `index` will overflow.
//
// Finally, the following right-hand sides of the matches do have a little
// bit of duplicated code across them, but I think writing it this way is
// worth it for readability and seeing very clearly each of our cases for
// different bounds checks and optimizations of those bounds checks. It is
// intentionally written in a straightforward case-matching style that will
// hopefully make it easy to port to ISLE one day.
match style {
// ====== Dynamic Memories ======
//
// 1. First special case for when `offset + access_size == 1`:
//
// index + 1 > bound
// ==> index >= bound
//
// 1.a. When Spectre mitigations are enabled, avoid duplicating
// bounds checks between the mitigations and the regular bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThanOrEqual,
lhs: index,
rhs: bound,
}),
)
}
// 1.b. Emit explicit `index >= bound` bounds checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 2. Second special case for when `offset + access_size <= min_size`.
//
// We know that `bound >= min_size`, so we can do the following
// comparison, without fear of the right-hand side wrapping around:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// 2.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 2.b. Emit explicit `index > bound - (offset + access_size)` bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, index, adjusted_bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for dynamic memories:
//
// index + offset + access_size > bound
//
// And we have to handle the overflow case in the left-hand side.
//
// 3.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if spectre => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: adjusted_index,
rhs: bound,
}),
)
}
// 3.b. Emit an explicit `index + offset + access_size > bound`
// check.
ir::HeapStyle::Dynamic { bound_gv } => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, adjusted_index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// ====== Static Memories ======
//
// With static memories we know the size of the heap bound at compile
// time.
//
// 1. First special case: trap immediately if `offset + access_size >
// bound`, since we will end up being out-of-bounds regardless of the
// given `index`.
ir::HeapStyle::Static { bound } if offset_and_size > bound.into() => {
pos.ins().trap(ir::TrapCode::HeapOutOfBounds);
// Split the block, as the trap is a terminator instruction.
let curr_block = pos.current_block().expect("Cursor is not in a block");
let new_block = pos.func.dfg.make_block();
pos.insert_block(new_block);
cfg.recompute_block(pos.func, curr_block);
cfg.recompute_block(pos.func, new_block);
let null = pos.ins().iconst(pointer_type, 0);
return null;
}
// 2. Second special case for when we can completely omit explicit
// bounds checks for 32-bit static memories.
//
// First, let's rewrite our comparison to move all of the constants
// to one side:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// We know the subtraction on the right-hand side won't wrap because
// we didn't hit the first special case.
//
// Additionally, we add our guard pages (if any) to the right-hand
// side, since we can rely on the virtual memory subsystem at runtime
// to catch out-of-bound accesses within the range `bound .. bound +
// guard_size`. So now we are dealing with
//
// index > bound + guard_size - (offset + access_size)
//
// Note that `bound + guard_size` cannot overflow for
// correctly-configured heaps, as otherwise the heap wouldn't fit in
// a 64-bit memory space.
//
// The complement of our should-this-trap comparison expression is
// the should-this-not-trap comparison expression:
//
// index <= bound + guard_size - (offset + access_size)
//
// If we know the right-hand side is greater than or equal to
// `u32::MAX`, then
//
// index <= u32::MAX <= bound + guard_size - (offset + access_size)
//
// This expression is always true when the heap is indexed with
// 32-bit integers because `index` cannot be larger than
// `u32::MAX`. This means that `index` is always either in bounds or
// within the guard page region, neither of which require emitting an
// explicit bounds check.
ir::HeapStyle::Static { bound }
if index_type == ir::types::I32
&& u64::from(u32::MAX)
<= u64::from(bound) + u64::from(guard_size) - offset_and_size =>
{
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for static memories.
//
// We have to explicitly test whether
//
// index > bound - (offset + access_size)
//
// and trap if so.
//
// Since we have to emit explicit bounds checks, we might as well be
// precise, not rely on the virtual memory subsystem at all, and not
// factor in the guard pages here.
//
// 3.a. Dedupe the Spectre mitigation and the explicit bounds check.
ir::HeapStyle::Static { bound } if spectre => {
// NB: this subtraction cannot wrap because we didn't hit the first
// special case.
let adjusted_bound = u64::from(bound) - offset_and_size;
let adjusted_bound = pos.ins().iconst(pointer_type, adjusted_bound as i64);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 3.b. Emit the explicit `index > bound - (offset + access_size)`
// check.
ir::HeapStyle::Static { bound } => {
// See comment in 3.a. above.
let adjusted_bound = u64::from(bound) - offset_and_size;
let oob = pos
.ins()
.icmp_imm(IntCC::UnsignedGreaterThan, index, adjusted_bound as i64);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
}
}
fn cast_index_to_pointer_ty(
index: ir::Value,
index_ty: ir::Type,
pointer_ty: ir::Type,
pos: &mut FuncCursor,
) -> ir::Value {
if index_ty == pointer_ty {
return index;
}
// Note that using 64-bit heaps on a 32-bit host is not currently supported,
// would require at least a bounds check here to ensure that the truncation
// from 64-to-32 bits doesn't lose any upper bits. For now though we're
// mostly interested in the 32-bit-heaps-on-64-bit-hosts cast.
assert!(index_ty.bits() < pointer_ty.bits());
// Convert `index` to `addr_ty`.
let extended_index = pos.ins().uextend(pointer_ty, index);
// Add debug value-label alias so that debuginfo can name the extended
// value as the address
let loc = pos.srcloc();
let loc = RelSourceLoc::from_base_offset(pos.func.params.base_srcloc(), loc);
pos.func
.stencil
.dfg
.add_value_label_alias(extended_index, loc, index);
extended_index
}
struct SpectreOobComparison {
cc: IntCC,
lhs: ir::Value,
rhs: ir::Value,
}
/// Emit code for the base address computation of a `heap_addr` instruction,
/// without any bounds checks (other than optional Spectre mitigations).
fn compute_addr(
isa: &dyn TargetIsa,
pos: &mut FuncCursor,
heap: ir::Heap,
addr_ty: ir::Type,
index: ir::Value,
offset: u32,
// If we are performing Spectre mitigation with conditional selects, the
// values to compare and the condition code that indicates an out-of bounds
// condition; on this condition, the conditional move will choose a
// speculatively safe address (a zero / null pointer) instead.
spectre_oob_comparison: Option<SpectreOobComparison>,
) -> ir::Value {
debug_assert_eq!(pos.func.dfg.value_type(index), addr_ty);
// Add the heap base address base
let base = if isa.flags().enable_pinned_reg() && isa.flags().use_pinned_reg_as_heap_base() {
let base = pos.ins().get_pinned_reg(isa.pointer_type());
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
} else {
let base_gv = pos.func.heaps[heap].base;
let base = pos.ins().global_value(addr_ty, base_gv);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(base));
base
};
if let Some(SpectreOobComparison { cc, lhs, rhs }) = spectre_oob_comparison {
let final_base = pos.ins().iadd(base, index);
// NB: The addition of the offset immediate must happen *before* the
// `select_spectre_guard`. If it happens after, then we potentially are
// letting speculative execution read the whole first 4GiB of memory.
let final_addr = if offset == 0 {
final_base
} else {
let final_addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_addr)
);
final_addr
};
let zero = pos.ins().iconst(addr_ty, 0);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(zero));
let cmp = pos.ins().icmp(cc, lhs, rhs);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(cmp));
let value = pos.ins().select_spectre_guard(cmp, zero, final_addr);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(value));
value
} else if offset == 0 {
let addr = pos.ins().iadd(base, index);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
} else {
let final_base = pos.ins().iadd(base, index);
trace!(
" inserting: {}",
pos.func.dfg.display_value_inst(final_base)
);
let addr = pos.ins().iadd_imm(final_base, offset as i64);
trace!(" inserting: {}", pos.func.dfg.display_value_inst(addr));
addr
}
}sourcefn imul_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn imul_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Integer multiplication by immediate constant.
Same as imul, but one operand is a sign extended 64 bit immediate constant.
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
Examples found in repository?
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
fn compute_addr(
inst: ir::Inst,
table: ir::Table,
addr_ty: ir::Type,
mut index: ir::Value,
index_ty: ir::Type,
element_offset: Offset32,
func: &mut ir::Function,
spectre_oob_cmp: Option<(ir::Value, ir::Value)>,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Convert `index` to `addr_ty`.
if index_ty != addr_ty {
index = pos.ins().uextend(addr_ty, index);
}
// Add the table base address base
let base_gv = pos.func.tables[table].base_gv;
let base = pos.ins().global_value(addr_ty, base_gv);
let element_size = pos.func.tables[table].element_size;
let mut offset;
let element_size: u64 = element_size.into();
if element_size == 1 {
offset = index;
} else if element_size.is_power_of_two() {
offset = pos
.ins()
.ishl_imm(index, i64::from(element_size.trailing_zeros()));
} else {
offset = pos.ins().imul_imm(index, element_size as i64);
}
let element_addr = if element_offset == Offset32::new(0) {
pos.ins().iadd(base, offset)
} else {
let imm: i64 = element_offset.into();
offset = pos.ins().iadd(base, offset);
pos.ins().iadd_imm(offset, imm)
};
let element_addr = if let Some((index, bound)) = spectre_oob_cmp {
let cond = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
// If out-of-bounds, choose the table base on the misspeculation path.
pos.ins().select_spectre_guard(cond, base, element_addr)
} else {
element_addr
};
let new_inst = pos.func.dfg.value_def(element_addr).inst().unwrap();
pos.func.dfg.replace_with_aliases(inst, new_inst);
pos.remove_inst();
}More examples
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}sourcefn udiv_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn udiv_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Unsigned integer division by an immediate constant.
Same as udiv, but one operand is a zero extended 64 bit immediate constant.
This operation traps if the divisor is zero.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
sourcefn sdiv_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn sdiv_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Signed integer division by an immediate constant.
Same as sdiv, but one operand is a sign extended 64 bit immediate constant.
This operation traps if the divisor is zero, or if the result is not
representable in B bits two’s complement. This only happens
when x = -2^{B-1}, Y = -1.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
sourcefn urem_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn urem_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Unsigned integer remainder with immediate divisor.
Same as urem, but one operand is a zero extended 64 bit immediate constant.
This operation traps if the divisor is zero.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
sourcefn srem_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn srem_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Signed integer remainder with immediate divisor.
Same as srem, but one operand is a sign extended 64 bit immediate constant.
This operation traps if the divisor is zero.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
sourcefn irsub_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn irsub_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Immediate reverse wrapping subtraction: a := Y - x \pmod{2^B}.
The immediate operand is a sign extended 64 bit constant.
Also works as integer negation when Y = 0. Use iadd_imm
with a negative immediate operand for the reverse immediate
subtraction.
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
Examples found in repository?
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}sourcefn iadd_cin(self, x: Value, y: Value, c_in: Value) -> Value
fn iadd_cin(self, x: Value, y: Value, c_in: Value) -> Value
Add integers with carry in.
Same as iadd with an additional carry input. Computes:
a = x + y + c_{in} \pmod 2^B
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
- c_in: Input carry flag
Outputs:
- a: A scalar integer type
sourcefn iadd_ifcin(self, x: Value, y: Value, c_in: Value) -> Value
fn iadd_ifcin(self, x: Value, y: Value, c_in: Value) -> Value
Add integers with carry in.
Same as iadd with an additional carry flag input. Computes:
a = x + y + c_{in} \pmod 2^B
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
- c_in: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
Outputs:
- a: A scalar integer type
sourcefn iadd_cout(self, x: Value, y: Value) -> (Value, Value)
fn iadd_cout(self, x: Value, y: Value) -> (Value, Value)
Add integers with carry out.
Same as iadd with an additional carry output.
a &= x + y \pmod 2^B \\
c_{out} &= x+y >= 2^B
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
Outputs:
- a: A scalar integer type
- c_out: Output carry flag
sourcefn iadd_ifcout(self, x: Value, y: Value) -> (Value, Value)
fn iadd_ifcout(self, x: Value, y: Value) -> (Value, Value)
Add integers with carry out.
Same as iadd with an additional carry flag output.
a &= x + y \pmod 2^B \\
c_{out} &= x+y >= 2^B
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
Outputs:
- a: A scalar integer type
- c_out: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
sourcefn iadd_carry(self, x: Value, y: Value, c_in: Value) -> (Value, Value)
fn iadd_carry(self, x: Value, y: Value, c_in: Value) -> (Value, Value)
Add integers with carry in and out.
Same as iadd with an additional carry input and output.
a &= x + y + c_{in} \pmod 2^B \\
c_{out} &= x + y + c_{in} >= 2^B
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
- c_in: Input carry flag
Outputs:
- a: A scalar integer type
- c_out: Output carry flag
sourcefn iadd_ifcarry(self, x: Value, y: Value, c_in: Value) -> (Value, Value)
fn iadd_ifcarry(self, x: Value, y: Value, c_in: Value) -> (Value, Value)
Add integers with carry in and out.
Same as iadd with an additional carry flag input and output.
a &= x + y + c_{in} \pmod 2^B \\
c_{out} &= x + y + c_{in} >= 2^B
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
- c_in: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
Outputs:
- a: A scalar integer type
- c_out: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
sourcefn uadd_overflow_trap<T1: Into<TrapCode>>(
self,
x: Value,
y: Value,
code: T1
) -> Value
fn uadd_overflow_trap<T1: Into<TrapCode>>(
self,
x: Value,
y: Value,
code: T1
) -> Value
Unsigned addition of x and y, trapping if the result overflows.
Accepts 32 or 64-bit integers, and does not support vector types.
Inputs:
- x: A 32 or 64-bit scalar integer type
- y: A 32 or 64-bit scalar integer type
- code: A trap reason code.
Outputs:
- a: A 32 or 64-bit scalar integer type
Examples found in repository?
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
fn bounds_check_and_compute_addr(
pos: &mut FuncCursor,
cfg: &mut ControlFlowGraph,
isa: &dyn TargetIsa,
heap: ir::Heap,
// Dynamic operand indexing into the heap.
index: ir::Value,
// Static immediate added to the index.
offset: u32,
// Static size of the heap access.
access_size: u8,
) -> ir::Value {
let pointer_type = isa.pointer_type();
let spectre = isa.flags().enable_heap_access_spectre_mitigation();
let offset_and_size = offset_plus_size(offset, access_size);
let ir::HeapData {
base: _,
min_size,
offset_guard_size: guard_size,
style,
index_type,
} = pos.func.heaps[heap].clone();
let index = cast_index_to_pointer_ty(index, index_type, pointer_type, pos);
// We need to emit code that will trap (or compute an address that will trap
// when accessed) if
//
// index + offset + access_size > bound
//
// or if the `index + offset + access_size` addition overflows.
//
// Note that we ultimately want a 64-bit integer (we only target 64-bit
// architectures at the moment) and that `offset` is a `u32` and
// `access_size` is a `u8`. This means that we can add the latter together
// as `u64`s without fear of overflow, and we only have to be concerned with
// whether adding in `index` will overflow.
//
// Finally, the following right-hand sides of the matches do have a little
// bit of duplicated code across them, but I think writing it this way is
// worth it for readability and seeing very clearly each of our cases for
// different bounds checks and optimizations of those bounds checks. It is
// intentionally written in a straightforward case-matching style that will
// hopefully make it easy to port to ISLE one day.
match style {
// ====== Dynamic Memories ======
//
// 1. First special case for when `offset + access_size == 1`:
//
// index + 1 > bound
// ==> index >= bound
//
// 1.a. When Spectre mitigations are enabled, avoid duplicating
// bounds checks between the mitigations and the regular bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThanOrEqual,
lhs: index,
rhs: bound,
}),
)
}
// 1.b. Emit explicit `index >= bound` bounds checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size == 1 => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 2. Second special case for when `offset + access_size <= min_size`.
//
// We know that `bound >= min_size`, so we can do the following
// comparison, without fear of the right-hand side wrapping around:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// 2.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() && spectre => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 2.b. Emit explicit `index > bound - (offset + access_size)` bounds
// checks.
ir::HeapStyle::Dynamic { bound_gv } if offset_and_size <= min_size.into() => {
let bound = pos.ins().global_value(pointer_type, bound_gv);
let adjusted_bound = pos.ins().iadd_imm(bound, -(offset_and_size as i64));
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, index, adjusted_bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for dynamic memories:
//
// index + offset + access_size > bound
//
// And we have to handle the overflow case in the left-hand side.
//
// 3.a. Dedupe bounds checks with Spectre mitigations.
ir::HeapStyle::Dynamic { bound_gv } if spectre => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: adjusted_index,
rhs: bound,
}),
)
}
// 3.b. Emit an explicit `index + offset + access_size > bound`
// check.
ir::HeapStyle::Dynamic { bound_gv } => {
let access_size_val = pos.ins().iconst(pointer_type, offset_and_size as i64);
let adjusted_index =
pos.ins()
.uadd_overflow_trap(index, access_size_val, ir::TrapCode::HeapOutOfBounds);
let bound = pos.ins().global_value(pointer_type, bound_gv);
let oob = pos
.ins()
.icmp(IntCC::UnsignedGreaterThan, adjusted_index, bound);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// ====== Static Memories ======
//
// With static memories we know the size of the heap bound at compile
// time.
//
// 1. First special case: trap immediately if `offset + access_size >
// bound`, since we will end up being out-of-bounds regardless of the
// given `index`.
ir::HeapStyle::Static { bound } if offset_and_size > bound.into() => {
pos.ins().trap(ir::TrapCode::HeapOutOfBounds);
// Split the block, as the trap is a terminator instruction.
let curr_block = pos.current_block().expect("Cursor is not in a block");
let new_block = pos.func.dfg.make_block();
pos.insert_block(new_block);
cfg.recompute_block(pos.func, curr_block);
cfg.recompute_block(pos.func, new_block);
let null = pos.ins().iconst(pointer_type, 0);
return null;
}
// 2. Second special case for when we can completely omit explicit
// bounds checks for 32-bit static memories.
//
// First, let's rewrite our comparison to move all of the constants
// to one side:
//
// index + offset + access_size > bound
// ==> index > bound - (offset + access_size)
//
// We know the subtraction on the right-hand side won't wrap because
// we didn't hit the first special case.
//
// Additionally, we add our guard pages (if any) to the right-hand
// side, since we can rely on the virtual memory subsystem at runtime
// to catch out-of-bound accesses within the range `bound .. bound +
// guard_size`. So now we are dealing with
//
// index > bound + guard_size - (offset + access_size)
//
// Note that `bound + guard_size` cannot overflow for
// correctly-configured heaps, as otherwise the heap wouldn't fit in
// a 64-bit memory space.
//
// The complement of our should-this-trap comparison expression is
// the should-this-not-trap comparison expression:
//
// index <= bound + guard_size - (offset + access_size)
//
// If we know the right-hand side is greater than or equal to
// `u32::MAX`, then
//
// index <= u32::MAX <= bound + guard_size - (offset + access_size)
//
// This expression is always true when the heap is indexed with
// 32-bit integers because `index` cannot be larger than
// `u32::MAX`. This means that `index` is always either in bounds or
// within the guard page region, neither of which require emitting an
// explicit bounds check.
ir::HeapStyle::Static { bound }
if index_type == ir::types::I32
&& u64::from(u32::MAX)
<= u64::from(bound) + u64::from(guard_size) - offset_and_size =>
{
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
// 3. General case for static memories.
//
// We have to explicitly test whether
//
// index > bound - (offset + access_size)
//
// and trap if so.
//
// Since we have to emit explicit bounds checks, we might as well be
// precise, not rely on the virtual memory subsystem at all, and not
// factor in the guard pages here.
//
// 3.a. Dedupe the Spectre mitigation and the explicit bounds check.
ir::HeapStyle::Static { bound } if spectre => {
// NB: this subtraction cannot wrap because we didn't hit the first
// special case.
let adjusted_bound = u64::from(bound) - offset_and_size;
let adjusted_bound = pos.ins().iconst(pointer_type, adjusted_bound as i64);
compute_addr(
isa,
pos,
heap,
pointer_type,
index,
offset,
Some(SpectreOobComparison {
cc: IntCC::UnsignedGreaterThan,
lhs: index,
rhs: adjusted_bound,
}),
)
}
// 3.b. Emit the explicit `index > bound - (offset + access_size)`
// check.
ir::HeapStyle::Static { bound } => {
// See comment in 3.a. above.
let adjusted_bound = u64::from(bound) - offset_and_size;
let oob = pos
.ins()
.icmp_imm(IntCC::UnsignedGreaterThan, index, adjusted_bound as i64);
pos.ins().trapnz(oob, ir::TrapCode::HeapOutOfBounds);
compute_addr(isa, pos, heap, pointer_type, index, offset, None)
}
}
}sourcefn isub_bin(self, x: Value, y: Value, b_in: Value) -> Value
fn isub_bin(self, x: Value, y: Value, b_in: Value) -> Value
Subtract integers with borrow in.
Same as isub with an additional borrow flag input. Computes:
a = x - (y + b_{in}) \pmod 2^B
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
- b_in: Input borrow flag
Outputs:
- a: A scalar integer type
sourcefn isub_ifbin(self, x: Value, y: Value, b_in: Value) -> Value
fn isub_ifbin(self, x: Value, y: Value, b_in: Value) -> Value
Subtract integers with borrow in.
Same as isub with an additional borrow flag input. Computes:
a = x - (y + b_{in}) \pmod 2^B
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
- b_in: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
Outputs:
- a: A scalar integer type
sourcefn isub_bout(self, x: Value, y: Value) -> (Value, Value)
fn isub_bout(self, x: Value, y: Value) -> (Value, Value)
Subtract integers with borrow out.
Same as isub with an additional borrow flag output.
a &= x - y \pmod 2^B \\
b_{out} &= x < y
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
Outputs:
- a: A scalar integer type
- b_out: Output borrow flag
sourcefn isub_ifbout(self, x: Value, y: Value) -> (Value, Value)
fn isub_ifbout(self, x: Value, y: Value) -> (Value, Value)
Subtract integers with borrow out.
Same as isub with an additional borrow flag output.
a &= x - y \pmod 2^B \\
b_{out} &= x < y
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
Outputs:
- a: A scalar integer type
- b_out: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
sourcefn isub_borrow(self, x: Value, y: Value, b_in: Value) -> (Value, Value)
fn isub_borrow(self, x: Value, y: Value, b_in: Value) -> (Value, Value)
Subtract integers with borrow in and out.
Same as isub with an additional borrow flag input and output.
a &= x - (y + b_{in}) \pmod 2^B \\
b_{out} &= x < y + b_{in}
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
- b_in: Input borrow flag
Outputs:
- a: A scalar integer type
- b_out: Output borrow flag
sourcefn isub_ifborrow(self, x: Value, y: Value, b_in: Value) -> (Value, Value)
fn isub_ifborrow(self, x: Value, y: Value, b_in: Value) -> (Value, Value)
Subtract integers with borrow in and out.
Same as isub with an additional borrow flag input and output.
a &= x - (y + b_{in}) \pmod 2^B \\
b_{out} &= x < y + b_{in}
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- y: A scalar integer type
- b_in: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
Outputs:
- a: A scalar integer type
- b_out: CPU flags representing the result of an integer comparison. These flags
can be tested with an :type:
intcccondition code.
sourcefn band(self, x: Value, y: Value) -> Value
fn band(self, x: Value, y: Value) -> Value
Bitwise and.
Inputs:
- x: Any integer, float, or vector type
- y: Any integer, float, or vector type
Outputs:
- a: Any integer, float, or vector type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn bor(self, x: Value, y: Value) -> Value
fn bor(self, x: Value, y: Value) -> Value
Bitwise or.
Inputs:
- x: Any integer, float, or vector type
- y: Any integer, float, or vector type
Outputs:
- a: Any integer, float, or vector type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn bxor(self, x: Value, y: Value) -> Value
fn bxor(self, x: Value, y: Value) -> Value
Bitwise xor.
Inputs:
- x: Any integer, float, or vector type
- y: Any integer, float, or vector type
Outputs:
- a: Any integer, float, or vector type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn bnot(self, x: Value) -> Value
fn bnot(self, x: Value) -> Value
Bitwise not.
Inputs:
- x: Any integer, float, or vector type
Outputs:
- a: Any integer, float, or vector type
sourcefn band_not(self, x: Value, y: Value) -> Value
fn band_not(self, x: Value, y: Value) -> Value
Bitwise and not.
Computes x & ~y.
Inputs:
- x: Any integer, float, or vector type
- y: Any integer, float, or vector type
Outputs:
- a: Any integer, float, or vector type
sourcefn bor_not(self, x: Value, y: Value) -> Value
fn bor_not(self, x: Value, y: Value) -> Value
Bitwise or not.
Computes x | ~y.
Inputs:
- x: Any integer, float, or vector type
- y: Any integer, float, or vector type
Outputs:
- a: Any integer, float, or vector type
sourcefn bxor_not(self, x: Value, y: Value) -> Value
fn bxor_not(self, x: Value, y: Value) -> Value
Bitwise xor not.
Computes x ^ ~y.
Inputs:
- x: Any integer, float, or vector type
- y: Any integer, float, or vector type
Outputs:
- a: Any integer, float, or vector type
sourcefn band_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn band_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Bitwise and with immediate.
Same as band, but one operand is a zero extended 64 bit immediate constant.
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
Examples found in repository?
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}sourcefn bor_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn bor_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Bitwise or with immediate.
Same as bor, but one operand is a zero extended 64 bit immediate constant.
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
sourcefn bxor_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn bxor_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Bitwise xor with immediate.
Same as bxor, but one operand is a zero extended 64 bit immediate constant.
Polymorphic over all scalar integer types, but does not support vector types.
Inputs:
- x: A scalar integer type
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar integer type
sourcefn rotl(self, x: Value, y: Value) -> Value
fn rotl(self, x: Value, y: Value) -> Value
Rotate left.
Rotate the bits in x by y places.
Inputs:
- x: Scalar or vector value to shift
- y: Number of bits to shift
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn rotr(self, x: Value, y: Value) -> Value
fn rotr(self, x: Value, y: Value) -> Value
Rotate right.
Rotate the bits in x by y places.
Inputs:
- x: Scalar or vector value to shift
- y: Number of bits to shift
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn rotl_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn rotl_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Rotate left by immediate.
Same as rotl, but one operand is a zero extended 64 bit immediate constant.
Inputs:
- x: Scalar or vector value to shift
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar or vector integer type
sourcefn rotr_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn rotr_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Rotate right by immediate.
Same as rotr, but one operand is a zero extended 64 bit immediate constant.
Inputs:
- x: Scalar or vector value to shift
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar or vector integer type
sourcefn ishl(self, x: Value, y: Value) -> Value
fn ishl(self, x: Value, y: Value) -> Value
Integer shift left. Shift the bits in x towards the MSB by y
places. Shift in zero bits to the LSB.
The shift amount is masked to the size of x.
When shifting a B-bits integer type, this instruction computes:
s &:= y \pmod B,
a &:= x \cdot 2^s \pmod{2^B}.
Inputs:
- x: Scalar or vector value to shift
- y: Number of bits to shift
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn ushr(self, x: Value, y: Value) -> Value
fn ushr(self, x: Value, y: Value) -> Value
Unsigned shift right. Shift bits in x towards the LSB by y
places, shifting in zero bits to the MSB. Also called a logical
shift.
The shift amount is masked to the size of the register.
When shifting a B-bits integer type, this instruction computes:
s &:= y \pmod B,
a &:= \lfloor x \cdot 2^{-s} \rfloor.
Inputs:
- x: Scalar or vector value to shift
- y: Number of bits to shift
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn sshr(self, x: Value, y: Value) -> Value
fn sshr(self, x: Value, y: Value) -> Value
Signed shift right. Shift bits in x towards the LSB by y
places, shifting in sign bits to the MSB. Also called an arithmetic
shift.
The shift amount is masked to the size of the register.
Inputs:
- x: Scalar or vector value to shift
- y: Number of bits to shift
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &dyn TargetIsa) {
trace!("Pre-legalization function:\n{}", func.display());
let mut pos = FuncCursor::new(func);
let func_begin = pos.position();
pos.set_position(func_begin);
while let Some(_block) = pos.next_block() {
let mut prev_pos = pos.position();
while let Some(inst) = pos.next_inst() {
match pos.func.dfg[inst] {
// control flow
InstructionData::CondTrap {
opcode:
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
arg,
code,
} => {
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
}
// memory and constants
InstructionData::UnaryGlobalValue {
opcode: ir::Opcode::GlobalValue,
global_value,
} => expand_global_value(inst, &mut pos.func, isa, global_value),
InstructionData::HeapAddr {
opcode: ir::Opcode::HeapAddr,
heap,
arg,
offset,
size,
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, offset, size),
InstructionData::HeapLoad {
opcode: ir::Opcode::HeapLoad,
heap_imm,
arg,
} => expand_heap_load(inst, &mut pos.func, cfg, isa, heap_imm, arg),
InstructionData::HeapStore {
opcode: ir::Opcode::HeapStore,
heap_imm,
args,
} => expand_heap_store(inst, &mut pos.func, cfg, isa, heap_imm, args[0], args[1]),
InstructionData::StackLoad {
opcode: ir::Opcode::StackLoad,
stack_slot,
offset,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
opcode: ir::Opcode::StackStore,
arg,
stack_slot,
offset,
} => {
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
opcode: ir::Opcode::DynamicStackLoad,
dynamic_stack_slot,
} => {
let ty = pos.func.dfg.value_type(pos.func.dfg.first_result(inst));
assert!(ty.is_dynamic_vector());
let addr_ty = isa.pointer_type();
let mut pos = FuncCursor::new(pos.func).at_inst(inst);
pos.use_srcloc(inst);
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::DynamicStackStore {
opcode: ir::Opcode::DynamicStackStore,
arg,
dynamic_stack_slot,
} => {
pos.use_srcloc(inst);
let addr_ty = isa.pointer_type();
let vector_ty = pos.func.dfg.value_type(arg);
assert!(vector_ty.is_dynamic_vector());
let addr = pos.ins().dynamic_stack_addr(addr_ty, dynamic_stack_slot);
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::TableAddr {
opcode: ir::Opcode::TableAddr,
table,
arg,
offset,
} => expand_table_addr(isa, inst, &mut pos.func, table, arg, offset),
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let is_signed = match opcode {
ir::Opcode::IaddImm
| ir::Opcode::IrsubImm
| ir::Opcode::ImulImm
| ir::Opcode::SdivImm
| ir::Opcode::SremImm
| ir::Opcode::IfcmpImm => true,
_ => false,
};
let imm = imm_const(&mut pos, arg, imm, is_signed);
let replace = pos.func.dfg.replace(inst);
match opcode {
// bitops
ir::Opcode::BandImm => {
replace.band(arg, imm);
}
ir::Opcode::BorImm => {
replace.bor(arg, imm);
}
ir::Opcode::BxorImm => {
replace.bxor(arg, imm);
}
// bitshifting
ir::Opcode::IshlImm => {
replace.ishl(arg, imm);
}
ir::Opcode::RotlImm => {
replace.rotl(arg, imm);
}
ir::Opcode::RotrImm => {
replace.rotr(arg, imm);
}
ir::Opcode::SshrImm => {
replace.sshr(arg, imm);
}
ir::Opcode::UshrImm => {
replace.ushr(arg, imm);
}
// math
ir::Opcode::IaddImm => {
replace.iadd(arg, imm);
}
ir::Opcode::IrsubImm => {
// note: arg order reversed
replace.isub(imm, arg);
}
ir::Opcode::ImulImm => {
replace.imul(arg, imm);
}
ir::Opcode::SdivImm => {
replace.sdiv(arg, imm);
}
ir::Opcode::SremImm => {
replace.srem(arg, imm);
}
ir::Opcode::UdivImm => {
replace.udiv(arg, imm);
}
ir::Opcode::UremImm => {
replace.urem(arg, imm);
}
// comparisons
ir::Opcode::IfcmpImm => {
replace.ifcmp(arg, imm);
}
_ => prev_pos = pos.position(),
};
}
// comparisons
InstructionData::IntCompareImm {
opcode: ir::Opcode::IcmpImm,
cond,
arg,
imm,
} => {
let imm = imm_const(&mut pos, arg, imm, true);
pos.func.dfg.replace(inst).icmp(cond, arg, imm);
}
_ => {
prev_pos = pos.position();
continue;
}
}
// Legalization implementations require fixpoint loop here.
// TODO: fix this.
pos.set_position(prev_pos);
}
}
trace!("Post-legalization function:\n{}", func.display());
}sourcefn ishl_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn ishl_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Integer shift left by immediate.
The shift amount is masked to the size of x.
Inputs:
- x: Scalar or vector value to shift
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
fn compute_addr(
inst: ir::Inst,
table: ir::Table,
addr_ty: ir::Type,
mut index: ir::Value,
index_ty: ir::Type,
element_offset: Offset32,
func: &mut ir::Function,
spectre_oob_cmp: Option<(ir::Value, ir::Value)>,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Convert `index` to `addr_ty`.
if index_ty != addr_ty {
index = pos.ins().uextend(addr_ty, index);
}
// Add the table base address base
let base_gv = pos.func.tables[table].base_gv;
let base = pos.ins().global_value(addr_ty, base_gv);
let element_size = pos.func.tables[table].element_size;
let mut offset;
let element_size: u64 = element_size.into();
if element_size == 1 {
offset = index;
} else if element_size.is_power_of_two() {
offset = pos
.ins()
.ishl_imm(index, i64::from(element_size.trailing_zeros()));
} else {
offset = pos.ins().imul_imm(index, element_size as i64);
}
let element_addr = if element_offset == Offset32::new(0) {
pos.ins().iadd(base, offset)
} else {
let imm: i64 = element_offset.into();
offset = pos.ins().iadd(base, offset);
pos.ins().iadd_imm(offset, imm)
};
let element_addr = if let Some((index, bound)) = spectre_oob_cmp {
let cond = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
// If out-of-bounds, choose the table base on the misspeculation path.
pos.ins().select_spectre_guard(cond, base, element_addr)
} else {
element_addr
};
let new_inst = pos.func.dfg.value_def(element_addr).inst().unwrap();
pos.func.dfg.replace_with_aliases(inst, new_inst);
pos.remove_inst();
}sourcefn ushr_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn ushr_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Unsigned shift right by immediate.
The shift amount is masked to the size of the register.
Inputs:
- x: Scalar or vector value to shift
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}sourcefn sshr_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
fn sshr_imm<T1: Into<Imm64>>(self, x: Value, Y: T1) -> Value
Signed shift right by immediate.
The shift amount is masked to the size of the register.
Inputs:
- x: Scalar or vector value to shift
- Y: A 64-bit immediate integer.
Outputs:
- a: A scalar or vector integer type
Examples found in repository?
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
fn do_divrem_transformation(divrem_info: &DivRemByConstInfo, pos: &mut FuncCursor, inst: Inst) {
let is_rem = match *divrem_info {
DivRemByConstInfo::DivU32(_, _)
| DivRemByConstInfo::DivU64(_, _)
| DivRemByConstInfo::DivS32(_, _)
| DivRemByConstInfo::DivS64(_, _) => false,
DivRemByConstInfo::RemU32(_, _)
| DivRemByConstInfo::RemU64(_, _)
| DivRemByConstInfo::RemS32(_, _)
| DivRemByConstInfo::RemS64(_, _) => true,
};
match *divrem_info {
// -------------------- U32 --------------------
// U32 div, rem by zero: ignore
DivRemByConstInfo::DivU32(_n1, 0) | DivRemByConstInfo::RemU32(_n1, 0) => {}
// U32 div by 1: identity
// U32 rem by 1: zero
DivRemByConstInfo::DivU32(n1, 1) | DivRemByConstInfo::RemU32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U32 div, rem by a power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 31);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U32 div, rem by non-power-of-2
DivRemByConstInfo::DivU32(n1, d) | DivRemByConstInfo::RemU32(n1, d) => {
debug_assert!(d >= 3);
let MU32 {
mul_by,
do_add,
shift_by,
} = magic_u32(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 32);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 31);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- U64 --------------------
// U64 div, rem by zero: ignore
DivRemByConstInfo::DivU64(_n1, 0) | DivRemByConstInfo::RemU64(_n1, 0) => {}
// U64 div by 1: identity
// U64 rem by 1: zero
DivRemByConstInfo::DivU64(n1, 1) | DivRemByConstInfo::RemU64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
// U64 div, rem by a power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d)
if d.is_power_of_two() =>
{
debug_assert!(d >= 2);
// compute k where d == 2^k
let k = d.trailing_zeros();
debug_assert!(k >= 1 && k <= 63);
if is_rem {
let mask = (1u64 << k) - 1;
pos.func.dfg.replace(inst).band_imm(n1, mask as i64);
} else {
pos.func.dfg.replace(inst).ushr_imm(n1, k as i64);
}
}
// U64 div, rem by non-power-of-2
DivRemByConstInfo::DivU64(n1, d) | DivRemByConstInfo::RemU64(n1, d) => {
debug_assert!(d >= 3);
let MU64 {
mul_by,
do_add,
shift_by,
} = magic_u64(d);
let qf; // final quotient
let q0 = pos.ins().iconst(I64, mul_by as i64);
let q1 = pos.ins().umulhi(n1, q0);
if do_add {
debug_assert!(shift_by >= 1 && shift_by <= 64);
let t1 = pos.ins().isub(n1, q1);
let t2 = pos.ins().ushr_imm(t1, 1);
let t3 = pos.ins().iadd(t2, q1);
// I never found any case where shift_by == 1 here.
// So there's no attempt to fold out a zero shift.
debug_assert_ne!(shift_by, 1);
qf = pos.ins().ushr_imm(t3, (shift_by - 1) as i64);
} else {
debug_assert!(shift_by >= 0 && shift_by <= 63);
// Whereas there are known cases here for shift_by == 0.
if shift_by > 0 {
qf = pos.ins().ushr_imm(q1, shift_by as i64);
} else {
qf = q1;
}
}
// Now qf holds the final quotient. If necessary calculate the
// remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
// -------------------- S32 --------------------
// S32 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS32(_n1, -1)
| DivRemByConstInfo::RemS32(_n1, -1)
| DivRemByConstInfo::DivS32(_n1, 0)
| DivRemByConstInfo::RemS32(_n1, 0) => {}
// S32 div by 1: identity
// S32 rem by 1: zero
DivRemByConstInfo::DivS32(n1, 1) | DivRemByConstInfo::RemS32(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I32, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS32(n1, d) | DivRemByConstInfo::RemS32(n1, d) => {
if let Some((is_negative, k)) = i32_is_power_of_two(d) {
// k can be 31 only in the case that d is -2^31.
debug_assert!(k >= 1 && k <= 31);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (32 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S32 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i32::wrapping_neg(1 << k) as i64);
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S32 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S32 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS32 { mul_by, shift_by } = magic_s32(d);
let q0 = pos.ins().iconst(I32, mul_by as i64);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 31);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 31);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d as i64);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
// -------------------- S64 --------------------
// S64 div, rem by zero or -1: ignore
DivRemByConstInfo::DivS64(_n1, -1)
| DivRemByConstInfo::RemS64(_n1, -1)
| DivRemByConstInfo::DivS64(_n1, 0)
| DivRemByConstInfo::RemS64(_n1, 0) => {}
// S64 div by 1: identity
// S64 rem by 1: zero
DivRemByConstInfo::DivS64(n1, 1) | DivRemByConstInfo::RemS64(n1, 1) => {
if is_rem {
pos.func.dfg.replace(inst).iconst(I64, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, n1);
}
}
DivRemByConstInfo::DivS64(n1, d) | DivRemByConstInfo::RemS64(n1, d) => {
if let Some((is_negative, k)) = i64_is_power_of_two(d) {
// k can be 63 only in the case that d is -2^63.
debug_assert!(k >= 1 && k <= 63);
let t1 = if k - 1 == 0 {
n1
} else {
pos.ins().sshr_imm(n1, (k - 1) as i64)
};
let t2 = pos.ins().ushr_imm(t1, (64 - k) as i64);
let t3 = pos.ins().iadd(n1, t2);
if is_rem {
// S64 rem by a power-of-2
let t4 = pos.ins().band_imm(t3, i64::wrapping_neg(1 << k));
// Curiously, we don't care here what the sign of d is.
pos.func.dfg.replace(inst).isub(n1, t4);
} else {
// S64 div by a power-of-2
let t4 = pos.ins().sshr_imm(t3, k as i64);
if is_negative {
pos.func.dfg.replace(inst).irsub_imm(t4, 0);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, t4);
}
}
} else {
// S64 div, rem by a non-power-of-2
debug_assert!(d < -2 || d > 2);
let MS64 { mul_by, shift_by } = magic_s64(d);
let q0 = pos.ins().iconst(I64, mul_by);
let q1 = pos.ins().smulhi(n1, q0);
let q2 = if d > 0 && mul_by < 0 {
pos.ins().iadd(q1, n1)
} else if d < 0 && mul_by > 0 {
pos.ins().isub(q1, n1)
} else {
q1
};
debug_assert!(shift_by >= 0 && shift_by <= 63);
let q3 = if shift_by == 0 {
q2
} else {
pos.ins().sshr_imm(q2, shift_by as i64)
};
let t1 = pos.ins().ushr_imm(q3, 63);
let qf = pos.ins().iadd(q3, t1);
// Now qf holds the final quotient. If necessary calculate
// the remainder instead.
if is_rem {
let tt = pos.ins().imul_imm(qf, d);
pos.func.dfg.replace(inst).isub(n1, tt);
} else {
replace_single_result_with_alias(&mut pos.func.dfg, inst, qf);
}
}
}
}
}sourcefn bitrev(self, x: Value) -> Value
fn bitrev(self, x: Value) -> Value
Reverse the bits of a integer.
Reverses the bits in x.
Inputs:
- x: A scalar integer type
Outputs:
- a: A scalar integer type
sourcefn clz(self, x: Value) -> Value
fn clz(self, x: Value) -> Value
Count leading zero bits.
Starting from the MSB in x, count the number of zero bits before
reaching the first one bit. When x is zero, returns the size of x
in bits.
Inputs:
- x: A scalar integer type
Outputs:
- a: A scalar integer type
sourcefn cls(self, x: Value) -> Value
fn cls(self, x: Value) -> Value
Count leading sign bits.
Starting from the MSB after the sign bit in x, count the number of
consecutive bits identical to the sign bit. When x is 0 or -1,
returns one less than the size of x in bits.
Inputs:
- x: A scalar integer type
Outputs:
- a: A scalar integer type
sourcefn ctz(self, x: Value) -> Value
fn ctz(self, x: Value) -> Value
Count trailing zeros.
Starting from the LSB in x, count the number of zero bits before
reaching the first one bit. When x is zero, returns the size of x
in bits.
Inputs:
- x: A scalar integer type
Outputs:
- a: A scalar integer type
sourcefn bswap(self, x: Value) -> Value
fn bswap(self, x: Value) -> Value
Reverse the byte order of an integer.
Reverses the bytes in x.
Inputs:
- x: A multi byte scalar integer type
Outputs:
- a: A multi byte scalar integer type
sourcefn popcnt(self, x: Value) -> Value
fn popcnt(self, x: Value) -> Value
Population count
Count the number of one bits in x.
Inputs:
- x: A scalar or vector integer type
Outputs:
- a: A scalar or vector integer type
sourcefn fcmp<T1: Into<FloatCC>>(self, Cond: T1, x: Value, y: Value) -> Value
fn fcmp<T1: Into<FloatCC>>(self, Cond: T1, x: Value, y: Value) -> Value
Floating point comparison.
Two IEEE 754-2008 floating point numbers, x and y, relate to each
other in exactly one of four ways:
== ==========================================
UN Unordered when one or both numbers is NaN.
EQ When `x = y`. (And `0.0 = -0.0`).
LT When `x < y`.
GT When `x > y`.
== ==========================================
The 14 floatcc condition codes each correspond to a subset of
the four relations, except for the empty set which would always be
false, and the full set which would always be true.
The condition codes are divided into 7 ‘ordered’ conditions which don’t include UN, and 7 unordered conditions which all include UN.
+-------+------------+---------+------------+-------------------------+
|Ordered |Unordered |Condition |
+=======+============+=========+============+=========================+
|ord |EQ | LT | GT|uno |UN |NaNs absent / present. |
+-------+------------+---------+------------+-------------------------+
|eq |EQ |ueq |UN | EQ |Equal |
+-------+------------+---------+------------+-------------------------+
|one |LT | GT |ne |UN | LT | GT|Not equal |
+-------+------------+---------+------------+-------------------------+
|lt |LT |ult |UN | LT |Less than |
+-------+------------+---------+------------+-------------------------+
|le |LT | EQ |ule |UN | LT | EQ|Less than or equal |
+-------+------------+---------+------------+-------------------------+
|gt |GT |ugt |UN | GT |Greater than |
+-------+------------+---------+------------+-------------------------+
|ge |GT | EQ |uge |UN | GT | EQ|Greater than or equal |
+-------+------------+---------+------------+-------------------------+
The standard C comparison operators, <, <=, >, >=, are all ordered,
so they are false if either operand is NaN. The C equality operator,
==, is ordered, and since inequality is defined as the logical
inverse it is unordered. They map to the floatcc condition
codes as follows:
==== ====== ============
C `Cond` Subset
==== ====== ============
`==` eq EQ
`!=` ne UN | LT | GT
`<` lt LT
`<=` le LT | EQ
`>` gt GT
`>=` ge GT | EQ
==== ====== ============
This subset of condition codes also corresponds to the WebAssembly floating point comparisons of the same name.
When this instruction compares floating point vectors, it returns a vector with the results of lane-wise comparisons.
Inputs:
- Cond: A floating point comparison condition code
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a:
Examples found in repository?
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn add_nan_canon_seq(pos: &mut FuncCursor, inst: Inst) {
// Select the instruction result, result type. Replace the instruction
// result and step forward before inserting the canonicalization sequence.
let val = pos.func.dfg.first_result(inst);
let val_type = pos.func.dfg.value_type(val);
let new_res = pos.func.dfg.replace_result(val, val_type);
let _next_inst = pos.next_inst().expect("block missing terminator!");
// Insert a comparison instruction, to check if `inst_res` is NaN. Select
// the canonical NaN value if `val` is NaN, assign the result to `inst`.
let is_nan = pos.ins().fcmp(FloatCC::NotEqual, new_res, new_res);
let scalar_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.select(is_nan, canon_nan, new_res);
};
let vector_select = |pos: &mut FuncCursor, canon_nan: Value| {
pos.ins()
.with_result(val)
.vselect(is_nan, canon_nan, new_res);
};
match val_type {
types::F32 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F64 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
scalar_select(pos, canon_nan);
}
types::F32X4 => {
let canon_nan = pos.ins().f32const(Ieee32::with_bits(CANON_32BIT_NAN));
let canon_nan = pos.ins().splat(types::F32X4, canon_nan);
vector_select(pos, canon_nan);
}
types::F64X2 => {
let canon_nan = pos.ins().f64const(Ieee64::with_bits(CANON_64BIT_NAN));
let canon_nan = pos.ins().splat(types::F64X2, canon_nan);
vector_select(pos, canon_nan);
}
_ => {
// Panic if the type given was not an IEEE floating point type.
panic!("Could not canonicalize NaN: Unexpected result type found.");
}
}
pos.prev_inst(); // Step backwards so the pass does not skip instructions.
}sourcefn ffcmp(self, x: Value, y: Value) -> Value
fn ffcmp(self, x: Value, y: Value) -> Value
Floating point comparison returning flags.
Compares two numbers like fcmp, but returns floating point CPU
flags instead of testing a specific condition.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- f: CPU flags representing the result of a floating point comparison. These
flags can be tested with a :type:
floatcccondition code.
sourcefn fadd(self, x: Value, y: Value) -> Value
fn fadd(self, x: Value, y: Value) -> Value
Floating point addition.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a: Result of applying operator to each lane
sourcefn fsub(self, x: Value, y: Value) -> Value
fn fsub(self, x: Value, y: Value) -> Value
Floating point subtraction.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a: Result of applying operator to each lane
sourcefn fmul(self, x: Value, y: Value) -> Value
fn fmul(self, x: Value, y: Value) -> Value
Floating point multiplication.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a: Result of applying operator to each lane
sourcefn fdiv(self, x: Value, y: Value) -> Value
fn fdiv(self, x: Value, y: Value) -> Value
Floating point division.
Unlike the integer division instructions andudiv`, this can’t trap. Division by zero is infinity or
NaN, depending on the dividend.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a: Result of applying operator to each lane
sourcefn sqrt(self, x: Value) -> Value
fn sqrt(self, x: Value) -> Value
Floating point square root.
Inputs:
- x: A scalar or vector floating point number
Outputs:
- a: Result of applying operator to each lane
sourcefn fma(self, x: Value, y: Value, z: Value) -> Value
fn fma(self, x: Value, y: Value, z: Value) -> Value
Floating point fused multiply-and-add.
Computes a := xy+z without any intermediate rounding of the
product.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
- z: A scalar or vector floating point number
Outputs:
- a: Result of applying operator to each lane
sourcefn fneg(self, x: Value) -> Value
fn fneg(self, x: Value) -> Value
Floating point negation.
Note that this is a pure bitwise operation.
Inputs:
- x: A scalar or vector floating point number
Outputs:
- a:
xwith its sign bit inverted
sourcefn fabs(self, x: Value) -> Value
fn fabs(self, x: Value) -> Value
Floating point absolute value.
Note that this is a pure bitwise operation.
Inputs:
- x: A scalar or vector floating point number
Outputs:
- a:
xwith its sign bit cleared
sourcefn fcopysign(self, x: Value, y: Value) -> Value
fn fcopysign(self, x: Value, y: Value) -> Value
Floating point copy sign.
Note that this is a pure bitwise operation. The sign bit from y is
copied to the sign bit of x.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a:
xwith its sign bit changed to that ofy
sourcefn fmin(self, x: Value, y: Value) -> Value
fn fmin(self, x: Value, y: Value) -> Value
Floating point minimum, propagating NaNs using the WebAssembly rules.
If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if each input NaN consists of a mantissa whose most significant bit is 1 and the rest is 0, then the output has the same form. Otherwise, the output mantissa’s most significant bit is 1 and the rest is unspecified.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a: The smaller of
xandy
sourcefn fmin_pseudo(self, x: Value, y: Value) -> Value
fn fmin_pseudo(self, x: Value, y: Value) -> Value
Floating point pseudo-minimum, propagating NaNs. This behaves differently from fmin.
See https://github.com/WebAssembly/simd/pull/122 for background.
The behaviour is defined as fmin_pseudo(a, b) = (b < a) ? b : a, and the behaviour
for zero or NaN inputs follows from the behaviour of < with such inputs.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a: The smaller of
xandy
sourcefn fmax(self, x: Value, y: Value) -> Value
fn fmax(self, x: Value, y: Value) -> Value
Floating point maximum, propagating NaNs using the WebAssembly rules.
If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if each input NaN consists of a mantissa whose most significant bit is 1 and the rest is 0, then the output has the same form. Otherwise, the output mantissa’s most significant bit is 1 and the rest is unspecified.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a: The larger of
xandy
sourcefn fmax_pseudo(self, x: Value, y: Value) -> Value
fn fmax_pseudo(self, x: Value, y: Value) -> Value
Floating point pseudo-maximum, propagating NaNs. This behaves differently from fmax.
See https://github.com/WebAssembly/simd/pull/122 for background.
The behaviour is defined as fmax_pseudo(a, b) = (a < b) ? b : a, and the behaviour
for zero or NaN inputs follows from the behaviour of < with such inputs.
Inputs:
- x: A scalar or vector floating point number
- y: A scalar or vector floating point number
Outputs:
- a: The larger of
xandy
sourcefn ceil(self, x: Value) -> Value
fn ceil(self, x: Value) -> Value
Round floating point round to integral, towards positive infinity.
Inputs:
- x: A scalar or vector floating point number
Outputs:
- a:
xrounded to integral value
sourcefn floor(self, x: Value) -> Value
fn floor(self, x: Value) -> Value
Round floating point round to integral, towards negative infinity.
Inputs:
- x: A scalar or vector floating point number
Outputs:
- a:
xrounded to integral value
sourcefn trunc(self, x: Value) -> Value
fn trunc(self, x: Value) -> Value
Round floating point round to integral, towards zero.
Inputs:
- x: A scalar or vector floating point number
Outputs:
- a:
xrounded to integral value
sourcefn nearest(self, x: Value) -> Value
fn nearest(self, x: Value) -> Value
Round floating point round to integral, towards nearest with ties to even.
Inputs:
- x: A scalar or vector floating point number
Outputs:
- a:
xrounded to integral value
sourcefn is_null(self, x: Value) -> Value
fn is_null(self, x: Value) -> Value
Reference verification.
The condition code determines if the reference type in question is null or not.
Inputs:
- x: A scalar reference type
Outputs:
- a: An integer type with 8 bits. WARNING: arithmetic on 8bit integers is incomplete
sourcefn is_invalid(self, x: Value) -> Value
fn is_invalid(self, x: Value) -> Value
Reference verification.
The condition code determines if the reference type in question is invalid or not.
Inputs:
- x: A scalar reference type
Outputs:
- a: An integer type with 8 bits. WARNING: arithmetic on 8bit integers is incomplete
sourcefn bitcast<T1: Into<MemFlags>>(self, MemTo: Type, MemFlags: T1, x: Value) -> Value
fn bitcast<T1: Into<MemFlags>>(self, MemTo: Type, MemFlags: T1, x: Value) -> Value
Reinterpret the bits in x as a different type.
The input and output types must be storable to memory and of the same size. A bitcast is equivalent to storing one type and loading the other type from the same address, both using the specified MemFlags.
Note that this operation only supports the big or little MemFlags.
The specified byte order only affects the result in the case where
input and output types differ in lane count/size. In this case, the
operation is only valid if a byte order specifier is provided.
Inputs:
- MemTo (controlling type variable):
- MemFlags: Memory operation flags
- x: Any type that can be stored in memory
Outputs:
- a: Bits of
xreinterpreted
sourcefn scalar_to_vector(self, TxN: Type, s: Value) -> Value
fn scalar_to_vector(self, TxN: Type, s: Value) -> Value
Copies a scalar value to a vector value. The scalar is copied into the least significant lane of the vector, and all other lanes will be zero.
Inputs:
- TxN (controlling type variable): A SIMD vector type
- s: A scalar value
Outputs:
- a: A vector value
sourcefn bmask(self, IntTo: Type, x: Value) -> Value
fn bmask(self, IntTo: Type, x: Value) -> Value
Convert x to an integer mask.
True maps to all 1s and false maps to all 0s. The result type must have the same number of vector lanes as the input.
Inputs:
- IntTo (controlling type variable): An integer type with the same number of lanes
- x: A scalar or vector whose values are truthy
Outputs:
- a: An integer type with the same number of lanes
sourcefn ireduce(self, IntTo: Type, x: Value) -> Value
fn ireduce(self, IntTo: Type, x: Value) -> Value
Convert x to a smaller integer type by discarding
the most significant bits.
This is the same as reducing modulo 2^n.
Inputs:
- IntTo (controlling type variable): A smaller integer type
- x: A scalar integer type
Outputs:
- a: A smaller integer type
Examples found in repository?
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
fn try_fold_extended_move(
pos: &mut FuncCursor,
inst: Inst,
opcode: Opcode,
arg: Value,
imm: immediates::Imm64,
) -> bool {
if let ValueDef::Result(arg_inst, _) = pos.func.dfg.value_def(arg) {
if let InstructionData::BinaryImm64 {
opcode: Opcode::IshlImm,
arg: prev_arg,
imm: prev_imm,
} = &pos.func.dfg[arg_inst]
{
if imm != *prev_imm {
return false;
}
let dest_ty = pos.func.dfg.ctrl_typevar(inst);
if dest_ty != pos.func.dfg.ctrl_typevar(arg_inst) || !dest_ty.is_int() {
return false;
}
let imm_bits: i64 = imm.into();
let ireduce_ty = match (dest_ty.lane_bits() as i64).wrapping_sub(imm_bits) {
8 => I8,
16 => I16,
32 => I32,
_ => return false,
};
let ireduce_ty = ireduce_ty.by(dest_ty.lane_count()).unwrap();
// This becomes a no-op, since ireduce_ty has a smaller lane width than
// the argument type (also the destination type).
let arg = *prev_arg;
let narrower_arg = pos.ins().ireduce(ireduce_ty, arg);
if opcode == Opcode::UshrImm {
pos.func.dfg.replace(inst).uextend(dest_ty, narrower_arg);
} else {
pos.func.dfg.replace(inst).sextend(dest_ty, narrower_arg);
}
return true;
}
}
false
}sourcefn snarrow(self, x: Value, y: Value) -> Value
fn snarrow(self, x: Value, y: Value) -> Value
Combine x and y into a vector with twice the lanes but half the integer width while
saturating overflowing values to the signed maximum and minimum.
The lanes will be concatenated after narrowing. For example, when x and y are i32x4
and x = [x3, x2, x1, x0] and y = [y3, y2, y1, y0], then after narrowing the value
returned is an i16x8: a = [y3', y2', y1', y0', x3', x2', x1', x0'].
Inputs:
- x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
- y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
Outputs:
- a:
sourcefn unarrow(self, x: Value, y: Value) -> Value
fn unarrow(self, x: Value, y: Value) -> Value
Combine x and y into a vector with twice the lanes but half the integer width while
saturating overflowing values to the unsigned maximum and minimum.
Note that all input lanes are considered signed: any negative lanes will overflow and be
replaced with the unsigned minimum, 0x00.
The lanes will be concatenated after narrowing. For example, when x and y are i32x4
and x = [x3, x2, x1, x0] and y = [y3, y2, y1, y0], then after narrowing the value
returned is an i16x8: a = [y3', y2', y1', y0', x3', x2', x1', x0'].
Inputs:
- x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
- y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
Outputs:
- a:
sourcefn uunarrow(self, x: Value, y: Value) -> Value
fn uunarrow(self, x: Value, y: Value) -> Value
Combine x and y into a vector with twice the lanes but half the integer width while
saturating overflowing values to the unsigned maximum and minimum.
Note that all input lanes are considered unsigned: any negative values will be interpreted as unsigned, overflowing and being replaced with the unsigned maximum.
The lanes will be concatenated after narrowing. For example, when x and y are i32x4
and x = [x3, x2, x1, x0] and y = [y3, y2, y1, y0], then after narrowing the value
returned is an i16x8: a = [y3', y2', y1', y0', x3', x2', x1', x0'].
Inputs:
- x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
- y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
Outputs:
- a:
sourcefn swiden_low(self, x: Value) -> Value
fn swiden_low(self, x: Value) -> Value
Widen the low lanes of x using signed extension.
This will double the lane width and halve the number of lanes.
Inputs:
- x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
Outputs:
- a:
sourcefn swiden_high(self, x: Value) -> Value
fn swiden_high(self, x: Value) -> Value
Widen the high lanes of x using signed extension.
This will double the lane width and halve the number of lanes.
Inputs:
- x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
Outputs:
- a:
sourcefn uwiden_low(self, x: Value) -> Value
fn uwiden_low(self, x: Value) -> Value
Widen the low lanes of x using unsigned extension.
This will double the lane width and halve the number of lanes.
Inputs:
- x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
Outputs:
- a:
sourcefn uwiden_high(self, x: Value) -> Value
fn uwiden_high(self, x: Value) -> Value
Widen the high lanes of x using unsigned extension.
This will double the lane width and halve the number of lanes.
Inputs:
- x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
Outputs:
- a:
sourcefn iadd_pairwise(self, x: Value, y: Value) -> Value
fn iadd_pairwise(self, x: Value, y: Value) -> Value
Does lane-wise integer pairwise addition on two operands, putting the combined results into a single vector result. Here a pair refers to adjacent lanes in a vector, i.e. i2 + (i2+1) for i == num_lanes/2. The first operand pairwise add results will make up the low half of the resulting vector while the second operand pairwise add results will make up the upper half of the resulting vector.
Inputs:
- x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
- y: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
Outputs:
- a: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
sourcefn widening_pairwise_dot_product_s(self, x: Value, y: Value) -> Value
fn widening_pairwise_dot_product_s(self, x: Value, y: Value) -> Value
Takes corresponding elements in x and y, performs a sign-extending length-doubling
multiplication on them, then adds adjacent pairs of elements to form the result. For
example, if the input vectors are [x3, x2, x1, x0] and [y3, y2, y1, y0], it produces
the vector [r1, r0], where r1 = sx(x3) * sx(y3) + sx(x2) * sx(y2) and
r0 = sx(x1) * sx(y1) + sx(x0) * sx(y0), and sx(n) sign-extends n to twice its width.
This will double the lane width and halve the number of lanes. So the resulting
vector has the same number of bits as x and y do (individually).
See https://github.com/WebAssembly/simd/pull/127 for background info.
Inputs:
- x: A SIMD vector type containing 8 integer lanes each 16 bits wide.
- y: A SIMD vector type containing 8 integer lanes each 16 bits wide.
Outputs:
- a:
sourcefn uextend(self, IntTo: Type, x: Value) -> Value
fn uextend(self, IntTo: Type, x: Value) -> Value
Convert x to a larger integer type by zero-extending.
Each lane in x is converted to a larger integer type by adding
zeroes. The result has the same numerical value as x when both are
interpreted as unsigned integers.
The result type must have the same number of vector lanes as the input, and each lane must not have fewer bits that the input lanes. If the input and output types are the same, this is a no-op.
Inputs:
- IntTo (controlling type variable): A larger integer type with the same number of lanes
- x: A scalar integer type
Outputs:
- a: A larger integer type with the same number of lanes
Examples found in repository?
32 33 34 35 36 37 38 39 40 41 42 43 44 45
fn imm_const(pos: &mut FuncCursor, arg: Value, imm: Imm64, is_signed: bool) -> Value {
let ty = pos.func.dfg.value_type(arg);
match (ty, is_signed) {
(I128, true) => {
let imm = pos.ins().iconst(I64, imm);
pos.ins().sextend(I128, imm)
}
(I128, false) => {
let imm = pos.ins().iconst(I64, imm);
pos.ins().uextend(I128, imm)
}
_ => pos.ins().iconst(ty.lane_type(), imm),
}
}More examples
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
fn cast_index_to_pointer_ty(
index: ir::Value,
index_ty: ir::Type,
pointer_ty: ir::Type,
pos: &mut FuncCursor,
) -> ir::Value {
if index_ty == pointer_ty {
return index;
}
// Note that using 64-bit heaps on a 32-bit host is not currently supported,
// would require at least a bounds check here to ensure that the truncation
// from 64-to-32 bits doesn't lose any upper bits. For now though we're
// mostly interested in the 32-bit-heaps-on-64-bit-hosts cast.
assert!(index_ty.bits() < pointer_ty.bits());
// Convert `index` to `addr_ty`.
let extended_index = pos.ins().uextend(pointer_ty, index);
// Add debug value-label alias so that debuginfo can name the extended
// value as the address
let loc = pos.srcloc();
let loc = RelSourceLoc::from_base_offset(pos.func.params.base_srcloc(), loc);
pos.func
.stencil
.dfg
.add_value_label_alias(extended_index, loc, index);
extended_index
}622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
fn try_fold_extended_move(
pos: &mut FuncCursor,
inst: Inst,
opcode: Opcode,
arg: Value,
imm: immediates::Imm64,
) -> bool {
if let ValueDef::Result(arg_inst, _) = pos.func.dfg.value_def(arg) {
if let InstructionData::BinaryImm64 {
opcode: Opcode::IshlImm,
arg: prev_arg,
imm: prev_imm,
} = &pos.func.dfg[arg_inst]
{
if imm != *prev_imm {
return false;
}
let dest_ty = pos.func.dfg.ctrl_typevar(inst);
if dest_ty != pos.func.dfg.ctrl_typevar(arg_inst) || !dest_ty.is_int() {
return false;
}
let imm_bits: i64 = imm.into();
let ireduce_ty = match (dest_ty.lane_bits() as i64).wrapping_sub(imm_bits) {
8 => I8,
16 => I16,
32 => I32,
_ => return false,
};
let ireduce_ty = ireduce_ty.by(dest_ty.lane_count()).unwrap();
// This becomes a no-op, since ireduce_ty has a smaller lane width than
// the argument type (also the destination type).
let arg = *prev_arg;
let narrower_arg = pos.ins().ireduce(ireduce_ty, arg);
if opcode == Opcode::UshrImm {
pos.func.dfg.replace(inst).uextend(dest_ty, narrower_arg);
} else {
pos.func.dfg.replace(inst).sextend(dest_ty, narrower_arg);
}
return true;
}
}
false
}58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
fn compute_addr(
inst: ir::Inst,
table: ir::Table,
addr_ty: ir::Type,
mut index: ir::Value,
index_ty: ir::Type,
element_offset: Offset32,
func: &mut ir::Function,
spectre_oob_cmp: Option<(ir::Value, ir::Value)>,
) {
let mut pos = FuncCursor::new(func).at_inst(inst);
pos.use_srcloc(inst);
// Convert `index` to `addr_ty`.
if index_ty != addr_ty {
index = pos.ins().uextend(addr_ty, index);
}
// Add the table base address base
let base_gv = pos.func.tables[table].base_gv;
let base = pos.ins().global_value(addr_ty, base_gv);
let element_size = pos.func.tables[table].element_size;
let mut offset;
let element_size: u64 = element_size.into();
if element_size == 1 {
offset = index;
} else if element_size.is_power_of_two() {
offset = pos
.ins()
.ishl_imm(index, i64::from(element_size.trailing_zeros()));
} else {
offset = pos.ins().imul_imm(index, element_size as i64);
}
let element_addr = if element_offset == Offset32::new(0) {
pos.ins().iadd(base, offset)
} else {
let imm: i64 = element_offset.into();
offset = pos.ins().iadd(base, offset);
pos.ins().iadd_imm(offset, imm)
};
let element_addr = if let Some((index, bound)) = spectre_oob_cmp {
let cond = pos
.ins()
.icmp(IntCC::UnsignedGreaterThanOrEqual, index, bound);
// If out-of-bounds, choose the table base on the misspeculation path.
pos.ins().select_spectre_guard(cond, base, element_addr)
} else {
element_addr
};
let new_inst = pos.func.dfg.value_def(element_addr).inst().unwrap();
pos.func.dfg.replace_with_aliases(inst, new_inst);
pos.remove_inst();
}sourcefn sextend(self, IntTo: Type, x: Value) -> Value
fn sextend(self, IntTo: Type, x: Value) -> Value
Convert x to a larger integer type by sign-extending.
Each lane in x is converted to a larger integer type by replicating
the sign bit. The result has the same numerical value as x when both
are interpreted as signed integers.
The result type must have the same number of vector lanes as the input, and each lane must not have fewer bits that the input lanes. If the input and output types are the same, this is a no-op.
Inputs:
- IntTo (controlling type variable): A larger integer type with the same number of lanes
- x: A scalar integer type
Outputs:
- a: A larger integer type with the same number of lanes
Examples found in repository?
32 33 34 35 36 37 38 39 40 41 42 43 44 45
fn imm_const(pos: &mut FuncCursor, arg: Value, imm: Imm64, is_signed: bool) -> Value {
let ty = pos.func.dfg.value_type(arg);
match (ty, is_signed) {
(I128, true) => {
let imm = pos.ins().iconst(I64, imm);
pos.ins().sextend(I128, imm)
}
(I128, false) => {
let imm = pos.ins().iconst(I64, imm);
pos.ins().uextend(I128, imm)
}
_ => pos.ins().iconst(ty.lane_type(), imm),
}
}More examples
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
fn try_fold_extended_move(
pos: &mut FuncCursor,
inst: Inst,
opcode: Opcode,
arg: Value,
imm: immediates::Imm64,
) -> bool {
if let ValueDef::Result(arg_inst, _) = pos.func.dfg.value_def(arg) {
if let InstructionData::BinaryImm64 {
opcode: Opcode::IshlImm,
arg: prev_arg,
imm: prev_imm,
} = &pos.func.dfg[arg_inst]
{
if imm != *prev_imm {
return false;
}
let dest_ty = pos.func.dfg.ctrl_typevar(inst);
if dest_ty != pos.func.dfg.ctrl_typevar(arg_inst) || !dest_ty.is_int() {
return false;
}
let imm_bits: i64 = imm.into();
let ireduce_ty = match (dest_ty.lane_bits() as i64).wrapping_sub(imm_bits) {
8 => I8,
16 => I16,
32 => I32,
_ => return false,
};
let ireduce_ty = ireduce_ty.by(dest_ty.lane_count()).unwrap();
// This becomes a no-op, since ireduce_ty has a smaller lane width than
// the argument type (also the destination type).
let arg = *prev_arg;
let narrower_arg = pos.ins().ireduce(ireduce_ty, arg);
if opcode == Opcode::UshrImm {
pos.func.dfg.replace(inst).uextend(dest_ty, narrower_arg);
} else {
pos.func.dfg.replace(inst).sextend(dest_ty, narrower_arg);
}
return true;
}
}
false
}sourcefn fpromote(self, FloatTo: Type, x: Value) -> Value
fn fpromote(self, FloatTo: Type, x: Value) -> Value
Convert x to a larger floating point format.
Each lane in x is converted to the destination floating point format.
This is an exact operation.
Cranelift currently only supports two floating point formats
f32andf64. This may change in the future.
The result type must have the same number of vector lanes as the input, and the result lanes must not have fewer bits than the input lanes.
Inputs:
- FloatTo (controlling type variable): A scalar or vector floating point number
- x: A scalar or vector floating point number
Outputs:
- a: A scalar or vector floating point number
sourcefn fdemote(self, FloatTo: Type, x: Value) -> Value
fn fdemote(self, FloatTo: Type, x: Value) -> Value
Convert x to a smaller floating point format.
Each lane in x is converted to the destination floating point format
by rounding to nearest, ties to even.
Cranelift currently only supports two floating point formats
f32andf64. This may change in the future.
The result type must have the same number of vector lanes as the input, and the result lanes must not have more bits than the input lanes.
Inputs:
- FloatTo (controlling type variable): A scalar or vector floating point number
- x: A scalar or vector floating point number
Outputs:
- a: A scalar or vector floating point number
sourcefn fvdemote(self, x: Value) -> Value
fn fvdemote(self, x: Value) -> Value
Convert x to a smaller floating point format.
Each lane in x is converted to the destination floating point format
by rounding to nearest, ties to even.
Cranelift currently only supports two floating point formats
f32andf64. This may change in the future.
Fvdemote differs from fdemote in that with fvdemote it targets vectors. Fvdemote is constrained to having the input type being F64x2 and the result type being F32x4. The result lane that was the upper half of the input lane is initialized to zero.
Inputs:
- x: A SIMD vector type consisting of 2 lanes of 64-bit floats
Outputs:
- a: A SIMD vector type consisting of 4 lanes of 32-bit floats
sourcefn fvpromote_low(self, a: Value) -> Value
fn fvpromote_low(self, a: Value) -> Value
Converts packed single precision floating point to packed double precision floating point.
Considering only the lower half of the register, the low lanes in x are interpreted as
single precision floats that are then converted to a double precision floats.
The result type will have half the number of vector lanes as the input. Fvpromote_low is constrained to input F32x4 with a result type of F64x2.
Inputs:
- a: A SIMD vector type consisting of 4 lanes of 32-bit floats
Outputs:
- x: A SIMD vector type consisting of 2 lanes of 64-bit floats
sourcefn fcvt_to_uint(self, IntTo: Type, x: Value) -> Value
fn fcvt_to_uint(self, IntTo: Type, x: Value) -> Value
Converts floating point scalars to unsigned integer.
Only operates on x if it is a scalar. If x is NaN or if
the unsigned integral value cannot be represented in the result
type, this instruction traps.
Inputs:
- IntTo (controlling type variable): A larger integer type with the same number of lanes
- x: A scalar only floating point number
Outputs:
- a: A larger integer type with the same number of lanes
sourcefn fcvt_to_sint(self, IntTo: Type, x: Value) -> Value
fn fcvt_to_sint(self, IntTo: Type, x: Value) -> Value
Converts floating point scalars to signed integer.
Only operates on x if it is a scalar. If x is NaN or if
the unsigned integral value cannot be represented in the result
type, this instruction traps.
Inputs:
- IntTo (controlling type variable): A larger integer type with the same number of lanes
- x: A scalar only floating point number
Outputs:
- a: A larger integer type with the same number of lanes
sourcefn fcvt_to_uint_sat(self, IntTo: Type, x: Value) -> Value
fn fcvt_to_uint_sat(self, IntTo: Type, x: Value) -> Value
Convert floating point to unsigned integer as fcvt_to_uint does, but saturates the input instead of trapping. NaN and negative values are converted to 0.
Inputs:
- IntTo (controlling type variable): A larger integer type with the same number of lanes
- x: A scalar or vector floating point number
Outputs:
- a: A larger integer type with the same number of lanes
sourcefn fcvt_to_sint_sat(self, IntTo: Type, x: Value) -> Value
fn fcvt_to_sint_sat(self, IntTo: Type, x: Value) -> Value
Convert floating point to signed integer as fcvt_to_sint does, but saturates the input instead of trapping. NaN values are converted to 0.
Inputs:
- IntTo (controlling type variable): A larger integer type with the same number of lanes
- x: A scalar or vector floating point number
Outputs:
- a: A larger integer type with the same number of lanes
sourcefn fcvt_from_uint(self, FloatTo: Type, x: Value) -> Value
fn fcvt_from_uint(self, FloatTo: Type, x: Value) -> Value
Convert unsigned integer to floating point.
Each lane in x is interpreted as an unsigned integer and converted to
floating point using round to nearest, ties to even.
The result type must have the same number of vector lanes as the input.
Inputs:
- FloatTo (controlling type variable): A scalar or vector floating point number
- x: A scalar or vector integer type
Outputs:
- a: A scalar or vector floating point number
sourcefn fcvt_from_sint(self, FloatTo: Type, x: Value) -> Value
fn fcvt_from_sint(self, FloatTo: Type, x: Value) -> Value
Convert signed integer to floating point.
Each lane in x is interpreted as a signed integer and converted to
floating point using round to nearest, ties to even.
The result type must have the same number of vector lanes as the input.
Inputs:
- FloatTo (controlling type variable): A scalar or vector floating point number
- x: A scalar or vector integer type
Outputs:
- a: A scalar or vector floating point number
sourcefn fcvt_low_from_sint(self, FloatTo: Type, x: Value) -> Value
fn fcvt_low_from_sint(self, FloatTo: Type, x: Value) -> Value
Converts packed signed 32-bit integers to packed double precision floating point.
Considering only the low half of the register, each lane in x is interpreted as a
signed 32-bit integer that is then converted to a double precision float. This
instruction differs from fcvt_from_sint in that it converts half the number of lanes
which are converted to occupy twice the number of bits. No rounding should be needed
for the resulting float.
The result type will have half the number of vector lanes as the input.
Inputs:
- FloatTo (controlling type variable): A scalar or vector floating point number
- x: A scalar or vector integer type
Outputs:
- a: A scalar or vector floating point number
sourcefn isplit(self, x: Value) -> (Value, Value)
fn isplit(self, x: Value) -> (Value, Value)
Split an integer into low and high parts.
Vectors of integers are split lane-wise, so the results have the same number of lanes as the input, but the lanes are half the size.
Returns the low half of x and the high half of x as two independent
values.
Inputs:
- x: An integer type with lanes from
i16upwards
Outputs:
- lo: The low bits of
x - hi: The high bits of
x
sourcefn iconcat(self, lo: Value, hi: Value) -> Value
fn iconcat(self, lo: Value, hi: Value) -> Value
Concatenate low and high bits to form a larger integer type.
Vectors of integers are concatenated lane-wise such that the result has the same number of lanes as the inputs, but the lanes are twice the size.
Inputs:
- lo: An integer type with lanes type to
i64 - hi: An integer type with lanes type to
i64
Outputs:
- a: The concatenation of
loandhi
sourcefn atomic_rmw<T1: Into<MemFlags>, T2: Into<AtomicRmwOp>>(
self,
AtomicMem: Type,
MemFlags: T1,
AtomicRmwOp: T2,
p: Value,
x: Value
) -> Value
fn atomic_rmw<T1: Into<MemFlags>, T2: Into<AtomicRmwOp>>(
self,
AtomicMem: Type,
MemFlags: T1,
AtomicRmwOp: T2,
p: Value,
x: Value
) -> Value
Atomically read-modify-write memory at p, with second operand x. The old value is
returned. p has the type of the target word size, and x may be an integer type of
8, 16, 32 or 64 bits, even on a 32-bit target. The type of the returned value is the
same as the type of x. This operation is sequentially consistent and creates
happens-before edges that order normal (non-atomic) loads and stores.
Inputs:
- AtomicMem (controlling type variable): Any type that can be stored in memory, which can be used in an atomic operation
- MemFlags: Memory operation flags
- AtomicRmwOp: Atomic Read-Modify-Write Ops
- p: An integer address type
- x: Value to be atomically stored
Outputs:
- a: Value atomically loaded
sourcefn atomic_cas<T1: Into<MemFlags>>(
self,
MemFlags: T1,
p: Value,
e: Value,
x: Value
) -> Value
fn atomic_cas<T1: Into<MemFlags>>(
self,
MemFlags: T1,
p: Value,
e: Value,
x: Value
) -> Value
Perform an atomic compare-and-swap operation on memory at p, with expected value e,
storing x if the value at p equals e. The old value at p is returned,
regardless of whether the operation succeeds or fails. p has the type of the target
word size, and x and e must have the same type and the same size, which may be an
integer type of 8, 16, 32 or 64 bits, even on a 32-bit target. The type of the returned
value is the same as the type of x and e. This operation is sequentially
consistent and creates happens-before edges that order normal (non-atomic) loads and
stores.
Inputs:
- MemFlags: Memory operation flags
- p: An integer address type
- e: Expected value in CAS
- x: Value to be atomically stored
Outputs:
- a: Value atomically loaded
sourcefn atomic_load<T1: Into<MemFlags>>(
self,
AtomicMem: Type,
MemFlags: T1,
p: Value
) -> Value
fn atomic_load<T1: Into<MemFlags>>(
self,
AtomicMem: Type,
MemFlags: T1,
p: Value
) -> Value
Atomically load from memory at p.
This is a polymorphic instruction that can load any value type which has a memory representation. It should only be used for integer types with 8, 16, 32 or 64 bits. This operation is sequentially consistent and creates happens-before edges that order normal (non-atomic) loads and stores.
Inputs:
- AtomicMem (controlling type variable): Any type that can be stored in memory, which can be used in an atomic operation
- MemFlags: Memory operation flags
- p: An integer address type
Outputs:
- a: Value atomically loaded
sourcefn atomic_store<T1: Into<MemFlags>>(self, MemFlags: T1, x: Value, p: Value) -> Inst
fn atomic_store<T1: Into<MemFlags>>(self, MemFlags: T1, x: Value, p: Value) -> Inst
Atomically store x to memory at p.
This is a polymorphic instruction that can store any value type with a memory representation. It should only be used for integer types with 8, 16, 32 or 64 bits. This operation is sequentially consistent and creates happens-before edges that order normal (non-atomic) loads and stores.
Inputs:
- MemFlags: Memory operation flags
- x: Value to be atomically stored
- p: An integer address type
sourcefn fence(self) -> Inst
fn fence(self) -> Inst
A memory fence. This must provide ordering to ensure that, at a minimum, neither loads nor stores of any kind may move forwards or backwards across the fence. This operation is sequentially consistent.
sourcefn extract_vector<T1: Into<Uimm8>>(self, x: Value, y: T1) -> Value
fn extract_vector<T1: Into<Uimm8>>(self, x: Value, y: T1) -> Value
Return a fixed length sub vector, extracted from a dynamic vector.
Inputs:
- x: The dynamic vector to extract from
- y: 128-bit vector index
Outputs:
- a: New fixed vector
sourcefn AtomicCas(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
arg0: Value,
arg1: Value,
arg2: Value
) -> (Inst, &'f mut DataFlowGraph)
fn AtomicCas(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
arg0: Value,
arg1: Value,
arg2: Value
) -> (Inst, &'f mut DataFlowGraph)
AtomicCas(imms=(flags: ir::MemFlags), vals=3)
sourcefn AtomicRmw(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
op: AtomicRmwOp,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn AtomicRmw(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
op: AtomicRmwOp,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
AtomicRmw(imms=(flags: ir::MemFlags, op: ir::AtomicRmwOp), vals=2)
sourcefn Binary(
self,
opcode: Opcode,
ctrl_typevar: Type,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn Binary(
self,
opcode: Opcode,
ctrl_typevar: Type,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
Binary(imms=(), vals=2)
Examples found in repository?
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014
fn swizzle(self, TxN: crate::ir::Type, x: ir::Value, y: ir::Value) -> Value {
let (inst, dfg) = self.Binary(Opcode::Swizzle, TxN, x, y);
dfg.first_result(inst)
}
/// Insert ``y`` as lane ``Idx`` in x.
///
/// The lane index, ``Idx``, is an immediate value, not an SSA value. It
/// must indicate a valid lane index for the type of ``x``.
///
/// Inputs:
///
/// - x: The vector to modify
/// - y: New lane value
/// - Idx: Lane index
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn insertlane<T1: Into<ir::immediates::Uimm8>>(self, x: ir::Value, y: ir::Value, Idx: T1) -> Value {
let Idx = Idx.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.TernaryImm8(Opcode::Insertlane, ctrl_typevar, Idx, x, y);
dfg.first_result(inst)
}
/// Extract lane ``Idx`` from ``x``.
///
/// The lane index, ``Idx``, is an immediate value, not an SSA value. It
/// must indicate a valid lane index for the type of ``x``. Note that the upper bits of ``a``
/// may or may not be zeroed depending on the ISA but the type system should prevent using
/// ``a`` as anything other than the extracted value.
///
/// Inputs:
///
/// - x: A SIMD vector type
/// - Idx: Lane index
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn extractlane<T1: Into<ir::immediates::Uimm8>>(self, x: ir::Value, Idx: T1) -> Value {
let Idx = Idx.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm8(Opcode::Extractlane, ctrl_typevar, Idx, x);
dfg.first_result(inst)
}
/// Signed integer minimum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer minimum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer maximum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer maximum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned average with rounding: `a := (x + y + 1) // 2`
///
/// The addition does not lose any information (such as from overflow).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn avg_round(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::AvgRound, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add with unsigned saturation.
///
/// This is similar to `iadd` but the operands are interpreted as unsigned integers and their
/// summed result, instead of wrapping, will be saturated to the highest unsigned integer for
/// the controlling type (e.g. `0xFF` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn uadd_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::UaddSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add with signed saturation.
///
/// This is similar to `iadd` but the operands are interpreted as signed integers and their
/// summed result, instead of wrapping, will be saturated to the lowest or highest
/// signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8). For example,
/// since an `sadd_sat.i8` of `0x70` and `0x70` is greater than `0x7F`, the result will be
/// clamped to `0x7F`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn sadd_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SaddSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Subtract with unsigned saturation.
///
/// This is similar to `isub` but the operands are interpreted as unsigned integers and their
/// difference, instead of wrapping, will be saturated to the lowest unsigned integer for
/// the controlling type (e.g. `0x00` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn usub_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::UsubSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Subtract with signed saturation.
///
/// This is similar to `isub` but the operands are interpreted as signed integers and their
/// difference, instead of wrapping, will be saturated to the lowest or highest
/// signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn ssub_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SsubSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Load from memory at ``p + Offset``.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn load<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Load, Mem, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store ``x`` to memory at ``p + Offset``.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: Value to be stored
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn store<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Store, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 8 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i8`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn uload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 8 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i8`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn sload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 8 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i8`` followed by ``store.i8``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 8 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore8, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 16 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i16`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn uload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 16 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i16`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn sload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 16 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i16`` followed by ``store.i16``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 16 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore16, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 32 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i32`` followed by ``uextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn uload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 32 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i32`` followed by ``sextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn sload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 32 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i32`` followed by ``store.i32``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 32 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore32, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 32x2 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 32x2 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a value from a stack slot at the constant offset.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// The offset is an immediate constant, not an SSA value. The memory
/// access cannot go out of bounds, i.e.
/// `sizeof(a) + Offset <= sizeof(SS)`.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn stack_load<T1: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackLoad, Mem, SS, Offset);
dfg.first_result(inst)
}
/// Store a value to a stack slot at a constant offset.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// The offset is an immediate constant, not an SSA value. The memory
/// access cannot go out of bounds, i.e.
/// `sizeof(a) + Offset <= sizeof(SS)`.
///
/// Inputs:
///
/// - x: Value to be stored
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
#[allow(non_snake_case)]
fn stack_store<T1: Into<ir::immediates::Offset32>>(self, x: ir::Value, SS: ir::StackSlot, Offset: T1) -> Inst {
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.StackStore(Opcode::StackStore, ctrl_typevar, SS, Offset, x).0
}
/// Get the address of a stack slot.
///
/// Compute the absolute address of a byte in a stack slot. The offset must
/// refer to a byte inside the stack slot:
/// `0 <= Offset < sizeof(SS)`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn stack_addr<T1: Into<ir::immediates::Offset32>>(self, iAddr: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackAddr, iAddr, SS, Offset);
dfg.first_result(inst)
}
/// Load a value from a dynamic stack slot.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - DSS: A dynamic stack slot
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn dynamic_stack_load(self, Mem: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackLoad, Mem, DSS);
dfg.first_result(inst)
}
/// Store a value to a dynamic stack slot.
///
/// This is a polymorphic instruction that can store any dynamic value type with a
/// memory representation.
///
/// Inputs:
///
/// - x: Value to be stored
/// - DSS: A dynamic stack slot
#[allow(non_snake_case)]
fn dynamic_stack_store(self, x: ir::Value, DSS: ir::DynamicStackSlot) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.DynamicStackStore(Opcode::DynamicStackStore, ctrl_typevar, DSS, x).0
}
/// Get the address of a dynamic stack slot.
///
/// Compute the absolute address of the first byte of a dynamic stack slot.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - DSS: A dynamic stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn dynamic_stack_addr(self, iAddr: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackAddr, iAddr, DSS);
dfg.first_result(inst)
}
/// Compute the value of global GV.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn global_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::GlobalValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a symbolic value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn symbol_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::SymbolValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a TLS (thread local storage) value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn tls_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::TlsValue, Mem, GV);
dfg.first_result(inst)
}
/// Bounds check and compute absolute address of ``index + Offset`` in heap memory.
///
/// Verify that the range ``index .. index + Offset + Size`` is in bounds for the
/// heap ``H``, and generate an absolute address that is safe to dereference.
///
/// 1. If ``index + Offset + Size`` is less than or equal ot the heap bound, return an
/// absolute address corresponding to a byte offset of ``index + Offset`` from the
/// heap's base address.
///
/// 2. If ``index + Offset + Size`` is greater than the heap bound, return the
/// ``NULL`` pointer or any other address that is guaranteed to generate a trap
/// when accessed.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - H: A heap.
/// - index: An unsigned heap offset
/// - Offset: Static offset immediate in bytes
/// - Size: Static size immediate in bytes
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn heap_addr<T1: Into<ir::immediates::Uimm32>, T2: Into<ir::immediates::Uimm8>>(self, iAddr: crate::ir::Type, H: ir::Heap, index: ir::Value, Offset: T1, Size: T2) -> Value {
let Offset = Offset.into();
let Size = Size.into();
let (inst, dfg) = self.HeapAddr(Opcode::HeapAddr, iAddr, H, Offset, Size, index);
dfg.first_result(inst)
}
/// Load a value from the given heap at address ``index + offset``,
/// trapping on out-of-bounds accesses.
///
/// Checks that ``index + offset .. index + offset + sizeof(a)`` is
/// within the heap's bounds, trapping if it is not. Otherwise, when
/// that range is in bounds, loads the value from the heap.
///
/// Traps on ``index + offset + sizeof(a)`` overflow.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - heap_imm: Reference to out-of-line heap access immediates
/// - index: Dynamic index (in bytes) into the heap
///
/// Outputs:
///
/// - a: The value loaded from the heap
#[allow(non_snake_case)]
fn heap_load<T1: Into<ir::HeapImm>>(self, Mem: crate::ir::Type, heap_imm: T1, index: ir::Value) -> Value {
let heap_imm = heap_imm.into();
let (inst, dfg) = self.HeapLoad(Opcode::HeapLoad, Mem, heap_imm, index);
dfg.first_result(inst)
}
/// Store ``a`` into the given heap at address ``index + offset``,
/// trapping on out-of-bounds accesses.
///
/// Checks that ``index + offset .. index + offset + sizeof(a)`` is
/// within the heap's bounds, trapping if it is not. Otherwise, when
/// that range is in bounds, stores the value into the heap.
///
/// Traps on ``index + offset + sizeof(a)`` overflow.
///
/// Inputs:
///
/// - heap_imm: Reference to out-of-line heap access immediates
/// - index: Dynamic index (in bytes) into the heap
/// - a: The value stored into the heap
#[allow(non_snake_case)]
fn heap_store<T1: Into<ir::HeapImm>>(self, heap_imm: T1, index: ir::Value, a: ir::Value) -> Inst {
let heap_imm = heap_imm.into();
let ctrl_typevar = self.data_flow_graph().value_type(index);
self.HeapStore(Opcode::HeapStore, ctrl_typevar, heap_imm, index, a).0
}
/// Gets the content of the pinned register, when it's enabled.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_pinned_reg(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetPinnedReg, iAddr);
dfg.first_result(inst)
}
/// Sets the content of the pinned register, when it's enabled.
///
/// Inputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn set_pinned_reg(self, addr: ir::Value) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(addr);
self.Unary(Opcode::SetPinnedReg, ctrl_typevar, addr).0
}
/// Get the address in the frame pointer register.
///
/// Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_frame_pointer(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetFramePointer, iAddr);
dfg.first_result(inst)
}
/// Get the address in the stack pointer register.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_stack_pointer(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetStackPointer, iAddr);
dfg.first_result(inst)
}
/// Get the PC where this function will transfer control to when it returns.
///
/// Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_return_address(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetReturnAddress, iAddr);
dfg.first_result(inst)
}
/// Bounds check and compute absolute address of a table entry.
///
/// Verify that the offset ``p`` is in bounds for the table T, and generate
/// an absolute address that is safe to dereference.
///
/// ``Offset`` must be less than the size of a table element.
///
/// 1. If ``p`` is not greater than the table bound, return an absolute
/// address corresponding to a byte offset of ``p`` from the table's
/// base address.
/// 2. If ``p`` is greater than the table bound, generate a trap.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - T: A table.
/// - p: An unsigned table offset
/// - Offset: Byte offset from element address
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn table_addr<T1: Into<ir::immediates::Offset32>>(self, iAddr: crate::ir::Type, T: ir::Table, p: ir::Value, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.TableAddr(Opcode::TableAddr, iAddr, T, Offset, p);
dfg.first_result(inst)
}
/// Integer constant.
///
/// Create a scalar integer SSA value with an immediate constant value, or
/// an integer vector where all the lanes have the same value.
///
/// Inputs:
///
/// - NarrowInt (controlling type variable): An integer type with lanes type to `i64`
/// - N: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A constant integer scalar or vector value
#[allow(non_snake_case)]
fn iconst<T1: Into<ir::immediates::Imm64>>(self, NarrowInt: crate::ir::Type, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryImm(Opcode::Iconst, NarrowInt, N);
dfg.first_result(inst)
}
/// Floating point constant.
///
/// Create a `f32` SSA value with an immediate constant value.
///
/// Inputs:
///
/// - N: A 32-bit immediate floating point number.
///
/// Outputs:
///
/// - a: A constant f32 scalar value
#[allow(non_snake_case)]
fn f32const<T1: Into<ir::immediates::Ieee32>>(self, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryIeee32(Opcode::F32const, types::INVALID, N);
dfg.first_result(inst)
}
/// Floating point constant.
///
/// Create a `f64` SSA value with an immediate constant value.
///
/// Inputs:
///
/// - N: A 64-bit immediate floating point number.
///
/// Outputs:
///
/// - a: A constant f64 scalar value
#[allow(non_snake_case)]
fn f64const<T1: Into<ir::immediates::Ieee64>>(self, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryIeee64(Opcode::F64const, types::INVALID, N);
dfg.first_result(inst)
}
/// SIMD vector constant.
///
/// Construct a vector with the given immediate bytes.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - N: The 16 immediate bytes of a 128-bit vector
///
/// Outputs:
///
/// - a: A constant vector value
#[allow(non_snake_case)]
fn vconst<T1: Into<ir::Constant>>(self, TxN: crate::ir::Type, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryConst(Opcode::Vconst, TxN, N);
dfg.first_result(inst)
}
/// SIMD vector shuffle.
///
/// Shuffle two vectors using the given immediate bytes. For each of the 16 bytes of the
/// immediate, a value i of 0-15 selects the i-th element of the first vector and a value i of
/// 16-31 selects the (i-16)th element of the second vector. Immediate values outside of the
/// 0-31 range place a 0 in the resulting vector lane.
///
/// Inputs:
///
/// - a: A vector value
/// - b: A vector value
/// - mask: The 16 immediate bytes used for selecting the elements to shuffle
///
/// Outputs:
///
/// - a: A vector value
#[allow(non_snake_case)]
fn shuffle<T1: Into<ir::Immediate>>(self, a: ir::Value, b: ir::Value, mask: T1) -> Value {
let mask = mask.into();
let (inst, dfg) = self.Shuffle(Opcode::Shuffle, types::INVALID, mask, a, b);
dfg.first_result(inst)
}
/// Null constant value for reference types.
///
/// Create a scalar reference SSA value with a constant null value.
///
/// Inputs:
///
/// - Ref (controlling type variable): A scalar reference type
///
/// Outputs:
///
/// - a: A constant reference null value
#[allow(non_snake_case)]
fn null(self, Ref: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::Null, Ref);
dfg.first_result(inst)
}
/// Just a dummy instruction.
///
/// Note: this doesn't compile to a machine code nop.
#[allow(non_snake_case)]
fn nop(self) -> Inst {
self.NullAry(Opcode::Nop, types::INVALID).0
}
/// Conditional select.
///
/// This instruction selects whole values. Use `vselect` for
/// lane-wise selection.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn select(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Select, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select intended for Spectre guards.
///
/// This operation is semantically equivalent to a select instruction.
/// However, it is guaranteed to not be removed or otherwise altered by any
/// optimization pass, and is guaranteed to result in a conditional-move
/// instruction, not a branch-based lowering. As such, it is suitable
/// for use when producing Spectre guards. For example, a bounds-check
/// may guard against unsafe speculation past a bounds-check conditional
/// branch by passing the address or index to be accessed through a
/// conditional move, also gated on the same condition. Because no
/// Spectre-vulnerable processors are known to perform speculation on
/// conditional move instructions, this is guaranteed to pick the
/// correct input. If the selected input in case of overflow is a "safe"
/// value, for example a null pointer that causes an exception in the
/// speculative path, this ensures that no Spectre vulnerability will
/// exist.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn select_spectre_guard(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::SelectSpectreGuard, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select of bits.
///
/// For each bit in `c`, this instruction selects the corresponding bit from `x` if the bit
/// in `c` is 1 and the corresponding bit from `y` if the bit in `c` is 0. See also:
/// `select`, `vselect`.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn bitselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Bitselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Split a vector into two halves.
///
/// Split the vector `x` into two separate values, each containing half of
/// the lanes from ``x``. The result may be two scalars if ``x`` only had
/// two lanes.
///
/// Inputs:
///
/// - x: Vector to split
///
/// Outputs:
///
/// - lo: Low-numbered lanes of `x`
/// - hi: High-numbered lanes of `x`
#[allow(non_snake_case)]
fn vsplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Vsplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Vector concatenation.
///
/// Return a vector formed by concatenating ``x`` and ``y``. The resulting
/// vector type has twice as many lanes as each of the inputs. The lanes of
/// ``x`` appear as the low-numbered lanes, and the lanes of ``y`` become
/// the high-numbered lanes of ``a``.
///
/// It is possible to form a vector by concatenating two scalars.
///
/// Inputs:
///
/// - x: Low-numbered lanes
/// - y: High-numbered lanes
///
/// Outputs:
///
/// - a: Concatenation of `x` and `y`
#[allow(non_snake_case)]
fn vconcat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Vconcat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Vector lane select.
///
/// Select lanes from ``x`` or ``y`` controlled by the lanes of the truthy
/// vector ``c``.
///
/// Inputs:
///
/// - c: Controlling vector
/// - x: Value to use where `c` is true
/// - y: Value to use where `c` is false
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn vselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Vselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if any lane in ``a`` is non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vany_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VanyTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if all lanes in ``i`` are non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vall_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VallTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar integer.
///
/// Return a scalar integer, consisting of the concatenation of the most significant bit
/// of each lane of ``a``.
///
/// Inputs:
///
/// - Int (controlling type variable): A scalar or vector integer type
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - x: A scalar or vector integer type
#[allow(non_snake_case)]
fn vhigh_bits(self, Int: crate::ir::Type, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::VhighBits, Int, a);
dfg.first_result(inst)
}
/// Integer comparison.
///
/// The condition code determines if the operands are interpreted as signed
/// or unsigned integers.
///
/// | Signed | Unsigned | Condition |
/// |--------|----------|-----------------------|
/// | eq | eq | Equal |
/// | ne | ne | Not equal |
/// | slt | ult | Less than |
/// | sge | uge | Greater than or equal |
/// | sgt | ugt | Greater than |
/// | sle | ule | Less than or equal |
///
/// When this instruction compares integer vectors, it returns a vector of
/// lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn icmp<T1: Into<ir::condcodes::IntCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompare(Opcode::Icmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant.
///
/// This is the same as the `icmp` instruction, except one operand is
/// a sign extended 64 bit immediate constant.
///
/// This instruction can only compare scalars. Use `icmp` for
/// lane-wise vector comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn icmp_imm<T1: Into<ir::condcodes::IntCC>, T2: Into<ir::immediates::Imm64>>(self, Cond: T1, x: ir::Value, Y: T2) -> Value {
let Cond = Cond.into();
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompareImm(Opcode::IcmpImm, ctrl_typevar, Cond, Y, x);
dfg.first_result(inst)
}
/// Compare scalar integers and return flags.
///
/// Compare two scalar integer values and return integer CPU flags
/// representing the result.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ifcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant and return flags.
///
/// Like `icmp_imm`, but returns integer CPU flags instead of testing
/// a specific condition code.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IfcmpImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Wrapping integer addition: `a := x + y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Iadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Wrapping integer subtraction: `a := x - y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn isub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Isub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer negation: `a := -x \pmod{2^B}`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ineg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ineg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Integer absolute value with wrapping: `a := |x|`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Iabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Wrapping integer multiplication: `a := x y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn imul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Imul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Fixed-point multiplication of numbers in the QN format, where N + 1
/// is the number bitwidth:
/// `a := signed_saturate((x * y + 1 << (Q - 1)) >> Q)`
///
/// Polymorphic over all integer types (scalar and vector) with 16- or
/// 32-bit numbers.
///
/// Inputs:
///
/// - x: A scalar or vector integer type with 16- or 32-bit numbers
/// - y: A scalar or vector integer type with 16- or 32-bit numbers
///
/// Outputs:
///
/// - a: A scalar or vector integer type with 16- or 32-bit numbers
#[allow(non_snake_case)]
fn sqmul_round_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SqmulRoundSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer division: `a := \lfloor {x \over y} \rfloor`.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Udiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer division rounded toward zero: `a := sign(xy)
/// \lfloor {|x| \over |y|}\rfloor`.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer remainder.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Urem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer remainder. The result has the sign of the dividend.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Srem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add immediate integer.
///
/// Same as `iadd`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IaddImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer multiplication by immediate constant.
///
/// Same as `imul`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn imul_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::ImulImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer division by an immediate constant.
///
/// Same as `udiv`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer division by an immediate constant.
///
/// Same as `sdiv`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, Y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer remainder with immediate divisor.
///
/// Same as `urem`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer remainder with immediate divisor.
///
/// Same as `srem`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Immediate reverse wrapping subtraction: `a := Y - x \pmod{2^B}`.
///
/// The immediate operand is a sign extended 64 bit constant.
///
/// Also works as integer negation when `Y = 0`. Use `iadd_imm`
/// with a negative immediate operand for the reverse immediate
/// subtraction.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn irsub_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IrsubImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_cin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry flag input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_ifcin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_cout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddCout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry flag output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddIfcout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_carry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry flag input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcarry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Unsigned addition of x and y, trapping if the result overflows.
///
/// Accepts 32 or 64-bit integers, and does not support vector types.
///
/// Inputs:
///
/// - x: A 32 or 64-bit scalar integer type
/// - y: A 32 or 64-bit scalar integer type
/// - code: A trap reason code.
///
/// Outputs:
///
/// - a: A 32 or 64-bit scalar integer type
#[allow(non_snake_case)]
fn uadd_overflow_trap<T1: Into<ir::TrapCode>>(self, x: ir::Value, y: ir::Value, code: T1) -> Value {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntAddTrap(Opcode::UaddOverflowTrap, ctrl_typevar, code, x, y);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_bin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_ifbin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfbin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_bout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubBout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifbout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubIfbout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_borrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBorrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifborrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfborrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Bitwise and.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Band, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bxor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise not.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bnot(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bnot, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Bitwise and not.
///
/// Computes `x & ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BandNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or not.
///
/// Computes `x | ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor not.
///
/// Computes `x ^ ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BxorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise and with immediate.
///
/// Same as `band`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn band_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BandImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise or with immediate.
///
/// Same as `bor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise xor with immediate.
///
/// Same as `bxor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bxor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BxorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate left.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate right.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate left by immediate.
///
/// Same as `rotl`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate right by immediate.
///
/// Same as `rotr`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer shift left. Shift the bits in ``x`` towards the MSB by ``y``
/// places. Shift in zero bits to the LSB.
///
/// The shift amount is masked to the size of ``x``.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= x \cdot 2^s \pmod{2^B}.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ishl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in zero bits to the MSB. Also called a *logical
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= \lfloor x \cdot 2^{-s} \rfloor.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ushr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in sign bits to the MSB. Also called an *arithmetic
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sshr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer shift left by immediate.
///
/// The shift amount is masked to the size of ``x``.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IshlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Reverse the bits of a integer.
///
/// Reverses the bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bitrev(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bitrev, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading zero bits.
///
/// Starting from the MSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn clz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Clz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading sign bits.
///
/// Starting from the MSB after the sign bit in ``x``, count the number of
/// consecutive bits identical to the sign bit. When ``x`` is 0 or -1,
/// returns one less than the size of x in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn cls(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Cls, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count trailing zeros.
///
/// Starting from the LSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn ctz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ctz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reverse the byte order of an integer.
///
/// Reverses the bytes in ``x``.
///
/// Inputs:
///
/// - x: A multi byte scalar integer type
///
/// Outputs:
///
/// - a: A multi byte scalar integer type
#[allow(non_snake_case)]
fn bswap(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bswap, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Population count
///
/// Count the number of one bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn popcnt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Popcnt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point comparison.
///
/// Two IEEE 754-2008 floating point numbers, `x` and `y`, relate to each
/// other in exactly one of four ways:
///
/// ```text
/// == ==========================================
/// UN Unordered when one or both numbers is NaN.
/// EQ When `x = y`. (And `0.0 = -0.0`).
/// LT When `x < y`.
/// GT When `x > y`.
/// == ==========================================
/// ```
///
/// The 14 `floatcc` condition codes each correspond to a subset of
/// the four relations, except for the empty set which would always be
/// false, and the full set which would always be true.
///
/// The condition codes are divided into 7 'ordered' conditions which don't
/// include UN, and 7 unordered conditions which all include UN.
///
/// ```text
/// +-------+------------+---------+------------+-------------------------+
/// |Ordered |Unordered |Condition |
/// +=======+============+=========+============+=========================+
/// |ord |EQ | LT | GT|uno |UN |NaNs absent / present. |
/// +-------+------------+---------+------------+-------------------------+
/// |eq |EQ |ueq |UN | EQ |Equal |
/// +-------+------------+---------+------------+-------------------------+
/// |one |LT | GT |ne |UN | LT | GT|Not equal |
/// +-------+------------+---------+------------+-------------------------+
/// |lt |LT |ult |UN | LT |Less than |
/// +-------+------------+---------+------------+-------------------------+
/// |le |LT | EQ |ule |UN | LT | EQ|Less than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// |gt |GT |ugt |UN | GT |Greater than |
/// +-------+------------+---------+------------+-------------------------+
/// |ge |GT | EQ |uge |UN | GT | EQ|Greater than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// ```
///
/// The standard C comparison operators, `<, <=, >, >=`, are all ordered,
/// so they are false if either operand is NaN. The C equality operator,
/// `==`, is ordered, and since inequality is defined as the logical
/// inverse it is *unordered*. They map to the `floatcc` condition
/// codes as follows:
///
/// ```text
/// ==== ====== ============
/// C `Cond` Subset
/// ==== ====== ============
/// `==` eq EQ
/// `!=` ne UN | LT | GT
/// `<` lt LT
/// `<=` le LT | EQ
/// `>` gt GT
/// `>=` ge GT | EQ
/// ==== ====== ============
/// ```
///
/// This subset of condition codes also corresponds to the WebAssembly
/// floating point comparisons of the same name.
///
/// When this instruction compares floating point vectors, it returns a
/// vector with the results of lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: A floating point comparison condition code
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn fcmp<T1: Into<ir::condcodes::FloatCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.FloatCompare(Opcode::Fcmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Floating point comparison returning flags.
///
/// Compares two numbers like `fcmp`, but returns floating point CPU
/// flags instead of testing a specific condition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - f: CPU flags representing the result of a floating point comparison. These
/// flags can be tested with a :type:`floatcc` condition code.
#[allow(non_snake_case)]
fn ffcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ffcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point addition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point subtraction.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fsub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fsub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point multiplication.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fmul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point division.
///
/// Unlike the integer division instructions ` and
/// `udiv`, this can't trap. Division by zero is infinity or
/// NaN, depending on the dividend.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point square root.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn sqrt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Sqrt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point fused multiply-and-add.
///
/// Computes `a := xy+z` without any intermediate rounding of the
/// product.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
/// - z: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fma(self, x: ir::Value, y: ir::Value, z: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::Fma, ctrl_typevar, x, y, z);
dfg.first_result(inst)
}
/// Floating point negation.
///
/// Note that this is a pure bitwise operation.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit inverted
#[allow(non_snake_case)]
fn fneg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Fneg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point absolute value.
///
/// Note that this is a pure bitwise operation.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit cleared
#[allow(non_snake_case)]
fn fabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Fabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point copy sign.
///
/// Note that this is a pure bitwise operation. The sign bit from ``y`` is
/// copied to the sign bit of ``x``.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit changed to that of ``y``
#[allow(non_snake_case)]
fn fcopysign(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fcopysign, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point minimum, propagating NaNs using the WebAssembly rules.
///
/// If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
/// each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
/// 0, then the output has the same form. Otherwise, the output mantissa's most significant
/// bit is 1 and the rest is unspecified.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The smaller of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point pseudo-minimum, propagating NaNs. This behaves differently from ``fmin``.
/// See <https://github.com/WebAssembly/simd/pull/122> for background.
///
/// The behaviour is defined as ``fmin_pseudo(a, b) = (b < a) ? b : a``, and the behaviour
/// for zero or NaN inputs follows from the behaviour of ``<`` with such inputs.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The smaller of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmin_pseudo(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::FminPseudo, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point maximum, propagating NaNs using the WebAssembly rules.
///
/// If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
/// each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
/// 0, then the output has the same form. Otherwise, the output mantissa's most significant
/// bit is 1 and the rest is unspecified.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The larger of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point pseudo-maximum, propagating NaNs. This behaves differently from ``fmax``.
/// See <https://github.com/WebAssembly/simd/pull/122> for background.
///
/// The behaviour is defined as ``fmax_pseudo(a, b) = (a < b) ? b : a``, and the behaviour
/// for zero or NaN inputs follows from the behaviour of ``<`` with such inputs.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The larger of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmax_pseudo(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::FmaxPseudo, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards positive infinity.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn ceil(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ceil, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards negative infinity.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn floor(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Floor, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards zero.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn trunc(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Trunc, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards nearest with ties to
/// even.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn nearest(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Nearest, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reference verification.
///
/// The condition code determines if the reference type in question is
/// null or not.
///
/// Inputs:
///
/// - x: A scalar reference type
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn is_null(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::IsNull, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reference verification.
///
/// The condition code determines if the reference type in question is
/// invalid or not.
///
/// Inputs:
///
/// - x: A scalar reference type
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn is_invalid(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::IsInvalid, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reinterpret the bits in `x` as a different type.
///
/// The input and output types must be storable to memory and of the same
/// size. A bitcast is equivalent to storing one type and loading the other
/// type from the same address, both using the specified MemFlags.
///
/// Note that this operation only supports the `big` or `little` MemFlags.
/// The specified byte order only affects the result in the case where
/// input and output types differ in lane count/size. In this case, the
/// operation is only valid if a byte order specifier is provided.
///
/// Inputs:
///
/// - MemTo (controlling type variable):
/// - MemFlags: Memory operation flags
/// - x: Any type that can be stored in memory
///
/// Outputs:
///
/// - a: Bits of `x` reinterpreted
#[allow(non_snake_case)]
fn bitcast<T1: Into<ir::MemFlags>>(self, MemTo: crate::ir::Type, MemFlags: T1, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let (inst, dfg) = self.LoadNoOffset(Opcode::Bitcast, MemTo, MemFlags, x);
dfg.first_result(inst)
}
/// Copies a scalar value to a vector value. The scalar is copied into the
/// least significant lane of the vector, and all other lanes will be zero.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - s: A scalar value
///
/// Outputs:
///
/// - a: A vector value
#[allow(non_snake_case)]
fn scalar_to_vector(self, TxN: crate::ir::Type, s: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::ScalarToVector, TxN, s);
dfg.first_result(inst)
}
/// Convert `x` to an integer mask.
///
/// True maps to all 1s and false maps to all 0s. The result type must have
/// the same number of vector lanes as the input.
///
/// Inputs:
///
/// - IntTo (controlling type variable): An integer type with the same number of lanes
/// - x: A scalar or vector whose values are truthy
///
/// Outputs:
///
/// - a: An integer type with the same number of lanes
#[allow(non_snake_case)]
fn bmask(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Bmask, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller integer type by discarding
/// the most significant bits.
///
/// This is the same as reducing modulo `2^n`.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A smaller integer type
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A smaller integer type
#[allow(non_snake_case)]
fn ireduce(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Ireduce, IntTo, x);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the signed maximum and minimum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn snarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Snarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered signed: any negative lanes will overflow and be
/// replaced with the unsigned minimum, `0x00`.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn unarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Unarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered unsigned: any negative values will be interpreted as unsigned, overflowing and being replaced with the unsigned maximum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uunarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Uunarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Does lane-wise integer pairwise addition on two operands, putting the
/// combined results into a single vector result. Here a pair refers to adjacent
/// lanes in a vector, i.e. i*2 + (i*2+1) for i == num_lanes/2. The first operand
/// pairwise add results will make up the low half of the resulting vector while
/// the second operand pairwise add results will make up the upper half of the
/// resulting vector.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
/// - y: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
#[allow(non_snake_case)]
fn iadd_pairwise(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddPairwise, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Takes corresponding elements in `x` and `y`, performs a sign-extending length-doubling
/// multiplication on them, then adds adjacent pairs of elements to form the result. For
/// example, if the input vectors are `[x3, x2, x1, x0]` and `[y3, y2, y1, y0]`, it produces
/// the vector `[r1, r0]`, where `r1 = sx(x3) * sx(y3) + sx(x2) * sx(y2)` and
/// `r0 = sx(x1) * sx(y1) + sx(x0) * sx(y0)`, and `sx(n)` sign-extends `n` to twice its width.
///
/// This will double the lane width and halve the number of lanes. So the resulting
/// vector has the same number of bits as `x` and `y` do (individually).
///
/// See <https://github.com/WebAssembly/simd/pull/127> for background info.
///
/// Inputs:
///
/// - x: A SIMD vector type containing 8 integer lanes each 16 bits wide.
/// - y: A SIMD vector type containing 8 integer lanes each 16 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn widening_pairwise_dot_product_s(self, x: ir::Value, y: ir::Value) -> Value {
let (inst, dfg) = self.Binary(Opcode::WideningPairwiseDotProductS, types::INVALID, x, y);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by zero-extending.
///
/// Each lane in `x` is converted to a larger integer type by adding
/// zeroes. The result has the same numerical value as `x` when both are
/// interpreted as unsigned integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn uextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Uextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by sign-extending.
///
/// Each lane in `x` is converted to a larger integer type by replicating
/// the sign bit. The result has the same numerical value as `x` when both
/// are interpreted as signed integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn sextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Sextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger floating point format.
///
/// Each lane in `x` is converted to the destination floating point format.
/// This is an exact operation.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have fewer bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fpromote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fpromote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have more bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fdemote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fdemote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// Fvdemote differs from fdemote in that with fvdemote it targets vectors.
/// Fvdemote is constrained to having the input type being F64x2 and the result
/// type being F32x4. The result lane that was the upper half of the input lane
/// is initialized to zero.
///
/// Inputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
///
/// Outputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
#[allow(non_snake_case)]
fn fvdemote(self, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fvdemote, types::INVALID, x);
dfg.first_result(inst)
}
/// Converts packed single precision floating point to packed double precision floating point.
///
/// Considering only the lower half of the register, the low lanes in `x` are interpreted as
/// single precision floats that are then converted to a double precision floats.
///
/// The result type will have half the number of vector lanes as the input. Fvpromote_low is
/// constrained to input F32x4 with a result type of F64x2.
///
/// Inputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
///
/// Outputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
#[allow(non_snake_case)]
fn fvpromote_low(self, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FvpromoteLow, types::INVALID, a);
dfg.first_result(inst)
}
/// Converts floating point scalars to unsigned integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUint, IntTo, x);
dfg.first_result(inst)
}
/// Converts floating point scalars to signed integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSint, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to unsigned integer as fcvt_to_uint does, but
/// saturates the input instead of trapping. NaN and negative values are
/// converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to signed integer as fcvt_to_sint does, but
/// saturates the input instead of trapping. NaN values are converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert unsigned integer to floating point.
///
/// Each lane in `x` is interpreted as an unsigned integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_uint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromUint, FloatTo, x);
dfg.first_result(inst)
}
/// Convert signed integer to floating point.
///
/// Each lane in `x` is interpreted as a signed integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Converts packed signed 32-bit integers to packed double precision floating point.
///
/// Considering only the low half of the register, each lane in `x` is interpreted as a
/// signed 32-bit integer that is then converted to a double precision float. This
/// instruction differs from fcvt_from_sint in that it converts half the number of lanes
/// which are converted to occupy twice the number of bits. No rounding should be needed
/// for the resulting float.
///
/// The result type will have half the number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_low_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtLowFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Split an integer into low and high parts.
///
/// Vectors of integers are split lane-wise, so the results have the same
/// number of lanes as the input, but the lanes are half the size.
///
/// Returns the low half of `x` and the high half of `x` as two independent
/// values.
///
/// Inputs:
///
/// - x: An integer type with lanes from `i16` upwards
///
/// Outputs:
///
/// - lo: The low bits of `x`
/// - hi: The high bits of `x`
#[allow(non_snake_case)]
fn isplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Isplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Concatenate low and high bits to form a larger integer type.
///
/// Vectors of integers are concatenated lane-wise such that the result has
/// the same number of lanes as the inputs, but the lanes are twice the
/// size.
///
/// Inputs:
///
/// - lo: An integer type with lanes type to `i64`
/// - hi: An integer type with lanes type to `i64`
///
/// Outputs:
///
/// - a: The concatenation of `lo` and `hi`
#[allow(non_snake_case)]
fn iconcat(self, lo: ir::Value, hi: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(lo);
let (inst, dfg) = self.Binary(Opcode::Iconcat, ctrl_typevar, lo, hi);
dfg.first_result(inst)
}sourcefn BinaryImm64(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Imm64,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn BinaryImm64(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Imm64,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
BinaryImm64(imms=(imm: ir::immediates::Imm64), vals=1)
Examples found in repository?
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837
fn ifcmp_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IfcmpImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Wrapping integer addition: `a := x + y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Iadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Wrapping integer subtraction: `a := x - y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn isub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Isub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer negation: `a := -x \pmod{2^B}`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ineg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ineg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Integer absolute value with wrapping: `a := |x|`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Iabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Wrapping integer multiplication: `a := x y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn imul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Imul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Fixed-point multiplication of numbers in the QN format, where N + 1
/// is the number bitwidth:
/// `a := signed_saturate((x * y + 1 << (Q - 1)) >> Q)`
///
/// Polymorphic over all integer types (scalar and vector) with 16- or
/// 32-bit numbers.
///
/// Inputs:
///
/// - x: A scalar or vector integer type with 16- or 32-bit numbers
/// - y: A scalar or vector integer type with 16- or 32-bit numbers
///
/// Outputs:
///
/// - a: A scalar or vector integer type with 16- or 32-bit numbers
#[allow(non_snake_case)]
fn sqmul_round_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SqmulRoundSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer division: `a := \lfloor {x \over y} \rfloor`.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Udiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer division rounded toward zero: `a := sign(xy)
/// \lfloor {|x| \over |y|}\rfloor`.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer remainder.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Urem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer remainder. The result has the sign of the dividend.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Srem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add immediate integer.
///
/// Same as `iadd`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IaddImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer multiplication by immediate constant.
///
/// Same as `imul`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn imul_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::ImulImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer division by an immediate constant.
///
/// Same as `udiv`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer division by an immediate constant.
///
/// Same as `sdiv`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, Y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer remainder with immediate divisor.
///
/// Same as `urem`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer remainder with immediate divisor.
///
/// Same as `srem`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Immediate reverse wrapping subtraction: `a := Y - x \pmod{2^B}`.
///
/// The immediate operand is a sign extended 64 bit constant.
///
/// Also works as integer negation when `Y = 0`. Use `iadd_imm`
/// with a negative immediate operand for the reverse immediate
/// subtraction.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn irsub_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IrsubImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_cin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry flag input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_ifcin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_cout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddCout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry flag output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddIfcout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_carry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry flag input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcarry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Unsigned addition of x and y, trapping if the result overflows.
///
/// Accepts 32 or 64-bit integers, and does not support vector types.
///
/// Inputs:
///
/// - x: A 32 or 64-bit scalar integer type
/// - y: A 32 or 64-bit scalar integer type
/// - code: A trap reason code.
///
/// Outputs:
///
/// - a: A 32 or 64-bit scalar integer type
#[allow(non_snake_case)]
fn uadd_overflow_trap<T1: Into<ir::TrapCode>>(self, x: ir::Value, y: ir::Value, code: T1) -> Value {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntAddTrap(Opcode::UaddOverflowTrap, ctrl_typevar, code, x, y);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_bin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_ifbin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfbin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_bout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubBout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifbout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubIfbout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_borrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBorrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifborrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfborrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Bitwise and.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Band, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bxor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise not.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bnot(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bnot, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Bitwise and not.
///
/// Computes `x & ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BandNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or not.
///
/// Computes `x | ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor not.
///
/// Computes `x ^ ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BxorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise and with immediate.
///
/// Same as `band`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn band_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BandImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise or with immediate.
///
/// Same as `bor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise xor with immediate.
///
/// Same as `bxor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bxor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BxorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate left.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate right.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate left by immediate.
///
/// Same as `rotl`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate right by immediate.
///
/// Same as `rotr`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer shift left. Shift the bits in ``x`` towards the MSB by ``y``
/// places. Shift in zero bits to the LSB.
///
/// The shift amount is masked to the size of ``x``.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= x \cdot 2^s \pmod{2^B}.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ishl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in zero bits to the MSB. Also called a *logical
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= \lfloor x \cdot 2^{-s} \rfloor.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ushr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in sign bits to the MSB. Also called an *arithmetic
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sshr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer shift left by immediate.
///
/// The shift amount is masked to the size of ``x``.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IshlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}More examples
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
fn simplify(pos: &mut FuncCursor, inst: Inst, native_word_width: u32) {
match pos.func.dfg[inst] {
InstructionData::Binary { opcode, args } => {
if let Some(mut imm) = resolve_imm64_value(&pos.func.dfg, args[1]) {
let new_opcode = match opcode {
Opcode::Iadd => Opcode::IaddImm,
Opcode::Imul => Opcode::ImulImm,
Opcode::Sdiv => Opcode::SdivImm,
Opcode::Udiv => Opcode::UdivImm,
Opcode::Srem => Opcode::SremImm,
Opcode::Urem => Opcode::UremImm,
Opcode::Band => Opcode::BandImm,
Opcode::Bor => Opcode::BorImm,
Opcode::Bxor => Opcode::BxorImm,
Opcode::Rotl => Opcode::RotlImm,
Opcode::Rotr => Opcode::RotrImm,
Opcode::Ishl => Opcode::IshlImm,
Opcode::Ushr => Opcode::UshrImm,
Opcode::Sshr => Opcode::SshrImm,
Opcode::Isub => {
imm = imm.wrapping_neg();
Opcode::IaddImm
}
Opcode::Ifcmp => Opcode::IfcmpImm,
_ => return,
};
let ty = pos.func.dfg.ctrl_typevar(inst);
if ty.bytes() <= native_word_width {
pos.func
.dfg
.replace(inst)
.BinaryImm64(new_opcode, ty, imm, args[0]);
// Repeat for BinaryImm simplification.
simplify(pos, inst, native_word_width);
}
} else if let Some(imm) = resolve_imm64_value(&pos.func.dfg, args[0]) {
let new_opcode = match opcode {
Opcode::Iadd => Opcode::IaddImm,
Opcode::Imul => Opcode::ImulImm,
Opcode::Band => Opcode::BandImm,
Opcode::Bor => Opcode::BorImm,
Opcode::Bxor => Opcode::BxorImm,
Opcode::Isub => Opcode::IrsubImm,
_ => return,
};
let ty = pos.func.dfg.ctrl_typevar(inst);
if ty.bytes() <= native_word_width {
pos.func
.dfg
.replace(inst)
.BinaryImm64(new_opcode, ty, imm, args[1]);
}
}
}
InstructionData::BinaryImm64 { opcode, arg, imm } => {
let ty = pos.func.dfg.ctrl_typevar(inst);
let mut arg = arg;
let mut imm = imm;
match opcode {
Opcode::IaddImm
| Opcode::ImulImm
| Opcode::BorImm
| Opcode::BandImm
| Opcode::BxorImm => {
// Fold binary_op(C2, binary_op(C1, x)) into binary_op(binary_op(C1, C2), x)
if let ValueDef::Result(arg_inst, _) = pos.func.dfg.value_def(arg) {
if let InstructionData::BinaryImm64 {
opcode: prev_opcode,
arg: prev_arg,
imm: prev_imm,
} = &pos.func.dfg[arg_inst]
{
if opcode == *prev_opcode
&& ty == pos.func.dfg.ctrl_typevar(arg_inst)
{
let lhs: i64 = imm.into();
let rhs: i64 = (*prev_imm).into();
let new_imm = match opcode {
Opcode::BorImm => lhs | rhs,
Opcode::BandImm => lhs & rhs,
Opcode::BxorImm => lhs ^ rhs,
Opcode::IaddImm => lhs.wrapping_add(rhs),
Opcode::ImulImm => lhs.wrapping_mul(rhs),
_ => panic!("can't happen"),
};
let new_imm = immediates::Imm64::from(new_imm);
let new_arg = *prev_arg;
pos.func
.dfg
.replace(inst)
.BinaryImm64(opcode, ty, new_imm, new_arg);
imm = new_imm;
arg = new_arg;
}
}
}
}
Opcode::UshrImm | Opcode::SshrImm => {
if pos.func.dfg.ctrl_typevar(inst).bytes() <= native_word_width
&& try_fold_extended_move(pos, inst, opcode, arg, imm)
{
return;
}
}
_ => {}
};
// Replace operations that are no-ops.
match (opcode, imm.into(), ty) {
(Opcode::IaddImm, 0, _)
| (Opcode::ImulImm, 1, _)
| (Opcode::SdivImm, 1, _)
| (Opcode::UdivImm, 1, _)
| (Opcode::BorImm, 0, _)
| (Opcode::BandImm, -1, _)
| (Opcode::BxorImm, 0, _)
| (Opcode::RotlImm, 0, _)
| (Opcode::RotrImm, 0, _)
| (Opcode::IshlImm, 0, _)
| (Opcode::UshrImm, 0, _)
| (Opcode::SshrImm, 0, _) => {
// Alias the result value with the original argument.
replace_single_result_with_alias(&mut pos.func.dfg, inst, arg);
}
(Opcode::ImulImm, 0, ty) | (Opcode::BandImm, 0, ty) if ty != I128 => {
// Replace by zero.
pos.func.dfg.replace(inst).iconst(ty, 0);
}
(Opcode::BorImm, -1, ty) if ty != I128 => {
// Replace by minus one.
pos.func.dfg.replace(inst).iconst(ty, -1);
}
_ => {}
}
}
InstructionData::IntCompare { opcode, cond, args } => {
debug_assert_eq!(opcode, Opcode::Icmp);
if let Some(imm) = resolve_imm64_value(&pos.func.dfg, args[1]) {
if pos.func.dfg.ctrl_typevar(inst).bytes() <= native_word_width {
pos.func.dfg.replace(inst).icmp_imm(cond, args[0], imm);
}
}
}
_ => {}
}
}sourcefn BinaryImm8(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Uimm8,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn BinaryImm8(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Uimm8,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
BinaryImm8(imms=(imm: ir::immediates::Uimm8), vals=1)
Examples found in repository?
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134
fn extractlane<T1: Into<ir::immediates::Uimm8>>(self, x: ir::Value, Idx: T1) -> Value {
let Idx = Idx.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm8(Opcode::Extractlane, ctrl_typevar, Idx, x);
dfg.first_result(inst)
}
/// Signed integer minimum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer minimum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer maximum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer maximum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned average with rounding: `a := (x + y + 1) // 2`
///
/// The addition does not lose any information (such as from overflow).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn avg_round(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::AvgRound, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add with unsigned saturation.
///
/// This is similar to `iadd` but the operands are interpreted as unsigned integers and their
/// summed result, instead of wrapping, will be saturated to the highest unsigned integer for
/// the controlling type (e.g. `0xFF` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn uadd_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::UaddSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add with signed saturation.
///
/// This is similar to `iadd` but the operands are interpreted as signed integers and their
/// summed result, instead of wrapping, will be saturated to the lowest or highest
/// signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8). For example,
/// since an `sadd_sat.i8` of `0x70` and `0x70` is greater than `0x7F`, the result will be
/// clamped to `0x7F`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn sadd_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SaddSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Subtract with unsigned saturation.
///
/// This is similar to `isub` but the operands are interpreted as unsigned integers and their
/// difference, instead of wrapping, will be saturated to the lowest unsigned integer for
/// the controlling type (e.g. `0x00` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn usub_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::UsubSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Subtract with signed saturation.
///
/// This is similar to `isub` but the operands are interpreted as signed integers and their
/// difference, instead of wrapping, will be saturated to the lowest or highest
/// signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn ssub_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SsubSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Load from memory at ``p + Offset``.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn load<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Load, Mem, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store ``x`` to memory at ``p + Offset``.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: Value to be stored
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn store<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Store, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 8 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i8`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn uload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 8 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i8`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn sload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 8 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i8`` followed by ``store.i8``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 8 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore8, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 16 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i16`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn uload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 16 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i16`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn sload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 16 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i16`` followed by ``store.i16``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 16 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore16, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 32 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i32`` followed by ``uextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn uload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 32 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i32`` followed by ``sextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn sload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 32 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i32`` followed by ``store.i32``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 32 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore32, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 32x2 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 32x2 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a value from a stack slot at the constant offset.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// The offset is an immediate constant, not an SSA value. The memory
/// access cannot go out of bounds, i.e.
/// `sizeof(a) + Offset <= sizeof(SS)`.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn stack_load<T1: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackLoad, Mem, SS, Offset);
dfg.first_result(inst)
}
/// Store a value to a stack slot at a constant offset.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// The offset is an immediate constant, not an SSA value. The memory
/// access cannot go out of bounds, i.e.
/// `sizeof(a) + Offset <= sizeof(SS)`.
///
/// Inputs:
///
/// - x: Value to be stored
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
#[allow(non_snake_case)]
fn stack_store<T1: Into<ir::immediates::Offset32>>(self, x: ir::Value, SS: ir::StackSlot, Offset: T1) -> Inst {
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.StackStore(Opcode::StackStore, ctrl_typevar, SS, Offset, x).0
}
/// Get the address of a stack slot.
///
/// Compute the absolute address of a byte in a stack slot. The offset must
/// refer to a byte inside the stack slot:
/// `0 <= Offset < sizeof(SS)`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn stack_addr<T1: Into<ir::immediates::Offset32>>(self, iAddr: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackAddr, iAddr, SS, Offset);
dfg.first_result(inst)
}
/// Load a value from a dynamic stack slot.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - DSS: A dynamic stack slot
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn dynamic_stack_load(self, Mem: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackLoad, Mem, DSS);
dfg.first_result(inst)
}
/// Store a value to a dynamic stack slot.
///
/// This is a polymorphic instruction that can store any dynamic value type with a
/// memory representation.
///
/// Inputs:
///
/// - x: Value to be stored
/// - DSS: A dynamic stack slot
#[allow(non_snake_case)]
fn dynamic_stack_store(self, x: ir::Value, DSS: ir::DynamicStackSlot) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.DynamicStackStore(Opcode::DynamicStackStore, ctrl_typevar, DSS, x).0
}
/// Get the address of a dynamic stack slot.
///
/// Compute the absolute address of the first byte of a dynamic stack slot.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - DSS: A dynamic stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn dynamic_stack_addr(self, iAddr: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackAddr, iAddr, DSS);
dfg.first_result(inst)
}
/// Compute the value of global GV.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn global_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::GlobalValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a symbolic value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn symbol_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::SymbolValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a TLS (thread local storage) value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn tls_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::TlsValue, Mem, GV);
dfg.first_result(inst)
}
/// Bounds check and compute absolute address of ``index + Offset`` in heap memory.
///
/// Verify that the range ``index .. index + Offset + Size`` is in bounds for the
/// heap ``H``, and generate an absolute address that is safe to dereference.
///
/// 1. If ``index + Offset + Size`` is less than or equal ot the heap bound, return an
/// absolute address corresponding to a byte offset of ``index + Offset`` from the
/// heap's base address.
///
/// 2. If ``index + Offset + Size`` is greater than the heap bound, return the
/// ``NULL`` pointer or any other address that is guaranteed to generate a trap
/// when accessed.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - H: A heap.
/// - index: An unsigned heap offset
/// - Offset: Static offset immediate in bytes
/// - Size: Static size immediate in bytes
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn heap_addr<T1: Into<ir::immediates::Uimm32>, T2: Into<ir::immediates::Uimm8>>(self, iAddr: crate::ir::Type, H: ir::Heap, index: ir::Value, Offset: T1, Size: T2) -> Value {
let Offset = Offset.into();
let Size = Size.into();
let (inst, dfg) = self.HeapAddr(Opcode::HeapAddr, iAddr, H, Offset, Size, index);
dfg.first_result(inst)
}
/// Load a value from the given heap at address ``index + offset``,
/// trapping on out-of-bounds accesses.
///
/// Checks that ``index + offset .. index + offset + sizeof(a)`` is
/// within the heap's bounds, trapping if it is not. Otherwise, when
/// that range is in bounds, loads the value from the heap.
///
/// Traps on ``index + offset + sizeof(a)`` overflow.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - heap_imm: Reference to out-of-line heap access immediates
/// - index: Dynamic index (in bytes) into the heap
///
/// Outputs:
///
/// - a: The value loaded from the heap
#[allow(non_snake_case)]
fn heap_load<T1: Into<ir::HeapImm>>(self, Mem: crate::ir::Type, heap_imm: T1, index: ir::Value) -> Value {
let heap_imm = heap_imm.into();
let (inst, dfg) = self.HeapLoad(Opcode::HeapLoad, Mem, heap_imm, index);
dfg.first_result(inst)
}
/// Store ``a`` into the given heap at address ``index + offset``,
/// trapping on out-of-bounds accesses.
///
/// Checks that ``index + offset .. index + offset + sizeof(a)`` is
/// within the heap's bounds, trapping if it is not. Otherwise, when
/// that range is in bounds, stores the value into the heap.
///
/// Traps on ``index + offset + sizeof(a)`` overflow.
///
/// Inputs:
///
/// - heap_imm: Reference to out-of-line heap access immediates
/// - index: Dynamic index (in bytes) into the heap
/// - a: The value stored into the heap
#[allow(non_snake_case)]
fn heap_store<T1: Into<ir::HeapImm>>(self, heap_imm: T1, index: ir::Value, a: ir::Value) -> Inst {
let heap_imm = heap_imm.into();
let ctrl_typevar = self.data_flow_graph().value_type(index);
self.HeapStore(Opcode::HeapStore, ctrl_typevar, heap_imm, index, a).0
}
/// Gets the content of the pinned register, when it's enabled.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_pinned_reg(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetPinnedReg, iAddr);
dfg.first_result(inst)
}
/// Sets the content of the pinned register, when it's enabled.
///
/// Inputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn set_pinned_reg(self, addr: ir::Value) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(addr);
self.Unary(Opcode::SetPinnedReg, ctrl_typevar, addr).0
}
/// Get the address in the frame pointer register.
///
/// Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_frame_pointer(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetFramePointer, iAddr);
dfg.first_result(inst)
}
/// Get the address in the stack pointer register.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_stack_pointer(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetStackPointer, iAddr);
dfg.first_result(inst)
}
/// Get the PC where this function will transfer control to when it returns.
///
/// Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_return_address(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetReturnAddress, iAddr);
dfg.first_result(inst)
}
/// Bounds check and compute absolute address of a table entry.
///
/// Verify that the offset ``p`` is in bounds for the table T, and generate
/// an absolute address that is safe to dereference.
///
/// ``Offset`` must be less than the size of a table element.
///
/// 1. If ``p`` is not greater than the table bound, return an absolute
/// address corresponding to a byte offset of ``p`` from the table's
/// base address.
/// 2. If ``p`` is greater than the table bound, generate a trap.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - T: A table.
/// - p: An unsigned table offset
/// - Offset: Byte offset from element address
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn table_addr<T1: Into<ir::immediates::Offset32>>(self, iAddr: crate::ir::Type, T: ir::Table, p: ir::Value, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.TableAddr(Opcode::TableAddr, iAddr, T, Offset, p);
dfg.first_result(inst)
}
/// Integer constant.
///
/// Create a scalar integer SSA value with an immediate constant value, or
/// an integer vector where all the lanes have the same value.
///
/// Inputs:
///
/// - NarrowInt (controlling type variable): An integer type with lanes type to `i64`
/// - N: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A constant integer scalar or vector value
#[allow(non_snake_case)]
fn iconst<T1: Into<ir::immediates::Imm64>>(self, NarrowInt: crate::ir::Type, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryImm(Opcode::Iconst, NarrowInt, N);
dfg.first_result(inst)
}
/// Floating point constant.
///
/// Create a `f32` SSA value with an immediate constant value.
///
/// Inputs:
///
/// - N: A 32-bit immediate floating point number.
///
/// Outputs:
///
/// - a: A constant f32 scalar value
#[allow(non_snake_case)]
fn f32const<T1: Into<ir::immediates::Ieee32>>(self, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryIeee32(Opcode::F32const, types::INVALID, N);
dfg.first_result(inst)
}
/// Floating point constant.
///
/// Create a `f64` SSA value with an immediate constant value.
///
/// Inputs:
///
/// - N: A 64-bit immediate floating point number.
///
/// Outputs:
///
/// - a: A constant f64 scalar value
#[allow(non_snake_case)]
fn f64const<T1: Into<ir::immediates::Ieee64>>(self, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryIeee64(Opcode::F64const, types::INVALID, N);
dfg.first_result(inst)
}
/// SIMD vector constant.
///
/// Construct a vector with the given immediate bytes.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - N: The 16 immediate bytes of a 128-bit vector
///
/// Outputs:
///
/// - a: A constant vector value
#[allow(non_snake_case)]
fn vconst<T1: Into<ir::Constant>>(self, TxN: crate::ir::Type, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryConst(Opcode::Vconst, TxN, N);
dfg.first_result(inst)
}
/// SIMD vector shuffle.
///
/// Shuffle two vectors using the given immediate bytes. For each of the 16 bytes of the
/// immediate, a value i of 0-15 selects the i-th element of the first vector and a value i of
/// 16-31 selects the (i-16)th element of the second vector. Immediate values outside of the
/// 0-31 range place a 0 in the resulting vector lane.
///
/// Inputs:
///
/// - a: A vector value
/// - b: A vector value
/// - mask: The 16 immediate bytes used for selecting the elements to shuffle
///
/// Outputs:
///
/// - a: A vector value
#[allow(non_snake_case)]
fn shuffle<T1: Into<ir::Immediate>>(self, a: ir::Value, b: ir::Value, mask: T1) -> Value {
let mask = mask.into();
let (inst, dfg) = self.Shuffle(Opcode::Shuffle, types::INVALID, mask, a, b);
dfg.first_result(inst)
}
/// Null constant value for reference types.
///
/// Create a scalar reference SSA value with a constant null value.
///
/// Inputs:
///
/// - Ref (controlling type variable): A scalar reference type
///
/// Outputs:
///
/// - a: A constant reference null value
#[allow(non_snake_case)]
fn null(self, Ref: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::Null, Ref);
dfg.first_result(inst)
}
/// Just a dummy instruction.
///
/// Note: this doesn't compile to a machine code nop.
#[allow(non_snake_case)]
fn nop(self) -> Inst {
self.NullAry(Opcode::Nop, types::INVALID).0
}
/// Conditional select.
///
/// This instruction selects whole values. Use `vselect` for
/// lane-wise selection.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn select(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Select, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select intended for Spectre guards.
///
/// This operation is semantically equivalent to a select instruction.
/// However, it is guaranteed to not be removed or otherwise altered by any
/// optimization pass, and is guaranteed to result in a conditional-move
/// instruction, not a branch-based lowering. As such, it is suitable
/// for use when producing Spectre guards. For example, a bounds-check
/// may guard against unsafe speculation past a bounds-check conditional
/// branch by passing the address or index to be accessed through a
/// conditional move, also gated on the same condition. Because no
/// Spectre-vulnerable processors are known to perform speculation on
/// conditional move instructions, this is guaranteed to pick the
/// correct input. If the selected input in case of overflow is a "safe"
/// value, for example a null pointer that causes an exception in the
/// speculative path, this ensures that no Spectre vulnerability will
/// exist.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn select_spectre_guard(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::SelectSpectreGuard, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select of bits.
///
/// For each bit in `c`, this instruction selects the corresponding bit from `x` if the bit
/// in `c` is 1 and the corresponding bit from `y` if the bit in `c` is 0. See also:
/// `select`, `vselect`.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn bitselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Bitselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Split a vector into two halves.
///
/// Split the vector `x` into two separate values, each containing half of
/// the lanes from ``x``. The result may be two scalars if ``x`` only had
/// two lanes.
///
/// Inputs:
///
/// - x: Vector to split
///
/// Outputs:
///
/// - lo: Low-numbered lanes of `x`
/// - hi: High-numbered lanes of `x`
#[allow(non_snake_case)]
fn vsplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Vsplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Vector concatenation.
///
/// Return a vector formed by concatenating ``x`` and ``y``. The resulting
/// vector type has twice as many lanes as each of the inputs. The lanes of
/// ``x`` appear as the low-numbered lanes, and the lanes of ``y`` become
/// the high-numbered lanes of ``a``.
///
/// It is possible to form a vector by concatenating two scalars.
///
/// Inputs:
///
/// - x: Low-numbered lanes
/// - y: High-numbered lanes
///
/// Outputs:
///
/// - a: Concatenation of `x` and `y`
#[allow(non_snake_case)]
fn vconcat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Vconcat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Vector lane select.
///
/// Select lanes from ``x`` or ``y`` controlled by the lanes of the truthy
/// vector ``c``.
///
/// Inputs:
///
/// - c: Controlling vector
/// - x: Value to use where `c` is true
/// - y: Value to use where `c` is false
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn vselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Vselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if any lane in ``a`` is non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vany_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VanyTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if all lanes in ``i`` are non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vall_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VallTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar integer.
///
/// Return a scalar integer, consisting of the concatenation of the most significant bit
/// of each lane of ``a``.
///
/// Inputs:
///
/// - Int (controlling type variable): A scalar or vector integer type
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - x: A scalar or vector integer type
#[allow(non_snake_case)]
fn vhigh_bits(self, Int: crate::ir::Type, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::VhighBits, Int, a);
dfg.first_result(inst)
}
/// Integer comparison.
///
/// The condition code determines if the operands are interpreted as signed
/// or unsigned integers.
///
/// | Signed | Unsigned | Condition |
/// |--------|----------|-----------------------|
/// | eq | eq | Equal |
/// | ne | ne | Not equal |
/// | slt | ult | Less than |
/// | sge | uge | Greater than or equal |
/// | sgt | ugt | Greater than |
/// | sle | ule | Less than or equal |
///
/// When this instruction compares integer vectors, it returns a vector of
/// lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn icmp<T1: Into<ir::condcodes::IntCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompare(Opcode::Icmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant.
///
/// This is the same as the `icmp` instruction, except one operand is
/// a sign extended 64 bit immediate constant.
///
/// This instruction can only compare scalars. Use `icmp` for
/// lane-wise vector comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn icmp_imm<T1: Into<ir::condcodes::IntCC>, T2: Into<ir::immediates::Imm64>>(self, Cond: T1, x: ir::Value, Y: T2) -> Value {
let Cond = Cond.into();
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompareImm(Opcode::IcmpImm, ctrl_typevar, Cond, Y, x);
dfg.first_result(inst)
}
/// Compare scalar integers and return flags.
///
/// Compare two scalar integer values and return integer CPU flags
/// representing the result.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ifcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant and return flags.
///
/// Like `icmp_imm`, but returns integer CPU flags instead of testing
/// a specific condition code.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IfcmpImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Wrapping integer addition: `a := x + y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Iadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Wrapping integer subtraction: `a := x - y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn isub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Isub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer negation: `a := -x \pmod{2^B}`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ineg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ineg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Integer absolute value with wrapping: `a := |x|`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Iabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Wrapping integer multiplication: `a := x y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn imul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Imul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Fixed-point multiplication of numbers in the QN format, where N + 1
/// is the number bitwidth:
/// `a := signed_saturate((x * y + 1 << (Q - 1)) >> Q)`
///
/// Polymorphic over all integer types (scalar and vector) with 16- or
/// 32-bit numbers.
///
/// Inputs:
///
/// - x: A scalar or vector integer type with 16- or 32-bit numbers
/// - y: A scalar or vector integer type with 16- or 32-bit numbers
///
/// Outputs:
///
/// - a: A scalar or vector integer type with 16- or 32-bit numbers
#[allow(non_snake_case)]
fn sqmul_round_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SqmulRoundSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer division: `a := \lfloor {x \over y} \rfloor`.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Udiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer division rounded toward zero: `a := sign(xy)
/// \lfloor {|x| \over |y|}\rfloor`.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer remainder.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Urem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer remainder. The result has the sign of the dividend.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Srem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add immediate integer.
///
/// Same as `iadd`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IaddImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer multiplication by immediate constant.
///
/// Same as `imul`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn imul_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::ImulImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer division by an immediate constant.
///
/// Same as `udiv`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer division by an immediate constant.
///
/// Same as `sdiv`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, Y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer remainder with immediate divisor.
///
/// Same as `urem`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer remainder with immediate divisor.
///
/// Same as `srem`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Immediate reverse wrapping subtraction: `a := Y - x \pmod{2^B}`.
///
/// The immediate operand is a sign extended 64 bit constant.
///
/// Also works as integer negation when `Y = 0`. Use `iadd_imm`
/// with a negative immediate operand for the reverse immediate
/// subtraction.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn irsub_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IrsubImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_cin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry flag input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_ifcin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_cout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddCout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry flag output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddIfcout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_carry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry flag input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcarry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Unsigned addition of x and y, trapping if the result overflows.
///
/// Accepts 32 or 64-bit integers, and does not support vector types.
///
/// Inputs:
///
/// - x: A 32 or 64-bit scalar integer type
/// - y: A 32 or 64-bit scalar integer type
/// - code: A trap reason code.
///
/// Outputs:
///
/// - a: A 32 or 64-bit scalar integer type
#[allow(non_snake_case)]
fn uadd_overflow_trap<T1: Into<ir::TrapCode>>(self, x: ir::Value, y: ir::Value, code: T1) -> Value {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntAddTrap(Opcode::UaddOverflowTrap, ctrl_typevar, code, x, y);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_bin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_ifbin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfbin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_bout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubBout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifbout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubIfbout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_borrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBorrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifborrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfborrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Bitwise and.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Band, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bxor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise not.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bnot(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bnot, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Bitwise and not.
///
/// Computes `x & ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BandNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or not.
///
/// Computes `x | ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor not.
///
/// Computes `x ^ ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BxorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise and with immediate.
///
/// Same as `band`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn band_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BandImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise or with immediate.
///
/// Same as `bor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise xor with immediate.
///
/// Same as `bxor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bxor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BxorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate left.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate right.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate left by immediate.
///
/// Same as `rotl`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate right by immediate.
///
/// Same as `rotr`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer shift left. Shift the bits in ``x`` towards the MSB by ``y``
/// places. Shift in zero bits to the LSB.
///
/// The shift amount is masked to the size of ``x``.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= x \cdot 2^s \pmod{2^B}.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ishl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in zero bits to the MSB. Also called a *logical
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= \lfloor x \cdot 2^{-s} \rfloor.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ushr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in sign bits to the MSB. Also called an *arithmetic
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sshr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer shift left by immediate.
///
/// The shift amount is masked to the size of ``x``.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IshlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Reverse the bits of a integer.
///
/// Reverses the bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bitrev(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bitrev, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading zero bits.
///
/// Starting from the MSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn clz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Clz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading sign bits.
///
/// Starting from the MSB after the sign bit in ``x``, count the number of
/// consecutive bits identical to the sign bit. When ``x`` is 0 or -1,
/// returns one less than the size of x in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn cls(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Cls, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count trailing zeros.
///
/// Starting from the LSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn ctz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ctz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reverse the byte order of an integer.
///
/// Reverses the bytes in ``x``.
///
/// Inputs:
///
/// - x: A multi byte scalar integer type
///
/// Outputs:
///
/// - a: A multi byte scalar integer type
#[allow(non_snake_case)]
fn bswap(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bswap, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Population count
///
/// Count the number of one bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn popcnt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Popcnt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point comparison.
///
/// Two IEEE 754-2008 floating point numbers, `x` and `y`, relate to each
/// other in exactly one of four ways:
///
/// ```text
/// == ==========================================
/// UN Unordered when one or both numbers is NaN.
/// EQ When `x = y`. (And `0.0 = -0.0`).
/// LT When `x < y`.
/// GT When `x > y`.
/// == ==========================================
/// ```
///
/// The 14 `floatcc` condition codes each correspond to a subset of
/// the four relations, except for the empty set which would always be
/// false, and the full set which would always be true.
///
/// The condition codes are divided into 7 'ordered' conditions which don't
/// include UN, and 7 unordered conditions which all include UN.
///
/// ```text
/// +-------+------------+---------+------------+-------------------------+
/// |Ordered |Unordered |Condition |
/// +=======+============+=========+============+=========================+
/// |ord |EQ | LT | GT|uno |UN |NaNs absent / present. |
/// +-------+------------+---------+------------+-------------------------+
/// |eq |EQ |ueq |UN | EQ |Equal |
/// +-------+------------+---------+------------+-------------------------+
/// |one |LT | GT |ne |UN | LT | GT|Not equal |
/// +-------+------------+---------+------------+-------------------------+
/// |lt |LT |ult |UN | LT |Less than |
/// +-------+------------+---------+------------+-------------------------+
/// |le |LT | EQ |ule |UN | LT | EQ|Less than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// |gt |GT |ugt |UN | GT |Greater than |
/// +-------+------------+---------+------------+-------------------------+
/// |ge |GT | EQ |uge |UN | GT | EQ|Greater than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// ```
///
/// The standard C comparison operators, `<, <=, >, >=`, are all ordered,
/// so they are false if either operand is NaN. The C equality operator,
/// `==`, is ordered, and since inequality is defined as the logical
/// inverse it is *unordered*. They map to the `floatcc` condition
/// codes as follows:
///
/// ```text
/// ==== ====== ============
/// C `Cond` Subset
/// ==== ====== ============
/// `==` eq EQ
/// `!=` ne UN | LT | GT
/// `<` lt LT
/// `<=` le LT | EQ
/// `>` gt GT
/// `>=` ge GT | EQ
/// ==== ====== ============
/// ```
///
/// This subset of condition codes also corresponds to the WebAssembly
/// floating point comparisons of the same name.
///
/// When this instruction compares floating point vectors, it returns a
/// vector with the results of lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: A floating point comparison condition code
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn fcmp<T1: Into<ir::condcodes::FloatCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.FloatCompare(Opcode::Fcmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Floating point comparison returning flags.
///
/// Compares two numbers like `fcmp`, but returns floating point CPU
/// flags instead of testing a specific condition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - f: CPU flags representing the result of a floating point comparison. These
/// flags can be tested with a :type:`floatcc` condition code.
#[allow(non_snake_case)]
fn ffcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ffcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point addition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point subtraction.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fsub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fsub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point multiplication.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fmul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point division.
///
/// Unlike the integer division instructions ` and
/// `udiv`, this can't trap. Division by zero is infinity or
/// NaN, depending on the dividend.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point square root.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn sqrt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Sqrt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point fused multiply-and-add.
///
/// Computes `a := xy+z` without any intermediate rounding of the
/// product.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
/// - z: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fma(self, x: ir::Value, y: ir::Value, z: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::Fma, ctrl_typevar, x, y, z);
dfg.first_result(inst)
}
/// Floating point negation.
///
/// Note that this is a pure bitwise operation.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit inverted
#[allow(non_snake_case)]
fn fneg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Fneg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point absolute value.
///
/// Note that this is a pure bitwise operation.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit cleared
#[allow(non_snake_case)]
fn fabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Fabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point copy sign.
///
/// Note that this is a pure bitwise operation. The sign bit from ``y`` is
/// copied to the sign bit of ``x``.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit changed to that of ``y``
#[allow(non_snake_case)]
fn fcopysign(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fcopysign, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point minimum, propagating NaNs using the WebAssembly rules.
///
/// If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
/// each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
/// 0, then the output has the same form. Otherwise, the output mantissa's most significant
/// bit is 1 and the rest is unspecified.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The smaller of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point pseudo-minimum, propagating NaNs. This behaves differently from ``fmin``.
/// See <https://github.com/WebAssembly/simd/pull/122> for background.
///
/// The behaviour is defined as ``fmin_pseudo(a, b) = (b < a) ? b : a``, and the behaviour
/// for zero or NaN inputs follows from the behaviour of ``<`` with such inputs.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The smaller of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmin_pseudo(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::FminPseudo, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point maximum, propagating NaNs using the WebAssembly rules.
///
/// If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
/// each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
/// 0, then the output has the same form. Otherwise, the output mantissa's most significant
/// bit is 1 and the rest is unspecified.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The larger of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point pseudo-maximum, propagating NaNs. This behaves differently from ``fmax``.
/// See <https://github.com/WebAssembly/simd/pull/122> for background.
///
/// The behaviour is defined as ``fmax_pseudo(a, b) = (a < b) ? b : a``, and the behaviour
/// for zero or NaN inputs follows from the behaviour of ``<`` with such inputs.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The larger of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmax_pseudo(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::FmaxPseudo, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards positive infinity.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn ceil(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ceil, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards negative infinity.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn floor(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Floor, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards zero.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn trunc(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Trunc, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards nearest with ties to
/// even.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn nearest(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Nearest, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reference verification.
///
/// The condition code determines if the reference type in question is
/// null or not.
///
/// Inputs:
///
/// - x: A scalar reference type
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn is_null(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::IsNull, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reference verification.
///
/// The condition code determines if the reference type in question is
/// invalid or not.
///
/// Inputs:
///
/// - x: A scalar reference type
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn is_invalid(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::IsInvalid, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reinterpret the bits in `x` as a different type.
///
/// The input and output types must be storable to memory and of the same
/// size. A bitcast is equivalent to storing one type and loading the other
/// type from the same address, both using the specified MemFlags.
///
/// Note that this operation only supports the `big` or `little` MemFlags.
/// The specified byte order only affects the result in the case where
/// input and output types differ in lane count/size. In this case, the
/// operation is only valid if a byte order specifier is provided.
///
/// Inputs:
///
/// - MemTo (controlling type variable):
/// - MemFlags: Memory operation flags
/// - x: Any type that can be stored in memory
///
/// Outputs:
///
/// - a: Bits of `x` reinterpreted
#[allow(non_snake_case)]
fn bitcast<T1: Into<ir::MemFlags>>(self, MemTo: crate::ir::Type, MemFlags: T1, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let (inst, dfg) = self.LoadNoOffset(Opcode::Bitcast, MemTo, MemFlags, x);
dfg.first_result(inst)
}
/// Copies a scalar value to a vector value. The scalar is copied into the
/// least significant lane of the vector, and all other lanes will be zero.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - s: A scalar value
///
/// Outputs:
///
/// - a: A vector value
#[allow(non_snake_case)]
fn scalar_to_vector(self, TxN: crate::ir::Type, s: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::ScalarToVector, TxN, s);
dfg.first_result(inst)
}
/// Convert `x` to an integer mask.
///
/// True maps to all 1s and false maps to all 0s. The result type must have
/// the same number of vector lanes as the input.
///
/// Inputs:
///
/// - IntTo (controlling type variable): An integer type with the same number of lanes
/// - x: A scalar or vector whose values are truthy
///
/// Outputs:
///
/// - a: An integer type with the same number of lanes
#[allow(non_snake_case)]
fn bmask(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Bmask, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller integer type by discarding
/// the most significant bits.
///
/// This is the same as reducing modulo `2^n`.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A smaller integer type
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A smaller integer type
#[allow(non_snake_case)]
fn ireduce(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Ireduce, IntTo, x);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the signed maximum and minimum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn snarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Snarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered signed: any negative lanes will overflow and be
/// replaced with the unsigned minimum, `0x00`.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn unarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Unarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered unsigned: any negative values will be interpreted as unsigned, overflowing and being replaced with the unsigned maximum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uunarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Uunarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Does lane-wise integer pairwise addition on two operands, putting the
/// combined results into a single vector result. Here a pair refers to adjacent
/// lanes in a vector, i.e. i*2 + (i*2+1) for i == num_lanes/2. The first operand
/// pairwise add results will make up the low half of the resulting vector while
/// the second operand pairwise add results will make up the upper half of the
/// resulting vector.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
/// - y: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
#[allow(non_snake_case)]
fn iadd_pairwise(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddPairwise, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Takes corresponding elements in `x` and `y`, performs a sign-extending length-doubling
/// multiplication on them, then adds adjacent pairs of elements to form the result. For
/// example, if the input vectors are `[x3, x2, x1, x0]` and `[y3, y2, y1, y0]`, it produces
/// the vector `[r1, r0]`, where `r1 = sx(x3) * sx(y3) + sx(x2) * sx(y2)` and
/// `r0 = sx(x1) * sx(y1) + sx(x0) * sx(y0)`, and `sx(n)` sign-extends `n` to twice its width.
///
/// This will double the lane width and halve the number of lanes. So the resulting
/// vector has the same number of bits as `x` and `y` do (individually).
///
/// See <https://github.com/WebAssembly/simd/pull/127> for background info.
///
/// Inputs:
///
/// - x: A SIMD vector type containing 8 integer lanes each 16 bits wide.
/// - y: A SIMD vector type containing 8 integer lanes each 16 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn widening_pairwise_dot_product_s(self, x: ir::Value, y: ir::Value) -> Value {
let (inst, dfg) = self.Binary(Opcode::WideningPairwiseDotProductS, types::INVALID, x, y);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by zero-extending.
///
/// Each lane in `x` is converted to a larger integer type by adding
/// zeroes. The result has the same numerical value as `x` when both are
/// interpreted as unsigned integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn uextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Uextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by sign-extending.
///
/// Each lane in `x` is converted to a larger integer type by replicating
/// the sign bit. The result has the same numerical value as `x` when both
/// are interpreted as signed integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn sextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Sextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger floating point format.
///
/// Each lane in `x` is converted to the destination floating point format.
/// This is an exact operation.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have fewer bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fpromote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fpromote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have more bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fdemote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fdemote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// Fvdemote differs from fdemote in that with fvdemote it targets vectors.
/// Fvdemote is constrained to having the input type being F64x2 and the result
/// type being F32x4. The result lane that was the upper half of the input lane
/// is initialized to zero.
///
/// Inputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
///
/// Outputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
#[allow(non_snake_case)]
fn fvdemote(self, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fvdemote, types::INVALID, x);
dfg.first_result(inst)
}
/// Converts packed single precision floating point to packed double precision floating point.
///
/// Considering only the lower half of the register, the low lanes in `x` are interpreted as
/// single precision floats that are then converted to a double precision floats.
///
/// The result type will have half the number of vector lanes as the input. Fvpromote_low is
/// constrained to input F32x4 with a result type of F64x2.
///
/// Inputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
///
/// Outputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
#[allow(non_snake_case)]
fn fvpromote_low(self, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FvpromoteLow, types::INVALID, a);
dfg.first_result(inst)
}
/// Converts floating point scalars to unsigned integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUint, IntTo, x);
dfg.first_result(inst)
}
/// Converts floating point scalars to signed integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSint, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to unsigned integer as fcvt_to_uint does, but
/// saturates the input instead of trapping. NaN and negative values are
/// converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to signed integer as fcvt_to_sint does, but
/// saturates the input instead of trapping. NaN values are converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert unsigned integer to floating point.
///
/// Each lane in `x` is interpreted as an unsigned integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_uint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromUint, FloatTo, x);
dfg.first_result(inst)
}
/// Convert signed integer to floating point.
///
/// Each lane in `x` is interpreted as a signed integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Converts packed signed 32-bit integers to packed double precision floating point.
///
/// Considering only the low half of the register, each lane in `x` is interpreted as a
/// signed 32-bit integer that is then converted to a double precision float. This
/// instruction differs from fcvt_from_sint in that it converts half the number of lanes
/// which are converted to occupy twice the number of bits. No rounding should be needed
/// for the resulting float.
///
/// The result type will have half the number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_low_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtLowFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Split an integer into low and high parts.
///
/// Vectors of integers are split lane-wise, so the results have the same
/// number of lanes as the input, but the lanes are half the size.
///
/// Returns the low half of `x` and the high half of `x` as two independent
/// values.
///
/// Inputs:
///
/// - x: An integer type with lanes from `i16` upwards
///
/// Outputs:
///
/// - lo: The low bits of `x`
/// - hi: The high bits of `x`
#[allow(non_snake_case)]
fn isplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Isplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Concatenate low and high bits to form a larger integer type.
///
/// Vectors of integers are concatenated lane-wise such that the result has
/// the same number of lanes as the inputs, but the lanes are twice the
/// size.
///
/// Inputs:
///
/// - lo: An integer type with lanes type to `i64`
/// - hi: An integer type with lanes type to `i64`
///
/// Outputs:
///
/// - a: The concatenation of `lo` and `hi`
#[allow(non_snake_case)]
fn iconcat(self, lo: ir::Value, hi: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(lo);
let (inst, dfg) = self.Binary(Opcode::Iconcat, ctrl_typevar, lo, hi);
dfg.first_result(inst)
}
/// Atomically read-modify-write memory at `p`, with second operand `x`. The old value is
/// returned. `p` has the type of the target word size, and `x` may be an integer type of
/// 8, 16, 32 or 64 bits, even on a 32-bit target. The type of the returned value is the
/// same as the type of `x`. This operation is sequentially consistent and creates
/// happens-before edges that order normal (non-atomic) loads and stores.
///
/// Inputs:
///
/// - AtomicMem (controlling type variable): Any type that can be stored in memory, which can be used in an atomic operation
/// - MemFlags: Memory operation flags
/// - AtomicRmwOp: Atomic Read-Modify-Write Ops
/// - p: An integer address type
/// - x: Value to be atomically stored
///
/// Outputs:
///
/// - a: Value atomically loaded
#[allow(non_snake_case)]
fn atomic_rmw<T1: Into<ir::MemFlags>, T2: Into<ir::AtomicRmwOp>>(self, AtomicMem: crate::ir::Type, MemFlags: T1, AtomicRmwOp: T2, p: ir::Value, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let AtomicRmwOp = AtomicRmwOp.into();
let (inst, dfg) = self.AtomicRmw(Opcode::AtomicRmw, AtomicMem, MemFlags, AtomicRmwOp, p, x);
dfg.first_result(inst)
}
/// Perform an atomic compare-and-swap operation on memory at `p`, with expected value `e`,
/// storing `x` if the value at `p` equals `e`. The old value at `p` is returned,
/// regardless of whether the operation succeeds or fails. `p` has the type of the target
/// word size, and `x` and `e` must have the same type and the same size, which may be an
/// integer type of 8, 16, 32 or 64 bits, even on a 32-bit target. The type of the returned
/// value is the same as the type of `x` and `e`. This operation is sequentially
/// consistent and creates happens-before edges that order normal (non-atomic) loads and
/// stores.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - e: Expected value in CAS
/// - x: Value to be atomically stored
///
/// Outputs:
///
/// - a: Value atomically loaded
#[allow(non_snake_case)]
fn atomic_cas<T1: Into<ir::MemFlags>>(self, MemFlags: T1, p: ir::Value, e: ir::Value, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.AtomicCas(Opcode::AtomicCas, ctrl_typevar, MemFlags, p, e, x);
dfg.first_result(inst)
}
/// Atomically load from memory at `p`.
///
/// This is a polymorphic instruction that can load any value type which has a memory
/// representation. It should only be used for integer types with 8, 16, 32 or 64 bits.
/// This operation is sequentially consistent and creates happens-before edges that order
/// normal (non-atomic) loads and stores.
///
/// Inputs:
///
/// - AtomicMem (controlling type variable): Any type that can be stored in memory, which can be used in an atomic operation
/// - MemFlags: Memory operation flags
/// - p: An integer address type
///
/// Outputs:
///
/// - a: Value atomically loaded
#[allow(non_snake_case)]
fn atomic_load<T1: Into<ir::MemFlags>>(self, AtomicMem: crate::ir::Type, MemFlags: T1, p: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let (inst, dfg) = self.LoadNoOffset(Opcode::AtomicLoad, AtomicMem, MemFlags, p);
dfg.first_result(inst)
}
/// Atomically store `x` to memory at `p`.
///
/// This is a polymorphic instruction that can store any value type with a memory
/// representation. It should only be used for integer types with 8, 16, 32 or 64 bits.
/// This operation is sequentially consistent and creates happens-before edges that order
/// normal (non-atomic) loads and stores.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: Value to be atomically stored
/// - p: An integer address type
#[allow(non_snake_case)]
fn atomic_store<T1: Into<ir::MemFlags>>(self, MemFlags: T1, x: ir::Value, p: ir::Value) -> Inst {
let MemFlags = MemFlags.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.StoreNoOffset(Opcode::AtomicStore, ctrl_typevar, MemFlags, x, p).0
}
/// A memory fence. This must provide ordering to ensure that, at a minimum, neither loads
/// nor stores of any kind may move forwards or backwards across the fence. This operation
/// is sequentially consistent.
#[allow(non_snake_case)]
fn fence(self) -> Inst {
self.NullAry(Opcode::Fence, types::INVALID).0
}
/// Return a fixed length sub vector, extracted from a dynamic vector.
///
/// Inputs:
///
/// - x: The dynamic vector to extract from
/// - y: 128-bit vector index
///
/// Outputs:
///
/// - a: New fixed vector
#[allow(non_snake_case)]
fn extract_vector<T1: Into<ir::immediates::Uimm8>>(self, x: ir::Value, y: T1) -> Value {
let y = y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm8(Opcode::ExtractVector, ctrl_typevar, y, x);
dfg.first_result(inst)
}sourcefn Branch(
self,
opcode: Opcode,
ctrl_typevar: Type,
destination: Block,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
fn Branch(
self,
opcode: Opcode,
ctrl_typevar: Type,
destination: Block,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
Branch(imms=(destination: ir::Block), vals=1)
Examples found in repository?
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
fn brz(mut self, c: ir::Value, block: ir::Block, args: &[Value]) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(c);
let mut vlist = ir::ValueList::default();
{
let pool = &mut self.data_flow_graph_mut().value_lists;
vlist.push(c, pool);
vlist.extend(args.iter().cloned(), pool);
}
self.Branch(Opcode::Brz, ctrl_typevar, block, vlist).0
}
/// Branch when non-zero.
///
/// Take the branch when ``c != 0``.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - block: Destination basic block
/// - args: block arguments
#[allow(non_snake_case)]
fn brnz(mut self, c: ir::Value, block: ir::Block, args: &[Value]) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(c);
let mut vlist = ir::ValueList::default();
{
let pool = &mut self.data_flow_graph_mut().value_lists;
vlist.push(c, pool);
vlist.extend(args.iter().cloned(), pool);
}
self.Branch(Opcode::Brnz, ctrl_typevar, block, vlist).0
}sourcefn BranchTable(
self,
opcode: Opcode,
ctrl_typevar: Type,
destination: Block,
table: JumpTable,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn BranchTable(
self,
opcode: Opcode,
ctrl_typevar: Type,
destination: Block,
table: JumpTable,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
BranchTable(imms=(destination: ir::Block, table: ir::JumpTable), vals=1)
sourcefn Call(
self,
opcode: Opcode,
ctrl_typevar: Type,
func_ref: FuncRef,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
fn Call(
self,
opcode: Opcode,
ctrl_typevar: Type,
func_ref: FuncRef,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
Call(imms=(func_ref: ir::FuncRef), vals=0)
sourcefn CallIndirect(
self,
opcode: Opcode,
ctrl_typevar: Type,
sig_ref: SigRef,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
fn CallIndirect(
self,
opcode: Opcode,
ctrl_typevar: Type,
sig_ref: SigRef,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
CallIndirect(imms=(sig_ref: ir::SigRef), vals=1)
sourcefn CondTrap(
self,
opcode: Opcode,
ctrl_typevar: Type,
code: TrapCode,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn CondTrap(
self,
opcode: Opcode,
ctrl_typevar: Type,
code: TrapCode,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
CondTrap(imms=(code: ir::TrapCode), vals=1)
Examples found in repository?
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
fn trapz<T1: Into<ir::TrapCode>>(self, c: ir::Value, code: T1) -> Inst {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(c);
self.CondTrap(Opcode::Trapz, ctrl_typevar, code, c).0
}
/// A resumable trap.
///
/// This instruction allows non-conditional traps to be used as non-terminal instructions.
///
/// Inputs:
///
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn resumable_trap<T1: Into<ir::TrapCode>>(self, code: T1) -> Inst {
let code = code.into();
self.Trap(Opcode::ResumableTrap, types::INVALID, code).0
}
/// Trap when non-zero.
///
/// If ``c`` is zero, execution continues at the following instruction.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn trapnz<T1: Into<ir::TrapCode>>(self, c: ir::Value, code: T1) -> Inst {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(c);
self.CondTrap(Opcode::Trapnz, ctrl_typevar, code, c).0
}
/// A resumable trap to be called when the passed condition is non-zero.
///
/// If ``c`` is zero, execution continues at the following instruction.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn resumable_trapnz<T1: Into<ir::TrapCode>>(self, c: ir::Value, code: T1) -> Inst {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(c);
self.CondTrap(Opcode::ResumableTrapnz, ctrl_typevar, code, c).0
}sourcefn DynamicStackLoad(
self,
opcode: Opcode,
ctrl_typevar: Type,
dynamic_stack_slot: DynamicStackSlot
) -> (Inst, &'f mut DataFlowGraph)
fn DynamicStackLoad(
self,
opcode: Opcode,
ctrl_typevar: Type,
dynamic_stack_slot: DynamicStackSlot
) -> (Inst, &'f mut DataFlowGraph)
DynamicStackLoad(imms=(dynamic_stack_slot: ir::DynamicStackSlot), vals=0)
Examples found in repository?
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
fn dynamic_stack_load(self, Mem: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackLoad, Mem, DSS);
dfg.first_result(inst)
}
/// Store a value to a dynamic stack slot.
///
/// This is a polymorphic instruction that can store any dynamic value type with a
/// memory representation.
///
/// Inputs:
///
/// - x: Value to be stored
/// - DSS: A dynamic stack slot
#[allow(non_snake_case)]
fn dynamic_stack_store(self, x: ir::Value, DSS: ir::DynamicStackSlot) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.DynamicStackStore(Opcode::DynamicStackStore, ctrl_typevar, DSS, x).0
}
/// Get the address of a dynamic stack slot.
///
/// Compute the absolute address of the first byte of a dynamic stack slot.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - DSS: A dynamic stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn dynamic_stack_addr(self, iAddr: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackAddr, iAddr, DSS);
dfg.first_result(inst)
}sourcefn DynamicStackStore(
self,
opcode: Opcode,
ctrl_typevar: Type,
dynamic_stack_slot: DynamicStackSlot,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn DynamicStackStore(
self,
opcode: Opcode,
ctrl_typevar: Type,
dynamic_stack_slot: DynamicStackSlot,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
DynamicStackStore(imms=(dynamic_stack_slot: ir::DynamicStackSlot), vals=1)
sourcefn FloatCompare(
self,
opcode: Opcode,
ctrl_typevar: Type,
cond: FloatCC,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn FloatCompare(
self,
opcode: Opcode,
ctrl_typevar: Type,
cond: FloatCC,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
FloatCompare(imms=(cond: ir::condcodes::FloatCC), vals=2)
sourcefn FuncAddr(
self,
opcode: Opcode,
ctrl_typevar: Type,
func_ref: FuncRef
) -> (Inst, &'f mut DataFlowGraph)
fn FuncAddr(
self,
opcode: Opcode,
ctrl_typevar: Type,
func_ref: FuncRef
) -> (Inst, &'f mut DataFlowGraph)
FuncAddr(imms=(func_ref: ir::FuncRef), vals=0)
sourcefn HeapAddr(
self,
opcode: Opcode,
ctrl_typevar: Type,
heap: Heap,
offset: Uimm32,
size: Uimm8,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn HeapAddr(
self,
opcode: Opcode,
ctrl_typevar: Type,
heap: Heap,
offset: Uimm32,
size: Uimm8,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
HeapAddr(imms=(heap: ir::Heap, offset: ir::immediates::Uimm32, size: ir::immediates::Uimm8), vals=1)
sourcefn HeapLoad(
self,
opcode: Opcode,
ctrl_typevar: Type,
heap_imm: HeapImm,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn HeapLoad(
self,
opcode: Opcode,
ctrl_typevar: Type,
heap_imm: HeapImm,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
HeapLoad(imms=(heap_imm: ir::HeapImm), vals=1)
sourcefn HeapStore(
self,
opcode: Opcode,
ctrl_typevar: Type,
heap_imm: HeapImm,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn HeapStore(
self,
opcode: Opcode,
ctrl_typevar: Type,
heap_imm: HeapImm,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
HeapStore(imms=(heap_imm: ir::HeapImm), vals=2)
sourcefn IntAddTrap(
self,
opcode: Opcode,
ctrl_typevar: Type,
code: TrapCode,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn IntAddTrap(
self,
opcode: Opcode,
ctrl_typevar: Type,
code: TrapCode,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
IntAddTrap(imms=(code: ir::TrapCode), vals=2)
sourcefn IntCompare(
self,
opcode: Opcode,
ctrl_typevar: Type,
cond: IntCC,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn IntCompare(
self,
opcode: Opcode,
ctrl_typevar: Type,
cond: IntCC,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
IntCompare(imms=(cond: ir::condcodes::IntCC), vals=2)
sourcefn IntCompareImm(
self,
opcode: Opcode,
ctrl_typevar: Type,
cond: IntCC,
imm: Imm64,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn IntCompareImm(
self,
opcode: Opcode,
ctrl_typevar: Type,
cond: IntCC,
imm: Imm64,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
IntCompareImm(imms=(cond: ir::condcodes::IntCC, imm: ir::immediates::Imm64), vals=1)
sourcefn Jump(
self,
opcode: Opcode,
ctrl_typevar: Type,
destination: Block,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
fn Jump(
self,
opcode: Opcode,
ctrl_typevar: Type,
destination: Block,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
Jump(imms=(destination: ir::Block), vals=0)
sourcefn Load(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
offset: Offset32,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn Load(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
offset: Offset32,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
Load(imms=(flags: ir::MemFlags, offset: ir::immediates::Offset32), vals=1)
Examples found in repository?
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
fn load<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Load, Mem, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store ``x`` to memory at ``p + Offset``.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: Value to be stored
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn store<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Store, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 8 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i8`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn uload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 8 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i8`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn sload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 8 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i8`` followed by ``store.i8``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 8 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore8, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 16 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i16`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn uload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 16 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i16`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn sload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 16 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i16`` followed by ``store.i16``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 16 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore16, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 32 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i32`` followed by ``uextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn uload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 32 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i32`` followed by ``sextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn sload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 32 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i32`` followed by ``store.i32``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 32 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore32, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 32x2 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 32x2 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}sourcefn LoadNoOffset(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn LoadNoOffset(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
LoadNoOffset(imms=(flags: ir::MemFlags), vals=1)
Examples found in repository?
3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089
fn bitcast<T1: Into<ir::MemFlags>>(self, MemTo: crate::ir::Type, MemFlags: T1, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let (inst, dfg) = self.LoadNoOffset(Opcode::Bitcast, MemTo, MemFlags, x);
dfg.first_result(inst)
}
/// Copies a scalar value to a vector value. The scalar is copied into the
/// least significant lane of the vector, and all other lanes will be zero.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - s: A scalar value
///
/// Outputs:
///
/// - a: A vector value
#[allow(non_snake_case)]
fn scalar_to_vector(self, TxN: crate::ir::Type, s: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::ScalarToVector, TxN, s);
dfg.first_result(inst)
}
/// Convert `x` to an integer mask.
///
/// True maps to all 1s and false maps to all 0s. The result type must have
/// the same number of vector lanes as the input.
///
/// Inputs:
///
/// - IntTo (controlling type variable): An integer type with the same number of lanes
/// - x: A scalar or vector whose values are truthy
///
/// Outputs:
///
/// - a: An integer type with the same number of lanes
#[allow(non_snake_case)]
fn bmask(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Bmask, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller integer type by discarding
/// the most significant bits.
///
/// This is the same as reducing modulo `2^n`.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A smaller integer type
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A smaller integer type
#[allow(non_snake_case)]
fn ireduce(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Ireduce, IntTo, x);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the signed maximum and minimum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn snarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Snarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered signed: any negative lanes will overflow and be
/// replaced with the unsigned minimum, `0x00`.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn unarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Unarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered unsigned: any negative values will be interpreted as unsigned, overflowing and being replaced with the unsigned maximum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uunarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Uunarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Does lane-wise integer pairwise addition on two operands, putting the
/// combined results into a single vector result. Here a pair refers to adjacent
/// lanes in a vector, i.e. i*2 + (i*2+1) for i == num_lanes/2. The first operand
/// pairwise add results will make up the low half of the resulting vector while
/// the second operand pairwise add results will make up the upper half of the
/// resulting vector.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
/// - y: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
#[allow(non_snake_case)]
fn iadd_pairwise(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddPairwise, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Takes corresponding elements in `x` and `y`, performs a sign-extending length-doubling
/// multiplication on them, then adds adjacent pairs of elements to form the result. For
/// example, if the input vectors are `[x3, x2, x1, x0]` and `[y3, y2, y1, y0]`, it produces
/// the vector `[r1, r0]`, where `r1 = sx(x3) * sx(y3) + sx(x2) * sx(y2)` and
/// `r0 = sx(x1) * sx(y1) + sx(x0) * sx(y0)`, and `sx(n)` sign-extends `n` to twice its width.
///
/// This will double the lane width and halve the number of lanes. So the resulting
/// vector has the same number of bits as `x` and `y` do (individually).
///
/// See <https://github.com/WebAssembly/simd/pull/127> for background info.
///
/// Inputs:
///
/// - x: A SIMD vector type containing 8 integer lanes each 16 bits wide.
/// - y: A SIMD vector type containing 8 integer lanes each 16 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn widening_pairwise_dot_product_s(self, x: ir::Value, y: ir::Value) -> Value {
let (inst, dfg) = self.Binary(Opcode::WideningPairwiseDotProductS, types::INVALID, x, y);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by zero-extending.
///
/// Each lane in `x` is converted to a larger integer type by adding
/// zeroes. The result has the same numerical value as `x` when both are
/// interpreted as unsigned integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn uextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Uextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by sign-extending.
///
/// Each lane in `x` is converted to a larger integer type by replicating
/// the sign bit. The result has the same numerical value as `x` when both
/// are interpreted as signed integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn sextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Sextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger floating point format.
///
/// Each lane in `x` is converted to the destination floating point format.
/// This is an exact operation.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have fewer bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fpromote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fpromote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have more bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fdemote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fdemote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// Fvdemote differs from fdemote in that with fvdemote it targets vectors.
/// Fvdemote is constrained to having the input type being F64x2 and the result
/// type being F32x4. The result lane that was the upper half of the input lane
/// is initialized to zero.
///
/// Inputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
///
/// Outputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
#[allow(non_snake_case)]
fn fvdemote(self, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fvdemote, types::INVALID, x);
dfg.first_result(inst)
}
/// Converts packed single precision floating point to packed double precision floating point.
///
/// Considering only the lower half of the register, the low lanes in `x` are interpreted as
/// single precision floats that are then converted to a double precision floats.
///
/// The result type will have half the number of vector lanes as the input. Fvpromote_low is
/// constrained to input F32x4 with a result type of F64x2.
///
/// Inputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
///
/// Outputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
#[allow(non_snake_case)]
fn fvpromote_low(self, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FvpromoteLow, types::INVALID, a);
dfg.first_result(inst)
}
/// Converts floating point scalars to unsigned integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUint, IntTo, x);
dfg.first_result(inst)
}
/// Converts floating point scalars to signed integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSint, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to unsigned integer as fcvt_to_uint does, but
/// saturates the input instead of trapping. NaN and negative values are
/// converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to signed integer as fcvt_to_sint does, but
/// saturates the input instead of trapping. NaN values are converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert unsigned integer to floating point.
///
/// Each lane in `x` is interpreted as an unsigned integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_uint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromUint, FloatTo, x);
dfg.first_result(inst)
}
/// Convert signed integer to floating point.
///
/// Each lane in `x` is interpreted as a signed integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Converts packed signed 32-bit integers to packed double precision floating point.
///
/// Considering only the low half of the register, each lane in `x` is interpreted as a
/// signed 32-bit integer that is then converted to a double precision float. This
/// instruction differs from fcvt_from_sint in that it converts half the number of lanes
/// which are converted to occupy twice the number of bits. No rounding should be needed
/// for the resulting float.
///
/// The result type will have half the number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_low_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtLowFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Split an integer into low and high parts.
///
/// Vectors of integers are split lane-wise, so the results have the same
/// number of lanes as the input, but the lanes are half the size.
///
/// Returns the low half of `x` and the high half of `x` as two independent
/// values.
///
/// Inputs:
///
/// - x: An integer type with lanes from `i16` upwards
///
/// Outputs:
///
/// - lo: The low bits of `x`
/// - hi: The high bits of `x`
#[allow(non_snake_case)]
fn isplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Isplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Concatenate low and high bits to form a larger integer type.
///
/// Vectors of integers are concatenated lane-wise such that the result has
/// the same number of lanes as the inputs, but the lanes are twice the
/// size.
///
/// Inputs:
///
/// - lo: An integer type with lanes type to `i64`
/// - hi: An integer type with lanes type to `i64`
///
/// Outputs:
///
/// - a: The concatenation of `lo` and `hi`
#[allow(non_snake_case)]
fn iconcat(self, lo: ir::Value, hi: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(lo);
let (inst, dfg) = self.Binary(Opcode::Iconcat, ctrl_typevar, lo, hi);
dfg.first_result(inst)
}
/// Atomically read-modify-write memory at `p`, with second operand `x`. The old value is
/// returned. `p` has the type of the target word size, and `x` may be an integer type of
/// 8, 16, 32 or 64 bits, even on a 32-bit target. The type of the returned value is the
/// same as the type of `x`. This operation is sequentially consistent and creates
/// happens-before edges that order normal (non-atomic) loads and stores.
///
/// Inputs:
///
/// - AtomicMem (controlling type variable): Any type that can be stored in memory, which can be used in an atomic operation
/// - MemFlags: Memory operation flags
/// - AtomicRmwOp: Atomic Read-Modify-Write Ops
/// - p: An integer address type
/// - x: Value to be atomically stored
///
/// Outputs:
///
/// - a: Value atomically loaded
#[allow(non_snake_case)]
fn atomic_rmw<T1: Into<ir::MemFlags>, T2: Into<ir::AtomicRmwOp>>(self, AtomicMem: crate::ir::Type, MemFlags: T1, AtomicRmwOp: T2, p: ir::Value, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let AtomicRmwOp = AtomicRmwOp.into();
let (inst, dfg) = self.AtomicRmw(Opcode::AtomicRmw, AtomicMem, MemFlags, AtomicRmwOp, p, x);
dfg.first_result(inst)
}
/// Perform an atomic compare-and-swap operation on memory at `p`, with expected value `e`,
/// storing `x` if the value at `p` equals `e`. The old value at `p` is returned,
/// regardless of whether the operation succeeds or fails. `p` has the type of the target
/// word size, and `x` and `e` must have the same type and the same size, which may be an
/// integer type of 8, 16, 32 or 64 bits, even on a 32-bit target. The type of the returned
/// value is the same as the type of `x` and `e`. This operation is sequentially
/// consistent and creates happens-before edges that order normal (non-atomic) loads and
/// stores.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - e: Expected value in CAS
/// - x: Value to be atomically stored
///
/// Outputs:
///
/// - a: Value atomically loaded
#[allow(non_snake_case)]
fn atomic_cas<T1: Into<ir::MemFlags>>(self, MemFlags: T1, p: ir::Value, e: ir::Value, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.AtomicCas(Opcode::AtomicCas, ctrl_typevar, MemFlags, p, e, x);
dfg.first_result(inst)
}
/// Atomically load from memory at `p`.
///
/// This is a polymorphic instruction that can load any value type which has a memory
/// representation. It should only be used for integer types with 8, 16, 32 or 64 bits.
/// This operation is sequentially consistent and creates happens-before edges that order
/// normal (non-atomic) loads and stores.
///
/// Inputs:
///
/// - AtomicMem (controlling type variable): Any type that can be stored in memory, which can be used in an atomic operation
/// - MemFlags: Memory operation flags
/// - p: An integer address type
///
/// Outputs:
///
/// - a: Value atomically loaded
#[allow(non_snake_case)]
fn atomic_load<T1: Into<ir::MemFlags>>(self, AtomicMem: crate::ir::Type, MemFlags: T1, p: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let (inst, dfg) = self.LoadNoOffset(Opcode::AtomicLoad, AtomicMem, MemFlags, p);
dfg.first_result(inst)
}sourcefn MultiAry(
self,
opcode: Opcode,
ctrl_typevar: Type,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
fn MultiAry(
self,
opcode: Opcode,
ctrl_typevar: Type,
args: ValueList
) -> (Inst, &'f mut DataFlowGraph)
MultiAry(imms=(), vals=0)
sourcefn NullAry(
self,
opcode: Opcode,
ctrl_typevar: Type
) -> (Inst, &'f mut DataFlowGraph)
fn NullAry(
self,
opcode: Opcode,
ctrl_typevar: Type
) -> (Inst, &'f mut DataFlowGraph)
NullAry(imms=(), vals=0)
Examples found in repository?
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116
fn debugtrap(self) -> Inst {
self.NullAry(Opcode::Debugtrap, types::INVALID).0
}
/// Terminate execution unconditionally.
///
/// Inputs:
///
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn trap<T1: Into<ir::TrapCode>>(self, code: T1) -> Inst {
let code = code.into();
self.Trap(Opcode::Trap, types::INVALID, code).0
}
/// Trap when zero.
///
/// if ``c`` is non-zero, execution continues at the following instruction.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn trapz<T1: Into<ir::TrapCode>>(self, c: ir::Value, code: T1) -> Inst {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(c);
self.CondTrap(Opcode::Trapz, ctrl_typevar, code, c).0
}
/// A resumable trap.
///
/// This instruction allows non-conditional traps to be used as non-terminal instructions.
///
/// Inputs:
///
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn resumable_trap<T1: Into<ir::TrapCode>>(self, code: T1) -> Inst {
let code = code.into();
self.Trap(Opcode::ResumableTrap, types::INVALID, code).0
}
/// Trap when non-zero.
///
/// If ``c`` is zero, execution continues at the following instruction.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn trapnz<T1: Into<ir::TrapCode>>(self, c: ir::Value, code: T1) -> Inst {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(c);
self.CondTrap(Opcode::Trapnz, ctrl_typevar, code, c).0
}
/// A resumable trap to be called when the passed condition is non-zero.
///
/// If ``c`` is zero, execution continues at the following instruction.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn resumable_trapnz<T1: Into<ir::TrapCode>>(self, c: ir::Value, code: T1) -> Inst {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(c);
self.CondTrap(Opcode::ResumableTrapnz, ctrl_typevar, code, c).0
}
/// Return from the function.
///
/// Unconditionally transfer control to the calling function, passing the
/// provided return values. The list of return values must match the
/// function signature's return types.
///
/// Inputs:
///
/// - rvals: return values
#[allow(non_snake_case)]
fn return_(mut self, rvals: &[Value]) -> Inst {
let mut vlist = ir::ValueList::default();
{
let pool = &mut self.data_flow_graph_mut().value_lists;
vlist.extend(rvals.iter().cloned(), pool);
}
self.MultiAry(Opcode::Return, types::INVALID, vlist).0
}
/// Direct function call.
///
/// Call a function which has been declared in the preamble. The argument
/// types must match the function's signature.
///
/// Inputs:
///
/// - FN: function to call, declared by `function`
/// - args: call arguments
///
/// Outputs:
///
/// - rvals: return values
#[allow(non_snake_case)]
fn call(mut self, FN: ir::FuncRef, args: &[Value]) -> Inst {
let mut vlist = ir::ValueList::default();
{
let pool = &mut self.data_flow_graph_mut().value_lists;
vlist.extend(args.iter().cloned(), pool);
}
self.Call(Opcode::Call, types::INVALID, FN, vlist).0
}
/// Indirect function call.
///
/// Call the function pointed to by `callee` with the given arguments. The
/// called function must match the specified signature.
///
/// Note that this is different from WebAssembly's ``call_indirect``; the
/// callee is a native address, rather than a table index. For WebAssembly,
/// `table_addr` and `load` are used to obtain a native address
/// from a table.
///
/// Inputs:
///
/// - SIG: function signature
/// - callee: address of function to call
/// - args: call arguments
///
/// Outputs:
///
/// - rvals: return values
#[allow(non_snake_case)]
fn call_indirect(mut self, SIG: ir::SigRef, callee: ir::Value, args: &[Value]) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(callee);
let mut vlist = ir::ValueList::default();
{
let pool = &mut self.data_flow_graph_mut().value_lists;
vlist.push(callee, pool);
vlist.extend(args.iter().cloned(), pool);
}
self.CallIndirect(Opcode::CallIndirect, ctrl_typevar, SIG, vlist).0
}
/// Get the address of a function.
///
/// Compute the absolute address of a function declared in the preamble.
/// The returned address can be used as a ``callee`` argument to
/// `call_indirect`. This is also a method for calling functions that
/// are too far away to be addressable by a direct `call`
/// instruction.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - FN: function to call, declared by `function`
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn func_addr(self, iAddr: crate::ir::Type, FN: ir::FuncRef) -> Value {
let (inst, dfg) = self.FuncAddr(Opcode::FuncAddr, iAddr, FN);
dfg.first_result(inst)
}
/// Vector splat.
///
/// Return a vector whose lanes are all ``x``.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - x: Value to splat to all lanes
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn splat(self, TxN: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Splat, TxN, x);
dfg.first_result(inst)
}
/// Vector swizzle.
///
/// Returns a new vector with byte-width lanes selected from the lanes of the first input
/// vector ``x`` specified in the second input vector ``s``. The indices ``i`` in range
/// ``[0, 15]`` select the ``i``-th element of ``x``. For indices outside of the range the
/// resulting lane is 0. Note that this operates on byte-width lanes.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - x: Vector to modify by re-arranging lanes
/// - y: Mask for re-arranging lanes
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn swizzle(self, TxN: crate::ir::Type, x: ir::Value, y: ir::Value) -> Value {
let (inst, dfg) = self.Binary(Opcode::Swizzle, TxN, x, y);
dfg.first_result(inst)
}
/// Insert ``y`` as lane ``Idx`` in x.
///
/// The lane index, ``Idx``, is an immediate value, not an SSA value. It
/// must indicate a valid lane index for the type of ``x``.
///
/// Inputs:
///
/// - x: The vector to modify
/// - y: New lane value
/// - Idx: Lane index
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn insertlane<T1: Into<ir::immediates::Uimm8>>(self, x: ir::Value, y: ir::Value, Idx: T1) -> Value {
let Idx = Idx.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.TernaryImm8(Opcode::Insertlane, ctrl_typevar, Idx, x, y);
dfg.first_result(inst)
}
/// Extract lane ``Idx`` from ``x``.
///
/// The lane index, ``Idx``, is an immediate value, not an SSA value. It
/// must indicate a valid lane index for the type of ``x``. Note that the upper bits of ``a``
/// may or may not be zeroed depending on the ISA but the type system should prevent using
/// ``a`` as anything other than the extracted value.
///
/// Inputs:
///
/// - x: A SIMD vector type
/// - Idx: Lane index
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn extractlane<T1: Into<ir::immediates::Uimm8>>(self, x: ir::Value, Idx: T1) -> Value {
let Idx = Idx.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm8(Opcode::Extractlane, ctrl_typevar, Idx, x);
dfg.first_result(inst)
}
/// Signed integer minimum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer minimum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer maximum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer maximum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned average with rounding: `a := (x + y + 1) // 2`
///
/// The addition does not lose any information (such as from overflow).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn avg_round(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::AvgRound, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add with unsigned saturation.
///
/// This is similar to `iadd` but the operands are interpreted as unsigned integers and their
/// summed result, instead of wrapping, will be saturated to the highest unsigned integer for
/// the controlling type (e.g. `0xFF` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn uadd_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::UaddSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add with signed saturation.
///
/// This is similar to `iadd` but the operands are interpreted as signed integers and their
/// summed result, instead of wrapping, will be saturated to the lowest or highest
/// signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8). For example,
/// since an `sadd_sat.i8` of `0x70` and `0x70` is greater than `0x7F`, the result will be
/// clamped to `0x7F`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn sadd_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SaddSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Subtract with unsigned saturation.
///
/// This is similar to `isub` but the operands are interpreted as unsigned integers and their
/// difference, instead of wrapping, will be saturated to the lowest unsigned integer for
/// the controlling type (e.g. `0x00` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn usub_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::UsubSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Subtract with signed saturation.
///
/// This is similar to `isub` but the operands are interpreted as signed integers and their
/// difference, instead of wrapping, will be saturated to the lowest or highest
/// signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn ssub_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SsubSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Load from memory at ``p + Offset``.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn load<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Load, Mem, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store ``x`` to memory at ``p + Offset``.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: Value to be stored
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn store<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Store, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 8 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i8`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn uload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 8 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i8`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn sload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 8 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i8`` followed by ``store.i8``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 8 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore8, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 16 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i16`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn uload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 16 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i16`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn sload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 16 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i16`` followed by ``store.i16``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 16 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore16, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 32 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i32`` followed by ``uextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn uload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 32 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i32`` followed by ``sextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn sload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 32 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i32`` followed by ``store.i32``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 32 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore32, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 32x2 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 32x2 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a value from a stack slot at the constant offset.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// The offset is an immediate constant, not an SSA value. The memory
/// access cannot go out of bounds, i.e.
/// `sizeof(a) + Offset <= sizeof(SS)`.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn stack_load<T1: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackLoad, Mem, SS, Offset);
dfg.first_result(inst)
}
/// Store a value to a stack slot at a constant offset.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// The offset is an immediate constant, not an SSA value. The memory
/// access cannot go out of bounds, i.e.
/// `sizeof(a) + Offset <= sizeof(SS)`.
///
/// Inputs:
///
/// - x: Value to be stored
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
#[allow(non_snake_case)]
fn stack_store<T1: Into<ir::immediates::Offset32>>(self, x: ir::Value, SS: ir::StackSlot, Offset: T1) -> Inst {
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.StackStore(Opcode::StackStore, ctrl_typevar, SS, Offset, x).0
}
/// Get the address of a stack slot.
///
/// Compute the absolute address of a byte in a stack slot. The offset must
/// refer to a byte inside the stack slot:
/// `0 <= Offset < sizeof(SS)`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn stack_addr<T1: Into<ir::immediates::Offset32>>(self, iAddr: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackAddr, iAddr, SS, Offset);
dfg.first_result(inst)
}
/// Load a value from a dynamic stack slot.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - DSS: A dynamic stack slot
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn dynamic_stack_load(self, Mem: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackLoad, Mem, DSS);
dfg.first_result(inst)
}
/// Store a value to a dynamic stack slot.
///
/// This is a polymorphic instruction that can store any dynamic value type with a
/// memory representation.
///
/// Inputs:
///
/// - x: Value to be stored
/// - DSS: A dynamic stack slot
#[allow(non_snake_case)]
fn dynamic_stack_store(self, x: ir::Value, DSS: ir::DynamicStackSlot) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.DynamicStackStore(Opcode::DynamicStackStore, ctrl_typevar, DSS, x).0
}
/// Get the address of a dynamic stack slot.
///
/// Compute the absolute address of the first byte of a dynamic stack slot.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - DSS: A dynamic stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn dynamic_stack_addr(self, iAddr: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackAddr, iAddr, DSS);
dfg.first_result(inst)
}
/// Compute the value of global GV.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn global_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::GlobalValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a symbolic value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn symbol_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::SymbolValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a TLS (thread local storage) value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn tls_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::TlsValue, Mem, GV);
dfg.first_result(inst)
}
/// Bounds check and compute absolute address of ``index + Offset`` in heap memory.
///
/// Verify that the range ``index .. index + Offset + Size`` is in bounds for the
/// heap ``H``, and generate an absolute address that is safe to dereference.
///
/// 1. If ``index + Offset + Size`` is less than or equal ot the heap bound, return an
/// absolute address corresponding to a byte offset of ``index + Offset`` from the
/// heap's base address.
///
/// 2. If ``index + Offset + Size`` is greater than the heap bound, return the
/// ``NULL`` pointer or any other address that is guaranteed to generate a trap
/// when accessed.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - H: A heap.
/// - index: An unsigned heap offset
/// - Offset: Static offset immediate in bytes
/// - Size: Static size immediate in bytes
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn heap_addr<T1: Into<ir::immediates::Uimm32>, T2: Into<ir::immediates::Uimm8>>(self, iAddr: crate::ir::Type, H: ir::Heap, index: ir::Value, Offset: T1, Size: T2) -> Value {
let Offset = Offset.into();
let Size = Size.into();
let (inst, dfg) = self.HeapAddr(Opcode::HeapAddr, iAddr, H, Offset, Size, index);
dfg.first_result(inst)
}
/// Load a value from the given heap at address ``index + offset``,
/// trapping on out-of-bounds accesses.
///
/// Checks that ``index + offset .. index + offset + sizeof(a)`` is
/// within the heap's bounds, trapping if it is not. Otherwise, when
/// that range is in bounds, loads the value from the heap.
///
/// Traps on ``index + offset + sizeof(a)`` overflow.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - heap_imm: Reference to out-of-line heap access immediates
/// - index: Dynamic index (in bytes) into the heap
///
/// Outputs:
///
/// - a: The value loaded from the heap
#[allow(non_snake_case)]
fn heap_load<T1: Into<ir::HeapImm>>(self, Mem: crate::ir::Type, heap_imm: T1, index: ir::Value) -> Value {
let heap_imm = heap_imm.into();
let (inst, dfg) = self.HeapLoad(Opcode::HeapLoad, Mem, heap_imm, index);
dfg.first_result(inst)
}
/// Store ``a`` into the given heap at address ``index + offset``,
/// trapping on out-of-bounds accesses.
///
/// Checks that ``index + offset .. index + offset + sizeof(a)`` is
/// within the heap's bounds, trapping if it is not. Otherwise, when
/// that range is in bounds, stores the value into the heap.
///
/// Traps on ``index + offset + sizeof(a)`` overflow.
///
/// Inputs:
///
/// - heap_imm: Reference to out-of-line heap access immediates
/// - index: Dynamic index (in bytes) into the heap
/// - a: The value stored into the heap
#[allow(non_snake_case)]
fn heap_store<T1: Into<ir::HeapImm>>(self, heap_imm: T1, index: ir::Value, a: ir::Value) -> Inst {
let heap_imm = heap_imm.into();
let ctrl_typevar = self.data_flow_graph().value_type(index);
self.HeapStore(Opcode::HeapStore, ctrl_typevar, heap_imm, index, a).0
}
/// Gets the content of the pinned register, when it's enabled.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_pinned_reg(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetPinnedReg, iAddr);
dfg.first_result(inst)
}
/// Sets the content of the pinned register, when it's enabled.
///
/// Inputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn set_pinned_reg(self, addr: ir::Value) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(addr);
self.Unary(Opcode::SetPinnedReg, ctrl_typevar, addr).0
}
/// Get the address in the frame pointer register.
///
/// Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_frame_pointer(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetFramePointer, iAddr);
dfg.first_result(inst)
}
/// Get the address in the stack pointer register.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_stack_pointer(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetStackPointer, iAddr);
dfg.first_result(inst)
}
/// Get the PC where this function will transfer control to when it returns.
///
/// Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_return_address(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetReturnAddress, iAddr);
dfg.first_result(inst)
}
/// Bounds check and compute absolute address of a table entry.
///
/// Verify that the offset ``p`` is in bounds for the table T, and generate
/// an absolute address that is safe to dereference.
///
/// ``Offset`` must be less than the size of a table element.
///
/// 1. If ``p`` is not greater than the table bound, return an absolute
/// address corresponding to a byte offset of ``p`` from the table's
/// base address.
/// 2. If ``p`` is greater than the table bound, generate a trap.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - T: A table.
/// - p: An unsigned table offset
/// - Offset: Byte offset from element address
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn table_addr<T1: Into<ir::immediates::Offset32>>(self, iAddr: crate::ir::Type, T: ir::Table, p: ir::Value, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.TableAddr(Opcode::TableAddr, iAddr, T, Offset, p);
dfg.first_result(inst)
}
/// Integer constant.
///
/// Create a scalar integer SSA value with an immediate constant value, or
/// an integer vector where all the lanes have the same value.
///
/// Inputs:
///
/// - NarrowInt (controlling type variable): An integer type with lanes type to `i64`
/// - N: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A constant integer scalar or vector value
#[allow(non_snake_case)]
fn iconst<T1: Into<ir::immediates::Imm64>>(self, NarrowInt: crate::ir::Type, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryImm(Opcode::Iconst, NarrowInt, N);
dfg.first_result(inst)
}
/// Floating point constant.
///
/// Create a `f32` SSA value with an immediate constant value.
///
/// Inputs:
///
/// - N: A 32-bit immediate floating point number.
///
/// Outputs:
///
/// - a: A constant f32 scalar value
#[allow(non_snake_case)]
fn f32const<T1: Into<ir::immediates::Ieee32>>(self, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryIeee32(Opcode::F32const, types::INVALID, N);
dfg.first_result(inst)
}
/// Floating point constant.
///
/// Create a `f64` SSA value with an immediate constant value.
///
/// Inputs:
///
/// - N: A 64-bit immediate floating point number.
///
/// Outputs:
///
/// - a: A constant f64 scalar value
#[allow(non_snake_case)]
fn f64const<T1: Into<ir::immediates::Ieee64>>(self, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryIeee64(Opcode::F64const, types::INVALID, N);
dfg.first_result(inst)
}
/// SIMD vector constant.
///
/// Construct a vector with the given immediate bytes.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - N: The 16 immediate bytes of a 128-bit vector
///
/// Outputs:
///
/// - a: A constant vector value
#[allow(non_snake_case)]
fn vconst<T1: Into<ir::Constant>>(self, TxN: crate::ir::Type, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryConst(Opcode::Vconst, TxN, N);
dfg.first_result(inst)
}
/// SIMD vector shuffle.
///
/// Shuffle two vectors using the given immediate bytes. For each of the 16 bytes of the
/// immediate, a value i of 0-15 selects the i-th element of the first vector and a value i of
/// 16-31 selects the (i-16)th element of the second vector. Immediate values outside of the
/// 0-31 range place a 0 in the resulting vector lane.
///
/// Inputs:
///
/// - a: A vector value
/// - b: A vector value
/// - mask: The 16 immediate bytes used for selecting the elements to shuffle
///
/// Outputs:
///
/// - a: A vector value
#[allow(non_snake_case)]
fn shuffle<T1: Into<ir::Immediate>>(self, a: ir::Value, b: ir::Value, mask: T1) -> Value {
let mask = mask.into();
let (inst, dfg) = self.Shuffle(Opcode::Shuffle, types::INVALID, mask, a, b);
dfg.first_result(inst)
}
/// Null constant value for reference types.
///
/// Create a scalar reference SSA value with a constant null value.
///
/// Inputs:
///
/// - Ref (controlling type variable): A scalar reference type
///
/// Outputs:
///
/// - a: A constant reference null value
#[allow(non_snake_case)]
fn null(self, Ref: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::Null, Ref);
dfg.first_result(inst)
}
/// Just a dummy instruction.
///
/// Note: this doesn't compile to a machine code nop.
#[allow(non_snake_case)]
fn nop(self) -> Inst {
self.NullAry(Opcode::Nop, types::INVALID).0
}
/// Conditional select.
///
/// This instruction selects whole values. Use `vselect` for
/// lane-wise selection.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn select(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Select, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select intended for Spectre guards.
///
/// This operation is semantically equivalent to a select instruction.
/// However, it is guaranteed to not be removed or otherwise altered by any
/// optimization pass, and is guaranteed to result in a conditional-move
/// instruction, not a branch-based lowering. As such, it is suitable
/// for use when producing Spectre guards. For example, a bounds-check
/// may guard against unsafe speculation past a bounds-check conditional
/// branch by passing the address or index to be accessed through a
/// conditional move, also gated on the same condition. Because no
/// Spectre-vulnerable processors are known to perform speculation on
/// conditional move instructions, this is guaranteed to pick the
/// correct input. If the selected input in case of overflow is a "safe"
/// value, for example a null pointer that causes an exception in the
/// speculative path, this ensures that no Spectre vulnerability will
/// exist.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn select_spectre_guard(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::SelectSpectreGuard, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select of bits.
///
/// For each bit in `c`, this instruction selects the corresponding bit from `x` if the bit
/// in `c` is 1 and the corresponding bit from `y` if the bit in `c` is 0. See also:
/// `select`, `vselect`.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn bitselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Bitselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Split a vector into two halves.
///
/// Split the vector `x` into two separate values, each containing half of
/// the lanes from ``x``. The result may be two scalars if ``x`` only had
/// two lanes.
///
/// Inputs:
///
/// - x: Vector to split
///
/// Outputs:
///
/// - lo: Low-numbered lanes of `x`
/// - hi: High-numbered lanes of `x`
#[allow(non_snake_case)]
fn vsplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Vsplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Vector concatenation.
///
/// Return a vector formed by concatenating ``x`` and ``y``. The resulting
/// vector type has twice as many lanes as each of the inputs. The lanes of
/// ``x`` appear as the low-numbered lanes, and the lanes of ``y`` become
/// the high-numbered lanes of ``a``.
///
/// It is possible to form a vector by concatenating two scalars.
///
/// Inputs:
///
/// - x: Low-numbered lanes
/// - y: High-numbered lanes
///
/// Outputs:
///
/// - a: Concatenation of `x` and `y`
#[allow(non_snake_case)]
fn vconcat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Vconcat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Vector lane select.
///
/// Select lanes from ``x`` or ``y`` controlled by the lanes of the truthy
/// vector ``c``.
///
/// Inputs:
///
/// - c: Controlling vector
/// - x: Value to use where `c` is true
/// - y: Value to use where `c` is false
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn vselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Vselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if any lane in ``a`` is non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vany_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VanyTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if all lanes in ``i`` are non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vall_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VallTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar integer.
///
/// Return a scalar integer, consisting of the concatenation of the most significant bit
/// of each lane of ``a``.
///
/// Inputs:
///
/// - Int (controlling type variable): A scalar or vector integer type
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - x: A scalar or vector integer type
#[allow(non_snake_case)]
fn vhigh_bits(self, Int: crate::ir::Type, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::VhighBits, Int, a);
dfg.first_result(inst)
}
/// Integer comparison.
///
/// The condition code determines if the operands are interpreted as signed
/// or unsigned integers.
///
/// | Signed | Unsigned | Condition |
/// |--------|----------|-----------------------|
/// | eq | eq | Equal |
/// | ne | ne | Not equal |
/// | slt | ult | Less than |
/// | sge | uge | Greater than or equal |
/// | sgt | ugt | Greater than |
/// | sle | ule | Less than or equal |
///
/// When this instruction compares integer vectors, it returns a vector of
/// lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn icmp<T1: Into<ir::condcodes::IntCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompare(Opcode::Icmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant.
///
/// This is the same as the `icmp` instruction, except one operand is
/// a sign extended 64 bit immediate constant.
///
/// This instruction can only compare scalars. Use `icmp` for
/// lane-wise vector comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn icmp_imm<T1: Into<ir::condcodes::IntCC>, T2: Into<ir::immediates::Imm64>>(self, Cond: T1, x: ir::Value, Y: T2) -> Value {
let Cond = Cond.into();
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompareImm(Opcode::IcmpImm, ctrl_typevar, Cond, Y, x);
dfg.first_result(inst)
}
/// Compare scalar integers and return flags.
///
/// Compare two scalar integer values and return integer CPU flags
/// representing the result.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ifcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant and return flags.
///
/// Like `icmp_imm`, but returns integer CPU flags instead of testing
/// a specific condition code.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IfcmpImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Wrapping integer addition: `a := x + y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Iadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Wrapping integer subtraction: `a := x - y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn isub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Isub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer negation: `a := -x \pmod{2^B}`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ineg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ineg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Integer absolute value with wrapping: `a := |x|`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Iabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Wrapping integer multiplication: `a := x y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn imul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Imul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Fixed-point multiplication of numbers in the QN format, where N + 1
/// is the number bitwidth:
/// `a := signed_saturate((x * y + 1 << (Q - 1)) >> Q)`
///
/// Polymorphic over all integer types (scalar and vector) with 16- or
/// 32-bit numbers.
///
/// Inputs:
///
/// - x: A scalar or vector integer type with 16- or 32-bit numbers
/// - y: A scalar or vector integer type with 16- or 32-bit numbers
///
/// Outputs:
///
/// - a: A scalar or vector integer type with 16- or 32-bit numbers
#[allow(non_snake_case)]
fn sqmul_round_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SqmulRoundSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer division: `a := \lfloor {x \over y} \rfloor`.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Udiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer division rounded toward zero: `a := sign(xy)
/// \lfloor {|x| \over |y|}\rfloor`.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer remainder.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Urem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer remainder. The result has the sign of the dividend.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Srem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add immediate integer.
///
/// Same as `iadd`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IaddImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer multiplication by immediate constant.
///
/// Same as `imul`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn imul_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::ImulImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer division by an immediate constant.
///
/// Same as `udiv`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer division by an immediate constant.
///
/// Same as `sdiv`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, Y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer remainder with immediate divisor.
///
/// Same as `urem`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer remainder with immediate divisor.
///
/// Same as `srem`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Immediate reverse wrapping subtraction: `a := Y - x \pmod{2^B}`.
///
/// The immediate operand is a sign extended 64 bit constant.
///
/// Also works as integer negation when `Y = 0`. Use `iadd_imm`
/// with a negative immediate operand for the reverse immediate
/// subtraction.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn irsub_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IrsubImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_cin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry flag input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_ifcin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_cout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddCout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry flag output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddIfcout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_carry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry flag input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcarry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Unsigned addition of x and y, trapping if the result overflows.
///
/// Accepts 32 or 64-bit integers, and does not support vector types.
///
/// Inputs:
///
/// - x: A 32 or 64-bit scalar integer type
/// - y: A 32 or 64-bit scalar integer type
/// - code: A trap reason code.
///
/// Outputs:
///
/// - a: A 32 or 64-bit scalar integer type
#[allow(non_snake_case)]
fn uadd_overflow_trap<T1: Into<ir::TrapCode>>(self, x: ir::Value, y: ir::Value, code: T1) -> Value {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntAddTrap(Opcode::UaddOverflowTrap, ctrl_typevar, code, x, y);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_bin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_ifbin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfbin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_bout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubBout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifbout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubIfbout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_borrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBorrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifborrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfborrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Bitwise and.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Band, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bxor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise not.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bnot(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bnot, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Bitwise and not.
///
/// Computes `x & ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BandNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or not.
///
/// Computes `x | ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor not.
///
/// Computes `x ^ ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BxorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise and with immediate.
///
/// Same as `band`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn band_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BandImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise or with immediate.
///
/// Same as `bor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise xor with immediate.
///
/// Same as `bxor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bxor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BxorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate left.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate right.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate left by immediate.
///
/// Same as `rotl`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate right by immediate.
///
/// Same as `rotr`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer shift left. Shift the bits in ``x`` towards the MSB by ``y``
/// places. Shift in zero bits to the LSB.
///
/// The shift amount is masked to the size of ``x``.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= x \cdot 2^s \pmod{2^B}.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ishl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in zero bits to the MSB. Also called a *logical
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= \lfloor x \cdot 2^{-s} \rfloor.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ushr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in sign bits to the MSB. Also called an *arithmetic
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sshr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer shift left by immediate.
///
/// The shift amount is masked to the size of ``x``.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IshlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Reverse the bits of a integer.
///
/// Reverses the bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bitrev(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bitrev, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading zero bits.
///
/// Starting from the MSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn clz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Clz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading sign bits.
///
/// Starting from the MSB after the sign bit in ``x``, count the number of
/// consecutive bits identical to the sign bit. When ``x`` is 0 or -1,
/// returns one less than the size of x in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn cls(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Cls, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count trailing zeros.
///
/// Starting from the LSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn ctz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ctz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reverse the byte order of an integer.
///
/// Reverses the bytes in ``x``.
///
/// Inputs:
///
/// - x: A multi byte scalar integer type
///
/// Outputs:
///
/// - a: A multi byte scalar integer type
#[allow(non_snake_case)]
fn bswap(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bswap, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Population count
///
/// Count the number of one bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn popcnt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Popcnt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point comparison.
///
/// Two IEEE 754-2008 floating point numbers, `x` and `y`, relate to each
/// other in exactly one of four ways:
///
/// ```text
/// == ==========================================
/// UN Unordered when one or both numbers is NaN.
/// EQ When `x = y`. (And `0.0 = -0.0`).
/// LT When `x < y`.
/// GT When `x > y`.
/// == ==========================================
/// ```
///
/// The 14 `floatcc` condition codes each correspond to a subset of
/// the four relations, except for the empty set which would always be
/// false, and the full set which would always be true.
///
/// The condition codes are divided into 7 'ordered' conditions which don't
/// include UN, and 7 unordered conditions which all include UN.
///
/// ```text
/// +-------+------------+---------+------------+-------------------------+
/// |Ordered |Unordered |Condition |
/// +=======+============+=========+============+=========================+
/// |ord |EQ | LT | GT|uno |UN |NaNs absent / present. |
/// +-------+------------+---------+------------+-------------------------+
/// |eq |EQ |ueq |UN | EQ |Equal |
/// +-------+------------+---------+------------+-------------------------+
/// |one |LT | GT |ne |UN | LT | GT|Not equal |
/// +-------+------------+---------+------------+-------------------------+
/// |lt |LT |ult |UN | LT |Less than |
/// +-------+------------+---------+------------+-------------------------+
/// |le |LT | EQ |ule |UN | LT | EQ|Less than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// |gt |GT |ugt |UN | GT |Greater than |
/// +-------+------------+---------+------------+-------------------------+
/// |ge |GT | EQ |uge |UN | GT | EQ|Greater than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// ```
///
/// The standard C comparison operators, `<, <=, >, >=`, are all ordered,
/// so they are false if either operand is NaN. The C equality operator,
/// `==`, is ordered, and since inequality is defined as the logical
/// inverse it is *unordered*. They map to the `floatcc` condition
/// codes as follows:
///
/// ```text
/// ==== ====== ============
/// C `Cond` Subset
/// ==== ====== ============
/// `==` eq EQ
/// `!=` ne UN | LT | GT
/// `<` lt LT
/// `<=` le LT | EQ
/// `>` gt GT
/// `>=` ge GT | EQ
/// ==== ====== ============
/// ```
///
/// This subset of condition codes also corresponds to the WebAssembly
/// floating point comparisons of the same name.
///
/// When this instruction compares floating point vectors, it returns a
/// vector with the results of lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: A floating point comparison condition code
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn fcmp<T1: Into<ir::condcodes::FloatCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.FloatCompare(Opcode::Fcmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Floating point comparison returning flags.
///
/// Compares two numbers like `fcmp`, but returns floating point CPU
/// flags instead of testing a specific condition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - f: CPU flags representing the result of a floating point comparison. These
/// flags can be tested with a :type:`floatcc` condition code.
#[allow(non_snake_case)]
fn ffcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ffcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point addition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point subtraction.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fsub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fsub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point multiplication.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fmul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point division.
///
/// Unlike the integer division instructions ` and
/// `udiv`, this can't trap. Division by zero is infinity or
/// NaN, depending on the dividend.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point square root.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn sqrt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Sqrt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point fused multiply-and-add.
///
/// Computes `a := xy+z` without any intermediate rounding of the
/// product.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
/// - z: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fma(self, x: ir::Value, y: ir::Value, z: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::Fma, ctrl_typevar, x, y, z);
dfg.first_result(inst)
}
/// Floating point negation.
///
/// Note that this is a pure bitwise operation.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit inverted
#[allow(non_snake_case)]
fn fneg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Fneg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point absolute value.
///
/// Note that this is a pure bitwise operation.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit cleared
#[allow(non_snake_case)]
fn fabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Fabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point copy sign.
///
/// Note that this is a pure bitwise operation. The sign bit from ``y`` is
/// copied to the sign bit of ``x``.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit changed to that of ``y``
#[allow(non_snake_case)]
fn fcopysign(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fcopysign, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point minimum, propagating NaNs using the WebAssembly rules.
///
/// If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
/// each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
/// 0, then the output has the same form. Otherwise, the output mantissa's most significant
/// bit is 1 and the rest is unspecified.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The smaller of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point pseudo-minimum, propagating NaNs. This behaves differently from ``fmin``.
/// See <https://github.com/WebAssembly/simd/pull/122> for background.
///
/// The behaviour is defined as ``fmin_pseudo(a, b) = (b < a) ? b : a``, and the behaviour
/// for zero or NaN inputs follows from the behaviour of ``<`` with such inputs.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The smaller of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmin_pseudo(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::FminPseudo, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point maximum, propagating NaNs using the WebAssembly rules.
///
/// If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
/// each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
/// 0, then the output has the same form. Otherwise, the output mantissa's most significant
/// bit is 1 and the rest is unspecified.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The larger of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point pseudo-maximum, propagating NaNs. This behaves differently from ``fmax``.
/// See <https://github.com/WebAssembly/simd/pull/122> for background.
///
/// The behaviour is defined as ``fmax_pseudo(a, b) = (a < b) ? b : a``, and the behaviour
/// for zero or NaN inputs follows from the behaviour of ``<`` with such inputs.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The larger of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmax_pseudo(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::FmaxPseudo, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards positive infinity.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn ceil(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ceil, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards negative infinity.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn floor(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Floor, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards zero.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn trunc(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Trunc, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards nearest with ties to
/// even.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn nearest(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Nearest, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reference verification.
///
/// The condition code determines if the reference type in question is
/// null or not.
///
/// Inputs:
///
/// - x: A scalar reference type
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn is_null(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::IsNull, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reference verification.
///
/// The condition code determines if the reference type in question is
/// invalid or not.
///
/// Inputs:
///
/// - x: A scalar reference type
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn is_invalid(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::IsInvalid, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reinterpret the bits in `x` as a different type.
///
/// The input and output types must be storable to memory and of the same
/// size. A bitcast is equivalent to storing one type and loading the other
/// type from the same address, both using the specified MemFlags.
///
/// Note that this operation only supports the `big` or `little` MemFlags.
/// The specified byte order only affects the result in the case where
/// input and output types differ in lane count/size. In this case, the
/// operation is only valid if a byte order specifier is provided.
///
/// Inputs:
///
/// - MemTo (controlling type variable):
/// - MemFlags: Memory operation flags
/// - x: Any type that can be stored in memory
///
/// Outputs:
///
/// - a: Bits of `x` reinterpreted
#[allow(non_snake_case)]
fn bitcast<T1: Into<ir::MemFlags>>(self, MemTo: crate::ir::Type, MemFlags: T1, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let (inst, dfg) = self.LoadNoOffset(Opcode::Bitcast, MemTo, MemFlags, x);
dfg.first_result(inst)
}
/// Copies a scalar value to a vector value. The scalar is copied into the
/// least significant lane of the vector, and all other lanes will be zero.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - s: A scalar value
///
/// Outputs:
///
/// - a: A vector value
#[allow(non_snake_case)]
fn scalar_to_vector(self, TxN: crate::ir::Type, s: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::ScalarToVector, TxN, s);
dfg.first_result(inst)
}
/// Convert `x` to an integer mask.
///
/// True maps to all 1s and false maps to all 0s. The result type must have
/// the same number of vector lanes as the input.
///
/// Inputs:
///
/// - IntTo (controlling type variable): An integer type with the same number of lanes
/// - x: A scalar or vector whose values are truthy
///
/// Outputs:
///
/// - a: An integer type with the same number of lanes
#[allow(non_snake_case)]
fn bmask(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Bmask, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller integer type by discarding
/// the most significant bits.
///
/// This is the same as reducing modulo `2^n`.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A smaller integer type
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A smaller integer type
#[allow(non_snake_case)]
fn ireduce(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Ireduce, IntTo, x);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the signed maximum and minimum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn snarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Snarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered signed: any negative lanes will overflow and be
/// replaced with the unsigned minimum, `0x00`.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn unarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Unarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered unsigned: any negative values will be interpreted as unsigned, overflowing and being replaced with the unsigned maximum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uunarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Uunarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Does lane-wise integer pairwise addition on two operands, putting the
/// combined results into a single vector result. Here a pair refers to adjacent
/// lanes in a vector, i.e. i*2 + (i*2+1) for i == num_lanes/2. The first operand
/// pairwise add results will make up the low half of the resulting vector while
/// the second operand pairwise add results will make up the upper half of the
/// resulting vector.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
/// - y: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
#[allow(non_snake_case)]
fn iadd_pairwise(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddPairwise, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Takes corresponding elements in `x` and `y`, performs a sign-extending length-doubling
/// multiplication on them, then adds adjacent pairs of elements to form the result. For
/// example, if the input vectors are `[x3, x2, x1, x0]` and `[y3, y2, y1, y0]`, it produces
/// the vector `[r1, r0]`, where `r1 = sx(x3) * sx(y3) + sx(x2) * sx(y2)` and
/// `r0 = sx(x1) * sx(y1) + sx(x0) * sx(y0)`, and `sx(n)` sign-extends `n` to twice its width.
///
/// This will double the lane width and halve the number of lanes. So the resulting
/// vector has the same number of bits as `x` and `y` do (individually).
///
/// See <https://github.com/WebAssembly/simd/pull/127> for background info.
///
/// Inputs:
///
/// - x: A SIMD vector type containing 8 integer lanes each 16 bits wide.
/// - y: A SIMD vector type containing 8 integer lanes each 16 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn widening_pairwise_dot_product_s(self, x: ir::Value, y: ir::Value) -> Value {
let (inst, dfg) = self.Binary(Opcode::WideningPairwiseDotProductS, types::INVALID, x, y);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by zero-extending.
///
/// Each lane in `x` is converted to a larger integer type by adding
/// zeroes. The result has the same numerical value as `x` when both are
/// interpreted as unsigned integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn uextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Uextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by sign-extending.
///
/// Each lane in `x` is converted to a larger integer type by replicating
/// the sign bit. The result has the same numerical value as `x` when both
/// are interpreted as signed integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn sextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Sextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger floating point format.
///
/// Each lane in `x` is converted to the destination floating point format.
/// This is an exact operation.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have fewer bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fpromote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fpromote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have more bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fdemote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fdemote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// Fvdemote differs from fdemote in that with fvdemote it targets vectors.
/// Fvdemote is constrained to having the input type being F64x2 and the result
/// type being F32x4. The result lane that was the upper half of the input lane
/// is initialized to zero.
///
/// Inputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
///
/// Outputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
#[allow(non_snake_case)]
fn fvdemote(self, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fvdemote, types::INVALID, x);
dfg.first_result(inst)
}
/// Converts packed single precision floating point to packed double precision floating point.
///
/// Considering only the lower half of the register, the low lanes in `x` are interpreted as
/// single precision floats that are then converted to a double precision floats.
///
/// The result type will have half the number of vector lanes as the input. Fvpromote_low is
/// constrained to input F32x4 with a result type of F64x2.
///
/// Inputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
///
/// Outputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
#[allow(non_snake_case)]
fn fvpromote_low(self, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FvpromoteLow, types::INVALID, a);
dfg.first_result(inst)
}
/// Converts floating point scalars to unsigned integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUint, IntTo, x);
dfg.first_result(inst)
}
/// Converts floating point scalars to signed integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSint, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to unsigned integer as fcvt_to_uint does, but
/// saturates the input instead of trapping. NaN and negative values are
/// converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to signed integer as fcvt_to_sint does, but
/// saturates the input instead of trapping. NaN values are converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert unsigned integer to floating point.
///
/// Each lane in `x` is interpreted as an unsigned integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_uint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromUint, FloatTo, x);
dfg.first_result(inst)
}
/// Convert signed integer to floating point.
///
/// Each lane in `x` is interpreted as a signed integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Converts packed signed 32-bit integers to packed double precision floating point.
///
/// Considering only the low half of the register, each lane in `x` is interpreted as a
/// signed 32-bit integer that is then converted to a double precision float. This
/// instruction differs from fcvt_from_sint in that it converts half the number of lanes
/// which are converted to occupy twice the number of bits. No rounding should be needed
/// for the resulting float.
///
/// The result type will have half the number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_low_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtLowFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Split an integer into low and high parts.
///
/// Vectors of integers are split lane-wise, so the results have the same
/// number of lanes as the input, but the lanes are half the size.
///
/// Returns the low half of `x` and the high half of `x` as two independent
/// values.
///
/// Inputs:
///
/// - x: An integer type with lanes from `i16` upwards
///
/// Outputs:
///
/// - lo: The low bits of `x`
/// - hi: The high bits of `x`
#[allow(non_snake_case)]
fn isplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Isplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Concatenate low and high bits to form a larger integer type.
///
/// Vectors of integers are concatenated lane-wise such that the result has
/// the same number of lanes as the inputs, but the lanes are twice the
/// size.
///
/// Inputs:
///
/// - lo: An integer type with lanes type to `i64`
/// - hi: An integer type with lanes type to `i64`
///
/// Outputs:
///
/// - a: The concatenation of `lo` and `hi`
#[allow(non_snake_case)]
fn iconcat(self, lo: ir::Value, hi: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(lo);
let (inst, dfg) = self.Binary(Opcode::Iconcat, ctrl_typevar, lo, hi);
dfg.first_result(inst)
}
/// Atomically read-modify-write memory at `p`, with second operand `x`. The old value is
/// returned. `p` has the type of the target word size, and `x` may be an integer type of
/// 8, 16, 32 or 64 bits, even on a 32-bit target. The type of the returned value is the
/// same as the type of `x`. This operation is sequentially consistent and creates
/// happens-before edges that order normal (non-atomic) loads and stores.
///
/// Inputs:
///
/// - AtomicMem (controlling type variable): Any type that can be stored in memory, which can be used in an atomic operation
/// - MemFlags: Memory operation flags
/// - AtomicRmwOp: Atomic Read-Modify-Write Ops
/// - p: An integer address type
/// - x: Value to be atomically stored
///
/// Outputs:
///
/// - a: Value atomically loaded
#[allow(non_snake_case)]
fn atomic_rmw<T1: Into<ir::MemFlags>, T2: Into<ir::AtomicRmwOp>>(self, AtomicMem: crate::ir::Type, MemFlags: T1, AtomicRmwOp: T2, p: ir::Value, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let AtomicRmwOp = AtomicRmwOp.into();
let (inst, dfg) = self.AtomicRmw(Opcode::AtomicRmw, AtomicMem, MemFlags, AtomicRmwOp, p, x);
dfg.first_result(inst)
}
/// Perform an atomic compare-and-swap operation on memory at `p`, with expected value `e`,
/// storing `x` if the value at `p` equals `e`. The old value at `p` is returned,
/// regardless of whether the operation succeeds or fails. `p` has the type of the target
/// word size, and `x` and `e` must have the same type and the same size, which may be an
/// integer type of 8, 16, 32 or 64 bits, even on a 32-bit target. The type of the returned
/// value is the same as the type of `x` and `e`. This operation is sequentially
/// consistent and creates happens-before edges that order normal (non-atomic) loads and
/// stores.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - e: Expected value in CAS
/// - x: Value to be atomically stored
///
/// Outputs:
///
/// - a: Value atomically loaded
#[allow(non_snake_case)]
fn atomic_cas<T1: Into<ir::MemFlags>>(self, MemFlags: T1, p: ir::Value, e: ir::Value, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.AtomicCas(Opcode::AtomicCas, ctrl_typevar, MemFlags, p, e, x);
dfg.first_result(inst)
}
/// Atomically load from memory at `p`.
///
/// This is a polymorphic instruction that can load any value type which has a memory
/// representation. It should only be used for integer types with 8, 16, 32 or 64 bits.
/// This operation is sequentially consistent and creates happens-before edges that order
/// normal (non-atomic) loads and stores.
///
/// Inputs:
///
/// - AtomicMem (controlling type variable): Any type that can be stored in memory, which can be used in an atomic operation
/// - MemFlags: Memory operation flags
/// - p: An integer address type
///
/// Outputs:
///
/// - a: Value atomically loaded
#[allow(non_snake_case)]
fn atomic_load<T1: Into<ir::MemFlags>>(self, AtomicMem: crate::ir::Type, MemFlags: T1, p: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let (inst, dfg) = self.LoadNoOffset(Opcode::AtomicLoad, AtomicMem, MemFlags, p);
dfg.first_result(inst)
}
/// Atomically store `x` to memory at `p`.
///
/// This is a polymorphic instruction that can store any value type with a memory
/// representation. It should only be used for integer types with 8, 16, 32 or 64 bits.
/// This operation is sequentially consistent and creates happens-before edges that order
/// normal (non-atomic) loads and stores.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: Value to be atomically stored
/// - p: An integer address type
#[allow(non_snake_case)]
fn atomic_store<T1: Into<ir::MemFlags>>(self, MemFlags: T1, x: ir::Value, p: ir::Value) -> Inst {
let MemFlags = MemFlags.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.StoreNoOffset(Opcode::AtomicStore, ctrl_typevar, MemFlags, x, p).0
}
/// A memory fence. This must provide ordering to ensure that, at a minimum, neither loads
/// nor stores of any kind may move forwards or backwards across the fence. This operation
/// is sequentially consistent.
#[allow(non_snake_case)]
fn fence(self) -> Inst {
self.NullAry(Opcode::Fence, types::INVALID).0
}sourcefn Shuffle(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Immediate,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn Shuffle(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Immediate,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
Shuffle(imms=(imm: ir::Immediate), vals=2)
sourcefn StackLoad(
self,
opcode: Opcode,
ctrl_typevar: Type,
stack_slot: StackSlot,
offset: Offset32
) -> (Inst, &'f mut DataFlowGraph)
fn StackLoad(
self,
opcode: Opcode,
ctrl_typevar: Type,
stack_slot: StackSlot,
offset: Offset32
) -> (Inst, &'f mut DataFlowGraph)
StackLoad(imms=(stack_slot: ir::StackSlot, offset: ir::immediates::Offset32), vals=0)
Examples found in repository?
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
fn stack_load<T1: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackLoad, Mem, SS, Offset);
dfg.first_result(inst)
}
/// Store a value to a stack slot at a constant offset.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// The offset is an immediate constant, not an SSA value. The memory
/// access cannot go out of bounds, i.e.
/// `sizeof(a) + Offset <= sizeof(SS)`.
///
/// Inputs:
///
/// - x: Value to be stored
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
#[allow(non_snake_case)]
fn stack_store<T1: Into<ir::immediates::Offset32>>(self, x: ir::Value, SS: ir::StackSlot, Offset: T1) -> Inst {
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.StackStore(Opcode::StackStore, ctrl_typevar, SS, Offset, x).0
}
/// Get the address of a stack slot.
///
/// Compute the absolute address of a byte in a stack slot. The offset must
/// refer to a byte inside the stack slot:
/// `0 <= Offset < sizeof(SS)`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn stack_addr<T1: Into<ir::immediates::Offset32>>(self, iAddr: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackAddr, iAddr, SS, Offset);
dfg.first_result(inst)
}sourcefn StackStore(
self,
opcode: Opcode,
ctrl_typevar: Type,
stack_slot: StackSlot,
offset: Offset32,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn StackStore(
self,
opcode: Opcode,
ctrl_typevar: Type,
stack_slot: StackSlot,
offset: Offset32,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
StackStore(imms=(stack_slot: ir::StackSlot, offset: ir::immediates::Offset32), vals=1)
sourcefn Store(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
offset: Offset32,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn Store(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
offset: Offset32,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
Store(imms=(flags: ir::MemFlags, offset: ir::immediates::Offset32), vals=2)
Examples found in repository?
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
fn store<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Store, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 8 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i8`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn uload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 8 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i8`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn sload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 8 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i8`` followed by ``store.i8``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 8 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore8, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 16 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i16`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn uload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 16 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i16`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn sload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 16 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i16`` followed by ``store.i16``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 16 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore16, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 32 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i32`` followed by ``uextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn uload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 32 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i32`` followed by ``sextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn sload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 32 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i32`` followed by ``store.i32``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 32 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore32, ctrl_typevar, MemFlags, Offset, x, p).0
}sourcefn StoreNoOffset(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn StoreNoOffset(
self,
opcode: Opcode,
ctrl_typevar: Type,
flags: MemFlags,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
StoreNoOffset(imms=(flags: ir::MemFlags), vals=2)
sourcefn TableAddr(
self,
opcode: Opcode,
ctrl_typevar: Type,
table: Table,
offset: Offset32,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn TableAddr(
self,
opcode: Opcode,
ctrl_typevar: Type,
table: Table,
offset: Offset32,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
TableAddr(imms=(table: ir::Table, offset: ir::immediates::Offset32), vals=1)
sourcefn Ternary(
self,
opcode: Opcode,
ctrl_typevar: Type,
arg0: Value,
arg1: Value,
arg2: Value
) -> (Inst, &'f mut DataFlowGraph)
fn Ternary(
self,
opcode: Opcode,
ctrl_typevar: Type,
arg0: Value,
arg1: Value,
arg2: Value
) -> (Inst, &'f mut DataFlowGraph)
Ternary(imms=(), vals=3)
Examples found in repository?
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164
fn select(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Select, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select intended for Spectre guards.
///
/// This operation is semantically equivalent to a select instruction.
/// However, it is guaranteed to not be removed or otherwise altered by any
/// optimization pass, and is guaranteed to result in a conditional-move
/// instruction, not a branch-based lowering. As such, it is suitable
/// for use when producing Spectre guards. For example, a bounds-check
/// may guard against unsafe speculation past a bounds-check conditional
/// branch by passing the address or index to be accessed through a
/// conditional move, also gated on the same condition. Because no
/// Spectre-vulnerable processors are known to perform speculation on
/// conditional move instructions, this is guaranteed to pick the
/// correct input. If the selected input in case of overflow is a "safe"
/// value, for example a null pointer that causes an exception in the
/// speculative path, this ensures that no Spectre vulnerability will
/// exist.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn select_spectre_guard(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::SelectSpectreGuard, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select of bits.
///
/// For each bit in `c`, this instruction selects the corresponding bit from `x` if the bit
/// in `c` is 1 and the corresponding bit from `y` if the bit in `c` is 0. See also:
/// `select`, `vselect`.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn bitselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Bitselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Split a vector into two halves.
///
/// Split the vector `x` into two separate values, each containing half of
/// the lanes from ``x``. The result may be two scalars if ``x`` only had
/// two lanes.
///
/// Inputs:
///
/// - x: Vector to split
///
/// Outputs:
///
/// - lo: Low-numbered lanes of `x`
/// - hi: High-numbered lanes of `x`
#[allow(non_snake_case)]
fn vsplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Vsplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Vector concatenation.
///
/// Return a vector formed by concatenating ``x`` and ``y``. The resulting
/// vector type has twice as many lanes as each of the inputs. The lanes of
/// ``x`` appear as the low-numbered lanes, and the lanes of ``y`` become
/// the high-numbered lanes of ``a``.
///
/// It is possible to form a vector by concatenating two scalars.
///
/// Inputs:
///
/// - x: Low-numbered lanes
/// - y: High-numbered lanes
///
/// Outputs:
///
/// - a: Concatenation of `x` and `y`
#[allow(non_snake_case)]
fn vconcat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Vconcat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Vector lane select.
///
/// Select lanes from ``x`` or ``y`` controlled by the lanes of the truthy
/// vector ``c``.
///
/// Inputs:
///
/// - c: Controlling vector
/// - x: Value to use where `c` is true
/// - y: Value to use where `c` is false
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn vselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Vselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if any lane in ``a`` is non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vany_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VanyTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if all lanes in ``i`` are non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vall_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VallTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar integer.
///
/// Return a scalar integer, consisting of the concatenation of the most significant bit
/// of each lane of ``a``.
///
/// Inputs:
///
/// - Int (controlling type variable): A scalar or vector integer type
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - x: A scalar or vector integer type
#[allow(non_snake_case)]
fn vhigh_bits(self, Int: crate::ir::Type, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::VhighBits, Int, a);
dfg.first_result(inst)
}
/// Integer comparison.
///
/// The condition code determines if the operands are interpreted as signed
/// or unsigned integers.
///
/// | Signed | Unsigned | Condition |
/// |--------|----------|-----------------------|
/// | eq | eq | Equal |
/// | ne | ne | Not equal |
/// | slt | ult | Less than |
/// | sge | uge | Greater than or equal |
/// | sgt | ugt | Greater than |
/// | sle | ule | Less than or equal |
///
/// When this instruction compares integer vectors, it returns a vector of
/// lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn icmp<T1: Into<ir::condcodes::IntCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompare(Opcode::Icmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant.
///
/// This is the same as the `icmp` instruction, except one operand is
/// a sign extended 64 bit immediate constant.
///
/// This instruction can only compare scalars. Use `icmp` for
/// lane-wise vector comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn icmp_imm<T1: Into<ir::condcodes::IntCC>, T2: Into<ir::immediates::Imm64>>(self, Cond: T1, x: ir::Value, Y: T2) -> Value {
let Cond = Cond.into();
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompareImm(Opcode::IcmpImm, ctrl_typevar, Cond, Y, x);
dfg.first_result(inst)
}
/// Compare scalar integers and return flags.
///
/// Compare two scalar integer values and return integer CPU flags
/// representing the result.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ifcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant and return flags.
///
/// Like `icmp_imm`, but returns integer CPU flags instead of testing
/// a specific condition code.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IfcmpImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Wrapping integer addition: `a := x + y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Iadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Wrapping integer subtraction: `a := x - y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn isub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Isub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer negation: `a := -x \pmod{2^B}`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ineg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ineg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Integer absolute value with wrapping: `a := |x|`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Iabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Wrapping integer multiplication: `a := x y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn imul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Imul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Fixed-point multiplication of numbers in the QN format, where N + 1
/// is the number bitwidth:
/// `a := signed_saturate((x * y + 1 << (Q - 1)) >> Q)`
///
/// Polymorphic over all integer types (scalar and vector) with 16- or
/// 32-bit numbers.
///
/// Inputs:
///
/// - x: A scalar or vector integer type with 16- or 32-bit numbers
/// - y: A scalar or vector integer type with 16- or 32-bit numbers
///
/// Outputs:
///
/// - a: A scalar or vector integer type with 16- or 32-bit numbers
#[allow(non_snake_case)]
fn sqmul_round_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SqmulRoundSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer division: `a := \lfloor {x \over y} \rfloor`.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Udiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer division rounded toward zero: `a := sign(xy)
/// \lfloor {|x| \over |y|}\rfloor`.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer remainder.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Urem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer remainder. The result has the sign of the dividend.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Srem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add immediate integer.
///
/// Same as `iadd`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IaddImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer multiplication by immediate constant.
///
/// Same as `imul`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn imul_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::ImulImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer division by an immediate constant.
///
/// Same as `udiv`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer division by an immediate constant.
///
/// Same as `sdiv`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, Y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer remainder with immediate divisor.
///
/// Same as `urem`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer remainder with immediate divisor.
///
/// Same as `srem`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Immediate reverse wrapping subtraction: `a := Y - x \pmod{2^B}`.
///
/// The immediate operand is a sign extended 64 bit constant.
///
/// Also works as integer negation when `Y = 0`. Use `iadd_imm`
/// with a negative immediate operand for the reverse immediate
/// subtraction.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn irsub_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IrsubImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_cin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry flag input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_ifcin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_cout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddCout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry flag output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddIfcout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_carry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry flag input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcarry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Unsigned addition of x and y, trapping if the result overflows.
///
/// Accepts 32 or 64-bit integers, and does not support vector types.
///
/// Inputs:
///
/// - x: A 32 or 64-bit scalar integer type
/// - y: A 32 or 64-bit scalar integer type
/// - code: A trap reason code.
///
/// Outputs:
///
/// - a: A 32 or 64-bit scalar integer type
#[allow(non_snake_case)]
fn uadd_overflow_trap<T1: Into<ir::TrapCode>>(self, x: ir::Value, y: ir::Value, code: T1) -> Value {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntAddTrap(Opcode::UaddOverflowTrap, ctrl_typevar, code, x, y);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_bin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_ifbin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfbin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_bout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubBout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifbout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubIfbout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_borrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBorrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifborrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfborrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Bitwise and.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Band, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bxor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise not.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bnot(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bnot, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Bitwise and not.
///
/// Computes `x & ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BandNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or not.
///
/// Computes `x | ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor not.
///
/// Computes `x ^ ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BxorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise and with immediate.
///
/// Same as `band`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn band_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BandImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise or with immediate.
///
/// Same as `bor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise xor with immediate.
///
/// Same as `bxor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bxor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BxorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate left.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate right.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate left by immediate.
///
/// Same as `rotl`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate right by immediate.
///
/// Same as `rotr`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer shift left. Shift the bits in ``x`` towards the MSB by ``y``
/// places. Shift in zero bits to the LSB.
///
/// The shift amount is masked to the size of ``x``.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= x \cdot 2^s \pmod{2^B}.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ishl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in zero bits to the MSB. Also called a *logical
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= \lfloor x \cdot 2^{-s} \rfloor.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ushr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in sign bits to the MSB. Also called an *arithmetic
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sshr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer shift left by immediate.
///
/// The shift amount is masked to the size of ``x``.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IshlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Reverse the bits of a integer.
///
/// Reverses the bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bitrev(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bitrev, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading zero bits.
///
/// Starting from the MSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn clz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Clz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading sign bits.
///
/// Starting from the MSB after the sign bit in ``x``, count the number of
/// consecutive bits identical to the sign bit. When ``x`` is 0 or -1,
/// returns one less than the size of x in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn cls(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Cls, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count trailing zeros.
///
/// Starting from the LSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn ctz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ctz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reverse the byte order of an integer.
///
/// Reverses the bytes in ``x``.
///
/// Inputs:
///
/// - x: A multi byte scalar integer type
///
/// Outputs:
///
/// - a: A multi byte scalar integer type
#[allow(non_snake_case)]
fn bswap(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bswap, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Population count
///
/// Count the number of one bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn popcnt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Popcnt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point comparison.
///
/// Two IEEE 754-2008 floating point numbers, `x` and `y`, relate to each
/// other in exactly one of four ways:
///
/// ```text
/// == ==========================================
/// UN Unordered when one or both numbers is NaN.
/// EQ When `x = y`. (And `0.0 = -0.0`).
/// LT When `x < y`.
/// GT When `x > y`.
/// == ==========================================
/// ```
///
/// The 14 `floatcc` condition codes each correspond to a subset of
/// the four relations, except for the empty set which would always be
/// false, and the full set which would always be true.
///
/// The condition codes are divided into 7 'ordered' conditions which don't
/// include UN, and 7 unordered conditions which all include UN.
///
/// ```text
/// +-------+------------+---------+------------+-------------------------+
/// |Ordered |Unordered |Condition |
/// +=======+============+=========+============+=========================+
/// |ord |EQ | LT | GT|uno |UN |NaNs absent / present. |
/// +-------+------------+---------+------------+-------------------------+
/// |eq |EQ |ueq |UN | EQ |Equal |
/// +-------+------------+---------+------------+-------------------------+
/// |one |LT | GT |ne |UN | LT | GT|Not equal |
/// +-------+------------+---------+------------+-------------------------+
/// |lt |LT |ult |UN | LT |Less than |
/// +-------+------------+---------+------------+-------------------------+
/// |le |LT | EQ |ule |UN | LT | EQ|Less than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// |gt |GT |ugt |UN | GT |Greater than |
/// +-------+------------+---------+------------+-------------------------+
/// |ge |GT | EQ |uge |UN | GT | EQ|Greater than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// ```
///
/// The standard C comparison operators, `<, <=, >, >=`, are all ordered,
/// so they are false if either operand is NaN. The C equality operator,
/// `==`, is ordered, and since inequality is defined as the logical
/// inverse it is *unordered*. They map to the `floatcc` condition
/// codes as follows:
///
/// ```text
/// ==== ====== ============
/// C `Cond` Subset
/// ==== ====== ============
/// `==` eq EQ
/// `!=` ne UN | LT | GT
/// `<` lt LT
/// `<=` le LT | EQ
/// `>` gt GT
/// `>=` ge GT | EQ
/// ==== ====== ============
/// ```
///
/// This subset of condition codes also corresponds to the WebAssembly
/// floating point comparisons of the same name.
///
/// When this instruction compares floating point vectors, it returns a
/// vector with the results of lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: A floating point comparison condition code
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn fcmp<T1: Into<ir::condcodes::FloatCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.FloatCompare(Opcode::Fcmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Floating point comparison returning flags.
///
/// Compares two numbers like `fcmp`, but returns floating point CPU
/// flags instead of testing a specific condition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - f: CPU flags representing the result of a floating point comparison. These
/// flags can be tested with a :type:`floatcc` condition code.
#[allow(non_snake_case)]
fn ffcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ffcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point addition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point subtraction.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fsub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fsub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point multiplication.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fmul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point division.
///
/// Unlike the integer division instructions ` and
/// `udiv`, this can't trap. Division by zero is infinity or
/// NaN, depending on the dividend.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point square root.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn sqrt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Sqrt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point fused multiply-and-add.
///
/// Computes `a := xy+z` without any intermediate rounding of the
/// product.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
/// - z: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fma(self, x: ir::Value, y: ir::Value, z: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::Fma, ctrl_typevar, x, y, z);
dfg.first_result(inst)
}sourcefn TernaryImm8(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Uimm8,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
fn TernaryImm8(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Uimm8,
arg0: Value,
arg1: Value
) -> (Inst, &'f mut DataFlowGraph)
TernaryImm8(imms=(imm: ir::immediates::Uimm8), vals=2)
sourcefn Trap(
self,
opcode: Opcode,
ctrl_typevar: Type,
code: TrapCode
) -> (Inst, &'f mut DataFlowGraph)
fn Trap(
self,
opcode: Opcode,
ctrl_typevar: Type,
code: TrapCode
) -> (Inst, &'f mut DataFlowGraph)
Trap(imms=(code: ir::TrapCode), vals=0)
Examples found in repository?
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn trap<T1: Into<ir::TrapCode>>(self, code: T1) -> Inst {
let code = code.into();
self.Trap(Opcode::Trap, types::INVALID, code).0
}
/// Trap when zero.
///
/// if ``c`` is non-zero, execution continues at the following instruction.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn trapz<T1: Into<ir::TrapCode>>(self, c: ir::Value, code: T1) -> Inst {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(c);
self.CondTrap(Opcode::Trapz, ctrl_typevar, code, c).0
}
/// A resumable trap.
///
/// This instruction allows non-conditional traps to be used as non-terminal instructions.
///
/// Inputs:
///
/// - code: A trap reason code.
#[allow(non_snake_case)]
fn resumable_trap<T1: Into<ir::TrapCode>>(self, code: T1) -> Inst {
let code = code.into();
self.Trap(Opcode::ResumableTrap, types::INVALID, code).0
}sourcefn Unary(
self,
opcode: Opcode,
ctrl_typevar: Type,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
fn Unary(
self,
opcode: Opcode,
ctrl_typevar: Type,
arg0: Value
) -> (Inst, &'f mut DataFlowGraph)
Unary(imms=(), vals=1)
Examples found in repository?
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993
fn splat(self, TxN: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Splat, TxN, x);
dfg.first_result(inst)
}
/// Vector swizzle.
///
/// Returns a new vector with byte-width lanes selected from the lanes of the first input
/// vector ``x`` specified in the second input vector ``s``. The indices ``i`` in range
/// ``[0, 15]`` select the ``i``-th element of ``x``. For indices outside of the range the
/// resulting lane is 0. Note that this operates on byte-width lanes.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - x: Vector to modify by re-arranging lanes
/// - y: Mask for re-arranging lanes
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn swizzle(self, TxN: crate::ir::Type, x: ir::Value, y: ir::Value) -> Value {
let (inst, dfg) = self.Binary(Opcode::Swizzle, TxN, x, y);
dfg.first_result(inst)
}
/// Insert ``y`` as lane ``Idx`` in x.
///
/// The lane index, ``Idx``, is an immediate value, not an SSA value. It
/// must indicate a valid lane index for the type of ``x``.
///
/// Inputs:
///
/// - x: The vector to modify
/// - y: New lane value
/// - Idx: Lane index
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn insertlane<T1: Into<ir::immediates::Uimm8>>(self, x: ir::Value, y: ir::Value, Idx: T1) -> Value {
let Idx = Idx.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.TernaryImm8(Opcode::Insertlane, ctrl_typevar, Idx, x, y);
dfg.first_result(inst)
}
/// Extract lane ``Idx`` from ``x``.
///
/// The lane index, ``Idx``, is an immediate value, not an SSA value. It
/// must indicate a valid lane index for the type of ``x``. Note that the upper bits of ``a``
/// may or may not be zeroed depending on the ISA but the type system should prevent using
/// ``a`` as anything other than the extracted value.
///
/// Inputs:
///
/// - x: A SIMD vector type
/// - Idx: Lane index
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn extractlane<T1: Into<ir::immediates::Uimm8>>(self, x: ir::Value, Idx: T1) -> Value {
let Idx = Idx.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm8(Opcode::Extractlane, ctrl_typevar, Idx, x);
dfg.first_result(inst)
}
/// Signed integer minimum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer minimum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer maximum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer maximum.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned average with rounding: `a := (x + y + 1) // 2`
///
/// The addition does not lose any information (such as from overflow).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn avg_round(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::AvgRound, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add with unsigned saturation.
///
/// This is similar to `iadd` but the operands are interpreted as unsigned integers and their
/// summed result, instead of wrapping, will be saturated to the highest unsigned integer for
/// the controlling type (e.g. `0xFF` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn uadd_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::UaddSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add with signed saturation.
///
/// This is similar to `iadd` but the operands are interpreted as signed integers and their
/// summed result, instead of wrapping, will be saturated to the lowest or highest
/// signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8). For example,
/// since an `sadd_sat.i8` of `0x70` and `0x70` is greater than `0x7F`, the result will be
/// clamped to `0x7F`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn sadd_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SaddSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Subtract with unsigned saturation.
///
/// This is similar to `isub` but the operands are interpreted as unsigned integers and their
/// difference, instead of wrapping, will be saturated to the lowest unsigned integer for
/// the controlling type (e.g. `0x00` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn usub_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::UsubSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Subtract with signed saturation.
///
/// This is similar to `isub` but the operands are interpreted as signed integers and their
/// difference, instead of wrapping, will be saturated to the lowest or highest
/// signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8).
///
/// Inputs:
///
/// - x: A SIMD vector type containing integers
/// - y: A SIMD vector type containing integers
///
/// Outputs:
///
/// - a: A SIMD vector type containing integers
#[allow(non_snake_case)]
fn ssub_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SsubSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Load from memory at ``p + Offset``.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn load<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Load, Mem, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store ``x`` to memory at ``p + Offset``.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: Value to be stored
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn store<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Store, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 8 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i8`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn uload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 8 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i8`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt8 (controlling type variable): An integer type with more than 8 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 8 bits
#[allow(non_snake_case)]
fn sload8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt8: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload8, iExt8, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 8 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i8`` followed by ``store.i8``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 8 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore8, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 16 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i16`` followed by ``uextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn uload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Uload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 16 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i16`` followed by ``sextend``.
///
/// Inputs:
///
/// - iExt16 (controlling type variable): An integer type with more than 16 bits
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 16 bits
#[allow(non_snake_case)]
fn sload16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, iExt16: crate::ir::Type, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let (inst, dfg) = self.Load(Opcode::Sload16, iExt16, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 16 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i16`` followed by ``store.i16``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 16 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore16<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore16, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load 32 bits from memory at ``p + Offset`` and zero-extend.
///
/// This is equivalent to ``load.i32`` followed by ``uextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn uload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load 32 bits from memory at ``p + Offset`` and sign-extend.
///
/// This is equivalent to ``load.i32`` followed by ``sextend``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: An integer type with more than 32 bits
#[allow(non_snake_case)]
fn sload32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Store the low 32 bits of ``x`` to memory at ``p + Offset``.
///
/// This is equivalent to ``ireduce.i32`` followed by ``store.i32``.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - x: An integer type with more than 32 bits
/// - p: An integer address type
/// - Offset: Byte offset from base address
#[allow(non_snake_case)]
fn istore32<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, x: ir::Value, p: ir::Value, Offset: T2) -> Inst {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.Store(Opcode::Istore32, ctrl_typevar, MemFlags, Offset, x, p).0
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i16x8
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload8x8<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload8x8, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i32x4
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload16x4<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload16x4, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load an 32x2 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn uload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Uload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a 32x2 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i64x2
/// vector.
///
/// Inputs:
///
/// - MemFlags: Memory operation flags
/// - p: An integer address type
/// - Offset: Byte offset from base address
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn sload32x2<T1: Into<ir::MemFlags>, T2: Into<ir::immediates::Offset32>>(self, MemFlags: T1, p: ir::Value, Offset: T2) -> Value {
let MemFlags = MemFlags.into();
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(p);
let (inst, dfg) = self.Load(Opcode::Sload32x2, ctrl_typevar, MemFlags, Offset, p);
dfg.first_result(inst)
}
/// Load a value from a stack slot at the constant offset.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// The offset is an immediate constant, not an SSA value. The memory
/// access cannot go out of bounds, i.e.
/// `sizeof(a) + Offset <= sizeof(SS)`.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn stack_load<T1: Into<ir::immediates::Offset32>>(self, Mem: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackLoad, Mem, SS, Offset);
dfg.first_result(inst)
}
/// Store a value to a stack slot at a constant offset.
///
/// This is a polymorphic instruction that can store any value type with a
/// memory representation.
///
/// The offset is an immediate constant, not an SSA value. The memory
/// access cannot go out of bounds, i.e.
/// `sizeof(a) + Offset <= sizeof(SS)`.
///
/// Inputs:
///
/// - x: Value to be stored
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
#[allow(non_snake_case)]
fn stack_store<T1: Into<ir::immediates::Offset32>>(self, x: ir::Value, SS: ir::StackSlot, Offset: T1) -> Inst {
let Offset = Offset.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.StackStore(Opcode::StackStore, ctrl_typevar, SS, Offset, x).0
}
/// Get the address of a stack slot.
///
/// Compute the absolute address of a byte in a stack slot. The offset must
/// refer to a byte inside the stack slot:
/// `0 <= Offset < sizeof(SS)`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - SS: A stack slot
/// - Offset: In-bounds offset into stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn stack_addr<T1: Into<ir::immediates::Offset32>>(self, iAddr: crate::ir::Type, SS: ir::StackSlot, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.StackLoad(Opcode::StackAddr, iAddr, SS, Offset);
dfg.first_result(inst)
}
/// Load a value from a dynamic stack slot.
///
/// This is a polymorphic instruction that can load any value type which
/// has a memory representation.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - DSS: A dynamic stack slot
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn dynamic_stack_load(self, Mem: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackLoad, Mem, DSS);
dfg.first_result(inst)
}
/// Store a value to a dynamic stack slot.
///
/// This is a polymorphic instruction that can store any dynamic value type with a
/// memory representation.
///
/// Inputs:
///
/// - x: Value to be stored
/// - DSS: A dynamic stack slot
#[allow(non_snake_case)]
fn dynamic_stack_store(self, x: ir::Value, DSS: ir::DynamicStackSlot) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(x);
self.DynamicStackStore(Opcode::DynamicStackStore, ctrl_typevar, DSS, x).0
}
/// Get the address of a dynamic stack slot.
///
/// Compute the absolute address of the first byte of a dynamic stack slot.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - DSS: A dynamic stack slot
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn dynamic_stack_addr(self, iAddr: crate::ir::Type, DSS: ir::DynamicStackSlot) -> Value {
let (inst, dfg) = self.DynamicStackLoad(Opcode::DynamicStackAddr, iAddr, DSS);
dfg.first_result(inst)
}
/// Compute the value of global GV.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn global_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::GlobalValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a symbolic value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn symbol_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::SymbolValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a TLS (thread local storage) value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn tls_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::TlsValue, Mem, GV);
dfg.first_result(inst)
}
/// Bounds check and compute absolute address of ``index + Offset`` in heap memory.
///
/// Verify that the range ``index .. index + Offset + Size`` is in bounds for the
/// heap ``H``, and generate an absolute address that is safe to dereference.
///
/// 1. If ``index + Offset + Size`` is less than or equal ot the heap bound, return an
/// absolute address corresponding to a byte offset of ``index + Offset`` from the
/// heap's base address.
///
/// 2. If ``index + Offset + Size`` is greater than the heap bound, return the
/// ``NULL`` pointer or any other address that is guaranteed to generate a trap
/// when accessed.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - H: A heap.
/// - index: An unsigned heap offset
/// - Offset: Static offset immediate in bytes
/// - Size: Static size immediate in bytes
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn heap_addr<T1: Into<ir::immediates::Uimm32>, T2: Into<ir::immediates::Uimm8>>(self, iAddr: crate::ir::Type, H: ir::Heap, index: ir::Value, Offset: T1, Size: T2) -> Value {
let Offset = Offset.into();
let Size = Size.into();
let (inst, dfg) = self.HeapAddr(Opcode::HeapAddr, iAddr, H, Offset, Size, index);
dfg.first_result(inst)
}
/// Load a value from the given heap at address ``index + offset``,
/// trapping on out-of-bounds accesses.
///
/// Checks that ``index + offset .. index + offset + sizeof(a)`` is
/// within the heap's bounds, trapping if it is not. Otherwise, when
/// that range is in bounds, loads the value from the heap.
///
/// Traps on ``index + offset + sizeof(a)`` overflow.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - heap_imm: Reference to out-of-line heap access immediates
/// - index: Dynamic index (in bytes) into the heap
///
/// Outputs:
///
/// - a: The value loaded from the heap
#[allow(non_snake_case)]
fn heap_load<T1: Into<ir::HeapImm>>(self, Mem: crate::ir::Type, heap_imm: T1, index: ir::Value) -> Value {
let heap_imm = heap_imm.into();
let (inst, dfg) = self.HeapLoad(Opcode::HeapLoad, Mem, heap_imm, index);
dfg.first_result(inst)
}
/// Store ``a`` into the given heap at address ``index + offset``,
/// trapping on out-of-bounds accesses.
///
/// Checks that ``index + offset .. index + offset + sizeof(a)`` is
/// within the heap's bounds, trapping if it is not. Otherwise, when
/// that range is in bounds, stores the value into the heap.
///
/// Traps on ``index + offset + sizeof(a)`` overflow.
///
/// Inputs:
///
/// - heap_imm: Reference to out-of-line heap access immediates
/// - index: Dynamic index (in bytes) into the heap
/// - a: The value stored into the heap
#[allow(non_snake_case)]
fn heap_store<T1: Into<ir::HeapImm>>(self, heap_imm: T1, index: ir::Value, a: ir::Value) -> Inst {
let heap_imm = heap_imm.into();
let ctrl_typevar = self.data_flow_graph().value_type(index);
self.HeapStore(Opcode::HeapStore, ctrl_typevar, heap_imm, index, a).0
}
/// Gets the content of the pinned register, when it's enabled.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_pinned_reg(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetPinnedReg, iAddr);
dfg.first_result(inst)
}
/// Sets the content of the pinned register, when it's enabled.
///
/// Inputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn set_pinned_reg(self, addr: ir::Value) -> Inst {
let ctrl_typevar = self.data_flow_graph().value_type(addr);
self.Unary(Opcode::SetPinnedReg, ctrl_typevar, addr).0
}
/// Get the address in the frame pointer register.
///
/// Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_frame_pointer(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetFramePointer, iAddr);
dfg.first_result(inst)
}
/// Get the address in the stack pointer register.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_stack_pointer(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetStackPointer, iAddr);
dfg.first_result(inst)
}
/// Get the PC where this function will transfer control to when it returns.
///
/// Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn get_return_address(self, iAddr: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::GetReturnAddress, iAddr);
dfg.first_result(inst)
}
/// Bounds check and compute absolute address of a table entry.
///
/// Verify that the offset ``p`` is in bounds for the table T, and generate
/// an absolute address that is safe to dereference.
///
/// ``Offset`` must be less than the size of a table element.
///
/// 1. If ``p`` is not greater than the table bound, return an absolute
/// address corresponding to a byte offset of ``p`` from the table's
/// base address.
/// 2. If ``p`` is greater than the table bound, generate a trap.
///
/// Inputs:
///
/// - iAddr (controlling type variable): An integer address type
/// - T: A table.
/// - p: An unsigned table offset
/// - Offset: Byte offset from element address
///
/// Outputs:
///
/// - addr: An integer address type
#[allow(non_snake_case)]
fn table_addr<T1: Into<ir::immediates::Offset32>>(self, iAddr: crate::ir::Type, T: ir::Table, p: ir::Value, Offset: T1) -> Value {
let Offset = Offset.into();
let (inst, dfg) = self.TableAddr(Opcode::TableAddr, iAddr, T, Offset, p);
dfg.first_result(inst)
}
/// Integer constant.
///
/// Create a scalar integer SSA value with an immediate constant value, or
/// an integer vector where all the lanes have the same value.
///
/// Inputs:
///
/// - NarrowInt (controlling type variable): An integer type with lanes type to `i64`
/// - N: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A constant integer scalar or vector value
#[allow(non_snake_case)]
fn iconst<T1: Into<ir::immediates::Imm64>>(self, NarrowInt: crate::ir::Type, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryImm(Opcode::Iconst, NarrowInt, N);
dfg.first_result(inst)
}
/// Floating point constant.
///
/// Create a `f32` SSA value with an immediate constant value.
///
/// Inputs:
///
/// - N: A 32-bit immediate floating point number.
///
/// Outputs:
///
/// - a: A constant f32 scalar value
#[allow(non_snake_case)]
fn f32const<T1: Into<ir::immediates::Ieee32>>(self, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryIeee32(Opcode::F32const, types::INVALID, N);
dfg.first_result(inst)
}
/// Floating point constant.
///
/// Create a `f64` SSA value with an immediate constant value.
///
/// Inputs:
///
/// - N: A 64-bit immediate floating point number.
///
/// Outputs:
///
/// - a: A constant f64 scalar value
#[allow(non_snake_case)]
fn f64const<T1: Into<ir::immediates::Ieee64>>(self, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryIeee64(Opcode::F64const, types::INVALID, N);
dfg.first_result(inst)
}
/// SIMD vector constant.
///
/// Construct a vector with the given immediate bytes.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - N: The 16 immediate bytes of a 128-bit vector
///
/// Outputs:
///
/// - a: A constant vector value
#[allow(non_snake_case)]
fn vconst<T1: Into<ir::Constant>>(self, TxN: crate::ir::Type, N: T1) -> Value {
let N = N.into();
let (inst, dfg) = self.UnaryConst(Opcode::Vconst, TxN, N);
dfg.first_result(inst)
}
/// SIMD vector shuffle.
///
/// Shuffle two vectors using the given immediate bytes. For each of the 16 bytes of the
/// immediate, a value i of 0-15 selects the i-th element of the first vector and a value i of
/// 16-31 selects the (i-16)th element of the second vector. Immediate values outside of the
/// 0-31 range place a 0 in the resulting vector lane.
///
/// Inputs:
///
/// - a: A vector value
/// - b: A vector value
/// - mask: The 16 immediate bytes used for selecting the elements to shuffle
///
/// Outputs:
///
/// - a: A vector value
#[allow(non_snake_case)]
fn shuffle<T1: Into<ir::Immediate>>(self, a: ir::Value, b: ir::Value, mask: T1) -> Value {
let mask = mask.into();
let (inst, dfg) = self.Shuffle(Opcode::Shuffle, types::INVALID, mask, a, b);
dfg.first_result(inst)
}
/// Null constant value for reference types.
///
/// Create a scalar reference SSA value with a constant null value.
///
/// Inputs:
///
/// - Ref (controlling type variable): A scalar reference type
///
/// Outputs:
///
/// - a: A constant reference null value
#[allow(non_snake_case)]
fn null(self, Ref: crate::ir::Type) -> Value {
let (inst, dfg) = self.NullAry(Opcode::Null, Ref);
dfg.first_result(inst)
}
/// Just a dummy instruction.
///
/// Note: this doesn't compile to a machine code nop.
#[allow(non_snake_case)]
fn nop(self) -> Inst {
self.NullAry(Opcode::Nop, types::INVALID).0
}
/// Conditional select.
///
/// This instruction selects whole values. Use `vselect` for
/// lane-wise selection.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn select(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Select, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select intended for Spectre guards.
///
/// This operation is semantically equivalent to a select instruction.
/// However, it is guaranteed to not be removed or otherwise altered by any
/// optimization pass, and is guaranteed to result in a conditional-move
/// instruction, not a branch-based lowering. As such, it is suitable
/// for use when producing Spectre guards. For example, a bounds-check
/// may guard against unsafe speculation past a bounds-check conditional
/// branch by passing the address or index to be accessed through a
/// conditional move, also gated on the same condition. Because no
/// Spectre-vulnerable processors are known to perform speculation on
/// conditional move instructions, this is guaranteed to pick the
/// correct input. If the selected input in case of overflow is a "safe"
/// value, for example a null pointer that causes an exception in the
/// speculative path, this ensures that no Spectre vulnerability will
/// exist.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn select_spectre_guard(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::SelectSpectreGuard, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Conditional select of bits.
///
/// For each bit in `c`, this instruction selects the corresponding bit from `x` if the bit
/// in `c` is 1 and the corresponding bit from `y` if the bit in `c` is 0. See also:
/// `select`, `vselect`.
///
/// Inputs:
///
/// - c: Controlling value to test
/// - x: Value to use when `c` is true
/// - y: Value to use when `c` is false
///
/// Outputs:
///
/// - a: Any integer, float, or reference scalar or vector type
#[allow(non_snake_case)]
fn bitselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Bitselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Split a vector into two halves.
///
/// Split the vector `x` into two separate values, each containing half of
/// the lanes from ``x``. The result may be two scalars if ``x`` only had
/// two lanes.
///
/// Inputs:
///
/// - x: Vector to split
///
/// Outputs:
///
/// - lo: Low-numbered lanes of `x`
/// - hi: High-numbered lanes of `x`
#[allow(non_snake_case)]
fn vsplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Vsplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Vector concatenation.
///
/// Return a vector formed by concatenating ``x`` and ``y``. The resulting
/// vector type has twice as many lanes as each of the inputs. The lanes of
/// ``x`` appear as the low-numbered lanes, and the lanes of ``y`` become
/// the high-numbered lanes of ``a``.
///
/// It is possible to form a vector by concatenating two scalars.
///
/// Inputs:
///
/// - x: Low-numbered lanes
/// - y: High-numbered lanes
///
/// Outputs:
///
/// - a: Concatenation of `x` and `y`
#[allow(non_snake_case)]
fn vconcat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Vconcat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Vector lane select.
///
/// Select lanes from ``x`` or ``y`` controlled by the lanes of the truthy
/// vector ``c``.
///
/// Inputs:
///
/// - c: Controlling vector
/// - x: Value to use where `c` is true
/// - y: Value to use where `c` is false
///
/// Outputs:
///
/// - a: A SIMD vector type
#[allow(non_snake_case)]
fn vselect(self, c: ir::Value, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Ternary(Opcode::Vselect, ctrl_typevar, c, x, y);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if any lane in ``a`` is non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vany_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VanyTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar boolean.
///
/// Return a scalar boolean true if all lanes in ``i`` are non-zero, false otherwise.
///
/// Inputs:
///
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - s: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn vall_true(self, a: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(a);
let (inst, dfg) = self.Unary(Opcode::VallTrue, ctrl_typevar, a);
dfg.first_result(inst)
}
/// Reduce a vector to a scalar integer.
///
/// Return a scalar integer, consisting of the concatenation of the most significant bit
/// of each lane of ``a``.
///
/// Inputs:
///
/// - Int (controlling type variable): A scalar or vector integer type
/// - a: A SIMD vector type
///
/// Outputs:
///
/// - x: A scalar or vector integer type
#[allow(non_snake_case)]
fn vhigh_bits(self, Int: crate::ir::Type, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::VhighBits, Int, a);
dfg.first_result(inst)
}
/// Integer comparison.
///
/// The condition code determines if the operands are interpreted as signed
/// or unsigned integers.
///
/// | Signed | Unsigned | Condition |
/// |--------|----------|-----------------------|
/// | eq | eq | Equal |
/// | ne | ne | Not equal |
/// | slt | ult | Less than |
/// | sge | uge | Greater than or equal |
/// | sgt | ugt | Greater than |
/// | sle | ule | Less than or equal |
///
/// When this instruction compares integer vectors, it returns a vector of
/// lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn icmp<T1: Into<ir::condcodes::IntCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompare(Opcode::Icmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant.
///
/// This is the same as the `icmp` instruction, except one operand is
/// a sign extended 64 bit immediate constant.
///
/// This instruction can only compare scalars. Use `icmp` for
/// lane-wise vector comparisons.
///
/// Inputs:
///
/// - Cond: An integer comparison condition code.
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn icmp_imm<T1: Into<ir::condcodes::IntCC>, T2: Into<ir::immediates::Imm64>>(self, Cond: T1, x: ir::Value, Y: T2) -> Value {
let Cond = Cond.into();
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntCompareImm(Opcode::IcmpImm, ctrl_typevar, Cond, Y, x);
dfg.first_result(inst)
}
/// Compare scalar integers and return flags.
///
/// Compare two scalar integer values and return integer CPU flags
/// representing the result.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ifcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Compare scalar integer to a constant and return flags.
///
/// Like `icmp_imm`, but returns integer CPU flags instead of testing
/// a specific condition code.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - f: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn ifcmp_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IfcmpImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Wrapping integer addition: `a := x + y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Iadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Wrapping integer subtraction: `a := x - y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn isub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Isub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer negation: `a := -x \pmod{2^B}`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ineg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ineg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Integer absolute value with wrapping: `a := |x|`.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn iabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Iabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Wrapping integer multiplication: `a := x y \pmod{2^B}`.
///
/// This instruction does not depend on the signed/unsigned interpretation
/// of the operands.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn imul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Imul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn umulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Umulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer multiplication, producing the high half of a
/// double-length result.
///
/// Polymorphic over all integer types (vector and scalar).
///
/// Inputs:
///
/// - x: A scalar or vector integer type
/// - y: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn smulhi(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Smulhi, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Fixed-point multiplication of numbers in the QN format, where N + 1
/// is the number bitwidth:
/// `a := signed_saturate((x * y + 1 << (Q - 1)) >> Q)`
///
/// Polymorphic over all integer types (scalar and vector) with 16- or
/// 32-bit numbers.
///
/// Inputs:
///
/// - x: A scalar or vector integer type with 16- or 32-bit numbers
/// - y: A scalar or vector integer type with 16- or 32-bit numbers
///
/// Outputs:
///
/// - a: A scalar or vector integer type with 16- or 32-bit numbers
#[allow(non_snake_case)]
fn sqmul_round_sat(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::SqmulRoundSat, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer division: `a := \lfloor {x \over y} \rfloor`.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Udiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer division rounded toward zero: `a := sign(xy)
/// \lfloor {|x| \over |y|}\rfloor`.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned integer remainder.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Urem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed integer remainder. The result has the sign of the dividend.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Srem, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Add immediate integer.
///
/// Same as `iadd`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IaddImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer multiplication by immediate constant.
///
/// Same as `imul`, but one operand is a sign extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn imul_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::ImulImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer division by an immediate constant.
///
/// Same as `udiv`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn udiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer division by an immediate constant.
///
/// Same as `sdiv`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero, or if the result is not
/// representable in `B` bits two's complement. This only happens
/// when `x = -2^{B-1}, Y = -1`.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn sdiv_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SdivImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned integer remainder with immediate divisor.
///
/// Same as `urem`, but one operand is a zero extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn urem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed integer remainder with immediate divisor.
///
/// Same as `srem`, but one operand is a sign extended 64 bit immediate constant.
///
/// This operation traps if the divisor is zero.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn srem_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SremImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Immediate reverse wrapping subtraction: `a := Y - x \pmod{2^B}`.
///
/// The immediate operand is a sign extended 64 bit constant.
///
/// Also works as integer negation when `Y = 0`. Use `iadd_imm`
/// with a negative immediate operand for the reverse immediate
/// subtraction.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn irsub_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IrsubImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_cin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry in.
///
/// Same as `iadd` with an additional carry flag input. Computes:
///
/// ```text
/// a = x + y + c_{in} \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn iadd_ifcin(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcin, ctrl_typevar, x, y, c_in);
dfg.first_result(inst)
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_cout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddCout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry out.
///
/// Same as `iadd` with an additional carry flag output.
///
/// ```text
/// a &= x + y \pmod 2^B \\
/// c_{out} &= x+y >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddIfcout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: Input carry flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: Output carry flag
#[allow(non_snake_case)]
fn iadd_carry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddCarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Add integers with carry in and out.
///
/// Same as `iadd` with an additional carry flag input and output.
///
/// ```text
/// a &= x + y + c_{in} \pmod 2^B \\
/// c_{out} &= x + y + c_{in} >= 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - c_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - c_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn iadd_ifcarry(self, x: ir::Value, y: ir::Value, c_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IaddIfcarry, ctrl_typevar, x, y, c_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Unsigned addition of x and y, trapping if the result overflows.
///
/// Accepts 32 or 64-bit integers, and does not support vector types.
///
/// Inputs:
///
/// - x: A 32 or 64-bit scalar integer type
/// - y: A 32 or 64-bit scalar integer type
/// - code: A trap reason code.
///
/// Outputs:
///
/// - a: A 32 or 64-bit scalar integer type
#[allow(non_snake_case)]
fn uadd_overflow_trap<T1: Into<ir::TrapCode>>(self, x: ir::Value, y: ir::Value, code: T1) -> Value {
let code = code.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.IntAddTrap(Opcode::UaddOverflowTrap, ctrl_typevar, code, x, y);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_bin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow in.
///
/// Same as `isub` with an additional borrow flag input. Computes:
///
/// ```text
/// a = x - (y + b_{in}) \pmod 2^B
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn isub_ifbin(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfbin, ctrl_typevar, x, y, b_in);
dfg.first_result(inst)
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_bout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubBout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow out.
///
/// Same as `isub` with an additional borrow flag output.
///
/// ```text
/// a &= x - y \pmod 2^B \\
/// b_{out} &= x < y
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifbout(self, x: ir::Value, y: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IsubIfbout, ctrl_typevar, x, y);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: Input borrow flag
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: Output borrow flag
#[allow(non_snake_case)]
fn isub_borrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubBorrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Subtract integers with borrow in and out.
///
/// Same as `isub` with an additional borrow flag input and output.
///
/// ```text
/// a &= x - (y + b_{in}) \pmod 2^B \\
/// b_{out} &= x < y + b_{in}
/// ```
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - y: A scalar integer type
/// - b_in: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
///
/// Outputs:
///
/// - a: A scalar integer type
/// - b_out: CPU flags representing the result of an integer comparison. These flags
/// can be tested with an :type:`intcc` condition code.
#[allow(non_snake_case)]
fn isub_ifborrow(self, x: ir::Value, y: ir::Value, b_in: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::IsubIfborrow, ctrl_typevar, x, y, b_in);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}
/// Bitwise and.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Band, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Bxor, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise not.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bnot(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bnot, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Bitwise and not.
///
/// Computes `x & ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn band_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BandNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise or not.
///
/// Computes `x | ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise xor not.
///
/// Computes `x ^ ~y`.
///
/// Inputs:
///
/// - x: Any integer, float, or vector type
/// - y: Any integer, float, or vector type
///
/// Outputs:
///
/// - a: Any integer, float, or vector type
#[allow(non_snake_case)]
fn bxor_not(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::BxorNot, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Bitwise and with immediate.
///
/// Same as `band`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn band_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BandImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise or with immediate.
///
/// Same as `bor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Bitwise xor with immediate.
///
/// Same as `bxor`, but one operand is a zero extended 64 bit immediate constant.
///
/// Polymorphic over all scalar integer types, but does not support vector
/// types.
///
/// Inputs:
///
/// - x: A scalar integer type
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bxor_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::BxorImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate left.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate right.
///
/// Rotate the bits in ``x`` by ``y`` places.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Rotr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Rotate left by immediate.
///
/// Same as `rotl`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Rotate right by immediate.
///
/// Same as `rotr`, but one operand is a zero extended 64 bit immediate constant.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn rotr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::RotrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Integer shift left. Shift the bits in ``x`` towards the MSB by ``y``
/// places. Shift in zero bits to the LSB.
///
/// The shift amount is masked to the size of ``x``.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= x \cdot 2^s \pmod{2^B}.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ishl, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Unsigned shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in zero bits to the MSB. Also called a *logical
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// When shifting a B-bits integer type, this instruction computes:
///
/// ```text
/// s &:= y \pmod B,
/// a &:= \lfloor x \cdot 2^{-s} \rfloor.
/// ```
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ushr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Signed shift right. Shift bits in ``x`` towards the LSB by ``y``
/// places, shifting in sign bits to the MSB. Also called an *arithmetic
/// shift*.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - y: Number of bits to shift
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Sshr, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Integer shift left by immediate.
///
/// The shift amount is masked to the size of ``x``.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ishl_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::IshlImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Unsigned shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn ushr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::UshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Signed shift right by immediate.
///
/// The shift amount is masked to the size of the register.
///
/// Inputs:
///
/// - x: Scalar or vector value to shift
/// - Y: A 64-bit immediate integer.
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn sshr_imm<T1: Into<ir::immediates::Imm64>>(self, x: ir::Value, Y: T1) -> Value {
let Y = Y.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.BinaryImm64(Opcode::SshrImm, ctrl_typevar, Y, x);
dfg.first_result(inst)
}
/// Reverse the bits of a integer.
///
/// Reverses the bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn bitrev(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bitrev, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading zero bits.
///
/// Starting from the MSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn clz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Clz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count leading sign bits.
///
/// Starting from the MSB after the sign bit in ``x``, count the number of
/// consecutive bits identical to the sign bit. When ``x`` is 0 or -1,
/// returns one less than the size of x in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn cls(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Cls, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Count trailing zeros.
///
/// Starting from the LSB in ``x``, count the number of zero bits before
/// reaching the first one bit. When ``x`` is zero, returns the size of x
/// in bits.
///
/// Inputs:
///
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A scalar integer type
#[allow(non_snake_case)]
fn ctz(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ctz, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reverse the byte order of an integer.
///
/// Reverses the bytes in ``x``.
///
/// Inputs:
///
/// - x: A multi byte scalar integer type
///
/// Outputs:
///
/// - a: A multi byte scalar integer type
#[allow(non_snake_case)]
fn bswap(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Bswap, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Population count
///
/// Count the number of one bits in ``x``.
///
/// Inputs:
///
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector integer type
#[allow(non_snake_case)]
fn popcnt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Popcnt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point comparison.
///
/// Two IEEE 754-2008 floating point numbers, `x` and `y`, relate to each
/// other in exactly one of four ways:
///
/// ```text
/// == ==========================================
/// UN Unordered when one or both numbers is NaN.
/// EQ When `x = y`. (And `0.0 = -0.0`).
/// LT When `x < y`.
/// GT When `x > y`.
/// == ==========================================
/// ```
///
/// The 14 `floatcc` condition codes each correspond to a subset of
/// the four relations, except for the empty set which would always be
/// false, and the full set which would always be true.
///
/// The condition codes are divided into 7 'ordered' conditions which don't
/// include UN, and 7 unordered conditions which all include UN.
///
/// ```text
/// +-------+------------+---------+------------+-------------------------+
/// |Ordered |Unordered |Condition |
/// +=======+============+=========+============+=========================+
/// |ord |EQ | LT | GT|uno |UN |NaNs absent / present. |
/// +-------+------------+---------+------------+-------------------------+
/// |eq |EQ |ueq |UN | EQ |Equal |
/// +-------+------------+---------+------------+-------------------------+
/// |one |LT | GT |ne |UN | LT | GT|Not equal |
/// +-------+------------+---------+------------+-------------------------+
/// |lt |LT |ult |UN | LT |Less than |
/// +-------+------------+---------+------------+-------------------------+
/// |le |LT | EQ |ule |UN | LT | EQ|Less than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// |gt |GT |ugt |UN | GT |Greater than |
/// +-------+------------+---------+------------+-------------------------+
/// |ge |GT | EQ |uge |UN | GT | EQ|Greater than or equal |
/// +-------+------------+---------+------------+-------------------------+
/// ```
///
/// The standard C comparison operators, `<, <=, >, >=`, are all ordered,
/// so they are false if either operand is NaN. The C equality operator,
/// `==`, is ordered, and since inequality is defined as the logical
/// inverse it is *unordered*. They map to the `floatcc` condition
/// codes as follows:
///
/// ```text
/// ==== ====== ============
/// C `Cond` Subset
/// ==== ====== ============
/// `==` eq EQ
/// `!=` ne UN | LT | GT
/// `<` lt LT
/// `<=` le LT | EQ
/// `>` gt GT
/// `>=` ge GT | EQ
/// ==== ====== ============
/// ```
///
/// This subset of condition codes also corresponds to the WebAssembly
/// floating point comparisons of the same name.
///
/// When this instruction compares floating point vectors, it returns a
/// vector with the results of lane-wise comparisons.
///
/// Inputs:
///
/// - Cond: A floating point comparison condition code
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn fcmp<T1: Into<ir::condcodes::FloatCC>>(self, Cond: T1, x: ir::Value, y: ir::Value) -> Value {
let Cond = Cond.into();
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.FloatCompare(Opcode::Fcmp, ctrl_typevar, Cond, x, y);
dfg.first_result(inst)
}
/// Floating point comparison returning flags.
///
/// Compares two numbers like `fcmp`, but returns floating point CPU
/// flags instead of testing a specific condition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - f: CPU flags representing the result of a floating point comparison. These
/// flags can be tested with a :type:`floatcc` condition code.
#[allow(non_snake_case)]
fn ffcmp(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Ffcmp, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point addition.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fadd(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fadd, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point subtraction.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fsub(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fsub, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point multiplication.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fmul(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmul, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point division.
///
/// Unlike the integer division instructions ` and
/// `udiv`, this can't trap. Division by zero is infinity or
/// NaN, depending on the dividend.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fdiv(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fdiv, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point square root.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn sqrt(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Sqrt, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point fused multiply-and-add.
///
/// Computes `a := xy+z` without any intermediate rounding of the
/// product.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
/// - z: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: Result of applying operator to each lane
#[allow(non_snake_case)]
fn fma(self, x: ir::Value, y: ir::Value, z: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(y);
let (inst, dfg) = self.Ternary(Opcode::Fma, ctrl_typevar, x, y, z);
dfg.first_result(inst)
}
/// Floating point negation.
///
/// Note that this is a pure bitwise operation.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit inverted
#[allow(non_snake_case)]
fn fneg(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Fneg, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point absolute value.
///
/// Note that this is a pure bitwise operation.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit cleared
#[allow(non_snake_case)]
fn fabs(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Fabs, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Floating point copy sign.
///
/// Note that this is a pure bitwise operation. The sign bit from ``y`` is
/// copied to the sign bit of ``x``.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` with its sign bit changed to that of ``y``
#[allow(non_snake_case)]
fn fcopysign(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fcopysign, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point minimum, propagating NaNs using the WebAssembly rules.
///
/// If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
/// each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
/// 0, then the output has the same form. Otherwise, the output mantissa's most significant
/// bit is 1 and the rest is unspecified.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The smaller of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmin(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmin, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point pseudo-minimum, propagating NaNs. This behaves differently from ``fmin``.
/// See <https://github.com/WebAssembly/simd/pull/122> for background.
///
/// The behaviour is defined as ``fmin_pseudo(a, b) = (b < a) ? b : a``, and the behaviour
/// for zero or NaN inputs follows from the behaviour of ``<`` with such inputs.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The smaller of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmin_pseudo(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::FminPseudo, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point maximum, propagating NaNs using the WebAssembly rules.
///
/// If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
/// each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
/// 0, then the output has the same form. Otherwise, the output mantissa's most significant
/// bit is 1 and the rest is unspecified.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The larger of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmax(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Fmax, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Floating point pseudo-maximum, propagating NaNs. This behaves differently from ``fmax``.
/// See <https://github.com/WebAssembly/simd/pull/122> for background.
///
/// The behaviour is defined as ``fmax_pseudo(a, b) = (a < b) ? b : a``, and the behaviour
/// for zero or NaN inputs follows from the behaviour of ``<`` with such inputs.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
/// - y: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: The larger of ``x`` and ``y``
#[allow(non_snake_case)]
fn fmax_pseudo(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::FmaxPseudo, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards positive infinity.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn ceil(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Ceil, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards negative infinity.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn floor(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Floor, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards zero.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn trunc(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Trunc, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Round floating point round to integral, towards nearest with ties to
/// even.
///
/// Inputs:
///
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: ``x`` rounded to integral value
#[allow(non_snake_case)]
fn nearest(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Nearest, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reference verification.
///
/// The condition code determines if the reference type in question is
/// null or not.
///
/// Inputs:
///
/// - x: A scalar reference type
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn is_null(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::IsNull, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reference verification.
///
/// The condition code determines if the reference type in question is
/// invalid or not.
///
/// Inputs:
///
/// - x: A scalar reference type
///
/// Outputs:
///
/// - a: An integer type with 8 bits.
/// WARNING: arithmetic on 8bit integers is incomplete
#[allow(non_snake_case)]
fn is_invalid(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::IsInvalid, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Reinterpret the bits in `x` as a different type.
///
/// The input and output types must be storable to memory and of the same
/// size. A bitcast is equivalent to storing one type and loading the other
/// type from the same address, both using the specified MemFlags.
///
/// Note that this operation only supports the `big` or `little` MemFlags.
/// The specified byte order only affects the result in the case where
/// input and output types differ in lane count/size. In this case, the
/// operation is only valid if a byte order specifier is provided.
///
/// Inputs:
///
/// - MemTo (controlling type variable):
/// - MemFlags: Memory operation flags
/// - x: Any type that can be stored in memory
///
/// Outputs:
///
/// - a: Bits of `x` reinterpreted
#[allow(non_snake_case)]
fn bitcast<T1: Into<ir::MemFlags>>(self, MemTo: crate::ir::Type, MemFlags: T1, x: ir::Value) -> Value {
let MemFlags = MemFlags.into();
let (inst, dfg) = self.LoadNoOffset(Opcode::Bitcast, MemTo, MemFlags, x);
dfg.first_result(inst)
}
/// Copies a scalar value to a vector value. The scalar is copied into the
/// least significant lane of the vector, and all other lanes will be zero.
///
/// Inputs:
///
/// - TxN (controlling type variable): A SIMD vector type
/// - s: A scalar value
///
/// Outputs:
///
/// - a: A vector value
#[allow(non_snake_case)]
fn scalar_to_vector(self, TxN: crate::ir::Type, s: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::ScalarToVector, TxN, s);
dfg.first_result(inst)
}
/// Convert `x` to an integer mask.
///
/// True maps to all 1s and false maps to all 0s. The result type must have
/// the same number of vector lanes as the input.
///
/// Inputs:
///
/// - IntTo (controlling type variable): An integer type with the same number of lanes
/// - x: A scalar or vector whose values are truthy
///
/// Outputs:
///
/// - a: An integer type with the same number of lanes
#[allow(non_snake_case)]
fn bmask(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Bmask, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller integer type by discarding
/// the most significant bits.
///
/// This is the same as reducing modulo `2^n`.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A smaller integer type
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A smaller integer type
#[allow(non_snake_case)]
fn ireduce(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Ireduce, IntTo, x);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the signed maximum and minimum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn snarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Snarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered signed: any negative lanes will overflow and be
/// replaced with the unsigned minimum, `0x00`.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn unarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Unarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Combine `x` and `y` into a vector with twice the lanes but half the integer width while
/// saturating overflowing values to the unsigned maximum and minimum.
///
/// Note that all input lanes are considered unsigned: any negative values will be interpreted as unsigned, overflowing and being replaced with the unsigned maximum.
///
/// The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
/// and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
/// returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
/// - y: A SIMD vector type containing integer lanes 16, 32, or 64 bits wide
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uunarrow(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::Uunarrow, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using signed extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn swiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::SwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the low lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_low(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenLow, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Widen the high lanes of `x` using unsigned extension.
///
/// This will double the lane width and halve the number of lanes.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn uwiden_high(self, x: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::UwidenHigh, ctrl_typevar, x);
dfg.first_result(inst)
}
/// Does lane-wise integer pairwise addition on two operands, putting the
/// combined results into a single vector result. Here a pair refers to adjacent
/// lanes in a vector, i.e. i*2 + (i*2+1) for i == num_lanes/2. The first operand
/// pairwise add results will make up the low half of the resulting vector while
/// the second operand pairwise add results will make up the upper half of the
/// resulting vector.
///
/// Inputs:
///
/// - x: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
/// - y: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
///
/// Outputs:
///
/// - a: A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.
#[allow(non_snake_case)]
fn iadd_pairwise(self, x: ir::Value, y: ir::Value) -> Value {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Binary(Opcode::IaddPairwise, ctrl_typevar, x, y);
dfg.first_result(inst)
}
/// Takes corresponding elements in `x` and `y`, performs a sign-extending length-doubling
/// multiplication on them, then adds adjacent pairs of elements to form the result. For
/// example, if the input vectors are `[x3, x2, x1, x0]` and `[y3, y2, y1, y0]`, it produces
/// the vector `[r1, r0]`, where `r1 = sx(x3) * sx(y3) + sx(x2) * sx(y2)` and
/// `r0 = sx(x1) * sx(y1) + sx(x0) * sx(y0)`, and `sx(n)` sign-extends `n` to twice its width.
///
/// This will double the lane width and halve the number of lanes. So the resulting
/// vector has the same number of bits as `x` and `y` do (individually).
///
/// See <https://github.com/WebAssembly/simd/pull/127> for background info.
///
/// Inputs:
///
/// - x: A SIMD vector type containing 8 integer lanes each 16 bits wide.
/// - y: A SIMD vector type containing 8 integer lanes each 16 bits wide.
///
/// Outputs:
///
/// - a:
#[allow(non_snake_case)]
fn widening_pairwise_dot_product_s(self, x: ir::Value, y: ir::Value) -> Value {
let (inst, dfg) = self.Binary(Opcode::WideningPairwiseDotProductS, types::INVALID, x, y);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by zero-extending.
///
/// Each lane in `x` is converted to a larger integer type by adding
/// zeroes. The result has the same numerical value as `x` when both are
/// interpreted as unsigned integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn uextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Uextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger integer type by sign-extending.
///
/// Each lane in `x` is converted to a larger integer type by replicating
/// the sign bit. The result has the same numerical value as `x` when both
/// are interpreted as signed integers.
///
/// The result type must have the same number of vector lanes as the input,
/// and each lane must not have fewer bits that the input lanes. If the
/// input and output types are the same, this is a no-op.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar integer type
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn sextend(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Sextend, IntTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a larger floating point format.
///
/// Each lane in `x` is converted to the destination floating point format.
/// This is an exact operation.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have fewer bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fpromote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fpromote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// The result type must have the same number of vector lanes as the input,
/// and the result lanes must not have more bits than the input lanes.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fdemote(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fdemote, FloatTo, x);
dfg.first_result(inst)
}
/// Convert `x` to a smaller floating point format.
///
/// Each lane in `x` is converted to the destination floating point format
/// by rounding to nearest, ties to even.
///
/// Cranelift currently only supports two floating point formats
/// - `f32` and `f64`. This may change in the future.
///
/// Fvdemote differs from fdemote in that with fvdemote it targets vectors.
/// Fvdemote is constrained to having the input type being F64x2 and the result
/// type being F32x4. The result lane that was the upper half of the input lane
/// is initialized to zero.
///
/// Inputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
///
/// Outputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
#[allow(non_snake_case)]
fn fvdemote(self, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::Fvdemote, types::INVALID, x);
dfg.first_result(inst)
}
/// Converts packed single precision floating point to packed double precision floating point.
///
/// Considering only the lower half of the register, the low lanes in `x` are interpreted as
/// single precision floats that are then converted to a double precision floats.
///
/// The result type will have half the number of vector lanes as the input. Fvpromote_low is
/// constrained to input F32x4 with a result type of F64x2.
///
/// Inputs:
///
/// - a: A SIMD vector type consisting of 4 lanes of 32-bit floats
///
/// Outputs:
///
/// - x: A SIMD vector type consisting of 2 lanes of 64-bit floats
#[allow(non_snake_case)]
fn fvpromote_low(self, a: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FvpromoteLow, types::INVALID, a);
dfg.first_result(inst)
}
/// Converts floating point scalars to unsigned integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUint, IntTo, x);
dfg.first_result(inst)
}
/// Converts floating point scalars to signed integer.
///
/// Only operates on `x` if it is a scalar. If `x` is NaN or if
/// the unsigned integral value cannot be represented in the result
/// type, this instruction traps.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar only floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSint, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to unsigned integer as fcvt_to_uint does, but
/// saturates the input instead of trapping. NaN and negative values are
/// converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_uint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToUintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert floating point to signed integer as fcvt_to_sint does, but
/// saturates the input instead of trapping. NaN values are converted to 0.
///
/// Inputs:
///
/// - IntTo (controlling type variable): A larger integer type with the same number of lanes
/// - x: A scalar or vector floating point number
///
/// Outputs:
///
/// - a: A larger integer type with the same number of lanes
#[allow(non_snake_case)]
fn fcvt_to_sint_sat(self, IntTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtToSintSat, IntTo, x);
dfg.first_result(inst)
}
/// Convert unsigned integer to floating point.
///
/// Each lane in `x` is interpreted as an unsigned integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_uint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromUint, FloatTo, x);
dfg.first_result(inst)
}
/// Convert signed integer to floating point.
///
/// Each lane in `x` is interpreted as a signed integer and converted to
/// floating point using round to nearest, ties to even.
///
/// The result type must have the same number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Converts packed signed 32-bit integers to packed double precision floating point.
///
/// Considering only the low half of the register, each lane in `x` is interpreted as a
/// signed 32-bit integer that is then converted to a double precision float. This
/// instruction differs from fcvt_from_sint in that it converts half the number of lanes
/// which are converted to occupy twice the number of bits. No rounding should be needed
/// for the resulting float.
///
/// The result type will have half the number of vector lanes as the input.
///
/// Inputs:
///
/// - FloatTo (controlling type variable): A scalar or vector floating point number
/// - x: A scalar or vector integer type
///
/// Outputs:
///
/// - a: A scalar or vector floating point number
#[allow(non_snake_case)]
fn fcvt_low_from_sint(self, FloatTo: crate::ir::Type, x: ir::Value) -> Value {
let (inst, dfg) = self.Unary(Opcode::FcvtLowFromSint, FloatTo, x);
dfg.first_result(inst)
}
/// Split an integer into low and high parts.
///
/// Vectors of integers are split lane-wise, so the results have the same
/// number of lanes as the input, but the lanes are half the size.
///
/// Returns the low half of `x` and the high half of `x` as two independent
/// values.
///
/// Inputs:
///
/// - x: An integer type with lanes from `i16` upwards
///
/// Outputs:
///
/// - lo: The low bits of `x`
/// - hi: The high bits of `x`
#[allow(non_snake_case)]
fn isplit(self, x: ir::Value) -> (Value, Value) {
let ctrl_typevar = self.data_flow_graph().value_type(x);
let (inst, dfg) = self.Unary(Opcode::Isplit, ctrl_typevar, x);
let results = &dfg.inst_results(inst)[0..2];
(results[0], results[1])
}sourcefn UnaryConst(
self,
opcode: Opcode,
ctrl_typevar: Type,
constant_handle: Constant
) -> (Inst, &'f mut DataFlowGraph)
fn UnaryConst(
self,
opcode: Opcode,
ctrl_typevar: Type,
constant_handle: Constant
) -> (Inst, &'f mut DataFlowGraph)
UnaryConst(imms=(constant_handle: ir::Constant), vals=0)
sourcefn UnaryGlobalValue(
self,
opcode: Opcode,
ctrl_typevar: Type,
global_value: GlobalValue
) -> (Inst, &'f mut DataFlowGraph)
fn UnaryGlobalValue(
self,
opcode: Opcode,
ctrl_typevar: Type,
global_value: GlobalValue
) -> (Inst, &'f mut DataFlowGraph)
UnaryGlobalValue(imms=(global_value: ir::GlobalValue), vals=0)
Examples found in repository?
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
fn global_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::GlobalValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a symbolic value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn symbol_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::SymbolValue, Mem, GV);
dfg.first_result(inst)
}
/// Compute the value of global GV, which is a TLS (thread local storage) value.
///
/// Inputs:
///
/// - Mem (controlling type variable): Any type that can be stored in memory
/// - GV: A global value.
///
/// Outputs:
///
/// - a: Value loaded
#[allow(non_snake_case)]
fn tls_value(self, Mem: crate::ir::Type, GV: ir::GlobalValue) -> Value {
let (inst, dfg) = self.UnaryGlobalValue(Opcode::TlsValue, Mem, GV);
dfg.first_result(inst)
}sourcefn UnaryIeee32(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Ieee32
) -> (Inst, &'f mut DataFlowGraph)
fn UnaryIeee32(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Ieee32
) -> (Inst, &'f mut DataFlowGraph)
UnaryIeee32(imms=(imm: ir::immediates::Ieee32), vals=0)
sourcefn UnaryIeee64(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Ieee64
) -> (Inst, &'f mut DataFlowGraph)
fn UnaryIeee64(
self,
opcode: Opcode,
ctrl_typevar: Type,
imm: Ieee64
) -> (Inst, &'f mut DataFlowGraph)
UnaryIeee64(imms=(imm: ir::immediates::Ieee64), vals=0)
Implementors§
impl<'f, T: InstBuilderBase<'f>> InstBuilder<'f> for T
Any type implementing InstBuilderBase gets all the InstBuilder methods for free.