Optimize this ecuations
how can i optimize this?:
// 139 cycles
x = 0.5*(1 + c);
x = 0.5*(x + c/x);
x = 0.5*(x + c/x);
x = 0.5*(x + c/x);
c is a constant
thnx
Are they floats or integers? What does this accomplish? Form there I can probably help...
I've figured out what it does, and I ahve a better question: why are trying to optimize somethign that approximates 1? That's completely stupid... Why not just use 1 and not a fancy set of equations that eat cycles like there's no tommorow?
So in answer to your original question:
[edited by - puzzler183 on June 30, 2002 12:46:58 PM]
I've figured out what it does, and I ahve a better question: why are trying to optimize somethign that approximates 1? That's completely stupid... Why not just use 1 and not a fancy set of equations that eat cycles like there's no tommorow?
So in answer to your original question:
x = 1;
[edited by - puzzler183 on June 30, 2002 12:46:58 PM]
precalculate c/x and then use it - you get 1 instead 3 divs
if using int. values change (blah)*0.5 to (blah)>>1 (shift instead mul)
write in asm
if using int. values change (blah)*0.5 to (blah)>>1 (shift instead mul)
write in asm

With best regards, Mirek Czerwiñski
It doesn''t aproximate one! It calculates a square root!
Maybe you should check the algo with different constants than 1
I don''t know anyway to optimise this except defining c and x as ''register'' (assuming you use c/c++), so acess to these two vars is as fast as possible. You could also calculate the difference between the two latest iterations and then quit the loop if you got enough precision.
Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Maybe you should check the algo with different constants than 1

I don''t know anyway to optimise this except defining c and x as ''register'' (assuming you use c/c++), so acess to these two vars is as fast as possible. You could also calculate the difference between the two latest iterations and then quit the loop if you got enough precision.
Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Yesterday we still stood at the verge of the abyss,today we're a step onward! Don't klick me!!!
quote:
Original post by MirekCz
precalculate c/x and then use it - you get 1 instead 3 divs
if using int. values change (blah)*0.5 to (blah)>>1 (shift instead mul)
write in asm![]()
you cannot precalculate c/x as it changex with every iteration...
Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Yesterday we still stood at the verge of the abyss,today we're a step onward! Don't klick me!!!
yes, is the square root
the numbers are floats, and i cant precalculate c/x because it changes between equations.
Maybe i can aproximate 1/x for c/x and convert it in c*aprox, but i dont know how aproximate 1/x.
thnx for your replys

Maybe i can aproximate 1/x for c/x and convert it in c*aprox, but i dont know how aproximate 1/x.
thnx for your replys
maybe in optimized fpu asm is more fast, but the fpu asm that i write is slow (too many instructions for do something)

Uh ok. With 4 repititions it gets close to one. You will ned about 1000...
I''ve tried something like:
_asm
{
fld c
fsqrt
fstp x
}
and it''s slower than standard sqrtf(), so I honestly doubt if it''s possible to beat the standard library.
Maybe someone has another suggestion?
_asm
{
fld c
fsqrt
fstp x
}
and it''s slower than standard sqrtf(), so I honestly doubt if it''s possible to beat the standard library.
Maybe someone has another suggestion?

This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement