[Info-vax] Anyone still around ? :-)

Louis Krupp lkrupp at nospam.pssw.com.invalid
Wed Oct 9 17:55:17 EDT 2019


On Tue, 8 Oct 2019 07:19:39 -0700 (PDT), osuvman50 at gmail.com wrote:

>I was considering making a post about the failure of the C compiler's optimizer
>to recognize and optimize the pattern:
>
>     choice = permutation % (CARDS_IN_DECK-i);
>     permutation = permutation / (CARDS_IN_DECK-i);
>
>but didn't think I'd get any constructive responses. (refactoring to eliminate a
>divide makes the whole program run 18% faster on both alpha and IA64).

For what it's worth, GNU C++ on Linux doesn't optimize it either, but
GNU Fortran does at optimization level 1. If you have a FORTRAN
compiler, you'll probably have to tweak this code a bit (getting rid
of the colons, for example) to try it:

subroutine s(permutation, choice, i)
    implicit none
    integer :: permutation, choice, i
    integer, parameter :: CARDS_IN_DECK = 52
    choice = mod(permutation, (CARDS_IN_DECK-i))
    permutation = permutation / (CARDS_IN_DECK-i)
end subroutine

Louis



More information about the Info-vax mailing list