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

Overlays and optimizations on the 8051

Is there anyway to "skip" an optimization level on Keil C51 ver 5.20?

I continually get linker warnings about recursive calls. I have read app note 129 (many projects ago, and now do what it suggests as second nature). If I drop the optimizations down to "Dead Code Elimination" (the one below "Data Overlay"), all my linker warnings go away. As I have more RAM than I'll ever need in this project, I'd like to just skip overlay entirely, and avoid its problems. Unfortunately, code space is limited, and I cannot do without the other optimizations.

I know I can do optimizations on a file by file basis (and have), but I'd like to avoid this if possible, and it still leaves that one file unoptimized.

BTW: What exactly does the "enable variable overlay" under the linker menu do anyway... I cannot tell any difference from the map file.

-nelson

  • The compiler optimizations have nothing to do with the warnings generated by the linker.

    If you want to disable variable overlaying, use the NOOVERLAY linker directive.

    Jon

  • The compiler optimizations have nothing to do with the warnings generated by the linker.

    then why does the warning go away when optimizations are turned nearly off. To me that means that something the compiler is doing affects how the linker is interpritting the object file.

    If you want to disable variable overlaying, use the NOOVERLAY linker directive

    This is the same as NOOL, which is what the linker box "enable variable overlay" adds when I leave it unchecked. The map file is identical (I diffed the 2 just now) with this option checked and unchecked. Purhaps I don't understand variable overlays? I was under the impression that if overlay is enabled, then my xdata space would use less space (and I know that I have multiple functions that CANNOT be executed at the same time and don't use static variables)

    opt level  xdata end
    6          0x57B     linker warning
    5          0x57B     linker warning
    4          0x57B     linker warning
    3          0x587     linker warning
    2          0x587     linker warning
    1          0x7C8     no linker warning
    
    The above tells me that overlay isn't truely disabled until I set compiler optimizations to 1, and this is where my linker warning disappears.

    The only thing I changed to get the above results is the optimization level. Using NOOL in the linker appears to have no affect.

    -nelson

  • What memory model are you using?
    That determines where the compiler puts variables - including locals - by default.
    If you're using a model which defaults to other than XDATA, then overlaying or not may well not affect your XDATA space.

  • "The compiler optimizations have nothing to do with the warnings generated by the linker."

    This is not entirely true; different Compiler optimisations will produce different objects, with the result that certain Linker warnings may or may not be raised; eg, the following is on p260 of the "Assembler and Utilities User's Guide 07.2000:"

    "C code that is translated with the Cx51 compiler directive OPTIMIZE (1) does not use the relocation type OVERLAYABLE. Therefore the local data segments of this code portions (sic) cannot be overlaid."

    As the original post was due to problems with overlays, the choice of optimisation level could affect the generation (or not) of overlay-related Linker warnings!

  • As I understand it, the Compiler just marks things as "Overlayable" or not; it's the Linker which does the actual overlaying.
    So, if you turn off Overlaying in your Linker options that should stop Overlaying - irrespective of Compiler options.

  • Right on!

    Except...xdata overlaying is not supported in V5. It is only available in V6 and later.

    This is the problem that Nelson is having. See the following article for more info.

    http://www.keil.com/support/docs/1855.htm

    Jon

  • Except...xdata overlaying is not supported in V5. It is only available in V6 and later.

    I assume that mean that my increase in xdata usage when I set compiler optimizations to below "data overlay" is because of moving idata variables to xdata?

    Regardless, it sounds like my initial question's answer is NO, there is no way to skip an optimzation level. If I want to avoid the compiler warning, I'll have to do a #pragma optimize() around each function/file that is causing the problem.... unless someone has a better solution?

    It also sounds like version 6 might handle this issue better... Neglecting uVision, how much better is v6 over v5? I usually maintain the philosophy to avoid changing revs in the middle of a project, if I -do- convince my client to upgrade, am I going to run into any upgrade problems (ie, the code works fine as is, just for the annoying overlay issue).

    legal issue: If you upgrade instead of purchase a new license, does that "legally" prevent you from using the older version?

    Thanks,
    -nelson

  • For what it's worth, when I switched from v5.5 to 6.0 on my 60KB of code project, I so no bugs as a result of the switch. I used less code and the compiles were twice as fast, but no ill effects.

    - Mark

  • I assume that mean that my increase in xdata usage when I set compiler optimizations to below "data overlay" is because of moving idata variables to xdata?

    The compiler doesn't move IDATA vars to XDATA in any optimization (or lack of optimization) step. :-)

    There must be some other optimization that isn't making more efficient use of XDATA.

    Regardless, it sounds like my initial question's answer is NO, there is no way to skip an optimzation level.

    That's correct. There is no way to "skip" an optimization level.

    If I want to avoid the compiler warning, I'll have to do a #pragma optimize() around each function/file that is causing the problem.... unless someone has a better solution?

    I'd suggest using the linker optimize directive to remove the resursive reference to the function. This is discussed in App Note 129.

    It also sounds like version 6 might handle this issue better...

    I'm not too sure about that. The V6 optimizer is nearly identical to the V5 optimizer for the first 6 levels. The V6 tools, offer 3 new optimization levels. Also, V6 offers XDATA overlaying.

    Neglecting uVision, how much better is v6 over v5?

    Numerous customers report cutting application sizes by as much as 40%. We've consistently seen 30% on real applications (over 16K).

    I usually maintain the philosophy to avoid changing revs in the middle of a project,

    I tend to agree with you.

    legal issue: If you upgrade instead of purchase a new license, does that "legally" prevent you from using the older version?

    No. As long as it's the same user on the same machine. You can't give your old V5 compiler away to a friend. (Well, unless you also give him your V6 updated compiler as well :-)

    Jon