https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121617

            Bug ID: 121617
           Summary: arithmetic result or 'fma' result is zero when
                    denormals are zero but result is not zero and normal
           Product: gcc
           Version: 13.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: madams846 at hotmail dot com
  Target Milestone: ---

For types 'float' and 'double', basic arithmetic or intrinsic functions fmaf
and fma have a normal result, but return zero when compiled with a switch for
denormals are zero -mdaz-ftz or -ffast-math or -Ofast.  The result would be
sub-normal but rounds up to normal minimum per rounding mode.  For types 'long
double' and 'float128', basic arithmetic and functions 'fmal' and 'fmaq' do not
return zero.  This bug arose when testing free-standing code for a fused
multiply addition.  This bug depends on whether gcc switch for denormals are
zero should allow for rounding mode. 

Test program 'bugdemo.c':

#include <stdio.h>
#include <math.h>
#include <float.h>

int main()  {

        float  af= FLT_MIN,  bf= 1.0F - FLT_EPSILON/2.0F,  cf= 0.0F ;
        printf("af bf cf     %7.18e   %7.18e   %7.18e \n",af,bf,cf);
        printf("fmaf(af,bf,cf)    %7.18e \n", fmaf(af,bf,cf) );
        printf("af*bf    %7.18e \n\n", af*bf );

        double  a= DBL_MIN,  b= 1.0 - DBL_EPSILON/2.0,  c= 0.0 ;
        printf("a b c     %7.18e   %7.18e   %7.18e \n",a,b,c);
        printf("fma(a,b,c)    %7.18e \n", fma(a,b,c) );
        printf("a*b    %7.18e \n\n", a*b );

        long double  al= LDBL_MIN,  bl= 1.0L - LDBL_EPSILON/2.0L,  cl= 0.0L ;
        printf("al bl cl     %7.24Le   %7.24Le   %7.24Le \n",al,bl,cl);
        printf("fmal(al,bl,cl)    %7.24Le \n", fmal(al,bl,cl) );
        printf("al*bl    %7.24Le \n\n", al*bl );

        return  0 ;
}

when compiled with 'gcc bugdemo.c -lm' returns:

af bf cf     1.175494350822287508e-38   9.999999403953552246e-01  
0.000000000000000000e+00
fmaf(af,bf,cf)    1.175494350822287508e-38
af*bf    1.175494350822287508e-38

a b c     2.225073858507201383e-308   9.999999999999998890e-01  
0.000000000000000000e+00
fma(a,b,c)    2.225073858507201383e-308
a*b    2.225073858507201383e-308

al bl cl     3.362103143112093506262678e-4932   9.999999999999999999457899e-01 
 0.000000000000000000000000e+00
fmal(al,bl,cl)    3.362103143112093506262678e-4932
al*bl    3.362103143112093506262678e-4932


but when compiled with 'gcc bugdemo.c -lm -mdaz-ftz' returns:

af bf cf     1.175494350822287508e-38   9.999999403953552246e-01  
0.000000000000000000e+00
fmaf(af,bf,cf)    0.000000000000000000e+00
af*bf    0.000000000000000000e+00

a b c     2.225073858507201383e-308   9.999999999999998890e-01  
0.000000000000000000e+00
fma(a,b,c)    0.000000000000000000e+00
a*b    0.000000000000000000e+00

al bl cl     3.362103143112093506262678e-4932   9.999999999999999999457899e-01 
 0.000000000000000000000000e+00
fmal(al,bl,cl)    3.362103143112093506262678e-4932
al*bl    3.362103143112093506262678e-4932


My system:  
WSL  5.10.102.1  
Dell PC 64-bit 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz 
Windows 11 Home 24H2  OS build 26100.4351

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
13.3.0-6ubuntu2~24.04' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-13
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-13-fG75Ri/gcc-13-13.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-fG75Ri/gcc-13-13.3.0/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04)

Reply via email to