免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2078 | 回复: 3
打印 上一主题 下一主题

mik老大请帮忙看看gcc的一个问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-05 15:24 |只看该作者 |倒序浏览
我问的:
================
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编码,看不懂啊

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
2 [报告]
发表于 2008-12-05 16:37 |只看该作者
这里的op是operand

论坛徽章:
0
3 [报告]
发表于 2008-12-05 16:47 |只看该作者
albcamus :
  偶的英文其实很菜,看看文档还可以。你能不能用中文来表述。


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

论坛徽章:
0
4 [报告]
发表于 2008-12-05 17:57 |只看该作者
琢磨明白了,谢谢2位呀! ^_^
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP