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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:20:38+00:00 2026-06-14T06:20:38+00:00

I have an unsigned short dst[16][16] matrix and a larger unsigned char src[m][n] matrix.

  • 0

I have an unsigned short dst[16][16] matrix and a larger unsigned char src[m][n] matrix.

Now I have to access in the src matrix and add a 16×16 submatrix to dst, using SSE2 or SSE3.

In an older implementation, I was sure that my summed values were never greater than 256, so I could do this:

for (int row = 0; row < 16; ++row)
{
    __m128i subMat = _mm_lddqu_si128(reinterpret_cast<const __m128i*>(src));
    dst[row] = _mm_add_epi8(dst[row], subMat);
    src += W; // Step to the next row I need to add
}

where W is an offset to reach the desired rows. This code works, but now my values in src are larger and summed could be greater than 256, so I need to store them as ushort.

I’ve tried the following, but it doesn’t work.

for (int row = 0; row < 16; ++row)
{
    __m128i subMat = _mm_lddqu_si128(reinterpret_cast<const __m128i*>(src));
    dst[row] = _mm_add_epi16(dst[row], subMat);
    src += W; // Step to the next row I need to add
}

How can I solve this problem?

EDIT

Thank you paul, but I think your offsets are wrong. I’ve tried your solution and seems that submatrix’s rows are added to the wrong dst’s rows. I hope the right solution is this:

for (int row = 0; row < 32; row += 2)
{
    __m128i subMat = _mm_lddqu_si128(reinterpret_cast<const __m128i*>(src));
    __m128i subMatLo = _mm_unpacklo_epi8(subMat, _mm_set1_epi8(0));
    __m128i subMatHi = _mm_unpackhi_epi8(subMat, _mm_set1_epi8(0));
    dst[row] = _mm_add_epi16(dst[row], subMatLo);
    dst[row + 1] = _mm_add_epi16(dst[row + 1], subMatHi);
    src += W;
}
  • 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-14T06:20:39+00:00Added an answer on June 14, 2026 at 6:20 am

    You need to unpack your vector of 16 x 8 bit values into two vectors of 8 x 16 bit values and then add both these vectors to your destination:

    for (int row = 0; row < 16; ++row)
    {
        __m128i subMat = _mm_lddqu_si128(reinterpret_cast<const __m128i*>(src));
        __m128i subMatLo = _mm_unpacklo_epi8(subMat, _mm_set1_epi8(0));
        __m128i subMatHi = _mm_unpackhi_epi8(subMat, _mm_set1_epi8(0));
        dst[row] = _mm_add_epi16(dst[row], subMatLo);
        dst[row + 1] = _mm_add_epi16(dst[row + 1], subMatHi);
        src += W;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem converting a char array to a unsigned short (UInt16). My
I have an unsigned char and I add integers to it but I want
I have a struct wich contains: struct mystruct{ int id[10]; char text[40]; unsigned short
I have an array as follows, unsigned char A[16] I am using this array
I have two variables: unsigned short a,b; /* When I compare them with a
I have such a C++ structure: typedef struct _FILE_OP_BLOCK { unsigned short fid; //
I have the following class: #include <array> template<unsigned short D> class Point { private:
I have unsigned char* , want to convert it to std::string . Can you
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr
I have an application where i HAVE to store unsigned short data in 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.