From 36f0ba9cbb69d0e70b5809993ff51c27c97e9467 Mon Sep 17 00:00:00 2001 From: Andrzej Janik Date: Thu, 17 Jul 2025 02:22:59 +0200 Subject: [PATCH] Apply rounding mode in fp div (#416) --- .../instruction_mode_to_global_mode/mod.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ptx/src/pass/instruction_mode_to_global_mode/mod.rs b/ptx/src/pass/instruction_mode_to_global_mode/mod.rs index 3d56dd0..d1c5489 100644 --- a/ptx/src/pass/instruction_mode_to_global_mode/mod.rs +++ b/ptx/src/pass/instruction_mode_to_global_mode/mod.rs @@ -1921,16 +1921,27 @@ fn get_modes(inst: &ast::Instruction) -> InstructionModes { .. }), .. - } - | ast::Instruction::Div { + } => InstructionModes::from_ftz(*type_, *flush_to_zero), + ast::Instruction::Div { data: ast::DivDetails::Float(ast::DivFloatDetails { type_, flush_to_zero, - .. + kind, }), .. - } => InstructionModes::from_ftz(*type_, *flush_to_zero), + } => { + let rounding = match kind { + ast::DivFloatKind::Rounding(rnd) => RoundingMode::from_ast(*rnd), + ast::DivFloatKind::Approx => RoundingMode::NearestEven, + ast::DivFloatKind::ApproxFull => RoundingMode::NearestEven, + }; + InstructionModes::new( + *type_, + flush_to_zero.map(DenormalMode::from_ftz), + Some(rounding), + ) + } ast::Instruction::Sin { data, .. } | ast::Instruction::Cos { data, .. } | ast::Instruction::Lg2 { data, .. } => InstructionModes::from_ftz_f32(data.flush_to_zero),