On Apr 8 2011, Michael Matz wrote:
It adds a new option -fstack-arrays which makes the frontend put all local arrays on stack memory. ...
Excellent!
I haven't rechecked performance now, but four months ago this was the result for the fortran benchmarks in cpu2006:
There is actually a much better approach, which was done in Algol 68 and seems now to be done only in Ada. As far as the compiler implementation goes, it is a trivial variation on what you have done, but there is a little more work in the run-time system. That is to use primary and secondary stacks. The primary is for the linkage, scalars, array descriptors and very small, fixed-size arrays. The secondary is for all other arrays with automatic scope. You get all of the benefits that you mention, because both are true stacks, and the scope of the secondary stack is controlled by that of the primary. You need a single secondary stack pointer (and preferably limit, for checking), which can be global variables. If a procedure uses the secondary stack, it needs to restore it on leaving, or when leaving a scope including an allocation - but you have already implemented that! The reason that it gives better performance is locality. Because the primary stack is much smaller and contains the critical scalars and pointers to arrays etc., calling procedures can involve MANY fewer cache misses. It also reduces the number of array overflows that cause complete chaos, because most small bounds errors trash other data, not constants or linkage. It also helps with Unixoid systems with fixed (and small) stack limits, because the secondary stack is just another data segment. I would love to say that I would try to work on this, but I really can't promise to do anything else until I have delivered on some of my long overdue promises. But I am very happy to discuss details - not that there ARE many more than I have described! Regards, Nick Maclaren.