Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!leah!rpi!batcomputer!cornell!uw-beaver!fluke!ssc-vax!dmg From: dmg@ssc-vax.UUCP (David Geary) Newsgroups: comp.sys.amiga Subject: Re: C Help Message-ID: <2579@ssc-vax.UUCP> Date: 6 Apr 89 00:22:59 GMT Organization: Boeing Aerospace Corp., Seattle WA Lines: 76 Subject: Re: C Help Newsgroups: comp.sys.amiga Todd Carpenter writes: |Greetings, oh great and mighty C wizards! I beg of you to aid a poor and |distraught traveller through the wide and turbulent C! With a plea like that, who could resist ;-) |I have 2 arrays. One describes the current state of a system, the next |describes a possible future state. The arrays are unsigned shorts. The future |state may be as simple as changing 1 of the values. I calculate the future |state often, and rarely actually accept it. Therefore, each time I must obtain |a copy of the current state, and make a change to it. This is time consuming. |BTW, I am using Lattice 5.0. This boils down to: |void moo(state,new_state) | ushort state[NUM_STATES], new_state[NUM_STATES]; | |{ | ushort i; | | for (i = 0; i != NUM_STATES; i++) | new_state[i] = state[i]; | | ... |} | |Anyone have any significantly faster ideas? Blitter? Number of states may be |up to 256. Well, whenever you are looping and are concerned with speed, use a register variable for the counter. IOW, instead of ushort i, use register ushort i. That may help somewhat, but, if you have a good compiler, it may optomize that in for you anyway. (I don't know if Lattice 5.0 would or not). Depending upon what you're doing with the two arrays between calls to moo() (thank goodness it's not foo()!), you could use pointers to each of the arrays, and simply switch pointers. This would be much faster. |In other news, I also do lots of math with this, but can do it in integer space |(i.e., for some of this I don't need floating point). However, if I remember |right, all divides in C are, by definition, done in double floating point. I Oh, no! Sheesh, that would be a mess. All floating point division is done using doubles, however, with the advent of ANSI C, that is not always true. (ANSI allows for single precision floating point division). |have the A2620, but an integer divide is *still* faster than a double float on |the 68881. So, if I have something like: | |unsigned moo() | unsigned i,j,k; | |{ | return(i*j/k); /* or any other obscure equation where I can afford */ | /* operations */ This is simply integer division. |} |Thanks, oh wise and mighty ones! I have sacrificed a pizza to thine eternal |glory! I'll take a pizza too ;-) -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ David Geary, Boeing Aerospace, Seattle ~ ~ "I wish I lived where it *only* rains 364 days a year" ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~