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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:36:46+00:00 2026-06-18T02:36:46+00:00

__m128* pSrc1 = (__m128*) string; __m128 m0 = _mm_set_ps1(0); //null character while(1) { __m128

  • 0
__m128* pSrc1 = (__m128*) string;
__m128 m0 = _mm_set_ps1(0);    //null character

while(1)
{
    __m128 result = __m128 _mm_cmpeq_ss(*pSrc1, m0);

    //if character is \0 then break

    //do some stuff here

    pSrc1++;
}

I have a string whose length can be a multiple of 16.
How do I break out of the loop if _mm_cmpeq_ss returns equal?

  • 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-18T02:36:47+00:00Added an answer on June 18, 2026 at 2:36 am

    If you’re trying to break out of the loop when you first encounter a \0 then you’ll need to do something like this:

    __m128i* pSrc1 = (__m128i *)string;         // init pointer to start of string
    __m128i m0 = _mm_set1_epi8(0);              // vector of 16 `\0` characters
    
    while (1)
    {
        __m128i v0 = _mm_loadu_si128(pSrc1);    // get 16 chars from string
        __m128i v1 = _mm_cmpeq_epi8(v0, m0);    // compare all 16 chars with '\0'
        int vmask = _mm_movemask_epi8(v1);      // get 16 comparison result bits
        if (vmask != 0)                         // if any bit is 1
            break;                              // we found a `\0`, break out of loop
        pSrc1++;                                // next 16 characters...
    }
    

    If you only want to test for \0 characters in certain positions and ignore any others then you can change the if (vmask != 0) test to something which matches your specific requirements.

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

Sidebar

Related Questions

I have the following piece of C code: __m128 pSrc1 = _mm_set1_ps(4.0f); __m128 pDest;
If I have a class like this: typedef union { __m128 quad; float numbers[4];
I have the code: float *mu_x_ptr; __m128 *tmp; __m128 *mm_mu_x; mu_x_ptr = _aligned_malloc(4*sizeof(float), 16);
I'm working on converting a bit of code to SSE, and while I have
In some code I have converted to SSE I preform some ray tracing, tracing
I've been trying my hand at optimising some code I have using microsoft's sse
I've got some code written using the MSVC SSE intrinsics. __m128 zero = _mm_setzero_ps();
I know that for the code below, Illegal below is undefined (while some compilers
Can I have a union like this union eight_floats_t { __m256 a; __m128 b[2];
I am trying to make some optimized code using SSE2 instructions. Currently, i have

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.