PR to add optimisation menu (to all boards individually)

User avatar
Pito
Posts: 1531
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: PR to add optimisation menu (to all boards individually)

Post by Pito » Sun Jul 30, 2017 11:04 am

Operation -Os optimisation -O3 & LTO optimisation __Improvement %
Is that correct? Is the -Os always faster?
Pukao Hats Cleaning Services Ltd.

User avatar
RogerClark
Posts: 6917
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: PR to add optimisation menu (to all boards individually)

Post by RogerClark » Sun Jul 30, 2017 12:08 pm

The other way around

-Os is always slower in the graphics test

fpiSTM
Posts: 192
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: PR to add optimisation menu (to all boards individually)

Post by fpiSTM » Mon Sep 18, 2017 8:24 am

@RogerClark,

just FYI,

I'm updating the pulseIn() function for the Arduino_Core_STM32 in order to have a better precision.
I saw you have hard coded the number of cycle per iteration (to 16) but since this new menu, depending of the optimization selected, this number is not always the same so the duration value is not correct for all Ox.

https://github.com/rogerclarkmelbourne/ ... f1.cpp#L42

I'm trying to find a generic way to compute this value (asm, DWT_CYCCNT,...) as I have to deal with all STM32 series.

User avatar
RogerClark
Posts: 6917
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: PR to add optimisation menu (to all boards individually)

Post by RogerClark » Mon Sep 18, 2017 8:28 am

Thanks

I'd noticed that software I2C was also affected by the optimisation setting, but because LibMaple now uses Hardware I2C for "Wire" its not so much of a problem, and will only impact people specifically choosing to use software I2C

Because the delay loops in software I2C are so short, I don't think there is a way to make it work correctly for all optimisation settings.

fpiSTM
Posts: 192
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: PR to add optimisation menu (to all boards individually)

Post by fpiSTM » Mon Sep 18, 2017 8:52 am

You could try to add this is the impacted function:

Code: Select all

__asm__("")
This will tell to the compiler to not optimize the function.
See https://gcc.gnu.org/onlinedocs/gcc-4.8. ... Attributes
noinline
This function attribute prevents a function from being considered for inlining. If the function does not have side-effects, there are optimizations other than inlining that cause function calls to be optimized away, although the function call is live. To keep such calls from being optimized away, put

asm ("");

Code: Select all

unsigned char i, j;
j = 0;
while(--j) {
    i = 0;
    while(--i)
        __asm__("");
}

victor_pv
Posts: 1654
Joined: Mon Apr 27, 2015 12:12 pm

Re: PR to add optimisation menu (to all boards individually)

Post by victor_pv » Mon Sep 18, 2017 1:49 pm

What about the "optimize" attribute to force a function to always be optimized witht he same level no matter what is used for the rest of the code?
That may help keep those timing loops always result in the same code.
Frederic, you mention DWT_CYCCNT, which has come up several times in the forum. Is there any ill effect from using it? I believe the concerns were about the effects of debugging, do I dont remember it was because it could be stopped or reset during debugging or what other reason.

fpiSTM
Posts: 192
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: PR to add optimisation menu (to all boards individually)

Post by fpiSTM » Mon Sep 18, 2017 3:39 pm

Thanks Victor, I will check about the optimize. :)
About the DWT CYCCNT, I'm just stating the investigation and I think I will not use that as not supported by M0 family. And probably you're right about debugging effect.

victor_pv
Posts: 1654
Joined: Mon Apr 27, 2015 12:12 pm

Re: PR to add optimisation menu (to all boards individually)

Post by victor_pv » Mon Sep 18, 2017 8:36 pm

I actually had hoped that you would say it's ok to use it :(

User avatar
RogerClark
Posts: 6917
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: PR to add optimisation menu (to all boards individually)

Post by RogerClark » Mon Sep 18, 2017 9:42 pm

Victor

can you give more details of the "optimize" attribute..

I investigated something similar when trying to get the original OV7670 camera code to run with our default optimization settings, i.e switch to -O2 for some code, but the pragma for this is not supported by the ARM version of GCC

fpiSTM
Posts: 192
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: PR to add optimisation menu (to all boards individually)

Post by fpiSTM » Tue Sep 19, 2017 4:12 am

I tried quickly yesterday and it seems to work, but I use the arm gcc v6, I do not test for v4.8

Code: Select all

#pragma GCC push_options
#pragma GCC optimize ("Os")
your function

#pragma GCC pop_options
After check the gcc documentations, it should work for 4.8:
https://gcc.gnu.org/onlinedocs/gcc-4.8. ... on-Pragmas
#pragma GCC optimize ("string"...)
This pragma allows you to set global optimization options for functions defined
later in the source file. One or more strings can be specified. Each function
that is defined after this point is as if attribute((optimize("STRING"))) was
specified for that function. The parenthesis around the options is optional. See
Section 6.30 [Function Attributes], page 350, for more information about the
optimize attribute and the attribute syntax.
The ‘#pragma GCC optimize’ pragma is not implemented in GCC versions ear-
lier than 4.4.
#pragma GCC push_options
#pragma GCC pop_options
These pragmas maintain a stack of the current target and optimization options.
It is intended for include files where you temporarily want to switch to using
a different ‘#pragma GCC target’ or ‘#pragma GCC optimize’ and then to pop
back to the previous options.
The ‘#pragma GCC push_options’ and ‘#pragma GCC pop_options’ pragmas
are not implemented in GCC versions earlier than 4.4

Post Reply