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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:11:04+00:00 2026-06-02T13:11:04+00:00

So i was trying to do an array operation that looked something like for

  • 0

So i was trying to do an array operation that looked something like

for (int i=0;i++i<32)
{
    output[offset+i] += input[i];
}

where output and input are float arrays (which are 16-byte aligned thanks to malloc). However, I can’t gurantee that offset%4=0. I was wondering how you could fix these alignment problems.

I though something like

while (offset+c %4 != 0)
{
    c++;
    output[offset+c] += input[c];
}

followed by an aligned loop – obviously this can’t work as we now need an unaligned access to input.

Is there a way to vectorize my original loop?

  • 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-02T13:11:06+00:00Added an answer on June 2, 2026 at 1:11 pm

    Moving comments to an answer:

    There are SSE instructions for misaligned memory accesses. They are accessible via the following intrinsics:

    • _mm_loadu_ps() – documentation
    • _mm_storeu_ps() – documentation

    and similarly for all the double and integer types.

    So if you can’t guarantee alignment, then this is the easy way to go. If possible, the ideal solution is to align your arrays from the start so that you avoid this problem altogether.

    There will still be a performance penalty for misaligned accesses, but they’re unavoidable unless you resort to extremely messy shift/shuffle hacks (such as _mm_alignr_epi8()).

    The code using _mm_loadu_ps and _mm_storeu_ps – this is actually 50% slower than what gcc does by itself

    for (int j=0;j<8;j++)
    {
        float* out = &output[offset+j*4];
        __m128 in = ((__m128*)input)[j]; //this is aligned so no need for _mm_loadu_ps
        __m128 res  = _mm_add_ps(in,_mm_loadu_ps(out)); //add values 
        _mm_storeu_ps(out,res); //store result
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pass array parameter to SQL commnd in C# like below,
Is it possible to create a capped sub-collection. I'm trying to do something like:
I'm trying to get the numerical (double) value from a byte array of 16
I'm trying to create a class that represents hours of operation in an Obj-C
I'm trying to create an array of byte s whose length is UInt32.MaxValue .
I have an array that after being sorted appears like this: var arr =
I was trying to learn writing stl like iterators, for that I wrote a
I am trying to array posts containing the value X within their meta_value. I’ve
I am trying to sub-array in MATLAB with no luck. This is what I
I'm trying to subclass Array in ruby to make it randomize its elements when

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.