4.15 Methods of minimizing function parameter passing overhead

There are a number of ways in which you can minimize the overhead of passing parameters to functions.

For example:
  • Ensure that functions take four or fewer arguments if each argument is a word or less in size. In C++, ensure that nonstatic member functions take three or fewer arguments because of the implicit this pointer argument that is usually passed in R0.
  • Ensure that a function does a significant amount of work if it requires more than four arguments, so that the cost of passing the stacked arguments is outweighed.
  • Put related arguments in a structure, and pass a pointer to the structure in any function call. This reduces the number of parameters and increases readability.
  • Minimize the number of long long parameters, because these take two argument words that have to be aligned on an even register index.
  • Minimize the number of double parameters when using software floating-point.
  • Avoid functions with a variable number of parameters. Functions taking a variable number of arguments effectively pass all their arguments on the stack.
Related concepts
4.16 Returning structures from functions through registers
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.