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



On Tue, 30 Aug 2005 08:25:47 -0700, glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
wrote in <o8CdnZ2dnZ1Fsx6NnZ2dndfnid6dnZ2dRVn-0Z2dnZ0@xxxxxxxxxxx>:
> N. Shamsundar wrote:

> (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

Why not
x=y
do i=0,31
if(iand(x,1).eq.0) exit
x=ishft(x,-1)
enddo
....
? Despite my grounding in older FORTRAN I find some of the newer constructs
more readable.

--
Ivan Reid, Electronic & Computer Engineering, ___ CMS Collaboration,
Brunel University. Ivan.Reid@[brunel.ac.uk|cern.ch] Room 40-1-B12, CERN
KotPT -- "for stupidity above and beyond the call of duty".
.



Relevant Pages

  • Re: [CHALLENGE] finding rightmost zero bit - C programmers take
    ... Despite my grounding in older FORTRAN I find some of the newer constructs ... The forward GOTO to a CONTINUE ending a DO-loop appears to be legal ... Prev by Date: ...
    (comp.lang.fortran)
  • Re: [CHALLENGE] finding rightmost zero bit - C programmers take
    ... Despite my grounding in older FORTRAN I find some of the newer constructs ... Bart ... Prev by Date: ...
    (comp.lang.fortran)
  • Re: complex arithmetics
    ... |> Your statement was true in some previous version of Fortran. ... |> can specify the KIND argument optionally, ... |REAL and CMPLX when no optional KIND argument is present. ... Prev by Date: ...
    (comp.lang.fortran)
  • Chopping off spaces at both ends
    ... trimintrinsic in fortran 95. ... and that is complicating string matching tests in one of my functions. ... Prev by Date: ...
    (comp.lang.python)
  • Re: DAY OF WEEK
    ... Fortran integer,integer divide operations, ... then you might translate JUST one line. ... Prev by Date: ...
    (comp.lang.pl1)