assembly - Subtracting from stack pointer for alignment? -


i have seen assembly code subtracts stack pointer before calling function without particular reason. space subtracted left empty , not used:

sub    esp, 8    ; stack align push   dword y push   dword [x] call   foo add    esp, 16 mov    [x], eax 

the writer of code added comment 'stack align', don't know meant 'stack align' nor how command sub esp, 8 achieving it.

any ideas?

if stack pointer aligned cache line when function entered, execution of functions place less stress on cache.

so, compiler system can organized insist functions entered sp aligned on cache line, , compiler, knowing how stack has been used @ each call site, how takes re-align sp before makes call.

that explain example. haven't seen many compilers this, since stack tends grow/shrink modest distances , overall doesn't put demand on cache virtue of reusing local storage again , again.

another use allocating space callee work in, or return result bigger fits in register. compiler wouldn't write comment that, person did this. maybe knew doing; maybe didn't. if called function doesn't need space, wasted instruction.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -