GCC - How to realign stack?

前端 未结 5 774
广开言路
广开言路 2021-02-09 05:45

I try to build an application which uses pthreads and __m128 SSE type. According to GCC manual, default stack alignment is 16 bytes. In order to use __m128, the requirement is t

5条回答
  •  时光说笑
    2021-02-09 06:44

    I have solved this problem. Here is my solution:

    void another_function(){
       __m128 y;
       ...
    }
    void *f(void *x){
    asm("pushl    %esp");
    asm("subl    $16,%esp");
    asm("andl    $-0x10,%esp");
    another_function();
    asm("popl %esp");
    }
    

    First, we increase the stack by 16 bytes. Second, we make least-significant nibble equal 0x0. We preserve the stack pointer using push/pop operands. We call another function, which has all its own local variables 16-byte aligned. All nested functions will also have their local variables 16-byte aligned.

    And It works!

提交回复
热议问题