• AVR Freaks

Hot!How: Build a couple of files differently than others?

Author
teds
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2021/02/19 18:02:35
  • Location: 0
  • Status: offline
2021/02/21 20:47:18 (permalink)
0

How: Build a couple of files differently than others?

I have a legacy application in which I can/need to optimize 1 or 2 c source files. How can I selectively control that these files have the -O1 compile time option, but the rest remain at -O0 (or empty)? I know I can do it within an independenly managed make file or some clever post build function (which does the re-compilation with -O1 and then rebuild the bin file), but it would be great if I could somehow state it within the project, so that it's easier to manage.
 
Ted
 
p.s., I did try searching for this question and couldn't find if it had been asked before - sorry if it has been.
#1

11 Replies Related Threads

    ric
    Super Member
    • Total Posts : 29918
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: How: Build a couple of files differently than others? 2021/02/22 16:51:15 (permalink)
    0
    Sorry, don't know how to do what you want, but I have to ask WHY do you want to do it?
    i.e. why do some files have to be at -O0?
    If the code doesn't work at other levels, it usually indicates a bug in the code.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    RISC
    Super Member
    • Total Posts : 5983
    • Reward points : 0
    • Status: offline
    Re: How: Build a couple of files differently than others? 2021/02/22 17:07:03 (permalink)
    4 (1)
    Hi,
    MPLAB X provides the capability to handle several project configurations.
    For each configuration you can exclude one or more files :
    https://microchipdeveloper.com/mplabx:project-configurations
    Regards
     

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #3
    teds
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2021/02/19 18:02:35
    • Location: 0
    • Status: offline
    Re: How: Build a couple of files differently than others? 2021/02/23 11:51:08 (permalink)
    4 (1)
    @ric Sorry, don't know how to do what you want, but I have to ask WHY do you want to do it?
    i.e. why do some files have to be at -O0?
    Some source doesn't lend itself nicely to optimization, so I want to exclude those files from the optimization, while including the files which won't be affected by optimizations.
     
    @RISC Sorry this doesn't suit my purpose, I need to include all files, just with different optimizations.
    #4
    ric
    Super Member
    • Total Posts : 29918
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: How: Build a couple of files differently than others? 2021/02/23 12:02:14 (permalink)
    5 (1)
    teds
    ...
    Some source doesn't lend itself nicely to optimization, so I want to exclude those files from the optimization,

    Once again, what does this mean?
    What aspect of optimisation is causing you problems?

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    JPortici
    Super Member
    • Total Posts : 1287
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: How: Build a couple of files differently than others? 2021/02/23 13:02:24 (permalink)
    0
    Usually the better thing to do would be write your code better, if optimizations break it.
    But i understand that it can't always be the case.
    Being GCC, in XC16 and XC32 individual functions can specify their optimization level (the attribute name and usage is in the compiler manual)
    I don't know if XC8 has a simillar option
    #6
    crosland
    Super Member
    • Total Posts : 2176
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: How: Build a couple of files differently than others? 2021/02/23 13:33:27 (permalink)
    0
    teds
    Some source doesn't lend itself nicely to optimization, so I want to exclude those files from the optimization,

    Why? If you have written perfect code that the compiler cannot optimise then it will not be optimised. Let the compiler decide.
     
    while including the files which won't be affected by optimizations.

     
    What do you mean by affected? They WILL be affected by optimisation if they are optimised.
     
    I need to include all files, just with different optimizations.

     
    WHY? If optimisation has a noticeable effect then you have buggy code. E.g.
     
    - Corruption or unexpected behaviour due to missing volatile qualifiers
    - Software delay loops.
     
     
    #7
    Murton Pike Systems
    Super Member
    • Total Posts : 224
    • Reward points : 0
    • Joined: 2020/09/10 02:13:01
    • Location: 0
    • Status: offline
    Re: How: Build a couple of files differently than others? 2021/02/23 19:35:20 (permalink)
    0
    Sometimes you dont want complier to optimise out code.
     
    On a pic32mx274 usb scope I want it to delay a set amount of cycles depending on scope timebase.
    So for say 1ms/division I want to loop 127 times I would add.
    for (cx=0;cx<delay;cx++);
     
    This code does nothing but a programmable delay so could be optimised out by the compiler.
    The usual ms and us inbuilt functions are not what I want.
    The delay is simply tweaked at the pc end until I get spot on.
    #8
    ric
    Super Member
    • Total Posts : 29918
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: How: Build a couple of files differently than others? 2021/02/23 19:39:12 (permalink)
    5 (1)
    Just add a "volatile" qualifier to the definition of that variable.
    That was already mentioned in JPortici's answer.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    RISC
    Super Member
    • Total Posts : 5983
    • Reward points : 0
    • Status: offline
    Re: How: Build a couple of files differently than others? 2021/02/24 02:43:43 (permalink)
    0
    Hi,
    teds
    @ric Sorry, don't know how to do what you want, but I have to ask WHY do you want to do it?
    i.e. why do some files have to be at -O0?
    Some source doesn't lend itself nicely to optimization, so I want to exclude those files from the optimization, while including the files which won't be affected by optimizations.
     
    @RISC Sorry this doesn't suit my purpose, I need to include all files, just with different optimizations.

     
    A possible way might be to create several configurations and change XC16 parameters in the project properties of each configuration
    Regards

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #10
    ric
    Super Member
    • Total Posts : 29918
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: How: Build a couple of files differently than others? 2021/02/24 02:50:18 (permalink)
    0
    I don't think teds has revealed which compiler they are using, which is a fairly important point...
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #11
    crosland
    Super Member
    • Total Posts : 2176
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: How: Build a couple of files differently than others? 2021/02/24 05:19:25 (permalink)
    5 (2)
    nigelwright7558
    Sometimes you dont want complier to optimise out code.

     
    If it's removing code that you want, then there's something wrong with the code.
    #12
    Jump to:
    © 2021 APG vNext Commercial Version 4.5