Andes Workshop
http://forum.andestech.com/

Set different optimization level for partial codes
http://forum.andestech.com/viewtopic.php?f=25&t=780
Page 1 of 1

Author:  cindy [ Sun Jan 12, 2014 1:05 pm ]
Post subject:  Set different optimization level for partial codes

Reference:
http://gcc.gnu.org/onlinedocs/gcc/Funct ... agmas.html

The following are two examples.
There is a warning message when compiling example 2.
It said this syntax is not supported. But actually, it works. The result is correct.

Example 1: just set optimization level for single function。
__attribute__((optimize("O0")))
int add (int a, int b )
{
int x = a;
int y = b;
return x + y;
}

int main ()
{
int r = 1;
int a = r;
int b = r;
func ();
return 0;
}

Example 2:Select partial codes to avoid optimization
Note! The syntax is not only for a function. Users can select arbitrary code segments.
#pragma GCC push_options
#pragma GCC optimize ("O0")

int add (int a, int b )
{
int x = a;
int y = b;
return x + y;
}

#pragma GCC pop_options
int main ()
{
int r = 1;
int a = r;
int b = r;
func ();
return 0;
}

#pragma GCC push_options
#pragma GCC pop_options
These two lines represent they will push the original options,
such as -Os.
Then pop the -Os back, to restore the original optimization settings.

Keyword:
optimize, optimization,最佳化,優化

Page 1 of 1 All times are UTC + 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/