refactor(naga): rename MathFunction::FindLsb to FirstTrailingBit

This commit is contained in:
Erich Gubler 2024-01-19 14:15:49 -05:00
parent 5b44baa8c8
commit 2f7c87f7af
12 changed files with 18 additions and 16 deletions

View File

@ -3647,7 +3647,7 @@ impl<'a, W: Write> Writer<'a, W> {
return Ok(());
}
Mf::FindLsb => "findLSB",
Mf::FirstTrailingBit => "findLSB",
Mf::FirstLeadingBit => "findMSB",
// data packing
Mf::Pack4x8snorm => "packSnorm4x8",
@ -3724,7 +3724,7 @@ impl<'a, W: Write> Writer<'a, W> {
// so they need to be cast to uint if the argument is also an uint.
let ret_might_need_int_to_uint = matches!(
fun,
Mf::FindLsb | Mf::FirstLeadingBit | Mf::CountOneBits | Mf::Abs
Mf::FirstTrailingBit | Mf::FirstLeadingBit | Mf::CountOneBits | Mf::Abs
);
// Some GLSL functions only accept signed integers (like abs),

View File

@ -3063,7 +3063,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
Mf::CountLeadingZeros => Function::CountLeadingZeros,
Mf::CountOneBits => Function::MissingIntOverload("countbits"),
Mf::ReverseBits => Function::MissingIntOverload("reversebits"),
Mf::FindLsb => Function::MissingIntReturnType("firstbitlow"),
Mf::FirstTrailingBit => Function::MissingIntReturnType("firstbitlow"),
Mf::FirstLeadingBit => Function::MissingIntReturnType("firstbithigh"),
Mf::ExtractBits => Function::Regular(EXTRACT_BITS_FUNCTION),
Mf::InsertBits => Function::Regular(INSERT_BITS_FUNCTION),

View File

@ -1875,7 +1875,7 @@ impl<W: Write> Writer<W> {
Mf::ReverseBits => "reverse_bits",
Mf::ExtractBits => "",
Mf::InsertBits => "",
Mf::FindLsb => "",
Mf::FirstTrailingBit => "",
Mf::FirstLeadingBit => "",
// data packing
Mf::Pack4x8snorm => "pack_float_to_snorm4x8",
@ -1920,7 +1920,7 @@ impl<W: Write> Writer<W> {
self.put_expression(arg1.unwrap(), context, false)?;
write!(self.out, ")")?;
}
Mf::FindLsb => {
Mf::FirstTrailingBit => {
let scalar = context.resolve_type(arg).scalar().unwrap();
let constant = scalar.width * 8 + 1;

View File

@ -1183,7 +1183,7 @@ impl<'w> BlockContext<'w> {
count_id,
))
}
Mf::FindLsb => MathOp::Ext(spirv::GLOp::FindILsb),
Mf::FirstTrailingBit => MathOp::Ext(spirv::GLOp::FindILsb),
Mf::FirstLeadingBit => {
if arg_ty.scalar_width() == Some(4) {
let thing = match arg_scalar_kind {

View File

@ -1710,7 +1710,7 @@ impl<W: Write> Writer<W> {
Mf::ReverseBits => Function::Regular("reverseBits"),
Mf::ExtractBits => Function::Regular("extractBits"),
Mf::InsertBits => Function::Regular("insertBits"),
Mf::FindLsb => Function::Regular("firstTrailingBit"),
Mf::FirstTrailingBit => Function::Regular("firstTrailingBit"),
Mf::FirstLeadingBit => Function::Regular("firstLeadingBit"),
// data packing
Mf::Pack4x8snorm => Function::Regular("pack4x8snorm"),

View File

@ -646,7 +646,7 @@ fn inject_standard_builtins(
"bitfieldReverse" => MathFunction::ReverseBits,
"bitfieldExtract" => MathFunction::ExtractBits,
"bitfieldInsert" => MathFunction::InsertBits,
"findLSB" => MathFunction::FindLsb,
"findLSB" => MathFunction::FirstTrailingBit,
"findMSB" => MathFunction::FirstLeadingBit,
_ => unreachable!(),
};
@ -695,7 +695,9 @@ fn inject_standard_builtins(
// we need to cast the return type of findLsb / findMsb
let mc = if scalar.kind == Sk::Uint {
match mc {
MacroCall::MathFunction(MathFunction::FindLsb) => MacroCall::FindLsbUint,
MacroCall::MathFunction(MathFunction::FirstTrailingBit) => {
MacroCall::FindLsbUint
}
MacroCall::MathFunction(MathFunction::FirstLeadingBit) => {
MacroCall::FindMsbUint
}
@ -1789,7 +1791,7 @@ impl MacroCall {
)?,
mc @ (MacroCall::FindLsbUint | MacroCall::FindMsbUint) => {
let fun = match mc {
MacroCall::FindLsbUint => MathFunction::FindLsb,
MacroCall::FindLsbUint => MathFunction::FirstTrailingBit,
MacroCall::FindMsbUint => MathFunction::FirstLeadingBit,
_ => unreachable!(),
};

View File

@ -3026,7 +3026,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
Glo::UnpackHalf2x16 => Mf::Unpack2x16float,
Glo::UnpackUnorm2x16 => Mf::Unpack2x16unorm,
Glo::UnpackSnorm2x16 => Mf::Unpack2x16snorm,
Glo::FindILsb => Mf::FindLsb,
Glo::FindILsb => Mf::FirstTrailingBit,
Glo::FindUMsb | Glo::FindSMsb => Mf::FirstLeadingBit,
// TODO: https://github.com/gfx-rs/naga/issues/2526
Glo::Modf | Glo::Frexp => return Err(Error::UnsupportedExtInst(inst_id)),

View File

@ -235,7 +235,7 @@ pub fn map_standard_fun(word: &str) -> Option<crate::MathFunction> {
"reverseBits" => Mf::ReverseBits,
"extractBits" => Mf::ExtractBits,
"insertBits" => Mf::InsertBits,
"firstTrailingBit" => Mf::FindLsb,
"firstTrailingBit" => Mf::FirstTrailingBit,
"firstLeadingBit" => Mf::FirstLeadingBit,
// data packing
"pack4x8snorm" => Mf::Pack4x8snorm,

View File

@ -1198,7 +1198,7 @@ pub enum MathFunction {
ReverseBits,
ExtractBits,
InsertBits,
FindLsb,
FirstTrailingBit,
FirstLeadingBit,
// data packing
Pack4x8snorm,

View File

@ -484,7 +484,7 @@ impl super::MathFunction {
Self::ReverseBits => 1,
Self::ExtractBits => 3,
Self::InsertBits => 4,
Self::FindLsb => 1,
Self::FirstTrailingBit => 1,
Self::FirstLeadingBit => 1,
// data packing
Self::Pack4x8snorm => 1,

View File

@ -788,7 +788,7 @@ impl<'a> ResolveContext<'a> {
Mf::ReverseBits |
Mf::ExtractBits |
Mf::InsertBits |
Mf::FindLsb |
Mf::FirstTrailingBit |
Mf::FirstLeadingBit => match *res_arg.inner_with(types) {
Ti::Scalar(scalar @ crate::Scalar {
kind: crate::ScalarKind::Sint | crate::ScalarKind::Uint,

View File

@ -1351,7 +1351,7 @@ impl super::Validator {
| Mf::CountOneBits
| Mf::ReverseBits
| Mf::FirstLeadingBit
| Mf::FindLsb => {
| Mf::FirstTrailingBit => {
if arg1_ty.is_some() || arg2_ty.is_some() || arg3_ty.is_some() {
return Err(ExpressionError::WrongArgumentCount(fun));
}