Re: [CHALLENGE] finding rightmost zero bit - C programmer's take



N. Shamsundar wrote:

(snip)

This task seemed one that was made for C, so here are my comments from that end (I program in C and Fortran).

(snip)

1. A good C compiler can produce inline code that beats assembler code; one reason: function call overhead in using the assembler functions.
2. The heart of the program (lines 12 and 13) is simple and natural in C. (This statement is in no way meant to be derogatory to Fortran.)

(snip)

   for(x=y, i=0; i<32; i++){
      if(! (x & 1))break;
      x=x >> 1;
      }

It is slightly less simple and slightly less natural in Fortran, but not so bad. I have no idea how much optimizing either compiler does on it.

      x=y
      do 1 i=0,31
      if(iand(x,1).eq.0) goto 2
      x=ishft(x,-1)
1     continue
2     continue

The logical functions are at least as old as IBM Fortran H with the XL
option, the first Fortran compiler that I knew of that was mostly (though not completely) written in Fortran. The logical operations
were needed to compile the compiler.


Treating a 32 bit integer as four separate unsigned bytes is
somewhat easier in C, though doing it completely according to
the standard isn't so easy.  That allows speeding up some
table lookup algorithms on some machines.

If implemented with conditional load and for uniform distribution
of return values, I believe mine will be close to the fastest.
For uniform distribution of input values the quick exit
unrolled loop should be fastest.  All are fairly sensitive to
branch timings, the limiting factor on many current processors.

-- glen

.



Relevant Pages

  • Re: A question on Newtons Method
    ... >> I can't believe you'd advise a noob to use a compiler which is still ... > production codes and codes from textbooks. ... > The Fortran standard generally does not specify the required behavior ... >> another important class of hassle which most numerical programmers ...
    (sci.math.num-analysis)
  • Fortran Resources (June)
    ... and the standard for the Fortran language and its derivatives. ... WHERE CAN I OBTAIN A FORTRAN 95 COMPILER? ... Absoft Fortran compilers, debuggers, and development tools for Windows, ... are available for Linux systems. ...
    (comp.lang.fortran)
  • Fortran Resources (July 2004)
    ... and the standard for the Fortran language and its derivatives. ... WHERE CAN I OBTAIN A FORTRAN 95 COMPILER? ... Absoft Fortran compilers, debuggers, and development tools for Windows, ... are available for Linux systems. ...
    (comp.lang.fortran)
  • Fortran Resources (August 2004)
    ... and the standard for the Fortran language and its derivatives. ... Absoft Fortran compilers, debuggers, and development tools for Windows, ... and Linux include source-compatible Fortran 95 compiler suites ... are available for Linux systems. ...
    (comp.lang.fortran)
  • Fortran Resources (Last Issue)
    ... the, then, new Fortran 90. ... and the standard for the Fortran language and its derivatives. ... WHERE CAN I OBTAIN A FORTRAN 95 COMPILER? ... The Fortran Company offers F, the subset language, for Unix and Windows, ...
    (comp.lang.fortran)