Array indexing vs. pointers...

David Harvey dharvey at wsccs.UUCP
Sun Oct 9 11:03:15 AEST 1988


In article <10332 at s.ms.uky.edu>, aash at ms.uky.edu ( Aashi Deacon ) writes:
> >    o	Try very hard to replace divides with other operations, as in:
> >		x / 10
> >	with:
> >		x * .1
> >    o	See if some calculations can be done using integer math.
> 
> Are these two points contradictory?
> Thanks for those good hints but I got stopped when I saw this first point.
> 
> According to theory, '.1' cannot be represented exactly as a floating
> point number because in base2 it is irrational.  Wouldn't then the
> first be better in this case?
> 
> aash
> aash at ms.uky.edu

For that matter, it is also very difficult to represent 10.0 (I am
assuming you are working with floating point) in any floating point
representation.  Also, if the operation is done in emulation mode (no
floating point in MPU or if math coprocessor it is not in machine) the
advantage will be nonexistent.  In other words, a sequence of left
shifts and adds is no better than a sequence of right shifts, et al.
Even with the coprocessor (math ops) a MUL takes approximately the same
amount of clock cycles a DIV does.  You would be much better served by
making variables that are used constantly registers (if you have float
registers) than some of this stuff.  Also, making Fortran indexing go
backwards and C's go forwards (better yet, use register pointers) for
multiply dimensioned arrays does wonders to reduce the page faulting
that normally occurs with multitasking/multiuser machines.

dharvey at wsccs

PS: Using the registers usually cuts time in half for affected
operations, IF you get the registers you asked for.



More information about the Comp.lang.c mailing list