Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 759605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:37:00+00:00 2026-05-14T15:37:00+00:00

I try to build an application which uses pthreads and __m128 SSE type. According

  • 0

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 the 16-byte alignment.

My target CPU supports SSE. I use a GCC compiler which doesn’t support runtime stack realignment (e.g. -mstackrealign). I cannot use any other GCC compiler version.

My test application looks like:

#include <xmmintrin.h>
#include <pthread.h>
void *f(void *x){
   __m128 y;
   ...
}
int main(void){
  pthread_t p;
  pthread_create(&p, NULL, f, NULL);
}

The application generates an exception and exits. After a simple debugging (printf “%p”, &y), I found that the variable y is not 16-byte aligned.

My question is: how can I realign the stack properly (16-byte) without using any GCC flags and attributes (they don’t help)? Should I use GCC inline Assembler within this thread function f()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:37:00+00:00Added an answer on May 14, 2026 at 3:37 pm

    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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a long shot, but I thought I might try before starting the
I use TeamCity which in turn invokes msbuild (.NET 4). I have a strange
For my last project i was using many frames in my delphi application ,so
I had the following set-up which worked perfectly fine: @Service public class MyService {
I'm trying to make a RESTful Web Service which implements all four CRUD operations.
I am very new to java and spring. I was trying out my first
I'm having trouble with my program crashing. I get that Program.exe has stopped working
I am using smart gwt 2.0.3 on windows xp. I have set a classpath
I've got three database projects. I'd like to have the base project contain common
I'm trying to run Fortify on a Visual Studio 2008 project. The project builds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.