This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Optimization level not working

Hi , I am working on LPC1788 with RTX , my code size is much bigger , so i want to optimize my code, after sarching through internet , there is optimization level(-O1 to -O3) specified by keil , but when i am using that optimization level(tried each level)in my code,but it is not working , not in debug mode also , why is this happened , please help or suggest.

Parents
  • Ok, so most likely a bug in your code, or some unsafe coding style/practices.

    Make sure to use volatile variables where appropriate, this would be variables that change outside normal programming flow, and hardware peripheral registers that can read different values each time you read them.

    Check also for uninitialized variables, and anything flagging warnings in your current code. Use #include files for all the library routines you use so it can check/verify the prototypes and calling routines.

    The optimizer can change code order and fold code it perceives as doing nothing in the context it is used. Code may be moved out of loops, load constants instead of using math, etc.

Reply
  • Ok, so most likely a bug in your code, or some unsafe coding style/practices.

    Make sure to use volatile variables where appropriate, this would be variables that change outside normal programming flow, and hardware peripheral registers that can read different values each time you read them.

    Check also for uninitialized variables, and anything flagging warnings in your current code. Use #include files for all the library routines you use so it can check/verify the prototypes and calling routines.

    The optimizer can change code order and fold code it perceives as doing nothing in the context it is used. Code may be moved out of loops, load constants instead of using math, etc.

Children