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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:32:52+00:00 2026-06-04T16:32:52+00:00

I am trying to speed up my method using SSE (On Visual Studio). I

  • 0

I am trying to speed up my method using SSE (On Visual Studio). I am a novice in the area. The main data types I work with in my method are bitsets of size 32 and the logical operation I mainly use is the AND operation (with _BitScanForward scarcely used). I was wondering if SSE instructions can be used to speed up my procedures.

This is how I am doing right now (I am completely done and cannot compare results directly):

I load the operands (bitsets) using _mm_set_ps. I use the to_ulong() on bitsets to convert them to unsigned long integers:

__m128 v1 = _mm_set_ps(b1.to_ulong(),b2.to_ulong(),b3.to_ulong(),b4.to_ulong());
__m128 v2 = _mm_set1_ps(b.to_ulong())

This is followed by the actual AND operation:

__m128 v3 = _mm_and_ps(v1,v2);

At this point, I have two questions:

  1. Is the way I am doing it (converting bitsets to unsigned long integers using to_ulong()) a good way to do it? I suspect that there is a large overhead that may kill the potential performance improvement I may get out of using SSE.

  2. What is the best way to store v3 back on memory in the shape of 4 bitsets? I am planning to use the _mm_storeu_ps intrinsic.

  • 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-04T16:32:54+00:00Added an answer on June 4, 2026 at 4:32 pm

    A couple of things:

    • if your bit sets are basically 32 bit ints then you should be using a suitable integer SIMD type, i.e. __m128i, not floating point (__m128)

    • _mm_set_XXX macros are relatively expensive – unlike regular SSE intrinsics they can generate quite a few instructions – if all you are doing is one AND operation then any performance benefit from the _mm_and_XXX operation will be more than wiped out by the cost of the _mm_set_XXX operations

    Ideally if you just want to AND a bunch of bit sets in arrays then the code should look something like this:

    const int N = 1024;
    
    int32_t b1[N]; // 2 x arrays of input bit sets
    int32_t b2[N];
    int32_t b3[N]; // 1 x array of output bit sets
    
    for (int i = 0; i < N; i += 4)
    {
        __m128i v1 = _mm_loadu_si128(&b1[i]); // load input bits sets
        __m128i v2 = _mm_loadu_si128(&b2[i]);
        __m128i v3 = _mm_and_si128(v1, v2);   // do the bitwise AND
        _mm_storeu_si128(&b3[i], v3);         // store the result
    }
    

    If you just want to AND an array in-place with a fixed mask then it would simplify to this:

    const int N = 1024;
    
    int32_t b1[N]; // input/output array of bit sets
    
    const __m128i v2 = _mm_set1_epi32(0x12345678); // mask
    
    for (int i = 0; i < N; i += 4)
    {
        __m128i v1 = _mm_loadu_si128(&b1[i]); // load input bits sets
        __m128i v3 = _mm_and_si128(v1, v2);   // do the bitwise AND
        _mm_storeu_si128(&b1[i], v3);         // store the result
    }
    

    Note: for better performance make sure your input/output arrays are 16 byte aligned and then use _mm_load_si128/_mm_store_si128 rather than their unaligned counterparts as above.

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

Sidebar

Related Questions

I am trying to speed up an often used query. Using a CompiledQuery seemed
I'm trying to speed up a large RSpec project's tests. In addition to using
I'm trying to get up to speed on using GWT Activities and Places. I'm
I'm trying to use Entity Framework for my model/data access, and running into speed
I'm trying to seed my database with the standard db/seeds.rb method. This works fine
I am trying to speed my gui that loads very slow slow when I
I was trying to speed up some code, and then I tried compiling a
I'm trying to speed up (or slow down) the Galleria imageslider by button. Is
I'm trying to speed up my code because it's running very long. I already
I am in a crucial project and I am trying to speed up the

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.