Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Static initiali...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 9369 of 10096
Post > Topic >>

Static initialization optimization

by Marcin Swiderski <sfider.best@[EMAIL PROTECTED] > Mar 12, 2008 at 07:37 PM

Hi all

I am currently playing around with compile time calculations using
template
programming. My idea is to calculate values of some function

int f(int i)

for i from 0 to n and initialize array (global or static member) with
those values.
I want n to also be calculated in compile time.

My solution compiled with GCC 4.2.3 to assembler (g++ -O2 -S) has
code below in static initialization section:

         movl    $1, _ZN10pow_of_twoILi30EE7values_E
         movl    $2, _ZN10pow_of_twoILi30EE7values_E+4
         ...
         movl    $536870912, _ZN10pow_of_twoILi30EE7values_E+116
         movl    $1073741824, _ZN10pow_of_twoILi30EE7values_E+120

Is there any way (compiler optimization option maybe) to generate
assembler
code below in .data section instead of above:

_ZN10pow_of_twoILi30EE7values_E:
         .long   1
         .long   2
         ...
         .long   536870912
         .long   1073741824

Such optimization would eliminate some overhead during program startup
and shrink binary file. Gain would not be large, but could be useful
for some
embadded systems.

My other thought was that such optimization would break the
initialization
order. But it shouldn't be a problem, because static array
initialization
works that way.

Cheers

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 1 Posts in Topic:
Static initialization optimization
Marcin Swiderski <sfid  2008-03-12 19:37:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:31:20 CDT 2008.