mik老大请帮忙看看gcc的一个问题

发布于 2022-09-23 12:40:23 字数 2693 浏览 17 评论 0

我问的:
================
Hi,

from the info manual of gcc, I get this:

info gcc: C extensions: Constraints: Modifiers

%
     Declares the instruction to be commutative for this operand and the
     following operand.  This means that the compiler may interchange
     the two operands if that is the cheapest way to make all operands
     fit the constraints.  GCC can only handle one commutative pair in
     an asm; if you use more, the compiler may fail.

But I missed the point. What's the benefit of using `%' to exchange two
operands?

I'm writing a gcc inline assembly HOWTO, and I'd like to get everything,
at least those who was mentioned in gcc.info or gccint.info, documented.

So would someone be kind enough to give an example on this? I searched
the Linux kernel with:
       
    $ find  arch/x86 -name "*.[ch]" -exec grep -H "asm[ _( ]" {} \;

for `asm' followed by a space, `(', `_' or a Tab. Nothing useful.

Thanks in advance.
-Jike

别人回答的:
==============
Let's say you have an opcode that adds two values, but if one is in a
register and one is in memory then the register has to be listed first
(perhaps because it's also the destination, for 2-op adds).  You have
two choices:

1. Describe all permutations of register/memory vs memory/register
   plus all the other things you might be able to add (constants, etc).

2. Describe one set and tell gcc that it doesn't matter which operand
   is which.

The '%' constraint modifier tells gcc that it may swap the two
operands if it wants to, without affecting the semantics of the insn.
This is often used for 2-op add and multiply so that gcc has more
flexibility about what the *output* register is (it can now match
either input reg, not just the 1st input reg) but obviously you
wouldn't use it with, say, subtraction.

Thus, it's mostly to help gcc do register allocation and optimization.

Also, this is more likely to be found in the MD pattern files used to
port gcc to your chip, than in inline assembly.

<<EOF

他说的2-op是什么意思? 我完全不懂opcode编码,看不懂啊

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

因为看清所以看轻 2022-09-30 12:40:23

这里的op是operand

枕花眠 2022-09-30 12:40:23

albcamus :
  偶的英文其实很菜,看看文档还可以。你能不能用中文来表述。

2-op 应该是指 2 个 operand 或者是 第 2 个operand

浅忆 2022-09-30 12:40:23

琢磨明白了,谢谢2位呀! ^_^

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文