Implement select and vselect instructions.
This gives us the opportunity to use the AsBool derived type variables and a Select instruction format with a non-default typevar_operand setting.
This commit is contained in:
@@ -656,35 +656,12 @@ load a constant into an SSA value.
|
||||
.. autoinst:: f32const
|
||||
.. autoinst:: f64const
|
||||
.. autoinst:: vconst
|
||||
|
||||
.. inst:: a = select c, x, y
|
||||
|
||||
Conditional select.
|
||||
|
||||
:arg b1 c: Controlling flag.
|
||||
:arg T x: Value to return when ``c`` is true.
|
||||
:arg T y: Value to return when ``c`` is false. Must be same type as ``x``.
|
||||
:result T a: Same type as ``x`` and ``y``.
|
||||
|
||||
This instruction selects whole values. Use :inst:`vselect` for lane-wise
|
||||
selection.
|
||||
.. autoinst:: select
|
||||
|
||||
Vector operations
|
||||
-----------------
|
||||
|
||||
.. inst:: a = vselect c, x, y
|
||||
|
||||
Vector lane select.
|
||||
|
||||
Select lanes from ``x`` or ``y`` controlled by the lanes of the boolean
|
||||
vector ``c``.
|
||||
|
||||
:arg b1xN c: Controlling flag vector.
|
||||
:arg TxN x: Vector with lanes selected by the true lanes of ``c``.
|
||||
Must be a vector type with the same number of lanes as ``c``.
|
||||
:arg TxN y: Vector with lanes selected by the false lanes of ``c``.
|
||||
Must be same type as ``x``.
|
||||
:result TxN a: Same type as ``x`` and ``y``.
|
||||
.. autoinst:: vselect
|
||||
|
||||
.. inst:: a = vbuild x, y, z, ...
|
||||
|
||||
|
||||
@@ -158,6 +158,11 @@ pub enum InstructionData {
|
||||
second_result: Value,
|
||||
args: [Value; 2],
|
||||
},
|
||||
Select {
|
||||
opcode: Opcode,
|
||||
ty: Type,
|
||||
args: [Value; 3],
|
||||
},
|
||||
Jump {
|
||||
opcode: Opcode,
|
||||
ty: Type,
|
||||
@@ -295,13 +300,13 @@ impl InstructionData {
|
||||
///
|
||||
/// Bits 4-7:
|
||||
/// Permitted set of types for the controlling type variable as an index into `TYPE_SETS`.
|
||||
///
|
||||
///
|
||||
/// Bits 8-15:
|
||||
/// Offset into `OPERAND_CONSTRAINT` table of the descriptors for this opcode. The first
|
||||
/// `fixed_results()` entries describe the result constraints, then follows constraints for the
|
||||
/// fixed `Value` input operands. The number of `Value` inputs isdetermined by the instruction
|
||||
/// format.
|
||||
///
|
||||
///
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct OpcodeConstraints(u16);
|
||||
|
||||
|
||||
@@ -156,6 +156,9 @@ pub fn write_instruction(w: &mut Write, func: &Function, inst: Inst) -> Result {
|
||||
BinaryImm { opcode, lhs, rhs, .. } => writeln!(w, "{} {}, {}", opcode, lhs, rhs),
|
||||
BinaryImmRev { opcode, lhs, rhs, .. } => writeln!(w, "{} {}, {}", opcode, lhs, rhs),
|
||||
BinaryOverflow { opcode, args, .. } => writeln!(w, "{} {}, {}", opcode, args[0], args[1]),
|
||||
Select { opcode, args, .. } => {
|
||||
writeln!(w, "{} {}, {}, {}", opcode, args[0], args[1], args[2])
|
||||
}
|
||||
Jump { opcode, ref data, .. } => writeln!(w, "{} {}", opcode, data),
|
||||
Branch { opcode, ref data, .. } => writeln!(w, "{} {}", opcode, data),
|
||||
BranchTable { opcode, arg, table, .. } => writeln!(w, "{} {}, {}", opcode, arg, table),
|
||||
|
||||
@@ -668,6 +668,7 @@ impl<'a> Parser<'a> {
|
||||
args: [lhs, rhs],
|
||||
}
|
||||
}
|
||||
InstructionFormat::Select |
|
||||
InstructionFormat::Jump |
|
||||
InstructionFormat::Branch |
|
||||
InstructionFormat::BranchTable |
|
||||
|
||||
Reference in New Issue
Block a user