Reducing compilation memory usage

Tony Wetmore tony.wetmore@solipsys.com
Sun Jan 20 13:19:00 GMT 2008


Alejandro Pulver wrote:
 >> RAM!  Of course we could make gcc more economical, and
 >> we could somewhat reduce memory usage, but you're asking
 >> for something really hard.
 >
 > I wasn't asking to change the program, I was just asking
 > if there is an already existing option.

I think Andrew may have meant that you are asking GCC to do something 
really hard, to optimize a single function that is so large.  And asking 
the compiler to do something that hard has a price -- it requires lots 
of memory, as you have discovered.

 > So far I have 2 alternatives in mind, do you have others (in addition
 > to adding RAM)?
 >
 > 1. Use 8 functions and files, with only 1000 cases each.
 > 2. Use 2 or more jump tables in the same file, reducing the total
 >    number of cases (if possible, have to check).
 >
 > Note that this program is focused on speed (currently the fastest MARS
 > simulator).

Well, it is currently the fastest MARS simulator that only implements a 
small subset of the overall instruction set, right?

And isn't your goal to implement the entire set?  You may indeed have to 
trade some speed for that extra functionality.  Of course, once you are 
finished, you may still have the fast MARS simulator (that implements 
the full instruction set).  But it may not be as fast as one that 
implements only a small fraction of the instructions. :)

Since I haven't looked at the code, I cannot offer good advice on how 
best to restructure it.

But one (hopefully simple) change might be to have every instruction 
implemented by its own function, so you would have 8,000 functions 
(perhaps even each in its own file).  Of course, I have no idea how that 
will impact performance.  Would the optimizer be able to improve 
performance enough to offset the overhead of the additional function 
calls?  I don't know.  I suspect you won't know either, unless you 
implement it and measure the performance.

I assume you have some benchmarks you can run, to compare against the 
original speed.  So you might want to try several different 
modifications, beginning with the simplest to implement.

Good luck!

--
Tony Wetmore




More information about the Gcc-help mailing list