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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:57:29+00:00 2026-05-29T09:57:29+00:00

This a follow-up question to this one . Now I would like to convert

  • 0

This a follow-up question to this one. Now I would like to convert in the opposite direction float –> unsigned int.
What is the optimal and accurate vector sequence of the following scalar operation?

float x = ...
unsigned int res = (unsigned int)x;
  • 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-29T09:57:30+00:00Added an answer on May 29, 2026 at 9:57 am

    This is based on an example from the old but useful Apple AltiVec-SSE migration documentation which unfortunately is now no longer available at http://developer.apple.com:

    inline __m128i _mm_ctu_ps(const __m128 f)
    {
        const __m128 two31 = _mm_set1_ps(0x1.0p31f);
        const __m128 two32 = _mm_add_ps(two31, two31);
        const __m128 zero = _mm_xor_ps(f,f);
    
        // check for overflow before conversion to int
        const __m128 overflow = _mm_cmpge_ps(f, two31);
        const __m128 overflow2 = _mm_cmpge_ps(f, two32);
        const __m128 subval = _mm_and_ps(overflow, two31);
        const __m128i addval = _mm_slli_epi32((__m128i)overflow, 31);
        __m128i result;
    
        // bias the value to signed space if it is >= 2**31
        f = _mm_sub_ps(f, subval);
    
        // clip at zero
        f = _mm_max_ps(f, zero);
    
        // convert to int with saturation
        result = _mm_cvtps_epi32(f); // rounding mode should be round to nearest
    
        // unbias
        result = _mm_add_epi32(result, addval);
    
        // patch up the overflow case
        result = _mm_or_si128(result, (__m128i)overflow2);
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a follow up question to this one . Now that I have
This is like a follow-up question to this one . Basically what I'm doing
This is a follow-up question to this one . Take a look at these
This is a follow-on question from the one I asked here . Can constraints
I have a follow-up question to this one . I created a new form,
This is really a follow on question to a previous one , where I
This question is a follow up on one of my other questions, Can I
This question is a follow on from this one ... I am binding to
This is a follow-up question to my previous one . Situation: Table 1: +--------------------+--------------------+
This is a follow-up questions on a previous one . Consider this code, which

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.