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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:36:00+00:00 2026-05-27T03:36:00+00:00

My initial attempt looked like this (supposed we want to multiply) __m128 mat[n]; /*

  • 0

My initial attempt looked like this (supposed we want to multiply)

  __m128 mat[n]; /* rows */
  __m128 vec[n] = {1,1,1,1};
  float outvector[n];
   for (int row=0;row<n;row++) {
       for(int k =3; k < 8; k = k+ 4)
       {
           __m128 mrow = mat[k];
           __m128 v = vec[row];
           __m128 sum = _mm_mul_ps(mrow,v);
           sum= _mm_hadd_ps(sum,sum); /* adds adjacent-two floats */
       }
           _mm_store_ss(&outvector[row],_mm_hadd_ps(sum,sum));
 }

But this clearly doesn’t work. How do I approach this?

I should load 4 at a time….

The other question is: if my array is very big (say n = 1000), how can I make it 16-bytes aligned? Is that even possible?

  • 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-27T03:36:01+00:00Added an answer on May 27, 2026 at 3:36 am

    OK… I’ll use a row-major matrix convention. Each row of [m] requires (2) __m128 elements to yield 8 floats. The 8×1 vector v is a column vector. Since you’re using the haddps instruction, I’ll assume SSE3 is available. Finding r = [m] * v :

    void mul (__m128 r[2], const __m128 m[8][2], const __m128 v[2])
    {
        __m128 t0, t1, t2, t3, r0, r1, r2, r3;
    
        t0 = _mm_mul_ps(m[0][0], v[0]);
        t1 = _mm_mul_ps(m[1][0], v[0]);
        t2 = _mm_mul_ps(m[2][0], v[0]);
        t3 = _mm_mul_ps(m[3][0], v[0]);
    
        t0 = _mm_hadd_ps(t0, t1);
        t2 = _mm_hadd_ps(t2, t3);
        r0 = _mm_hadd_ps(t0, t2);
    
        t0 = _mm_mul_ps(m[0][1], v[1]);
        t1 = _mm_mul_ps(m[1][1], v[1]);
        t2 = _mm_mul_ps(m[2][1], v[1]);
        t3 = _mm_mul_ps(m[3][1], v[1]);
    
        t0 = _mm_hadd_ps(t0, t1);
        t2 = _mm_hadd_ps(t2, t3);
        r1 = _mm_hadd_ps(t0, t2);
    
        t0 = _mm_mul_ps(m[4][0], v[0]);
        t1 = _mm_mul_ps(m[5][0], v[0]);
        t2 = _mm_mul_ps(m[6][0], v[0]);
        t3 = _mm_mul_ps(m[7][0], v[0]);
    
        t0 = _mm_hadd_ps(t0, t1);
        t2 = _mm_hadd_ps(t2, t3);
        r2 = _mm_hadd_ps(t0, t2);
    
        t0 = _mm_mul_ps(m[4][1], v[1]);
        t1 = _mm_mul_ps(m[5][1], v[1]);
        t2 = _mm_mul_ps(m[6][1], v[1]);
        t3 = _mm_mul_ps(m[7][1], v[1]);
    
        t0 = _mm_hadd_ps(t0, t1);
        t2 = _mm_hadd_ps(t2, t3);
        r3 = _mm_hadd_ps(t0, t2);
    
        r[0] = _mm_add_ps(r0, r1);
        r[1] = _mm_add_ps(r2, r3);
    }
    

    As for alignment, a variable of a type __m128 should be automatically aligned on the stack. With dynamic memory, this is not a safe assumption. Some malloc / new implementations may only return memory guaranteed to be 8-byte aligned.

    The intrinsics header provides _mm_malloc and _mm_free. The align parameter should be (16) in this case.

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

Sidebar

Related Questions

The initial problem starts like this. There are 6 states. At each state when
I am working on access a database using F# and my initial attempt at
I have HTML like this: <div> <div class=a> content1 </div> content 2 <div class=a>
I use parameterized queries, like this: SELECT * FROM foo WHERE bar = :p0
How can I set an element to have multiple classes? Initial attempt: element.setAttribute(class,class1,class2); element.className=class1
I've been trying to implement a huffman decoder, and my initial attempt suffered from
I practiced an array of strings with no initial values. Attempt 1 #include <stdio.h>
I'm trying to teach myself some C++ and as an initial project, I want
Initial tests indicate that GDI+ (writing in VB.NET) is not fast enough for my
My initial question was here and was related to the postgres backend. Postgres subquery,

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.