Understanding basic inline NEON assembly
Considering this question : how to write inline assembly codes about LOOP in Xcode LLVM?
Which is answered with the following inline assembly code :
void brighten_neon(unsigned char* src, unsigned char* dst, int numPixels, int intensity) {
asm volatile (
"t mov r4, #0n"
"t vdup.8 d1, %3n"
"Lloop2:n"
"t cmp r4, %2n"
"t bge Lend2n"
"t vld1.8 d0, [%0]!n"
"t vqadd.s8 d0, d0, d1n"
"t vst1.8 d0, [%1]!n"
"t add r4, r4, #8n"
"t b Lloop2n"
"Lend2:n"
: "=r"(src), "=r"(dst), "=r"(numPixels), "=r"(intensity)
: "0"(src), "1"(dst), "2"(numPixels), "3"(intensity)
: "cc", "r4", "d1", "d0");
}
I was wondering what the three last line in the asembly code means ? It seems like the parameters are defined here with the register names etc that are used inline. Can someone elaborate on this ? Does anyone know any good resources explaining this ?
I don't know much about ARM assembly specifically, but in GCC's inline assembly syntax, the three sections are output registers, input registers, and clobbered registers, respectively. The registers are numbered in the order that they appear, and in this case the input registers refer to the same variables as the output registers in the same order. =r
is architecture-specific, but probably means something like "any general-purpose register".
So you can expect the compiler to pick four convenient registers to put the four variables into (most likely the ones the ARM calling convention puts them in?), and to make sure that cc
, r4
, d1
, d0
are saved if necessary. You can refer to the four registers using %0
, %1
, %2
, %3
in your assembly. In turn, the compiler can expect that when you've finished, you won't have clobbered any other registers, and the new values of the variables will be in the new registers (which happen to be the same as the old registers in this case).
See also GCC-Inline-Assembly-HOWTO -- it's a bit old, but you should be able to get the general idea from it.
链接地址: http://www.djcxy.com/p/59746.html上一篇: GNU g ++内联汇编块,如Apple g ++ / Visual C ++?
下一篇: 了解基本的在线NEON组装