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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:28:09+00:00 2026-06-05T00:28:09+00:00

I am working with SSE2 instruction set in MS Visual Studio. I am using

  • 0

I am working with SSE2 instruction set in MS Visual Studio. I am using it to do some calculations with 16-bit data.

Suppose i have 8 values loaded into a SSE register. I want to add a constant (e.g. 42) to all of them. Here is how i would like my code to look.

__m128i values; // 8 values, 16 bits each
const __m128i my_const_42 = ???; // What should i write here?
values = _mm_add_epi16(values, my_const_2); // Add 42 to the 8 values

Now, how can i define the constant? The following two ways work, but one is inefficient, and the other is ugly.

  1. my_const_42 = _mm_set_epi16(42, 42, 42, 42, 42, 42, 42, 42) – compiler generates 8 commands to “build” the constant
  2. my_const_42 = {42, 0, 42, 0, 42, 0, 42, 0, 42, 0, 42, 0, 42, 0, 42, 0} – hard to understand what is going on; changing 42 to e.g. -42 is not trivial

Is there any way to express the 128-bit constant more conveniently?

  • 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-05T00:28:10+00:00Added an answer on June 5, 2026 at 12:28 am

    Ninety percent of the battle is finding the correct intrinsic. The MSDN Library is pretty well organized, start at this page. From there, drill down like this:

    • You know you want to use “MMX, SSE and SSE2 Intrinsics”, click that link
    • You know you want to use “Streaming SIMD Extensions 2”, click that link
    • Next attractive link is “Integer Memory and Initialization” since you don’t want floating point
    • You’ll get two relevant links, Load and Set Operations
    • Load just gets you the ones you already found

    Set is golden, out pops _mm_set1_epi16 (short w)

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

Sidebar

Related Questions

I have this function which uses SSE2 to add some values together it's supposed
I am working in the optimization of an algorithm using SSE2 instructions. But I
Working with some basic java apps on CentOS 5 linux and I have my
i'm working in Visual Studio 2008 and in the project settings I see the
Working on a website that has Employee and Branch entities, using a database table
Working on a new app and using restful-authentication. I was trying to make it
I'm working on a bit of code and I'm trying to optimize it as
Working sample using one Table SELECT t.* FROM ( SELECT TITLE.name, (TITLE.value-TITLE.msp) AS Lower,
Working with a Lucene index, I have a standard document format that looks something
Working in Java: I have a JFrame class, and separate classes for my two

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.