本文介绍了错误:匹配约束在输出操作数中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让GCC内联汇编程序接受Power9的某些内联汇编.

I'm having trouble getting GCC inline assembler to accept some inline assembly for Power9.

我要让GCC接受的常规程序集是darn 3, 1,其中3r3,而1是在文档中称为L的参数.它在big-endian上反汇编:

The regular assembly I am trying to get GCC to accept is darn 3, 1, where 3 is r3 and 1 is parameter called L in the docs. It disassembles to this on big-endian:

0:   e6 05 61 7c    darn    r3,1

在小端上:

0:   7c 61 05 e6    darn    r3,1

由于各种原因和问题,包括旧的编译器和冒充其他编译器的编译器,我想为指令发布字节码.我的测试程序:

Due to various reasons and problems, including old compilers and compilers that pretend to be other compilers, I want to issue byte codes for the instruction. My test program:

gcc112:~$ cat test.c
#include <stdint.h>

void random()
{
  volatile uint64_t x = __builtin_darn();

  __asm__ __volatile__ ("darn 3, 1");

  uint64_t y;
  __asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6  \n" : "=r3" (y));
}

编译它会导致:

$ /opt/cfarm/gcc-latest/bin/gcc -mcpu=power9 -c test.c
test.c: In function 'random':
test.c:10:3: error: matching constraint not valid in output operand
   __asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6  \n" : "=r3" (y));
   ^~~~~~~
test.c:10:3: error: matching constraint not valid in output operand
test.c:10:3: error: invalid lvalue in asm output 0

这是GCC内联汇编手册中应涵盖的部分,但我看不出有什么解释: 6.45.2.3输出操作数.我还检查了简单和机器约束,但没有看到.

Here's the section of the GCC inline assembly manual that should cover it, but I don't see it expalined: 6.45.2.3 Output Operands. I also checked simple and machine constraints but did not see it.

如何告诉GCC执行指令,然后将r3移到y?

How do I tell GCC to execute the instruction, and then move r3 into y?

我们使用rdrand在x86上执行相同的操作.在2.9版以上的所有GCC版本上,它都可以正常工作:

We do the same thing on x86 with rdrand. It works without problems on all version of GCC going back to 2.9:

uint64_t temp;
__asm__ __volatile__
(
    // radrand rax with retry
    "1:\n"
    ".byte 0x48, 0x0f, 0xc7, 0xf0;\n"
    "jnc 1b;\n"
    : "=a" (temp)
    : : "cc"
);

推荐答案

将我的(未经测试的)评论移至答案以尝试解决此问题

我不熟悉r3作为输出约束.我猜想这是为了指示输出将在'r3'寄存器中,但是我不认为您可以这样做(尽管我不是powerpc的机器约束).相反,也许您可​​以尝试:

I'm not familiar with r3 as an output constraint. I'm guessing this is intended to indicate that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Instead, perhaps you could try:

register uint64_t y asm("r3");

(即,将y设为本地寄存器变量),然后仅使用"= r"作为约束?

(ie make y a local register variable) and then just use "=r" as the constraint?

这篇关于错误:匹配约束在输出操作数中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:39