teds
New Member
- Total Posts : 2
- Reward points : 0
- Joined: 2021/02/19 18:02:35
- Location: 0
- Status: offline
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.
|
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)
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.
To get a useful answer, always state which PIC you are using!
|
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)
|
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)
@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.
|
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)
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?
To get a useful answer, always state which PIC you are using!
|
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)
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
|
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)
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.
|
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)
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.
|
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)
Just add a "volatile" qualifier to the definition of that variable. That was already mentioned in JPortici's answer.
To get a useful answer, always state which PIC you are using!
|
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)
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
|
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)
I don't think teds has revealed which compiler they are using, which is a fairly important point...
To get a useful answer, always state which PIC you are using!
|
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)
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.
|