Welcome, visitor! [ Register | Loginrss

 

$2.00

restore it before returning. If you use alloca

Description

those two blocks.Sometimes that lower orange block is 16 bytes, and I don’t know why. RS GoldThe cases where I’ve seen it happen, no saved registers with 24 bytes of local variables is the simplest, the compiler could have had a 24 byte local variable block with the top aligned to 16 bytes and no padding at all the last 8 bytes would be taken care of by the return address pushed on the stack . Maybe there is no purpose, and this is room for improvement for the compiler.Aligning all of these pieces might be the best thing since sliced silicon! It lets the compiler easily align local variables. It can also easily determine if aligned SSE load store instructions can be used or not. If RSP wasn’t aligned, the compiler would have to always use the unaligned instructions or add alignment code to the prologue of certain functions.Aligning every stack frame is an elegant solution, and I think the extra few bytes of padding is a small, worthwhile price to pay for the ability to use optimal SSE instructions. Those instructions can handle data in any format, not just floating point numbers. You might see the compiler use them to move 16 bytes of data quickly. Since the SSE registers are sure to exist and stack data can be aligned, there’s no reason to use the x87 FPU instructions unless you REALLY want that precision . For x87 the bell tolls. Time marches on.The frame pointerThe frame pointer is not always used. If the stack pointer doesn’t change within the body of a function, it’s not necessary to remember where it was previously. The function epilogue already knows how to restore it before returning. If you use alloca, RSP will jump around and RBP will be used as a fame pointer. Instead of remembering how far RSP moved during the body of the function, the compiler uses the frame pointer as an anchor point to restore RSP before returning. RBP is always the register chosen to be the frame pointer.I’ve also seen MSVC use a frame pointer for reasons that I am admittedly uncertain of. From what I can tell, the frame pointer will be used if a function needs to pass enough struct parameters by-value and the amount of stack space needed for the temporary objects is within a certain range the structs section of the last post explains those temporary objects .I think there’s a required ratio between the number of params and their size. IE: 6 structs of 8 bytes, but not 3 structs of 16rssong

Ad Reference ID: 967567a3c3f35189

Sponsored Links

Leave a Reply

To inquire about this ad listing, complete the form below to send a message to the ad poster.

Sponsored Ads