Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove gotos when possible #56

Open
Beliavsky opened this issue Mar 25, 2024 · 0 comments
Open

Remove gotos when possible #56

Beliavsky opened this issue Mar 25, 2024 · 0 comments

Comments

@Beliavsky
Copy link

Beliavsky commented Mar 25, 2024

I think stdlib_scsum1 in stdlib_linalg_lapack_s.f90 can be rewritten without gotos as

     pure real(sp) function stdlib_scsum1(n,cx,incx)
        ! -- lapack auxiliary routine --
        ! -- lapack is a software package provided by univ. of tennessee,    --
        ! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
           ! Scalar Arguments
           integer(ilp),intent(in) :: incx,n
           ! Array Arguments
           complex(sp),intent(in) :: cx(*)
        ! =====================================================================
           ! Local Scalars
           integer(ilp) :: i,nincx
           real(sp) :: stemp
           ! Intrinsic Functions
           intrinsic :: abs
           ! Executable Statements
           stdlib_scsum1 = zero
           stemp = zero
           if (n <= 0) return
           if (incx /= 1) then
               ! code for increment not equal to 1
               nincx = n*incx
               do i = 1,nincx,incx
                  ! next line modified.
                  stemp = stemp + abs(cx(i))
               end do
               stdlib_scsum1 = stemp
           else
               ! code for increment equal to 1
               do i = 1,n
                  ! next line modified.
                  stemp = stemp + abs(cx(i))
               end do
               stdlib_scsum1 = stemp
           end if
           return
     end function stdlib_scsum1

The original is

     pure real(sp) function stdlib_scsum1(n,cx,incx)
        ! -- lapack auxiliary routine --
        ! -- lapack is a software package provided by univ. of tennessee,    --
        ! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
           ! Scalar Arguments
           integer(ilp),intent(in) :: incx,n
           ! Array Arguments
           complex(sp),intent(in) :: cx(*)
        ! =====================================================================
           ! Local Scalars
           integer(ilp) :: i,nincx
           real(sp) :: stemp
           ! Intrinsic Functions
           intrinsic :: abs
           ! Executable Statements
           stdlib_scsum1 = zero
           stemp = zero
           if (n <= 0) return
           if (incx == 1) go to 20
           ! code for increment not equal to 1
           nincx = n*incx
           do i = 1,nincx,incx
              ! next line modified.
              stemp = stemp + abs(cx(i))
           end do
           stdlib_scsum1 = stemp
           return
           ! code for increment equal to 1
           20 continue
           do i = 1,n
              ! next line modified.
              stemp = stemp + abs(cx(i))
           end do
           stdlib_scsum1 = stemp
           return
     end function stdlib_scsum1

A general question is whether doing the work to eliminate as many gotos as possible is worth it. If it has to be done manually, perhaps not.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant