by Taniwha · 6y ago · 0 comments
There may be multiple reasons but a performance reason of which I’m aware is downward stacks are more efficient for allocating aligned memory:
sp = (sp - size) & align;
That’s only two instructions, with a stack that grows upward: sp += size;
if (sp & (align - 1))
sp += align - (sp & (align - 1));
Which is a few more instructions. Of course you can alleviate this by requiring an alignment invariant in the ABI, which is usually done anyway.Heaps of course can grow downwards
With modern 64-bit address spaces actual running out of space is not an issue (especially since we're dynamically moving around code, heaps and stacks for security reasons anyway)