C++ Logo

std-proposals

Advanced search

Re: [std-proposals] 回复: A Proposal about A New Keyword assure

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Mon, 2 Jun 2025 05:03:36 +0200
Do you propose to recommend/specify to the compiler at the caller site, which optimizations can be selected?   If the function is not inlined and you want to use a different function entry point to skip some code and branches, then it would be quite random, whether that is possible.    - If the function is not generated in the same translation unit, the object files or libraries have to somehow store those entry points.  - The compiler would be much more effective to generate that flexibility, if it had a notion or list of possible assurances  - Beside assert/assume/contracts there is also the possibility to provide boolean expressions as function parameters or template parameters or as overloaded parameter types       sqrt(positivedouble d)       sqrt(double d, bool positive = false)       template<bool positive = false> sqrt(double d)    You would have to specify, how your solution is different and what improvements it brings to the table.   -----Ursprüngliche Nachricht----- Von:SD SH <Z5515zwy_at_[hidden]> Gesendet:So 01.06.2025 17:32 Betreff:回复: [std-proposals] A Proposal about A New Keyword assure An:std-proposals_at_[hidden]; CC:Sebastian Wittmeier <wittmeier_at_[hidden]>; True, but not only inlined functions. It can make compiler jump to the excepted branch without redundant check-ups. We can even use 1 function and many tag. Like this:   _func: ; fastcall ; rcx = int para1 ; rdx = bool para2 cmp rdx, 0 jne _func_para2_true cmp rcx, 0 jl _func_para2_true_para1_l0 _func_para2_false_para1_geq0 ; ... ret _func_para2_true: ; ... ret _func_para2_true_para1_l0: ; ... ret   In fact, even if compiler not inlined the function, it still works. For example, _func(i assure(i >= 0, b assure(!b)) will be:     call _func_para2_false_para1_geq0 And 2 branches will be skipped.   I think compiler couldn't do above well.  

Received on 2025-06-02 03:11:35