Newsgroups: comp.sys.amiga.programmer Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!mintaka!geech.gnu.ai.mit.edu!rjc From: rjc@geech.gnu.ai.mit.edu (Ray Cromwell) Subject: Re: Lemmings - a tutorial Part V (last) Message-ID: <1991Apr5.023508.17157@mintaka.lcs.mit.edu> Sender: news@mintaka.lcs.mit.edu Organization: The Internet References: <1991Apr4.224045.10542@starnet.uucp> Date: Fri, 5 Apr 91 02:35:08 GMT Lines: 57 In article <1991Apr4.224045.10542@starnet.uucp> sschaem@starnet.uucp (Stephan Schaem) writes: > > > For the Mulu #17 and optimization. > mulu #17 42 cycle. > other example 26, but it use 2 register. The multiplication tricks are old and a result of simple mathematics. Simply decompose an operation into binary shifts and adds. Consider multiplying by the number 40. This is easy. 40=32 + 8 So C * 40=32C + 8C Multiplying by 32 and 8 are just shift operations. So multiplying register D0 by 40 in binary math is: move.l d0,d1 lsl.l #5,d0 lsl.l #3,d1 add.l d0,d1 With this method, you can decompose any number into its binary components and use shift operations. The problem is, it's very hardware dependent. So what you do on a 68000, may actually slow a 68040 down. The problem is, the programmer has to constantly decide which method is more optimal. For instance, a mulu on a 68040 might take 1 clock cycle to execute, therefore it would be optimal to use mulu almost all the time. Depending on memory speed, cache size, and processor type, you have to decide the optimal method whereas the compiler will do this for you instantly. Meanwhile, you're still looking at that motorola cycle chart factoring in all the hardware specs. > If you dont have the luxary and have better use of it (for you loop) > you are over 42 cycles not using mulu. > And other solution in some cases are mulu tables... > > And when will you have C compiler with AI? Optimization is not only > tricks, but logical solution for you code. > Again, how many compiler break up large loops for registers usage? > And when time comes where you need to save 2 or 4 cycle in a loop you > dont use C for the job... > And actually 2 or 4 cycle can make A huge diference. Yea, when your loop has 20000 iterations, but come on. If you get to the point where you need to kill the OS to gain 2 cycles, you need to go back to the drawing board and redesign you game, because you've made a design flaw. -- /~\_______________________________________________________________________/~\ |n| rjc@albert.ai.mit.edu Amiga, the computer for the creative mind. |n| |~| .-. .-. |~| |_|________________________________| |_| |________________________________|_|