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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:24:18+00:00 2026-05-20T06:24:18+00:00

In my project I have implemented basic class CVector. This class contains float* pointer

  • 0

In my project I have implemented basic class CVector.
This class contains float* pointer to raw floating point array.
This array is allocated dynamicly using standard malloc() function.

Now I have to speed up some computation using such vectors. Unfortunately as the memory isn’t alocated using _mm_malloc() it is not aligned.

As I understand I have two options:

1) Rewrite code which allocates memory to use _mm_malloc() and for example use the code like this:

void sub(float* v1, float* v2, float* v3, int size) 
{  
    __m128* p_v1 = (__m128*)v1;  
    __m128* p_v2 = (__m128*)v2;  
    __m128 res;

    for(int i = 0; i < size/4; ++i)  
    {  
        res = _mm_sub_ps(*p_v1,*p_v2);  
        _mm_store_ps(v3,res);  
        ++p_v1;  
        ++p_v2;  
        v3 += 4;  
    }
}

2) The second option is to use _mm_loadu_ps() instruction to load __m128 from unaligned memory and then use it for computation.

void sub(float* v1, float* v2, float* v3, int size)
{  
    __m128 p_v1;  
    __m128 p_v2;  
    __m128 res;

    for(int i = 0; i < size/4; ++i)  
    {  
        p_v1 = _mm_loadu_ps(v1);   
        p_v2 = _mm_loadu_ps(v2);  
        res = _mm_sub_ps(p_v1,p_v2);    
        _mm_store_ps(v3,res);  
        v1 += 4;  
        v2 += 4;  
        v3 += 4;  
    }
}

So my question is which option will be better or faster?

  • 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-20T06:24:19+00:00Added an answer on May 20, 2026 at 6:24 am

    Reading unaligned SSE values is extraordinary expensive. Check the Intel manuals, volume 4, chapter 2.2.5.1. The core type makes a difference, i7 has extra hardware to make it less costly. But reading a value that straddles the cpu cache line boundary is still 4.5 times slower than reading an aligned value. It is ten times slower on previous architectures.

    That’s massive, get the memory aligned to avoid that perf hit. Never heard of _mm_malloc, use _aligned_malloc() from the Microsoft CRT to get properly aligned memory from the heap.

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

Sidebar

Related Questions

I have implemented a very basic plug-in system as part of a static library
I have this error when building and running my project in xCode: RootViewController may
For a project I have a specification with formulas, I have to implement. In
Working on a project at the moment and we have to implement soft deletion
In a project have been involved in I needed to render tables with columns
I have project that I'm working on that is going to require a webserver.
For a particular project I have, no server side code is allowed. How can
For a small project I have to parse pdf files and take a specific
In my DSL project I have a shape with a number of decorators that
In a recent project I have nearly completed we used an architecture that as

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.