Mail Archives: djgpp/1997/01/20/18:38:42
well i had a look thru the code produced to see if i could find any evidence of
this and it seems you're sort of right. converting floats to integer produces a
whole lot of code i couldn't figure out because i don't have a list of fp
instructions in at&t syntax but the sheer number of them suggests they take some
considerable time :) however, converting integer to float has no penalty at all
that i can see, meaning that :
unsigned long b,c;
float a;
a=(float)b*c;
is faster than
a=b*c;
(the latter does a mul followed by a conversion to fp)
provided you can make sure the destination of the operation is a float and avoid
the translation back into integer, you appear to have saved some considerable
cycles (10 in the best case on a pentium and 4 at worst) extending the analogy to
integer division gives even better savings.
the weird world of floating point arithmetic :)
nik
In article <853780174 DOT 909237 AT araga DOT funcom DOT com>, kurt DOT skauen AT funcom DOT com (Kurt Skauen) writes:
|>
|> gpt20 AT thor DOT cam DOT ac DOT uk (G.P. Tootell) wrote:
|> >i would be better writing - (and changing a to a float)
|> >
|> >a=1.0/b; (because fdiv is still faster than idiv in most cases)
|> >c=(float)x*a;
|> >d=(float)y*a;
|> >
|> >ie. to change the integers into floating wherever possible to make use of the
|> >fmul timings, which outstrip every other timing even in worst case!
|> >
|> >
|> >so there must be a catch somewhere of course ;)
|> >perhaps the changing from float->int and vice versa takes a lot of time?
|> >anyone?
|>
|> I don't have the excact numbers, but float to int, and int to float
|> conversions are supposed to be very slow. So normaly it is a good idea
|> to avoid them. But since the FPU can process one instruction in
|> parallel with the CPU (four on Cyrics I heard?), you can execute all
|> FPU instrucions on *ONE* cycle as long as you have enough integer
|> instructions to fill in between each FPU instruction.
|>
|> Kurt. Programmer Funcom/R&D
|> The above expressions is not ment to represent Funcom.
|>
|>
--
- Raw text -