Bug 100662 - intrinsic::ieee_arithmetic fails on aarch, powerpc architectures on FreeBSD
Summary: intrinsic::ieee_arithmetic fails on aarch, powerpc architectures on FreeBSD
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 10.3.0
: P4 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: fortran-ieee
  Show dependency treegraph
 
Reported: 2021-05-18 19:13 UTC by Yuri
Modified: 2024-06-13 09:51 UTC (History)
6 users (show)

See Also:
Host:
Target: aarch64-freebsd, powerpc-freebsd
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-08-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri 2021-05-18 19:13:22 UTC
Fortran codes using intrinsic::ieee_arithmetic on aarch, powerpc architectures fail to compile.

See details in this FreeBSD bug report: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255890
Comment 1 kargls 2021-05-18 22:24:33 UTC
Looks like an OS problem.  Not sure GCC can do anything here.
Comment 2 Yuri 2021-05-18 22:27:32 UTC
intrinsic::ieee_arithmetic works fine on amd64/i386 architectures on the same OS.

What do you think is missing/wrong in the OS that causes it?
Comment 3 Yuri 2021-05-18 22:47:30 UTC
On amd64 gcc installs the file finclude/ieee_arithmetic.mod and on aarch64 this file isn't installed.

What is installed is defined by the gcc build process.
Comment 4 Steve Kargl 2021-05-19 00:23:53 UTC
On Tue, May 18, 2021 at 10:47:30PM +0000, yuri at tsoft dot com wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100662
> 
> --- Comment #3 from Yuri <yuri at tsoft dot com> ---
> On amd64 gcc installs the file finclude/ieee_arithmetic.mod
> and on aarch64 this file isn't installed.
> 
> What is installed is defined by the gcc build process.
> 

Does FreeBSD support IEEE754 on aarch64?  What does config.log
say about IEEE modules?
Comment 5 Yuri 2021-05-19 00:56:57 UTC
config.log doesn't contain the IEEE string even on amd64.

libgfortran/configure.host seems to only enable IEEE modules on i?86 | x86_64 architectures through this code:

> case "${host_cpu}" in
>   i?86 | x86_64)
>     if test "x${have_soft_float}" = "xyes"; then
>       fpu_host='fpu-generic'
>     else
>       fpu_host='fpu-387'
>     fi
>     ieee_support='yes'
>     ;;
> esac

What does gcc need from OS for IEEE754?
Shouldn't it just compile with relevant to IEEE754 opcodes?
Comment 6 Steve Kargl 2021-05-19 01:10:09 UTC
On Wed, May 19, 2021 at 12:56:57AM +0000, yuri at tsoft dot com wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100662
> 
> --- Comment #5 from Yuri <yuri at tsoft dot com> ---
> config.log doesn't contain the IEEE string even on amd64.
> 
> libgfortran/configure.host seems to only enable IEEE modules on i?86 | x86_64
> architectures through this code:
> 
> > case "${host_cpu}" in
> >   i?86 | x86_64)
> >     if test "x${have_soft_float}" = "xyes"; then
> >       fpu_host='fpu-generic'
> >     else
> >       fpu_host='fpu-387'
> >     fi
> >     ieee_support='yes'
> >     ;;
> > esac
> 
> What does gcc need from OS for IEEE754?
> Shouldn't it just compile with relevant to IEEE754 opcodes?
> 

In 

x86_64-unknown-freebsd14.0/libgfortran/config.log

I see

configure:26522: FPU dependent file will be fpu-387.h
configure:26524: Support for IEEE modules: yes

Looking at libgfortran/configure and libgfortran/configure.host
and looking in libgfortran/config/, it seems you'll need to define
an fpu-aarch64.h

I don't have an aarch64 system nor access to such a system,
so can't help you more.
Comment 7 Yuri 2021-05-19 01:43:28 UTC
fpu-387.h is in the gcc10 source tree:
> $ find . -name "fpu-*"
> ./work/gcc-10.3.0/libgfortran/config/fpu-generic.h
> ./work/gcc-10.3.0/libgfortran/config/fpu-sysv.h
> ./work/gcc-10.3.0/libgfortran/config/fpu-glibc.h
> ./work/gcc-10.3.0/libgfortran/config/fpu-aix.h
> ./work/gcc-10.3.0/libgfortran/config/fpu-387.h

fpu-aarch64.h isn't in the gcc10 tree, and not among FreeBSD-installed headers.

It seems that it is missing in gcc?
Comment 8 Steve Kargl 2021-05-19 02:26:55 UTC
On Wed, May 19, 2021 at 01:43:28AM +0000, yuri at tsoft dot com wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100662
> 
> --- Comment #7 from Yuri <yuri at tsoft dot com> ---
> fpu-387.h is in the gcc10 source tree:
> > $ find . -name "fpu-*"
> > ./work/gcc-10.3.0/libgfortran/config/fpu-generic.h
> > ./work/gcc-10.3.0/libgfortran/config/fpu-sysv.h
> > ./work/gcc-10.3.0/libgfortran/config/fpu-glibc.h
> > ./work/gcc-10.3.0/libgfortran/config/fpu-aix.h
> > ./work/gcc-10.3.0/libgfortran/config/fpu-387.h
> 
> fpu-aarch64.h isn't in the gcc10 tree, and not among FreeBSD-installed headers.
> 
> It seems that it is missing in gcc?
> 

Yes, you would need to write the fpu-aarch64.h header.
Comment 9 ripero84 2021-05-19 09:45:12 UTC
Steve, is this a GCC bug or a FreeBSD bug (or if it is something else, what side does this belong to)?

Other OSs seem to be able to compile gfortran with these modules for these architectures, see, e.g., https://packages.ubuntu.com/focal/arm64/gfortran-10/filelist and https://packages.ubuntu.com/focal/ppc64el/gfortran-10/filelist).  And they seem to have been able to do so since the introduction of the three Fortran IEEE intrinsic modules in GCC 5 (https://packages.ubuntu.com/bionic/amd64/gfortran-5/filelist and https://packages.ubuntu.com/bionic/ppc64el/gfortran-5/filelist). Therefore, some kind of solution must exist for this - and probably has been there for over half a decade. (Apologies for not being able to provide a better insight from the Ubuntu sources.)

Thank you.
Comment 10 Steve Kargl 2021-05-19 15:19:27 UTC
On Wed, May 19, 2021 at 09:45:12AM +0000, ripero84 at gmail dot com wrote:
> --- Comment #9 from ripero84 at gmail dot com ---
> Steve, is this a GCC bug or a FreeBSD bug (or if it is something else, what
> side does this belong to)?

I suppose it is both.  AFAIK, there is no longer an active FreeBSD
maintainer for GCC (if there were, the few non-gfortran PR/patches
I submitted would have been committed).  I no longer send patches
to GCC for gfortran as I know virtually nothing about git.

> Other OSs seem to be able to compile gfortran with these modules for these
> architectures, see, e.g.,
> https://packages.ubuntu.com/focal/arm64/gfortran-10/filelist and
> https://packages.ubuntu.com/focal/ppc64el/gfortran-10/filelist).  And they seem
> to have been able to do so since the introduction of the three Fortran IEEE
> intrinsic modules in GCC 5
> (https://packages.ubuntu.com/bionic/amd64/gfortran-5/filelist and
> https://packages.ubuntu.com/bionic/ppc64el/gfortran-5/filelist). Therefore,
> some kind of solution must exist for this - and probably has been there for
> over half a decade. (Apologies for not being able to provide a better insight
> from the Ubuntu sources.)

ubuntu is glibc.  You (or something) needs to read libgfortran/configure.host,
and add the needed logic for FreeBSD to pick up an appropriate fpu-*.h
file on aarch64.  The first 3 non-comment lines of that file are

# DEFAULTS
fpu_host='fpu-generic'
ieee_support='no'

which is what non-i386/amd64 FreeBSD systems likely use.  It seems
fpu-generic.h provides stubs for a few functions required to build
gfortran.  After gfortran is built, installation does not install
useless ieee*.mod files.  Note, a standard conforming Fortran
compiler is not required to support the ieee modules.

Furhter down in the file, there is a check for fenv compatibilities,

if test "x${have_feenableexcept}" = "xyes"; then
  fpu_host='fpu-glibc'
  ieee_support='yes'
fi

but the name of the file seems too specific to glibc.  If fenv
facilities are available, I would have thought the file would
be named fpu-fenv.h.  My guess is that configure does not find
fenv on aarch64 FreeBSD and/or aarch64 FreeBSD does not support
fenv.
Comment 11 ripero84 2021-05-25 19:34:23 UTC
Thank you very much for the information and your help.
Comment 12 Gerald Pfeifer 2021-08-12 19:12:58 UTC
Andreas, is this something you may be able to have a look at?
(It's about the architectures you used to "play" with on FreeBSD.)
Comment 13 Andreas Tobler 2021-08-12 20:04:14 UTC
I try to find some spare cycles to look into. But I can only investigate the aarch64 part. The powerpcs are gone here.
Comment 14 kargls 2021-08-12 20:56:22 UTC
(In reply to Gerald Pfeifer from comment #12)
> Andreas, is this something you may be able to have a look at?
> (It's about the architectures you used to "play" with on FreeBSD.)

There are other PRs that affect (all archs on) FreeBSD that have been
orphaned.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89991
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89125
Comment 15 Andreas Tobler 2021-08-29 20:31:57 UTC
Regarding comment #10, Steve is right with his guess, configure doesn't find the fenv functionalities needed. The reason is pretty simple, for aarch64 and powerpc, they are not public. A quick trial showed that if they are visible, then gfortran is 'happy' and nearly all ieee testcases pass. I did not investigate the failing parts.
The big issue is, how can we make them available to libm. This is an OS issue and not a gcc issue.
The only thing I'm confused in gcc land, as Steve as well, why is the file named fpu-glibc and not fpu-fenv?
Regarding the OS issue, it might take a while to (re)solve this.
Comment 16 Piotr Kubaj 2022-05-16 14:20:47 UTC
This issue has been fixed in FreeBSD's main branch on powerpc* in https://cgit.freebsd.org/src/commit/?id=448c505c33cc334193590f3844406d6a74f26e2a

Similar fix could be done for other affected architectures.
Comment 17 Sergey Fedorov 2022-09-10 13:47:12 UTC
The same failure happens on MacOS PPC with GCC12:

/opt/local/var/macports/build/_opt_PPCRosettaPorts_science_OpenCoarrays/OpenCoarrays/work/OpenCoarrays-2.10.0/src/tests/integration/pde_solvers/coarrayBurgers/main.F90:3:20:

    3 |   use, intrinsic :: ieee_arithmetic, only : ieee_is_nan
      |                    1
Fatal Error: Cannot find an intrinsic module named 'ieee_arithmetic' at (1)
compilation terminated.
Error: command:
   `/opt/local/bin/mpif90-mpich-gcc12 -I/opt/local/var/macports/build/_opt_PPCRosettaPorts_science_OpenCoarrays/OpenCoarrays/work/build/include/OpenCoarrays-2.10.0_GNU-12.2.0 -fcoarray=lib -DGCC_GE_7 -DGCC_GE_8 -DHAVE_MPI -DMPI_WORKING_MODULE -DPREFIX_NAME=_gfortran_caf_ -I/opt/local/var/macports/build/_opt_PPCRosettaPorts_science_OpenCoarrays/OpenCoarrays/work/build/src/tests/integration/pde_solvers/coarrayBurgers/library -pipe -Os -m32 -mmacosx-version-min=10.6 -c /opt/local/var/macports/build/_opt_PPCRosettaPorts_science_OpenCoarrays/OpenCoarrays/work/OpenCoarrays-2.10.0/src/tests/integration/pde_solvers/coarrayBurgers/main.F90 -o CMakeFiles/coarray_burgers_pde.dir/main.F90.o`
failed to compile.
Comment 18 Sergey Fedorov 2024-06-13 09:51:59 UTC
(In reply to Piotr Kubaj from comment #16)
> This issue has been fixed in FreeBSD's main branch on powerpc* in
> https://cgit.freebsd.org/src/commit/
> ?id=448c505c33cc334193590f3844406d6a74f26e2a
> 
> Similar fix could be done for other affected architectures.

Piotr, could you say, are there test results for the current gfortran on FreeBSD ppc32 somewhere? To have some meaningful reference.