[英]Assembly branch instruction, bne- 0b
Taken from Google Protobuf PowerPC GCC, there are methods for 32 bit architecture, but none for 64 bit. 取自Google Protobuf PowerPC GCC,有一些方法可用于32位体系结构,但没有方法可用于64位。
I see the 0:
flag, and later a bne- 0b
branch if not equal to a flag before current address. 我看到
0:
标志,如果不等于当前地址之前的标志,则看到bne- 0b
分支。
What does the -
do in the bne-
statement? -
在bne-
语句中做什么?
Specifically, when I write a version of this for 64 bit, I get syntax errors if I use 0:
and bne- 0b
, but the 32 bit version works just fine. 具体来说,当我为64位版本编写此版本时,如果使用
0:
和bne- 0b
, bne- 0b
出现语法错误,但是32位版本可以正常工作。
Why does it accept a word as a flag, but not 0:
? 为什么它接受一个单词作为标记,而不接受
0:
:?
Below is the Protobuf 32 bit method. 下面是Protobuf 32位方法。
inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr,
Atomic32 increment) {
Atomic32 temp;
__asm__ __volatile__(
"0: \n\t" // flag
"lwarx %[temp],0,%[ptr] \n\t"
"add %[temp],%[increment],%[temp] \n\t"
"stwcx. %[temp],0,%[ptr] \n\t"
"bne- 0b \n\t" // branch not equal <dash> flag before
: [temp] "=&r"(temp)
: [increment] "r"(increment), [ptr] "r"(ptr)
: "cc", "memory");
return temp;
}
Below is my attempt at a 64 bit version. 以下是我尝试的64位版本。
inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64 *ptr,
Atomic64 increment) {
Atomic64 temp;
__asm__ __volatile__(
"0: \n\t"
"ldarx %[temp],0,%[ptr] \n\t"
"add %[temp],%[increment],%[temp] \n\t"
"stdcx. %[temp],0,%[ptr] \n\t"
"bne- 0b \n\t"
: [temp] "=&r"(temp)
: [increment] "r"(increment), [ptr] "r"(ptr)
: "cc", "memory");
return temp;
}
Note that Atomic32
is an int
, and Atomic64
is a long
. 请注意,
Atomic32
是一个int
,而Atomic64
是一个long
。
Also, if I replace the 0:
flag by a word, such as loopai64:
, I don't get errors. 另外,如果我将
0:
标志替换为一个单词(例如loopai64:
,则不会出错。 However, when I run the compiler, it gets stuck in an infinite loop. 但是,当我运行编译器时,它陷入了无限循环。
The 0:
is a local label. 0:
是本地标签。 However, directional branch, such as bne- 0b
( 0b
means jump to first instance of label 0
that is above current location) are not supported on all architectures. 但是,并非所有架构都支持定向分支,例如
bne- 0b
( 0b
表示跳转到当前位置上方的标签0
第一个实例)。
In the end, I solved the issue by using longer label names. 最后,我通过使用更长的标签名称解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.