How to detect -Os (smaller rather then faster) optimization in code? lazarus / 62-General ---------------------------------------------------------------------- avra · 2021-07-12 08:46 I would like optional inlining of some methods depending on -Os optimization setting. How can I detect in code if this optimization is active? I failed to find relevant info. ---------------------------------------------------------------------- marcov · 2021-07-12 09:02 Afaik all inline depends on the complexity metric of a function being lower than some threshold. I assume for size optimization that threshold is lower and zero. Short answer: besides on or off, inlining is not under the user's influence afaik Only short options are testable with $ifopt, and that is only level 2 optimization ---------------------------------------------------------------------- avra · 2021-07-12 09:26 Quote from: marcov on July 12, 2021, 11:02:39 ambesides on or off, inlining is not under the user's influence afaikI meant my own inlining, not compiler decided inlining. I have a type helper where I would like to have a specific method inlined or not, depending on -Os active or not. Quote from: marcov on July 12, 2021, 11:02:39 amOnly short options are testable with $ifopt, and that is only level 2 optimizationSo there is no short option for $OPTIMIZATION SIZE that I can use in my type helper method to detect if specific optimization is active? Something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure SetBit(const aIndex: TQuadwordBits; const aNewValue: boolean); {$IFOPT SOME_SHORT_NAME_FOR_OPT_SIZE_SWITCH+} {$ELSE} inline;{$ENDIF}Is it sensible/reasonable to ask for it in bug tracker? Thanks! I appreciate your input. ---------------------------------------------------------------------- marcov · 2021-07-12 09:44 I don't think there is one. You can file a bugreport of course, though personally I think this is a bit over the top. Even if people agree, I suspect it wouldn't be the fastest resolved bug in history :-) Simply add a define to your build modes seems a way more logical way of going about it. ---------------------------------------------------------------------- jamie · 2021-07-12 10:34 I think it depends if this is a Runtime option or a compile time option ? For me what I do is use the custom options in the IDE and add a define for compile options.. You won't see the define in your source code but the compiler will.  As for runtime, if you are dealing with helpers and want to diverge an operation due to how it's getting called then you may have issues. ---------------------------------------------------------------------- avra · 2021-07-12 11:53 Quote from: marcov on July 12, 2021, 11:44:12 amSimply add a define to your build modes seems a way more logical way of going about it.I do not find that practical. I was hoping to get my code intentionally and controllably smaller or faster (by controlling inlining optimization by me and not letting compiler decide), based just on a check if the user has set -Os or appropriate checkbox in IDE or command line. If that wouldn't be a complete misunderstanding or misuse of -Os on my side then I will file a bugreport anyway. I do see a usecase for such a feature. Quote from: jamie on July 12, 2021, 12:34:01 pmI think it depends if this is a Runtime option or a compile time option ?Compile time. User does or does not set this checkbox: Lazarus / Project / Project Options / Compiler Options / Compilation and Linking / Smaller rather then faster (-Os). I want to detect it to decide if my code should use inline or not. Thanks! ---------------------------------------------------------------------- marcov · 2021-07-12 14:37 Quote from: avra on July 12, 2021, 01:53:40 pmQuote from: marcov on July 12, 2021, 11:44:12 amSimply add a define to your build modes seems a way more logical way of going about it.I do not find that practical. I was hoping to get my code intentionally and controllably smaller or faster (by controlling inlining optimization by me and not letting compiler decide), Inline is always a hint only, never a guarantee. ---------------------------------------------------------------------- jamie · 2021-07-12 15:56 I see that Borland C++ has the _Always_Inline option.. So the Borland boys must of thought being like the others was important!