From 3e0418ba02d40eb209519bc8d847481f516fc6d6 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Wed, 23 Apr 2025 09:21:10 -0700 Subject: [PATCH] intel/executor: Fix bfloat example for converting F to packed BF In float pointing rules adding +0.0f preserves all values except for -0.0f, so what we want here is to add -0.0f. In the future we should add proper support for float immediates in the assembler. Fixes: fafdd242850 ("intel/executor: Update bfloat example") Reviewed-by: Ian Romanick Part-of: --- src/intel/executor/examples/bfloat.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/intel/executor/examples/bfloat.lua b/src/intel/executor/examples/bfloat.lua index b0cc7365711..d84ba809ef0 100644 --- a/src/intel/executor/examples/bfloat.lua +++ b/src/intel/executor/examples/bfloat.lua @@ -17,16 +17,18 @@ local r = execute { add(8) g12<1>BF g11<1>BF g4<1>F {A@1}; // Converting F to packed BF doesn't work, so add the value - // to 0.0f instead. This will preserve the NaN. + // to -0.0f instead. This will preserve the NaN. Note +0.0f + // would not work since it doesn't preserve -0.0f! - add(8) g20<1>BF g4<1>F 0F {A@1}; // F -> BF. + mov(8) g20<1>UD 0x80000000UD {A@1}; // -0.0f. + add(8) g21<1>BF g4<1>F g20<1>F {A@1}; // F -> BF. // Converting BF to F doesn't work, so for a packed source, // shift-left the bits to expand it into an UD instead. - shl(8) g30<1>UD g20<1>UW 16UW {A@1}; // BF -> F. + shl(8) g30<1>UD g21<1>UW 16UW {A@1}; // BF -> F. - mad(8) g40<1>BF g12<1>BF g20<1>BF g5<1>F {A@1}; + mad(8) g40<1>BF g12<1>BF g21<1>BF g5<1>F {A@1}; add(8) g41<1>BF g40<1>BF g30<1>F {A@1}; shl(8) g42<1>UD g41<1>UW 16UW {A@1}; // BF -> F.