0

Can anyone link me to an example of how to use #pragma optimize("some_values_for_02", on) in order to mimic the global 02 optimization for a select few functions.

I have looked around in the msdn docs and also on SO, this is the best ive seen so far: In VC++ what is the #pragma equivalent of /O2 compiler option (optimize for speed)

That answer's link is no longer active though.

What does the syntax look like? Do I need to use multiple #pragmas to mimic the 02 optimization? The linked answer mentions trying to add #pragma intrinsic and #pragma auto_inline

If you can point me to source in the wild that i can read as an example that could work too.

Thanks

Bwebb
  • 675
  • 4
  • 14

1 Answers1

1

/O2 == /Og /Oi /Ot /Oy /Ob2 /GF /Gy. Step by step:

  • /Og: Global Optimizations:

    /Og is deprecated. These optimizations are now generally enabled by default

    ~> don't care. Anyway:

    You can enable or disable global optimization on a function-by-function basis using the optimize pragma together with the g option.

    #pragma optimize("g", on)
    


  • /Oi: intrinsic

    #pragma intrinsic(_disable, _outp, fabs, strcmp, _enable, _outpw, labs, strcpy,
                      _inp, _rotl, memcmp, strlen, _inpw, _rotr, memcpy, _lrotl,
                      _strset, memset, _lrotr, abs, strcat)
    


  • /Ot: optimize

    #pragma optimize("t", on)
    


  • /Oy: optimize

    #pragma optimize("y", on)
    


  • /Ob2 Inline Function Expansion:

    The compiler treats the inline expansion options and keywords as suggestions. There is no guarantee that any function will be expanded inline. You can disable inline expansions, but you cannot force the compiler to inline a particular function, even when using the __forceinline keyword.

    ~> Don't care.


  • /GF dunno.

  • /Gy dunno.


End result:

#pragma intrinsic(_disable, _outp, fabs, strcmp, _enable, _outpw, labs, strcpy,
                  _inp, _rotl, memcmp, strlen, _inpw, _rotr, memcpy, _lrotl,
                  _strset, memset, _lrotr, abs, strcat)
#pragma optimize("gty", on)

Just one last thing: Why??

Swordfish
  • 12,971
  • 3
  • 21
  • 43
  • I dont want to affect a whole project with decades old legacy code, but I added an ISR on a seperate thread that runs millions of times a minute and i want to minimize the instruction set or more importantly the execution time. – Bwebb Feb 26 '19 at 22:55