nak: Fix fneg to do fadd(-0, x)
Thanks to floating point sillyness, fadd(0, x) isn't a no-op but fadd(-0, x) is. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24998>
This commit is contained in:

committed by
Marge Bot

parent
2c1cc06d03
commit
a43e6addca
@@ -360,7 +360,7 @@ impl<'a> ShaderFromNir<'a> {
|
||||
let (x, y) = match alu.op {
|
||||
nir_op_fabs => (srcs[0].fabs(), Src::new_zero()),
|
||||
nir_op_fadd => (srcs[0], srcs[1]),
|
||||
nir_op_fneg => (srcs[0].fneg(), Src::new_zero()),
|
||||
nir_op_fneg => (Src::new_zero().fneg(), srcs[0].fneg()),
|
||||
_ => panic!("Unhandled case"),
|
||||
};
|
||||
assert!(alu.def.bit_size() == 32);
|
||||
|
@@ -1088,7 +1088,23 @@ impl Src {
|
||||
|
||||
pub fn is_zero(&self) -> bool {
|
||||
match self.src_ref {
|
||||
SrcRef::Zero => true,
|
||||
SrcRef::Zero | SrcRef::Imm32(0) => match self.src_mod {
|
||||
SrcMod::None | SrcMod::FAbs | SrcMod::INeg => true,
|
||||
SrcMod::FNeg | SrcMod::FNegAbs | SrcMod::BNot => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_fneg_zero(&self, src_type: SrcType) -> bool {
|
||||
match self.src_ref {
|
||||
SrcRef::Zero | SrcRef::Imm32(0) => match self.src_mod {
|
||||
SrcMod::FNeg | SrcMod::FNegAbs => true,
|
||||
_ => false,
|
||||
}
|
||||
SrcRef::Imm32(0x80000000) => {
|
||||
src_type == SrcType::F32 && self.src_mod.is_none()
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@@ -313,9 +313,9 @@ impl CopyPropPass {
|
||||
let dst = dst[0];
|
||||
|
||||
if !add.saturate {
|
||||
if add.srcs[0].is_zero() {
|
||||
if add.srcs[0].is_fneg_zero(SrcType::F32) {
|
||||
self.add_copy(dst, SrcType::F32, add.srcs[1]);
|
||||
} else if add.srcs[1].is_zero() {
|
||||
} else if add.srcs[1].is_fneg_zero(SrcType::F32) {
|
||||
self.add_copy(dst, SrcType::F32, add.srcs[0]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user