|
From: Marc V. O. <mar...@ea...> - 2004-06-18 19:30:30
|
Hi, on 6/18/04 4:26 AM, Stephan Assmus at sup...@gm... wrote: > I also think it is really worth looking into what Marc Van Olmen wrote. > I knew of that trick but never really put it to use because at the time > I read about it, I didn't know my way arround that level of byte > juggling. > > Where I read about it, it was called Packed Multiply. The idea is > similar to SIMD, only for portable C code. Of course it works only for > uint8 calulations. I'm going to explain it in my words, because for me, > the code Marc posted takes a second look to understand it. Basically > you put 2 uint8 values in the first and third byte of a uint32. Then > you do the multiplication by a uint8 value, now your two values have 16 > bit results in the first half and second half of the uint32, to scale > them correctly, you shift by one byte to the right and mask out the > lower half of the upper value, which is now in the upper half of the > lower value. Now you're back to two uint8 on byte one and three of the > uint32. I think that should work on both big endian and little endian This also works with a signed value that is the weirdest thing about it. I don't exactly understand completely why it works also with signed because I always assume that a signed number was just one bit being used for a sign but it is more then that all bits are reversed until the last significant bit , it took me a day to grasp this. Because (Source-destintation)*alpha + destintation, where (source-destination) can be negative. |