Dear bug-gcc Group,
This concerns gcc (gfortran) 14.2.1 on an x86_64 Red Hat Linux system. I am
using the ieee_next_after function from the (intrinsic) ieee_arithmetic module
in an inner loop and I noticed that it takes very much CPU time. It seems
unreasonable to me and so I am reporting it as a bug.
The following test program provides a timing comparison between two simple
nested loops. In the first instance the inner loop contains a multiply
operation and in the second instance the inner loop invokes ieee_next_after. I
use the Fortran intrinsic cpu_time for timing. There is a slight bit of baggage
in the code (a call to random_number()) just to make sure that an optimizing
compiler can not optimize away big parts of the calculation.
The output (using an Intel i7-1165G7 processor and compiling with `gfortran
-O5`) shows a time of 0.09 seconds for the calculation that contains the
multiplication in the inner loop and a time of 20.7 seconds for the calculation
that invokes ieee_next_after. It tells me that the cost of ieee_next_after is
at least about 200 multiplication operations.
program main
!..use and access
use iso_fortran_env, only : wp => real64
use ieee_arithmetic
implicit none
!..data
integer, parameter :: m=10000, n=10000
integer :: i, j
real (kind=wp) :: tim0, tim1, t0, r
!..executable part
r = 0
call cpu_time (tim0)
do i = 0, m-1
call random_number (t0)
do j = 0, n-1
t0 = t0*(1-epsilon(t0))
r = r+t0
end do
end do
call cpu_time (tim1)
write (*,*) 'simple arithmetic:', tim1-tim0, r
r = 0
call cpu_time (tim0)
do i = 0, m-1
call random_number (t0)
do j = 0, n-1
t0 = ieee_next_after(t0,0.0_wp)
r = r+t0
end do
end do
call cpu_time (tim1)
write (*,*) 'ieee_next_after:', tim1-tim0, r
stop
end program main
Cordially,
Bas Braams
https://www.cwi.nl/en/people/bastiaan-braams/