You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frexp() always returns a positive mantissa, even for negative input. In this example, the first float argument at output line 7 should be -0.5 rather than 0.5.
Unfortunately I think that this behavior may well be baked in to DXBC and DXIL, so we need to be careful about fixing it. See #7737 that explicitly adds an abs and notes the difference between HLSL and C++'s implementations of frexp.
Note however that the SPIR-V translation (to OpExtInst ... FrexpStruct, with no absolute value operation) is defined to agree with the C++ standard, so there is an inconsistency. (I do recognize that fixing this would break some existing code. I submitted this issue primarily to have something to point to as an XFAIL reason in LLVM's offload test suite.)
I almost think the right fix here (at least temporarily) is that the SPIRV code generation in DXC insert an abs call on the input to frexp. That would make the compilers compatible and consistent.
Separately TC57 should decide if the behavior should change to align with C/C++.
If it's worth making a breaking change, why not make them compatible in the direction that 1) agrees with the C++ standard and 2) preserves more information? The programmer can get the absolute value easily enough if that's what's desired. (Note that I'm a compiler guy rather than a graphics guy, so maybe I'm missing something here. Is it just that DXIL is most often targeted?)
Activity
damyanp commentedon Nov 20, 2026
Unfortunately I think that this behavior may well be baked in to DXBC and DXIL, so we need to be careful about fixing it. See #7737 that explicitly adds an abs and notes the difference between HLSL and C++'s implementations of frexp.
danbrown-amd commentedon Nov 23, 2026
Note however that the SPIR-V translation (to
OpExtInst ... FrexpStruct, with no absolute value operation) is defined to agree with the C++ standard, so there is an inconsistency. (I do recognize that fixing this would break some existing code. I submitted this issue primarily to have something to point to as an XFAIL reason in LLVM's offload test suite.)llvm-beanz commentedon Nov 25, 2026
I almost think the right fix here (at least temporarily) is that the SPIRV code generation in DXC insert an abs call on the input to frexp. That would make the compilers compatible and consistent.
Separately TC57 should decide if the behavior should change to align with C/C++.
danbrown-amd commentedon Nov 25, 2026
If it's worth making a breaking change, why not make them compatible in the direction that 1) agrees with the C++ standard and 2) preserves more information? The programmer can get the absolute value easily enough if that's what's desired. (Note that I'm a compiler guy rather than a graphics guy, so maybe I'm missing something here. Is it just that DXIL is most often targeted?)