[hlsl-out] Clean up repetition in write_mapped_math_functions.

Since every `match` arm ends up looking up the type of the operation's
first argument, just do that once. This avoids a repetitive lookup for
`Abs`.
This commit is contained in:
Jim Blandy
2025-02-12 11:10:24 -08:00
parent a25098f5ec
commit bafeee6680

View File

@@ -1011,6 +1011,8 @@ impl<W: Write> super::Writer<'_, W> {
arg3: _arg3,
} = *expression
{
let arg_ty = func_ctx.resolve_type(arg, &module.types);
match fun {
crate::MathFunction::ExtractBits => {
// The behavior of our extractBits polyfill is undefined if offset + count > bit_width. We need
@@ -1025,7 +1027,6 @@ impl<W: Write> super::Writer<'_, W> {
// c = min(count, w - o)
//
// bitfieldExtract(x, o, c)
let arg_ty = func_ctx.resolve_type(arg, &module.types);
let scalar = arg_ty.scalar().unwrap();
let components = arg_ty.components();
@@ -1068,7 +1069,6 @@ impl<W: Write> super::Writer<'_, W> {
crate::MathFunction::InsertBits => {
// The behavior of our insertBits polyfill has the same constraints as the extractBits polyfill.
let arg_ty = func_ctx.resolve_type(arg, &module.types);
let scalar = arg_ty.scalar().unwrap();
let components = arg_ty.components();
@@ -1126,12 +1126,8 @@ impl<W: Write> super::Writer<'_, W> {
writeln!(self.out, "}}")?;
}
crate::MathFunction::Abs
if matches!(
func_ctx.resolve_type(arg, &module.types).scalar(),
Some(crate::Scalar::I32)
) =>
if matches!(arg_ty.scalar(), Some(crate::Scalar::I32)) =>
{
let arg_ty = func_ctx.resolve_type(arg, &module.types);
let scalar = arg_ty.scalar().unwrap();
let components = arg_ty.components();