4 ms·
push rbp ; <- stack alignment push This shouldn't be needed. 8 byte alignment is fine for the CPU itself. The purpose of 16 byte alignment is to facilita
by qb45 10y ago
push rbp ; <- stack alignment push
This shouldn't be needed. 8 byte alignment is fine for the CPU itself. The purpose of 16 byte alignment is to facilitate making 16 byte aligned stack allocations.
- bjourne 10y agoRSP needs to be aligned to 16 bytes at CALL sites. See f.e https://blogs.msdn.microsoft.com/oldnewthing/20040114-00/?p=41053 https://blogs.msdn.microsoft.com/oldnewthing/20040114-00/?p=...
- qb45 10y agoSee the first answer here http://stackoverflow.com/questions/612443/why-does-the-mac-abi-require-16-byte-stack-alignment-for-x86-32 http://stackoverflow.com/questions/612443/why-does-the-mac-a... I also checked similar manual for AMD and it doesn't seem to mention RSP alignment at all, except that "some calling conventions may require ...". The CPU doesn't care. It only matters when you call functions which allocate 16B objects on the stack.* This function calls only itself and pushes only 8B words on the stack so it's fine with 8B alignment. * Some functions generated by C compilers do and they segfault if you call them with wrong alignment. Ask me how I know. edit: OK, so I downloaded this code. Results: as-is: 78111us push rbp: 73093us sub rsp,8: 72332us sub rax,8: 72222us Seems to be a matter of instruction alignment, nothing to do with the stack.