7 Replies Latest reply on Jan 16, 2013 6:48 PM by user_199038981

    PSoC 3 code reduction

    user_199038981

      Hi,

         

       

         

      I am using the PSoc 3 development kit and implementing a USBUART. What is the best way to eliminate the code it generates that will not be needed? Is it ok to simply delete the automatically generated C code and header files or is there something that should be done through the IDE?

         

      Nick_Danger

        • 1. Re: PSoC 3 code reduction
          user_14586677

          The Keil compiler has extensive optimizations, including unused code segments

             

          and code that cannot be reached. Here is a summary -

             

           

             

          General Optimizations

             

           

             
                
          • Common Block Subroutines (Level 9)
            Recurring instruction sequences are detected and converted into subroutines. The Cx51 Compiler rearranges code to obtain larger recurring sequences.
          •     
          • Common Block Subroutines (Linker Optimization) (Level 9)
            Recurring instruction sequences are detected and converted into subroutines. The linker rearranges code to obtain larger recurring sequences.
          •     
          • Common Tail Merging (Level 8)
            When there are multiple calls to a single function, some of the setup code can be reused, thereby reducing program size.
          •     
          • Constant Folding (Level 0)
            The compiler performs calculations that reduce expressions to numeric constants, where possible. This includes calculations of run-time addresses.
          •     
          • Dead Code Elimination (Level 1)
            Unused code fragments, artifacts, and code which cannot be reached is removed.
          •     
          • Extended Index Access Optimizing (Level 7)
            DPTR is used for register variables where appropriate. Pointer and array access are optimized for both execution speed and code size.
          •     
          • Global Common Subexpression Elimination (Level 5)
            The compiler detects multiple uses of the same expression or subexpression within a function. The value is calculated only once and stored in a register for reuse where appropriate.
          •     
          • Jump Negation (Level 1)
            Conditional jumps are closely examined to see if they can be streamlined or eliminated by the inversion of the test logic.
          •     
          • Jump Optimizing (Level 0)
            The compiler always extends jumps to the final target. Jumps to jumps are eliminated.
          •     
          • Local Common Subexpression Elimination (Level 4)
            The compiler detects multiple uses of the same expression or subexpression. The value is calculated only once and reused where possible. Superfluous expression calculations are eliminated from the code.
          •     
          • Loop Rotation (Level 6)
            Program loops are rotated if the resulting program code is faster and more efficient. The loop expression of for and while loops is evaluated once at the top of the loop and then at the bottom of the loop. This optimization generates more code but speeds up execution.
          •     
          • Rearrange Code (Linker Optimization) (Level 10)
            When detecting common block subroutines, code is rearranged to obtain larger recurring sequences.
          •     
          • Register Variables (Level 4)
            Automatic variables and up to three function arguments may be located in registers. No data memory is reserved for variables located in registers.
          •     
          • Reuse of Common Entry Code (Linker Optimization) (Level 8)
            Entry code is reused when multiple calls are made to a single function. Reusing common entry code reduces program size.
          •     
          • Reuse of Common Exit Code (Linker Optimization) (Level 11)
            Identical exit sequences are reused. This may reduce the size of common block subroutines.
          •     
          • Simple Access Optimizing (Level 0)
            The compiler optimizes access of internal data and bit addresses in the 8051 system.
          •     
          • Simple Loop Optimizing (Level 4)
            Program loops that fill a memory range with a constant are converted and optimized.
          •    
             

          Regards, Dana.

          • 2. Re: PSoC 3 code reduction
            user_1377889

             It is NOT good to mess around in generated code.There are some optimization settingd in PSSoC Creator, one of them is to remove dead code which indeed will remove all unnecessary functions.

               

            To be found under Project -> Build Settings -> Linker

               

             

               

            Bob

            • 3. Re: PSoC 3 code reduction
              user_1377889

              Dana was 2 mins faster and a lot more detailled...

                 

               

                 

              Bob

              • 4. Re: PSoC 3 code reduction
                user_14586677

                As Bob points out tool generated code generally speaking will get regenerated

                   

                on next build. Trying to override the tool can get some unpredictable results. You

                   

                can generally count on todays tools to eliminate unused code. That certainly is

                   

                the case with Keil. Bob can speak to the effecacy of GNU.

                   

                 

                   

                Note on debugging, generally turn optimization off in compiler when debugging,

                   

                then turn it on for final builds. Not this potentially affects SW timing loops, and code

                   

                performance when disabled, keep that in mind.

                   

                 

                   

                Regards, Dana.,

                • 5. Re: PSoC 3 code reduction
                  user_199038981

                  Thanks for the quick response. I think I didn't express my question accurately. I'm not looking for code optimization, I'm looking to eliminate the code generated for the USBUART that I don't need. There are C and H files for things like audio, HID, etc that don't apply to anything we're doing. Can't I eliminate those files some way, maybe in the configuration IDE? I only want to use the cdc functionality. We need all the space we can get.

                  • 6. Re: PSoC 3 code reduction
                    user_14586677

                    Code optimization and reduction somewhat vague terms.

                       

                     

                       

                    The compiler will eliminate unused code, as well as optimize the

                       

                    used code.

                       

                     

                       

                    If you need a precise answer you might post a case at Keil and ask what

                       

                    the granularity of code will be eliminated, if unused, Eg,. does it work

                       

                    down to the individual API call ? Clearly if certain APIs use common

                       

                    code fragments what does the compiler do ? Can it still eliminate part

                       

                    of the API code ?

                       

                     

                       

                    By the way, your post is in the wrong forum, should be in PSOC Creator forum.

                       

                     

                       

                    Regards, Dana.

                    • 7. Re: PSoC 3 code reduction
                      user_199038981

                      Ok, thanks!