Re: [CHALLENGE] finding rightmost zero bit
- From: "James Van Buskirk" <not_valid@xxxxxxxxxxx>
- Date: Mon, 29 Aug 2005 16:15:31 -0600
"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
.
- References:
- [CHALLENGE] finding rightmost zero bit
- From: Bart Vandewoestyne
- Re: [CHALLENGE] finding rightmost zero bit
- From: James Van Buskirk
- Re: [CHALLENGE] finding rightmost zero bit
- From: Bart Vandewoestyne
- [CHALLENGE] finding rightmost zero bit
- Prev by Date: Re: [CHALLENGE] finding rightmost zero bit
- Next by Date: Re: [CHALLENGE] finding rightmost zero bit
- Previous by thread: Re: [CHALLENGE] finding rightmost zero bit
- Next by thread: Re: finding rightmost zero bit
- Index(es):
Relevant Pages
|