3 ms·
All modern platforms have decreasing stacks, so just AND it with ~(alignment-1). Of course, you now need to keep track of the old stack pointer so you can rest
by david-given 10y ago
All modern platforms have decreasing stacks, so just AND it with ~(alignment-1).
Of course, you now need to keep track of the old stack pointer so you can restore it. Most code saves the old stack pointer into the fp, so you can just do sp = fp to undo any pushes without needing to care about how much was pushed; but it's cleaner and more efficient to have the compiler arrange things on the stack so that everything's already aligned and you don't need to do it programmatically.
...why, yes, I have spend the past couple of months with my head buried inside a compiler backend; why do you ask?