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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:34:16+00:00 2026-05-24T00:34:16+00:00

I am looking for doing shl(mult(var1,var2),1) operation, where mult multiplies var1 and var2 (both

  • 0

I am looking for doing shl(mult(var1,var2),1) operation, where mult multiplies var1 and var2 (both are 16-bit signed integers) and shl shifts left arithmetically the multiplication result. Result must be saturated, i.e., int32 max or int32 min if overflow or underflow occurs and mult(-32768,-32768)=2147483647.

I need to make this op for multiple values in an efficient way for which I think using MMX/SSE instruction set. I though about making mult(sign_extesion(var1), shl(sign_extension(var2))) but I’ve just discovered no MMX mult() saturation version exists. Do you know any other way to get it?

  • 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-24T00:34:18+00:00Added an answer on May 24, 2026 at 12:34 am

    I think the following should work for you. There is only one potential overflow case (SHRT_MIN * SHRT_MIN) and it handles this explicitly:

    #include <limits.h>
    #include <mmintrin.h>
    
    int main(void)
    {        
        __m64 v1 = _mm_set_pi16(0, SHRT_MAX, 0, SHRT_MIN);
        __m64 v2 = _mm_set_pi16(0, SHRT_MIN, 0, SHRT_MIN);
        __m64 v = _mm_madd_pi16(v1, v2); // 16 x 16 signed multiply
        v = _mm_slli_pi32(v, 1);         // shift left by 1 bit to get full range
        __m64 vcmp = _mm_cmpeq_pi32(v, _mm_set1_pi32(INT_MIN));
                                         // test for SHRT_MIN * SHRT_MIN overflow
        v = _mm_add_pi32(v, vcmp);       // and correct if needed
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking at a complex bit of JavaScript, which is doing all sorts of
I'm looking for doing a Pivot Table query in vb.net. I've found a lot
I'm looking for another way of doing the following: function call_any_function(func, parameters){ // func
I'm doing a grad-school software engineering project and I'm looking for the protocol that
I have JavaScript that is doing activity periodically. When the user is not looking
I've been looking into JOIN, subqueries and other ways of doing this, but I
We're currently looking into doing some performance tweaking on a website which relies heavily
The specific thing I am looking at doing can be found on the App
I am looking at doing a small web application for learning purposes, using .NET.
I'm looking at doing some initial tests and experiments with a toy language and

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.