Date: Mon, 2 Jun 2025 04:55:00 +0000
Yes. So it can only be used if you know what branch will be (may be) check.
We don't know what paraments will be entered in callee, but we know in caller. So unction programmer can only think about what it need to do in all cases, and caller uses assure to choose entry point.
*
Store entry points?
No. Caller just finds the case it need.
*
Why don't use template?
The size of code using template is too large and it is too slow.
In many cases, different cases can be generated to the same code, it's much smaller and faster.
Template need more effort to program.
*
Other reasons of using assure?
It's clearer.
________________________________
发件人: Std-Proposals <std-proposals-bounces_at_[hidden]> 代表 Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]>
发送时间: 2025年6月2日 11:03
收件人: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
抄送: Sebastian Wittmeier <wittmeier_at_projectalpha.org>
主题: Re: [std-proposals] 回复: A Proposal about A New Keyword assure
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.
We don't know what paraments will be entered in callee, but we know in caller. So unction programmer can only think about what it need to do in all cases, and caller uses assure to choose entry point.
*
Store entry points?
No. Caller just finds the case it need.
*
Why don't use template?
The size of code using template is too large and it is too slow.
In many cases, different cases can be generated to the same code, it's much smaller and faster.
Template need more effort to program.
*
Other reasons of using assure?
It's clearer.
________________________________
发件人: Std-Proposals <std-proposals-bounces_at_[hidden]> 代表 Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]>
发送时间: 2025年6月2日 11:03
收件人: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
抄送: Sebastian Wittmeier <wittmeier_at_projectalpha.org>
主题: Re: [std-proposals] 回复: A Proposal about A New Keyword assure
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 04:55:06