Products & Services Solutions Academia Support User Community Company

eml.inline - Control inlining in generated code

Syntax

eml.inline('always')
eml.inline('never')
eml.inline('default')

Description

eml.inline('always') forces inlining of the current function in generated code.

eml.inline('never') prevents inlining of the current function in generated code. For example, you may want to prevent inlining to simplify the mapping between the M-source code and the generated C code.

eml.inline('default') uses internal heuristics to determine whether or not to inline the current function.

In most cases, the heuristics used by the Embedded MATLAB subset produce highly optimized code. Use eml.inline only when you need to fine-tune these optimizations.

Place the eml.inline directive inside the function to which it applies.

Examples

Preventing Function Inlining

In this simple example, function foo will not be inlined in the generated code.

function y = foo(x)
  eml.inline('never');
  y = x;
end

Using eml.inline In Control Flow Statements

You can use eml.inline in control flow code. When the Embedded MATLAB subset detects contradictory eml.inline directives, it uses the default inlining heuristic and issues a warning.

Suppose you want to generate code for a division function that will be embedded in a system with limited memory. To optimize memory use in the generated code, the following function safe_division manually controls inlining based on whether it performs scalar division or vector division.

function y = safe_division(dividend, divisor)

% For scalar division, inlining produces smaller code
% than the function call itself.  
if isscalar(dividend) && isscalar(divisor)
   eml.inline('always');
else
% Vector division produces a for-loop.
% Prohibit inlining to reduce code size.
   eml.inline('never');
end

if any(divisor == 0)
   error('Can not divide by 0');
end

y = dividend / divisor;
  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS