Message-ID: <32A2268E.3A09@gbrmpa.gov.au> Date: Mon, 02 Dec 1996 08:56:39 +0800 From: Leath Muller Reply-To: leathm AT gbrmpa DOT gov DOT au Organization: Great Barrier Reef Marine Park Authority MIME-Version: 1.0 To: "G.P. Tootell" CC: djgpp AT delorie DOT com Subject: Re: Optimization References: <57hg9b$or5 AT kannews DOT ca DOT newbridge DOT com> <329C4CD4 DOT 7474 AT cornell DOT edu> <329C62F6 DOT 23F6 AT stud DOT warande DOT ruu DOT nl> <329E2E2B DOT 3D02 AT gbrmpa DOT gov DOT au> <57mflm$bta AT lyra DOT csx DOT cam DOT ac DOT uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit G.P. Tootell wrote: > > |> Actually, this is even faster if you: > |> c = 1 / (x * y); > |> a1 = b1 * c; > |> a2 = b2 * c; > |> a3 = b3 * c; > |> A divide takes 39 cycles on a normal double divide, a mul takes 3 > |> cycles. > |> Using your method, you have 3 divides (117 cycles) and one mul for 120 > |> cycles. > |> Using the second method, you have 39 + 9 cycles, or 48... :) > |> > |> Leathal. > > except you forgot that if c isn't a float then you may well round the > value of c down so much as to adversely affect the calculation of a1-3. > and if c is a float then the code probably becomes slower than before > i dunno. Well, you would be mad to declare c as an int, and do an inverse multiply on it... :) Besides, if it was an int, I would have written the code as: c = (int) (1 / (x * y)); (assuming x and y _are_ floats/doubles) Leathal.