Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C optimization question

Name: Anonymous 2007-12-06 20:03

Here is my situation.

I have an array of 16-bit signed integers that is updated every iteration of the while(1) loop in my code's main function.  Obviously I am aiming to optimize the updating algorithms as much as possible.  Now, my problem is this:  Other optimizations I have made in other places in the code (involving lookup tables) expect the value of each element to be somewhere between -127 and 127.  The new value of the array is dependent upon previous adjacent values in the array. Occasionally it is possible for the calculations to result in a value outside of the expected bounds.  Once this happens, it is indeed possible for a systemic breakdown in the integrity of the data (insofar as more and more values go outside of the expected bounds). 

I have been thinking about a quick way to clip the values to -127 or 127 if the values are outside of these bounds.  Obviously I could do an "if(array[i] > 127) array[i] = 127;" but that isn't very efficient.  I tried it bitwise doing the following:

        array[i] = (snipped expression) & -127;

but that did not work either.  My reasoning was that that particular value would eliminate any bits outside of the sign and the bits corresponding with 2^7 and above.

Can someone tell me what I am doing wrong, or suggest an efficient alternative?

Name: Anonymous 2007-12-06 21:01

>>7
Because of the fact that systemic breakdowns are possible (a few bad values can rapidly make others around it "bad", and thus it spreads further), adding more elements to my lookup tables would only be delaying the inevitable.  Sure, it might take longer to go above 256, or 512, or 1024, but if something wasn't done to prevent a value from EVER going above the imposed bounds, it would  happen eventually.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List