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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:08:04+00:00 2026-05-27T04:08:04+00:00

I want to multiply the data stored in one xmm register with a single

  • 0

I want to multiply the data stored in one xmm register with a single float value and save the result in a xmm register.
I made a little graphic to explain it a bit better.

enter image description here

As you see I got a xmm0 register with my data in it. For example it contains:

xmm0 = |4.0|2.5|3.5|2.0|

Each floating point is stored in 4 bytes. My xmm0 register is 128 bits, 16 bytes long.

That works pretty good. Now I want to store 0.5 in another xmm register, e.g. xmm1, and multiply this register with the xmm0 register so that each value stored in xmm0 is multiplied with 0.5.

I have absolutely no idea how to store 0.5 in an XMM register.
Any suggestions?

Btw: It’s Inline Assembler in C++.

void filter(image* src_image, image* dst_image)
{
    float* src = src_image->data;
    float* dst = dst_image->data;

    __asm__ __volatile__ (              
        "movaps (%%esi), %%xmm0\n"      
        // Multiply %xmm0 with a float, e.g. 0.5
        "movaps %%xmm0, (%%edi)\n" 

        :
        : "S"(src), "D"(dst) :  
    );
}

This is the quiet simple version of the thing i want to do. I got some image data stored in a float array. The pointer to these arrays are passed to assembly. movaps takes the first 4 float values of the array, stores these 16 bytes in the xmm0 register. After this xmm0 should be multiplied with e.g. 0.5. Than the “new” values shall be stored in the array from edi.

  • 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-27T04:08:05+00:00Added an answer on May 27, 2026 at 4:08 am

    As people noted in comments, for this sort of very simple operation, it’s essentially always better to use intrinsics:

    void filter(image* src_image, image* dst_image)
    {
        const __m128 data = _mm_load_ps(src_image->data);
        const __m128 scaled = _mm_mul_ps(data, _mm_set1_ps(0.5f));
        _mm_store_ps(dst_image->data, scaled);
    }
    

    You should only resort to an inline ASM if the compiler is generating bad code (and only after filing a bug with the compiler vendor).

    If you really want to stay in assembly, there are many ways to accomplish this task. You could define a scale vector outside of the ASM block:

        const __m128 half = _mm_set1_ps(0.5f);
    

    and then use it inside the ASM just like you use other operands.

    You can do it without any loads, if you really want to:

        "mov    $0x3f000000, %%eax\n"  // encoding of 0.5
        "movd   %%eax,       %%xmm1\n" // move to xmm1
        "shufps $0, %%xmm1,  %%xmm1\n" // splat across all lanes of xmm1
    

    Those are just two approaches. There are lots of other ways. You might spend some quality time with the Intel Instruction Set Reference.

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

Sidebar

Related Questions

I want to query some data in multiple tables as if it were one
I want to share a data with multiple processes. My first attempt is to
I am building a query to gather data from multiple tables. I want to
I have multiple SharePoint lists and want to display data from them on to
I am performing data changes on multiple databases, and I want to implement a
In a system with multiple concurrent tasks operating on data, I want to order
I want to multiply long numbers which are given in a 2^32 basis. I
so we have this matrix a=[1;2;3] and we want to multiply it by itself
I have multiple tables . I have created one stored procedure where I am
I want to call multiple MySQL stored routines sequentially with PHP, but I can

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.