??? 05/31/12 09:19 Modified: 05/31/12 09:20 Read: times |
#187585 - Compilers not knowing the target chip. Responding to: ???'s previous message |
Maarten Brock said:
Christoph Franck said:
x = (x >= 0) ? (x >> 10) : (-((-x) >> 10));is so much faster and results in smaller code? (provided the case (x == NEGATIVE_MAX) never occurs or is handled separately) If I now IAR this is exactly why they will call the division routine for signed 64-bit integers. They will never sacrifice correctness under any circumstance for code size or speed. The above is only different from an actual division for one single case, which can easily be handled separately. x = ((x >= 0) || (-x == x)) ? (x >> 10) : (-((-x) >> 10)); should take care of this. What does it generate for unsigned 64-bit integers? And why did you not use unsigned as recommended in the article? The calculation is a part of a digital filter, and mixing signed and unsigned integers in the filter algorithm would be messy. However, the compiler would use a shift in case of an unsigned long long being divided by a power of two. My point is: The compiler should know the target chip much better than I do and know how to perform a division by a power of two on the target chip without using the big, slow, universal division routine. Even if it has to distinguish between two or three different cases, the result will still be faster and smaller than using the actual 64-bit division routine. |