User Tools

Site Tools


embedded

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
embedded [2020/04/05 18:53] jrsetiembedded [2020/04/05 18:57] (current) – [Tips] jrseti
Line 11: Line 11:
  
 =====Tips===== =====Tips=====
 +
 +On ARM Processors: 
 +
   * Unordered List ItemGenerally local variables are allocated in registers. However if we take the address of a local variable, compiler will not allocate the variable to register.   * Unordered List ItemGenerally local variables are allocated in registers. However if we take the address of a local variable, compiler will not allocate the variable to register.
   * The compiler will never put the global variable into register.   * The compiler will never put the global variable into register.
   * Try to ensure that small functions take four or fewer arguments. These will not use the stack for argument passing. It will copied into registers.   * Try to ensure that small functions take four or fewer arguments. These will not use the stack for argument passing. It will copied into registers.
-  * If a function needs more than four arguments, try to ensure that it does a significant amount of work, so that the cost of passing the stacked arguments is +  * If a function needs more than four arguments, try to ensure that it does a significant amount of work, so that the cost of passing the stacked arguments is outweighed.
-outweighed.+
   * Pass pointers to structures instead of passing the structure itself.   * Pass pointers to structures instead of passing the structure itself.
   * Put related arguments in a structure, and pass a pointer to the structure to functions. This will reduce the number of parameters and increase readability.   * Put related arguments in a structure, and pass a pointer to the structure to functions. This will reduce the number of parameters and increase readability.
   * Minimize the number of long long parameters, as these take two argument words. This also applies to doubles if software floating-point is enabled.   * Minimize the number of long long parameters, as these take two argument words. This also applies to doubles if software floating-point is enabled.
-  * Avoid functions with a parameter that is passed partially in a register and partially on the stack (split-argument). This is not handled efficiently by the current +  * Avoid functions with a parameter that is passed partially in a register and partially on the stack (split-argument). This is not handled efficiently by the current compilers: all register arguments are pushed on the stack.
-compilers: all register arguments are pushed on the stack.+
   * Avoid functions with a variable number of parameters. Varargs functions   * Avoid functions with a variable number of parameters. Varargs functions
 +
 +On Arm there is the "pure" keyword which tells the compiler the computation is all contained within the function so the compiler can optimize it as much as possible. Not dependent on outside variables.
 +
 +Example:
 +<code>
 +__pure int square(int x)
 +{ return x * x;
 +}
 +</code>
  
 =====Integral Types====== =====Integral Types======
embedded.1586112837.txt.gz · Last modified: 2020/04/05 18:53 by jrseti