-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Open
Labels
Description
For the following code:
subroutine sum_and_prod(v, n, s, p)
implicit none (type, external)
integer, intent(in) :: n
real, intent(in) :: v(n)
real, intent(out) :: s, p
s = sum(v)
p = product(v)
end subroutine sum_and_prodflang produces native ASM code for summation, while for product there is a call to runtime library.
Even if length of vector is known (and small):
subroutine sum_and_prod_vec3(v, s, p)
implicit none (type, external)
real, intent(in) :: v(3)
real, intent(out) :: s, p
s = sum(v)
p = product(v)
end subroutine sum_and_prod_vec3ASM still have call of runtime library.
It would be nice to avoid any calls especially for short arrays.
ASM output:
https://godbolt.org/z/d3Edr9GG4