Andes Workshop

It is currently Fri Mar 29, 2024 2:51 am

All times are UTC + 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Set different optimization level for partial codes
PostPosted: Sun Jan 12, 2014 1:05 pm 
Offline
User avatar

Joined: Fri Mar 04, 2011 9:36 pm
Posts: 500
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,最佳化,優化


Top
 Profile Send private message E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group