Rename as_bool to as_truthy, and fix TypeSet::as_bool (#6027)

This commit is contained in:
Trevor Elliott
2023-03-17 14:11:24 -07:00
committed by GitHub
parent 2c40c267d4
commit 78dbe93f21
6 changed files with 49 additions and 33 deletions

View File

@@ -228,7 +228,7 @@ impl TypeVar {
"The `wider` constraint only applies to scalar ints or floats"
);
}
DerivedFunc::LaneOf | DerivedFunc::AsBool | DerivedFunc::DynamicToVector => {
DerivedFunc::LaneOf | DerivedFunc::AsTruthy | DerivedFunc::DynamicToVector => {
/* no particular assertions */
}
}
@@ -249,8 +249,8 @@ impl TypeVar {
pub fn lane_of(&self) -> TypeVar {
self.derived(DerivedFunc::LaneOf)
}
pub fn as_bool(&self) -> TypeVar {
self.derived(DerivedFunc::AsBool)
pub fn as_truthy(&self) -> TypeVar {
self.derived(DerivedFunc::AsTruthy)
}
pub fn half_width(&self) -> TypeVar {
self.derived(DerivedFunc::HalfWidth)
@@ -332,7 +332,7 @@ impl ops::Deref for TypeVar {
#[derive(Clone, Copy, Debug, Hash, PartialEq)]
pub(crate) enum DerivedFunc {
LaneOf,
AsBool,
AsTruthy,
HalfWidth,
DoubleWidth,
SplitLanes,
@@ -346,7 +346,7 @@ impl DerivedFunc {
pub fn name(self) -> &'static str {
match self {
DerivedFunc::LaneOf => "lane_of",
DerivedFunc::AsBool => "as_bool",
DerivedFunc::AsTruthy => "as_truthy",
DerivedFunc::HalfWidth => "half_width",
DerivedFunc::DoubleWidth => "double_width",
DerivedFunc::SplitLanes => "split_lanes",
@@ -425,7 +425,7 @@ impl TypeSet {
fn image(&self, derived_func: DerivedFunc) -> TypeSet {
match derived_func {
DerivedFunc::LaneOf => self.lane_of(),
DerivedFunc::AsBool => self.as_bool(),
DerivedFunc::AsTruthy => self.as_truthy(),
DerivedFunc::HalfWidth => self.half_width(),
DerivedFunc::DoubleWidth => self.double_width(),
DerivedFunc::SplitLanes => self.half_width().double_vector(),
@@ -443,10 +443,19 @@ impl TypeSet {
copy
}
/// Return a TypeSet describing the image of self across as_bool.
fn as_bool(&self) -> TypeSet {
/// Return a TypeSet describing the image of self across as_truthy.
fn as_truthy(&self) -> TypeSet {
let mut copy = self.clone();
copy.ints = NumSet::new();
// If this type set represents a scalar, `as_truthy` produces an I8, otherwise it returns a
// vector of the same number of lanes, whose elements are integers of the same width. For
// example, F32X4 gets turned into I32X4, while I32 gets turned into I8.
if self.lanes.len() == 1 && self.lanes.contains(&1) {
copy.ints = NumSet::from([8]);
} else {
copy.ints.extend(&self.floats)
}
copy.floats = NumSet::new();
copy.refs = NumSet::new();
copy
@@ -814,7 +823,7 @@ fn test_typevar_builder_inverted_bounds_panic() {
}
#[test]
fn test_as_bool() {
fn test_as_truthy() {
let a = TypeSetBuilder::new()
.simd_lanes(2..8)
.ints(8..8)
@@ -824,6 +833,14 @@ fn test_as_bool() {
a.lane_of(),
TypeSetBuilder::new().ints(8..8).floats(32..32).build()
);
let mut a_as_truthy = TypeSetBuilder::new().simd_lanes(2..8).build();
a_as_truthy.ints = num_set![8, 32];
assert_eq!(a.as_truthy(), a_as_truthy);
let a = TypeSetBuilder::new().ints(8..32).floats(32..64).build();
let a_as_truthy = TypeSetBuilder::new().ints(8..8).build();
assert_eq!(a.as_truthy(), a_as_truthy);
}
#[test]

View File

@@ -684,7 +684,7 @@ fn gen_opcodes(all_inst: &AllInstructions, fmt: &mut Formatter) {
/// Each operand constraint is represented as a string, one of:
/// - `Concrete(vt)`, where `vt` is a value type name.
/// - `Free(idx)` where `idx` is an index into `type_sets`.
/// - `Same`, `Lane`, `AsBool` for controlling typevar-derived constraints.
/// - `Same`, `Lane`, `AsTruthy` for controlling typevar-derived constraints.
fn get_constraint<'entries, 'table>(
operand: &'entries Operand,
ctrl_typevar: Option<&TypeVar>,
@@ -793,7 +793,7 @@ fn gen_type_constraints(all_inst: &AllInstructions, fmt: &mut Formatter) {
// constraint is represented as a string, one of:
// - `Concrete(vt)`, where `vt` is a value type name.
// - `Free(idx)` where `idx` is an index into `type_sets`.
// - `Same`, `Lane`, `AsBool` for controlling typevar-derived constraints.
// - `Same`, `Lane`, `AsTruthy` for controlling typevar-derived constraints.
let mut operand_seqs = UniqueSeqTable::new();
// Preload table with constraints for typical binops.

View File

@@ -1627,7 +1627,7 @@ pub(crate) fn define(
Operand::new("x", Int),
Operand::new("y", Int),
])
.operands_out(vec![Operand::new("a", &Int.as_bool())]),
.operands_out(vec![Operand::new("a", &Int.as_truthy())]),
);
ig.push(
@@ -2684,7 +2684,7 @@ pub(crate) fn define(
Operand::new("x", Float),
Operand::new("y", Float),
])
.operands_out(vec![Operand::new("a", &Float.as_bool())]),
.operands_out(vec![Operand::new("a", &Float.as_truthy())]),
);
ig.push(