Hi everyone, I try to add an instruction to x86. The instruction is a multiply-add instruction MULADD A, B, C; //A = A + B * C. I use the instruction by inline assemble as below int x, y, z; ..... .... x = 0; asm("MULADD %0, %1, %2":"=r"(x):"0"(x), "r"(y), "r"(z)); ..... .... The backend does allocate registers %edx, %edi, %esi for x,y, z respectively, but its assemble output is MULADD %edx, %edx, %esi I expects it could output: MULADD %edx, %edi, %esi What's matter with my constraints of inline asm? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091229/b5e47b29/attachment.html>
On Dec 29, 2009, at 3:09 AM, Heyu Zhu wrote:> Hi everyone, > > I try to add an instruction to x86. The instruction is a multiply-add instruction > MULADD A, B, C; //A = A + B * C. > I use the instruction by inline assemble as below > > int x, y, z; > ..... .... > x = 0; > asm("MULADD %0, %1, %2":"=r"(x):"0"(x), "r"(y), "r"(z)); > ..... .... > > The backend does allocate registers %edx, %edi, %esi for x,y, z respectively, > but its assemble output is > MULADD %edx, %edx, %esi > I expects it could output: > MULADD %edx, %edi, %esi > > What's matter with my constraints of inline asm? >The constraint tells the compiler what registers are valid to use. "r" means that it can use any register. You need to tell the compiler what registers need to be used, because it doesn't look inside the asm string. Please take a look at the GCC documentation for more details: http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Extended-Asm http://gcc.gnu.org/onlinedocs/gcc/Constraints.html#Constraints -Chris
After look at documents of inline assemble, i have known its reason. Thanks! 2009/12/30, Chris Lattner <clattner at apple.com>:> > > On Dec 29, 2009, at 3:09 AM, Heyu Zhu wrote: > > > Hi everyone, > > > > I try to add an instruction to x86. The instruction is a multiply-add > instruction > > MULADD A, B, C; //A = A + B * C. > > I use the instruction by inline assemble as below > > > > int x, y, z; > > ..... .... > > x = 0; > > asm("MULADD %0, %1, %2":"=r"(x):"0"(x), "r"(y), "r"(z)); > > ..... .... > > > > The backend does allocate registers %edx, %edi, %esi for x,y, z > respectively, > > but its assemble output is > > MULADD %edx, %edx, %esi > > I expects it could output: > > MULADD %edx, %edi, %esi > > > > What's matter with my constraints of inline asm? > > > > The constraint tells the compiler what registers are valid to use. "r" > means that it can use any register. You need to tell the compiler what > registers need to be used, because it doesn't look inside the asm > string. Please take a look at the GCC documentation for more details: > http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Extended-Asm > http://gcc.gnu.org/onlinedocs/gcc/Constraints.html#Constraints > > -Chris > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091230/3eb39ad9/attachment.html>
Reasonably Related Threads
- [LLVMdev] Question to use inline assemble in X86
- [LLVMdev] Function permutation at IR bytecode level
- mdct_backward with fused muladd?
- [LLVMdev] How to bind a register variable with a given general purpose register?
- [LLVMdev] newbie qustion: how to generate machine code for target thumb?