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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:37:01+00:00 2026-06-07T17:37:01+00:00

I have a function that needs to be as fast as possible, and it

  • 0

I have a function that needs to be as fast as possible, and it uses only integer operations. It runs on the AMD64 architecture, and I need to do a few push/pops in order to have enough registers to work with. Now I’m wondering, the x64 ABI states that the first four floating-point registers (XMM0, XMM1, XMM2, and XMM3) are volatile and do not need to be preserved across function calls.

So I figured I could store the 64-bit registers I need to preserve in the lower 64 bits of those registers (i.e. MM0, MM1, …) via movq (MMX or SSE instruction set) instead of using the stack, saving myself a few memory load/stores. Furthermore I wouldn’t need to store the FPU state using EMMS – which would defeat the purpose – since I am not actually manipulating the floating-point registers but only using them as storage (and anyway, the x87 unit is hardly used at all under x64, as it is essentially superseded by SSE)

I have done the modification and it works (no crashes, and an observable 4% increase in performance), but I am wondering, does this “hack” really work or would it introduce any particular side effects I might have missed (like FPU state corruption even though I don’t use it, that sort of thing). And will load/storing to an FPU register always be faster than a memory load/store on any current architecture?

And, yes, this optimization is really needed. And to be fair, this isn’t something that would severely degrade code maintenance cost, a one-line comment would be enough to explain the trick. So if I can get a couple less clocks per byte for free with no unintended consequences, I’ll gladly take them 🙂

Thanks.

  • 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-07T17:37:03+00:00Added an answer on June 7, 2026 at 5:37 pm

    The EMMS instruction is only necessary to clear the state after MMX operations. SSE instructions do not require it. So that certainly won’t conflict.

    Of course, you should keep in mind that different compilers and OS’es use different calling conventions, and some may treat those four registers differently.

    However, as long as that is kept in mind, I don’t see a problem with this approach. You’re using all registers the way they’re supposed to be used according to the ABI.

    And assuming this is written in assembly, there’s no need to consider whether this may hinder compiler optimization (a C/C++ function which dives into ASM and starts talking about specific registers makes it a lot harder for the compiler to optimize the code)

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

Sidebar

Related Questions

I have a function that needs to access a variable in its parent environment
I have a function that needs to call a virtual method many times in
I have a function that needs to append a sequence of numbers (starting with
I have a c# function that needs to write to a SQL image column.
I have a function that might fail, so the value it returns needs to
We have a moderate size (40-odd function) C API that needs to be called
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;
I have a win form that creates a site in IIS7. One function needs
I have a function that i need to call on iframe mousemove(). But i
I have a database that I need to query over and over as fast

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.