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 9052417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:10:00+00:00 2026-06-16T13:10:00+00:00

I am trying to calculate squared Euclidean distance between two 4d float vectors using

  • 0

I am trying to calculate squared Euclidean distance between two 4d float vectors using SSE2. My os is Mac OS X 10.7 Lion.

When I use Apple LLVM compiler in XCode 4.5.2 everything is fine. But when I switch into GCC 4.2 in project’s settings I have error EXC_BAD_ACCESS at _mm_mul_ps operation.

When I compile code from command line (g++ main.cpp) without additional arguments I have “Segmentation fault”. But when I enable any optimization level (O1, O2, O3, Os) except O0 everything works.

I can not reproduce this issue on my Ubuntu 12.04 with GCC 4.6.3.

#include <stdio.h>
#include <emmintrin.h>

typedef float SPPixel[4];

float sp_squared_color_diff(const SPPixel px1, const SPPixel px2) {
    SPPixel d;
    __m128 sse_px1 = _mm_load_ps(px1);
    __m128 sse_px2 = _mm_load_ps(px2);
    sse_px1 = _mm_sub_ps(sse_px1, sse_px2);
    sse_px2 = _mm_mul_ps(sse_px1, sse_px1); // EXC_BAD_ACCESS

    _mm_store_ps(d, sse_px2);
    return d[0] + d[1] + d[2] + d[3];
}

int main(int argc, const char * argv[]) {
    SPPixel a __attribute__ ((aligned (16))) = {1, 2, 3, 4};
    SPPixel b __attribute__ ((aligned (16))) = {2, 4, 6, 8};
    float result = sp_squared_color_diff(a, b);
    printf("result = %f\n", result);
    return 0;
}
  • 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-16T13:10:01+00:00Added an answer on June 16, 2026 at 1:10 pm

    The local variable d is misaligned. Fix the alignment in the typedef for SPPixel rather than having to remember it on every definition.

    Change:

    typedef float SPPixel[4];
    

    to:

    typedef float SPPixel[4] __attribute__ ((aligned(16)));
    

    and then you can also remove the __attribute__ ((aligned(16))) qualifiers in main.

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

Sidebar

Related Questions

I'm trying to calculate elapsed hours between two times. When calculating PM to AM
Im trying to calculate the how many days there are between two dates and
I am trying to calculate the difference between given two times and i find
am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I'm trying to calculate the number of pairwise differences between a long list of
I'm trying to calculate the difference between 2 dates, the current date and the
I'm trying to calculate the fft of an image using CUFFT. It seems like
I'm trying to calculate autocorrelation of sample windows in a time series using the
I am trying to take two numbers and get the square of them. Using
Am trying to calculate the number of rows in a table depending on a

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.