Re: [CHALLENGE] finding rightmost zero bit



"Bart Vandewoestyne" <MyFirstName.MyLastName@xxxxxxxxxx> wrote in message
news:1125343568.215856@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> Sorry James, but in my challenges, all programs must be written
> in 100% standard-conforming Fortran, no other languages like assembler,
> C, whatever... and above all that, the syntax must be
> F-compatible :-)

No, you just don't get it. Given that there is a solution
using a hardware instruction, the trick is to persuade the
compiler to generate the instruction. On CVF, and I would
assume ifort, the extension would be TRAILZ. I don't know
whether g95, for example, has such an extension, but it's
possible for compilers to recognize code which cries out
for such an instruction and produce it without the need
for using an extension. As an example,

j = ishft(i, -iand(right_shift_count,31))

should generate a single machine instruction on a 32-bit
machine, but many compilers don't recognize this idiom
and generate many more instructions. I would be nice if
compilers could spot these shortcuts; double-wide integer
multiplication is a common one as well.

> By the way... would it make a difference in speed if we were counting from
0
> and restrict ourselves to 100% standard-conforming F-syntax?
> Could somebody come up with a faster algorithm if we were
> indexing from 0 instead of 1?

See my algorithm. Counting from 1 requires an extra instruction.

> OK. Thanks for this comment. If i have some time to play, i
> might... but not now ;-)

Well, unless you can time random data, you are not going to
see the effects of branch prediction.

real harvest(100)
integer i, j
integer irandom(size(harvest))
integer total

call random_seed()
call random_number(harvest)
irandom = ishft(1,int(harvest*31))
total = 0
do i = 1, 500000
do j = 1, size(harvest)
total = total+findpos(irandom(j))
end do
end do
write(*,*) total
end

.... would be an example that might stress your algorithm
a little more.

P.S. you really haven't defined what findpos(-1) is ...

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


.



Relevant Pages

  • Re: non load/store architecture?
    ... because the pipelining masks the latency. ... DEC compilers actually were ... get in there to write a decent instruction schedule. ... reasons why the Itanium is such a bad solution in most cases is that ...
    (comp.arch.embedded)
  • Re: Hi
    ... ARM9 that is an entirely different instruction as on an ARM2 (in ... mode bits or flags are is affected. ... Yes the original ARM compilers could use BL in conditional execution. ...
    (comp.sys.arm)
  • Re: Performance comparison Alpha ES40 vs Itanium rx3600
    ... instruction, but I guess it depends on your definition of instruction. ... RISC instructions, since that appeared to be the topic under discussion. ... All the magic that compilers were supposed to perform ... the theory behind EPIC/IA64 is VLIW which by definition means each ...
    (comp.os.vms)
  • Re: What micros do you actually hate to work with?
    ... Li-ion battery charger in C 858 bytes of machine object code on a 68S08. ... Compilers can do maintainable optimizations on many processors that are not possible to maintain in hand written assembler. ... Skip in a PIC used by compilers to avoid memory management to jump over a single instruction. ...
    (comp.arch.embedded)
  • Re: Fixed Point Square Root Improvements?
    ... of an n x n-bit multiplication, while the other instruction delivers ... it retrieves srtTabentries. ... An __int64 (or long long with other compilers) is simply represented ... Each of the two loops creates the entries for one binade. ...
    (comp.lang.asm.x86)