Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
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.

List of 33 messages in thread
TopicAuthorDate
Where can one learn Intermediate C techniques for 8051            01/01/70 00:00      
   on the right track            01/01/70 00:00      
      one more thing            01/01/70 00:00      
         Not uncommon bid bad coding standards to comply with            01/01/70 00:00      
         Not afraid of globals, but...            01/01/70 00:00      
   More keil optimizer interesting tidbits            01/01/70 00:00      
      optimization            01/01/70 00:00      
      nothing gained, nothing lost            01/01/70 00:00      
         I don't            01/01/70 00:00      
            you can do both            01/01/70 00:00      
               That is not helping the compiler            01/01/70 00:00      
                  exact same            01/01/70 00:00      
                     Technically, they are not the same            01/01/70 00:00      
                        Hmmm...            01/01/70 00:00      
                        C don't do full evaluation of logical expressions            01/01/70 00:00      
                           In discrete mathematics proving one is not a proof            01/01/70 00:00      
                              Lazy evaluation demanded            01/01/70 00:00      
                                 I have learned something new because of this            01/01/70 00:00      
                                    me too            01/01/70 00:00      
                                       Very Important            01/01/70 00:00      
                              Breaks.            01/01/70 00:00      
                                 Compile the code            01/01/70 00:00      
                                    To be more exact            01/01/70 00:00      
                                       Stop It!!            01/01/70 00:00      
                                          That is exactly what I intended            01/01/70 00:00      
                                             Switch Break.            01/01/70 00:00      
               obfusciating code to help the compiler is a VERY bad idea            01/01/70 00:00      
                  the source of this            01/01/70 00:00      
   Where can one learn Intermediate C techniques for 8051            01/01/70 00:00      
   Getting the least out of your compiler            01/01/70 00:00      
      Maybe IAR should follow their own advice?            01/01/70 00:00      
         provided the case ...            01/01/70 00:00      
            Compilers not knowing the target chip.            01/01/70 00:00      

Back to Subject List