Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow Type::narrow() and Type::widen() from producing bitwidths between 1 and 8 bits #6622

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,25 @@ struct Type {
return Type(code(), bits(), new_lanes, handle_type);
}

/** Return Type with the same type code and number of lanes, but with twice as many bits. */
/** Return Type with the same type code and number of lanes, but with at least twice as many bits. */
Type widen() const {
return with_bits(bits() * 2);
if (bits() == 1) {
// Widening a 1-bit type should produce an 8-bit type.
return with_bits(8);
} else {
return with_bits(bits() * 2);
}
}

/** Return Type with the same type code and number of lanes, but with half as many bits. */
/** Return Type with the same type code and number of lanes, but with at most half as many bits. */
Type narrow() const {
return with_bits(bits() / 2);
internal_assert(bits() != 1) << "Attempting to narrow a 1-bit type\n";
if (bits() == 8) {
// Narrowing an 8-bit type should produce a 1-bit type.
return with_bits(1);
} else {
return with_bits(bits() / 2);
}
}

/** Type to be printed when declaring handles of this type. */
Expand Down