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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:53:33+00:00 2026-05-11T05:53:33+00:00

I have highly optimized piece of C++ and making even small changes in places

  • 0

I have highly optimized piece of C++ and making even small changes in places far from hot spots can hit performance as much as 20%. After deeper investigation it turned out to be (probably) slightly different registers used in hot spots. I can control inlineing with always_inline attribute, but can I control register allocation?

  • 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. 2026-05-11T05:53:34+00:00Added an answer on May 11, 2026 at 5:53 am

    If you really want to mess with the register alloation then you can force GCC to allocate local and global variables in certain registers.

    You do this with a special variable declaration like this:

     register int test_integer asm ('EBX'); 

    Works for other architectures as well, just replace EBX with a target specific register name.

    For more info on this I suggest you take a look at the gcc documentation:

    http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Local-Reg-Vars.html

    My suggestion however is not to mess with the register allocation unless you have very good reasons for it. If you allocate some registers yourself the allocator has less registers to work with and you may end up with a code that is worse than the code you started with.

    If your function is that performance critical that you get 20% performance differences between compiles it may be a good idea to write that thing in inline-assembler.


    EDIT: As strager pointed out the compiler is not forced to use the register for the variable. It’s only forced to use the register if the variable is used at all. E.g. if the variable it does not survive an optimization pass it won’t be used. Also the register can be used for other variables as well.

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

Sidebar

Related Questions

Sometimes, it would be convenient to have a highly optimized function for regex search
I have intranet highly user interactive ASP.net applications, which now I am going to
I have a web-based application which is very highly reliant on jquery / javascript,
Have someone tried out DeCAL in Delphi 2009? I'm thinking about upgrading from 2007,
have not tested on windows. but in ubuntu when u disconnect from the network,
We have an app with highly interrelated data, i.e. there are many cases where
I have a highly complicated web site that is under source control and has
I have a project I need to be working on from two different computers,
I have the following (highly simplified) XML document that I am reading into my
I have been asked to develop a highly secure B2B File Transfer system between

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.