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

  • Home
  • SEARCH
  • 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 8939757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:53:24+00:00 2026-06-15T10:53:24+00:00

We trying to do some SSE operations, however, at the end of add_sse function,

  • 0

We trying to do some SSE operations, however, at the end of add_sse function, we trying to read back the value just computed, it will give us a seg fault. BUT, if we just print the value in the for loop, the result is ok.
Also it is ok to just read the element 0 in each array. read element 1 and beyond will cause seg fault.

Could any one help us to identify the problem? we tried everything, but still dont understand we there would be a seg fault. THanks

void main()
{
    ResultCounter *c_sse=(ResultCounter *)memalign(16,sizeof(ResultCounter)*4);    

    resetCounter (c_sse);  //initial struct to all 0

    add_sse (1,2, 3,4, c_sse);
}

void add_sse (unsigned int first, unsigned int second, unsigned int third, unsigned int fourth, ResultCounter *c)
{
    __attribute__((align(16))) int m_intarray[4] = {first, second, third,fourth};

    __attribute__((align(16))) int m_Larray[4] = {c[0].L, c[1].L, c[2].L,c[3].L};
    __attribute__((align(16))) int m_Marray[4] = {c[0].M, c[1].M, c[2].M,c[3].M};
    __attribute__((align(16))) int m_Harray[4] = {c[0].H, c[1].H, c[2].H,c[3].H};

    __m128i N = _mm_load_si128(&m_intarray[0]);
    __m128i L = _mm_load_si128(&m_Larray[0]);
    __m128i M = _mm_load_si128(&m_Marray[0]);
    __m128i H = _mm_load_si128(&m_Harray[0]);

    __m128i Lcarry = _mm_and_si128 (L, N);

    L = _mm_xor_si128 (L, N);

    __m128i Mcarry = _mm_and_si128 (M, Lcarry); 

    M = _mm_xor_si128 (M, Lcarry);

    H = _mm_or_si128 (H,Mcarry);

    _mm_store_si128(&m_Larray[0], L);
    _mm_store_si128(&m_Marray[0], M);
    _mm_store_si128(&m_Harray[0], H);

    for(i = 0; i < 4; i++) {
        //printf ("L:%d,addr=%u,M:%u,addr=%u,H:%u,addr=%u\n",m_Larray[i],&m_Larray[i],m_Marray[i],&m_Marray[i],m_Harray[i],&m_Harray[i]);
        c[i].L=m_Larray[i];
        c[i].M=m_Marray[i];
        c[i].H=m_Harray[i];
    }
}

//The struct used in main function.
typedef struct
{
    unsigned int L;
    unsigned int M;
    unsigned int H;
} ResultCounter;
  • 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-06-15T10:53:25+00:00Added an answer on June 15, 2026 at 10:53 am

    The problem is that the ResultCounter struct is 12 bytes in size, so although the first element of your array, c[0] is 16 byte aligned, the second element, c[1], is not. The quickest/easiest fix for now would be to add 4 bytes of padding to this struct, e.g. an additional unused int:

    typedef struct
    {
        unsigned int L;
        unsigned int M;
        unsigned int H;
        unsigned int unused;
    } ResultCounter;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to rewrite some code to make use of SSE. However, for some
I am trying to optimize some arithmetic by using the MMX and SSE instruction
I'm very new to SIMD/SSE and I'm trying to do some simple image filtering
I've been trying my hand at optimising some code I have using microsoft's sse
So I'm trying some code out to convert numbers into strings. However, I noticed
I'm trying to write some computationally intensive code for Windows x64 target, with SSE
I am trying some examples for DateDiff Function SELECT DATEDIFF(day,'2008-06-05','2008-08-05') AS DiffDate This statement
I am trying some simple code on fork. When I give code like this,
I discovered Guice last week... I'm trying some easy tricks with it. However, I'm
I'm trying some iOS test applications on the new Mac mini, that supports Bluetooth

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.