3

CSAPP explains that SSE instructions operate on 16-byte blocks of data and it needs memory addresses to be multiple of 16.

But what's the relationship with stack frame? Does it means SSE instructions operate on stack frame? If so, what's the commonly used instructions?

phuclv
  • 37,963
  • 15
  • 156
  • 475
jinge
  • 785
  • 1
  • 7
  • 20
  • Possible duplicate of [Why does the x86-64 / AMD64 System V ABI mandate a 16 byte stack alignment?](https://stackoverflow.com/q/49391001) re: that calling-convention design decision. – Peter Cordes May 18 '22 at 16:19

1 Answers1

5

Yes, the alignmentment of stack frame is set so any instruction could work on any data type which you could potentially store in the stack frame.

So on x86/x86_64 for example there are SSE instructions which suppose that the memory address is aligned to 16 bytes. Compiler then supposes that the stack frame is aligned 16 bytes so it could arrange the local variables that they are aligned too if needed. SSE instructions (like any other) can operate on any memory, including global, heap or stack.

The same it is actually for heap - when you allocate structure longer than 16 (or equal), the malloc/new must return 16-bytes aligned address so that kind of instruction could work with it.

Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43
  • 1
    Wow, I see, thanks to your answer. Simply speaking, it's because if stack frame doesn't align, the data inside it will never align, right? So stack frame is providing an aligned baseline. – jinge Feb 29 '16 at 14:24