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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:33:06+00:00 2026-06-13T14:33:06+00:00

I have a simple problem. Having a starting uint_32 value (say 125) and a

  • 0

I have a simple problem. Having a starting uint_32 value (say 125) and a __m128i of operands to add, for example (+5,+10,-1,-5). What I would like to get as fast as possible is a vector (125 + 5, 125 + 5 + 10, 125 + 5 + 10 – 1, 125 + 5 + 10 – 1 – 5), i.e. cumulatively add values from the operands to the starting value. So far the only solution I can think of is doing an addition of 4 __m128i variables. For the example, they would be

/* pseudoSSE code... */
__m128i src =     (125,125,125,125)
__m128i operands =(5,10,-1,-5)

/*  Here I omit the partitioning of operands into add1,..add4 for brevity  */

__m128i add1 =    (+05,+05,+05,+05)
__m128i add2 =    (+00,+10,+10,+10)
__m128i add3 =    (+00,+00,-01,-01)
__m128i add4 =    (+00,+00,+00,-05)
__m128i res1 = _mm_add_epu32( add1, add2 )
__m128i res2 = _mm_add_epu32( add3, add4 )
__m128i res3 = _mm_add_epu32( res1, add2 )
__m128i res  = _mm_add_epu32( res3, src  )

Like this, I get what I wanted. For this solution I am going to need to set all add_ variables and then perform 4 additions. What Im really asking is whether this can be done faster. Either via some different algo or maybe using some specialized SSE functions that I do not know yet (something like _mm_cumulative_sum()). Many thanks.

  • 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-13T14:33:07+00:00Added an answer on June 13, 2026 at 2:33 pm

    Thank you all guys for your help. Determined to figure out which version is the fastest, I wrote a test app.

    1/ nonSSE version does all the stuff just as you would expect.

    int iRep;
    int iCycle;
    int iVal = 25;
    int a1, a2, a3, a4;
    int dst1 [4];
    for ( iCycle = 0; iCycle < CYCLE_COUNT; iCycle++ )
        for ( iRep = 0; iRep < REP_COUNT; iRep++ )
            {   
              a1 = a2 = a3 = a4 = iRep;
              dst1[0] = iVal + a1;
              dst1[1] = dst1[0] + a2;
              dst1[2] = dst1[1] + a3;
              dst1[3] = dst1[2] + a4;
            }
    

    2/ SSE-4 additions does what I proposed, i.e.

    __m128i _a1, _a2, _a3, _a4;
    __m128i _res1, _res2, _res3;
    __m128i _val;
    __m128i _res;
    
    for ( iCycle = 0; iCycle < CYCLE_COUNT; iCycle++ )
        for ( iRep = 0; iRep < REP_COUNT; iRep++ ){ 
            a1 = a2 = a3 = a4 = iRep;
    
            _val = _mm_set1_epi32( iVal );
            _a1  = _mm_set_epi32 (a1, a1, a1, a1 );
            _a2  = _mm_set_epi32 (a2, a2, a2, 0  );
            _a3  = _mm_set_epi32 (a3, a3, 0 , 0  );
            _a4  = _mm_set_epi32 (a4, 0 , 0 , 0  );
    
            _res1 = _mm_add_epi32( _a1, _a2     );
            _res2 = _mm_add_epi32( _a3, _a4     );
            _res3 = _mm_add_epi32( _val, _res1  );
            _res  = _mm_add_epi32( _res3, _res2 );
        }
    

    3/ SSE-3 additions does what Evgeny proposed, i.e.

    __m128i shift1, shift2, operands ;
    for ( iCycle = 0; iCycle < CYCLE_COUNT; iCycle++ )
        for ( iRep = 0; iRep < REP_COUNT; iRep++ ){ 
            a1 = a2 = a3 = a4 = iRep;
    
            _val = _mm_set1_epi32( iVal );
            operands = _mm_set_epi32(a1,a2,a3,a4);
    
            shift1 = _mm_add_epi32( operands,               
                     _mm_and_si128(_mm_shuffle_epi32(operands, 0xF9),   _mm_set_epi32(0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF)   ));
            shift2 = _mm_add_epi32( shift1, 
                     _mm_and_si128(_mm_shuffle_epi32(shift1, 0xFE),     _mm_set_epi32(0,0,0xFFFFFFFF,0xFFFFFFFF)            ));
            _res = _mm_add_epi32(_val, shift2); 
            }
    

    The results for

     #define REP_COUNT    100000
     #define CYCLE_COUNT  100000
    

    are

      non-SSE        -> 6.118s
      SSE-4additions -> 20.775s
      SSE-3additions -> 14.873s
    

    Rather surprising…

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

Sidebar

Related Questions

I'm having trouble solving this problem. I have to find all simple paths starting
hey guys having this really simple problem but cant seem to figure out have
I have a simple problem with SQL SERVER charindex function. DECLARE @VAR1 varchar SET
I have a simple problem that I have not been able to find an
I have a simple problem while putting text in multiple table! please have a
I have a simple problem that I've been stuck on for some time and
I have a simple problem that i cannot solve. I have a dictionary: aa
I have a simple problem but I am not sure how to solve it.
I have a simple problem but no matter what I try I can't see
I have a simple problem with XML got from database. Now, this XML can

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.