Path: utzoo!yunexus!geac!syntron!jtsv16!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!mailrus!wasatch!utah-gr!uplherc!sp7040!obie!wsccs!dharvey From: dharvey@wsccs.UUCP (David Harvey) Newsgroups: comp.lang.c Subject: Re: Array indexing vs. pointers... Summary: Remember the real machine under your pseudo-machine. Message-ID: <711@wsccs.UUCP> Date: 9 Oct 88 01:03:15 GMT Article-I.D.: wsccs.711 References: <836@proxftl.UUCP> <3105@hubcap.UUCP> <1700@dataio.Data-IO.COM> <10332@s.ms.uky.edu> Lines: 35 In article <10332@s.ms.uky.edu>, aash@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@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@wsccs PS: Using the registers usually cuts time in half for affected operations, IF you get the registers you asked for.