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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Christoph Franck
05/31/12 03:19
Modified:
  05/31/12 03:20

Read: 599 times
Sindelfingen
Germany


 
#187585 - Compilers not knowing the target chip.
Responding to: Maarten Brock'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      David Good      05/22/12 17:42      
   on the right track        Maarten Brock      05/23/12 06:11      
      one more thing      Erik Malund      05/23/12 07:15      
         Not uncommon bid bad coding standards to comply with      Per Westermark      05/23/12 08:14      
         Not afraid of globals, but...      David Good      05/23/12 10:07      
   More keil optimizer interesting tidbits      David Good      05/24/12 16:24      
      optimization      Maarten Brock      05/25/12 05:35      
      nothing gained, nothing lost      Erik Malund      05/25/12 07:53      
         I don't      Per Westermark      05/25/12 07:58      
            you can do both      Erik Malund      05/25/12 09:44      
               That is not helping the compiler      Justin Fontes      05/25/12 16:31      
                  exact same      Maarten Brock      05/26/12 03:36      
                     Technically, they are not the same      Justin Fontes      05/26/12 11:17      
                        Hmmm...      Andy Neil      05/26/12 23:46      
                        C don't do full evaluation of logical expressions      Per Westermark      05/28/12 06:33      
                           In discrete mathematics proving one is not a proof      Justin Fontes      05/28/12 14:02      
                              Lazy evaluation demanded        Per Westermark      05/28/12 14:51      
                                 I have learned something new because of this      Justin Fontes      05/28/12 17:54      
                                    me too      Andy Peters      06/01/12 11:43      
                                       Very Important      Michael Karas      06/01/12 14:30      
                              Breaks.      Michael Karas      05/28/12 17:57      
                                 Compile the code      Justin Fontes      05/28/12 18:28      
                                    To be more exact      Justin Fontes      05/28/12 19:11      
                                       Stop It!!        Michael Karas      05/28/12 22:01      
                                          That is exactly what I intended      Justin Fontes      05/29/12 10:16      
                                             Switch Break.      Michael Karas      05/29/12 22:04      
               obfusciating code to help the compiler is a VERY bad idea      Andy Neil      05/27/12 07:13      
                  the source of this      Erik Malund      05/27/12 07:17      
   Where can one learn Intermediate C techniques for 8051      Andy Neil      05/26/12 23:56      
   Getting the least out of your compiler        Andy Neil      05/27/12 07:25      
      Maybe IAR should follow their own advice?      Christoph Franck      05/30/12 02:05      
         provided the case ...      Maarten Brock      05/30/12 06:29      
            Compilers not knowing the target chip.      Christoph Franck      05/31/12 03:19      

Back to Subject List