指令重新排序 [英] instruction re-ordering
问题描述
各位大家好!
假设我有以下功能:
void
call_once(int *完成,无效(*例程)(无效))
{
if(!(* done)){/ * L1 * /
routine(); / * L2 * /
* done = 1; / * L3 * /
}
}
符合ANSI C标准的编译器有权重新订购L2和L3,即
执行以下序列:
* done = 1;
routine();
提前致谢!
Loic。
loic -... @ gmx.net写道:
各位大家好!
假设我有以下功能:
void
call_once(int * done,void(* routine)(void))
{
if(!(* done) )){/ * L1 * /
routine(); / * L2 * /
* done = 1; / * L3 * /
}
}
符合ANSI C标准的编译器有权重新订购L2和L3,即
执行以下序列:
* done = 1;
routine();
当且仅当它知道两个序列的行为
相同时才允许这样做。因此,如果它不知道常规
是否可以访问*完成,则无法重新排序语句。
Harald van D?3k a ??暴击:
loic -... @ gmx.net写道:
>>大家好!
假设我有以下功能:
void
call_once(int * done,void(* routine) )(无效))
{
if(!(* done)){/ * L1 * /
routine(); / * L2 * /
* done = 1; / * L3 * /
}
是否符合ANSI C标准的编译器有权重新排序L2和L3,即
执行以下序列:
* done = 1;
routine();
当且仅当它知道两个序列的行为
相同时才允许这样做。因此,如果它不知道常规
是否可以访问*完成,则无法重新排序语句。
那可能只有在
call_once(int * restrict done,void(* routine)(void))时才能完成
如果限制关键词本来是肯定的,你可以做到。
jacob navia写道:
Harald van D?3k a ??暴击:
loic -... @ gmx.net写道:
>大家好!
假设我有以下功能:
void
call_once(int * done,void(* routine)(void))
{
if(!(* done)){/ * L1 * /
routine(); / * L2 * /
* done = 1; / * L3 * /
}
是否符合ANSI C标准的编译器可以重新订购L2和L3,即执行以下操作而是序列:
* done = 1;
routine();
当且仅当它知道两个序列的行为
相同时才允许这样做。因此,如果它不知道例行程序是否可以访问*完成,它就不能对语句重新排序。
只有在
call_once(int * restrict done,void(* routine)(void))时才可以这样做
如果限制关键字会被使用是的,你可以做到。
如果编译器选择内联特定的调用
来调用call_once,也可以这样做。
Hello everybody!
Assume that I have the following function:
void
call_once(int* done, void(*routine)(void))
{
if (!(*done)) { /* L1 */
routine(); /* L2 */
*done = 1; /* L3 */
}
}
Is an ANSI C compliant compiler authorized to re-order L2 and L3, i.e.
execute the following sequence instead:
*done = 1;
routine();
Thanks in advance!
Loic.
loic-...@gmx.net wrote:Hello everybody!
Assume that I have the following function:
void
call_once(int* done, void(*routine)(void))
{
if (!(*done)) { /* L1 */
routine(); /* L2 */
*done = 1; /* L3 */
}
}
Is an ANSI C compliant compiler authorized to re-order L2 and L3, i.e.
execute the following sequence instead:
*done = 1;
routine();It is allowed to do that if and only if it can know that the behaviour
for both sequences is the same. So if it doesn''t know whether routine
can access *done, it can''t reorder the statements.
Harald van D?3k a ??crit :loic-...@gmx.net wrote:
>>Hello everybody!
Assume that I have the following function:
void
call_once(int* done, void(*routine)(void))
{
if (!(*done)) { /* L1 */
routine(); /* L2 */
*done = 1; /* L3 */
}
}
Is an ANSI C compliant compiler authorized to re-order L2 and L3, i.e.
execute the following sequence instead:
*done = 1;
routine();
It is allowed to do that if and only if it can know that the behaviour
for both sequences is the same. So if it doesn''t know whether routine
can access *done, it can''t reorder the statements.
That could be done only if
call_once(int* restrict done, void(*routine)(void))
If the "restrict" keywords would have been used yes, you could have done it.
jacob navia wrote:Harald van D?3k a ??crit :loic-...@gmx.net wrote:
>Hello everybody!
Assume that I have the following function:
void
call_once(int* done, void(*routine)(void))
{
if (!(*done)) { /* L1 */
routine(); /* L2 */
*done = 1; /* L3 */
}
}
Is an ANSI C compliant compiler authorized to re-order L2 and L3, i.e.
execute the following sequence instead:
*done = 1;
routine();
It is allowed to do that if and only if it can know that the behaviour
for both sequences is the same. So if it doesn''t know whether routine
can access *done, it can''t reorder the statements.
That could be done only if
call_once(int* restrict done, void(*routine)(void))
If the "restrict" keywords would have been used yes, you could have done it.It can also be done if the compiler chooses to inline a specific call
to call_once.
这篇关于指令重新排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!