Opened 9 years ago

Last modified 9 years ago

#3510 assigned defect

inline function

Reported by: Vitalij Ruge Owned by: Willi Braun
Priority: critical Milestone: Future
Component: *unknown* Version:
Keywords: inline function Cc:

Description

OM generate for the following example:

model foo
  function f
    input Real x;
    output Real y;
  protected
    Real tmp1;
    Real tmp2;
  algorithm
    tmp1 := sin(x) + 1 + 2 + 3 + 4 + 5;
    tmp2 := cos(tmp1) * tmp1 - tmp1;
    y := exp(tmp1 * tmp2) + abs(tmp1);
    annotation(Inline = true);
  end f;

  Real y = f(time ^ 2);
end foo;

the following code:

y = exp((15.0 + sin(time ^ 2.0)) * (cos(15.0 + sin(time ^ 2.0)) * (15.0 + sin(time ^ 2.0)) - (15.0 + sin(time ^ 2.0)))) + abs(15.0 + sin(time ^ 2.0))

The tmp-vars are removed. (probaly losing a lot of speed)

In the spec. p. 214 we find:

If “Inline = true”, the model developer proposes to inline the function. This
means, that the body of the function is included at all places where the function is
called.

expectation code with function body:

model foo
  Real f_x_1 = time ^ 2;
  Real f_tmp1_1 = sin(f_x_1) + 1 + 2 + 3 + 4 + 5;
  Real f_tmp2_1 = cos(f_tmp1_1) * f_tmp1_1- f_tmp1_1;
  Real f_y_1 = exp(f_tmp1_1* f_tmp2_1) + abs(f_tmp1_1);
  Real y = f_y_1;
end foo;

Change History (1)

comment:1 by Vitalij Ruge, 9 years ago

Owner: changed from somebody to Willi Braun
Status: newassigned
Note: See TracTickets for help on using tickets.