<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>编译点滴 &#187; 链接</title>
	<atom:link href="http://www.lingcc.com/tag/%e9%93%be%e6%8e%a5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lingcc.com</link>
	<description>编译器、虚拟机、程序设计语言、体系结构、软件调试、操作系统等等</description>
	<lastBuildDate>Sat, 04 Feb 2012 06:56:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>认识静态链接库</title>
		<link>http://www.lingcc.com/2010/05/25/10951/</link>
		<comments>http://www.lingcc.com/2010/05/25/10951/#comments</comments>
		<pubDate>Tue, 25 May 2010 13:33:01 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[系统软件及库]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[compiler infrastructure]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[操作系统 Operating system]]></category>
		<category><![CDATA[系统健壮性]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[编译器开发]]></category>
		<category><![CDATA[运行时技术]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10951</guid>
		<description><![CDATA[介绍静态链接库是什么，为何要有静态链接库，动态链接库和共享库，如何使用，创建，编辑静态练级库。<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GNU工具链学习笔记</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC中的pie和fpie选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gcc和Open64中的-fPIC选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F11%2F11300%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">软链接和硬链接</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F02%2F19%2F9897%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">经验之谈:做好预防措施,保护好自己的电脑的13个Tips</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/07/10916/' rel='bookmark' title='期待未来-一张趣图'>期待未来-一张趣图</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/07/16/11081/' rel='bookmark' title='多面体模型是编译器循环优化的未来吗？'>多面体模型是编译器循环优化的未来吗？</a></li>
<li><a href='http://www.lingcc.com/2008/08/27/9982/' rel='bookmark' title='zz Linux下的段错误的原因及调试'>zz Linux下的段错误的原因及调试</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<h4>什么是静态链接库？</h4>
<p>静态链接库，即static library或 statically-linked library。和动态链接库，即dynamic library 或dynamicly-linked library相对，是Windows和Linux系统中比较常用的库文件。Windows中分别用SLL和DLL文件表示，Linux中分别是.a和.so文件.</p>
<p>静态链接库实际是一些object files(.o文件)和头文件的压缩包，通过GNU工具链中的ar(archiver)程序创建。</p>
<h5>静态链接库、动态链接库和共享库</h5>
<p>那为何还要有动态链接库呢？静态练级库虽然能很好的节省编译时间。对于一个简单的ls程序，我们需要有屏幕输出，有字符串和格式操作，有文件系统访问等等函数，都要在一个程序中。此时，这个程序会很大。一个小小的ls可能都会有好几兆。如果还有个rm程序，同样也需要屏幕输出，文件系统访问。那么这两个东西，我们可以放到两个库文件里，在执行ls，或者rm的时候，用到屏幕输出操作，就将相应的函数对应的机器码载入内存中，执行。然后再从内存中释放。接着载入文件系统访问的相关函数。这样我们的程序就能变小很多。这种可以动态装载到内存中的库文件就是动态链接库了。Windows下的DLL文件就是动态链接库。</p>
<p><span id="more-10951"></span></p>
<p>还有个问题，其实ls和rm使用的屏幕输出函数是一样的。内存很小的时候，同时执行ls和rm，有必要同时载入两份相同的代码到内存中吗？于是就有了共享库，不同的程序可以共享相同的代码。都可以访问，执行。于是就有了共享库的概念。Linux下的.so文件就是共享库。</p>
<p>这时候又有个问题，程序执行时，访存，跳转的地址是一定的，那两个程序又如何共享相同的库代码呢？这就靠位置无关的代码生成了。本博曾经写过文章介绍它们，请参考<a href="http://www.lingcc.com/2009/11/20/10065/" target="_blank">Gcc和Open64中的-fPIC选项</a> 和<a href="http://www.lingcc.com/2010/01/08/10609/" target="_blank">GCC中的pie和fpie选项</a>两篇文章。</p>
<p>下图是关于共享库和静态链接库的示意图，可以简单看出些区别。</p>
<div id="attachment_10952" class="wp-caption alignnone" style="width: 351px"><a href="http://www.lingcc.com/wp-content/uploads/2010/05/figure2.gif"><img class="size-full wp-image-10952" title="静态链接库和共享库" src="http://www.lingcc.com/wp-content/uploads/2010/05/figure2.gif" alt="" width="341" height="265" /></a><p class="wp-caption-text">静态链接库和共享库</p></div>
<h4>为什么要有静态链接库？</h4>
<p>首先，随着程序规模的增加，有些常用函数可能不需要每次都编译，于是就可以把它们作为库的方式来存放。这样用户就能很方便的链接生成最后的程序，不用一遍遍的重新编译某些常用程序文件。必须内核，硬件驱动，文件系统，glibc等等库文件，一些基本函数都采用了这种形式。</p>
<p>其次，一些闭源代码，可以通过库的方式来发布，这样可以保证代码不公开。</p>
<p>再次，相比动态链接的程序，或者共享库程序，连接到静态库的程序会快1%-5%左右。</p>
<p>另外，有些特殊环境，必须使用静态链接库。比如在Linux系统，需要chroot到另一个系统环境中时，动态链接库就不再起作用，因为那些是在原来系统的文件树下，如/usr/lib.但在chroot的环境中，无法访问。</p>
<h4>怎么用静态链接库？</h4>
<p>既然静态链接库的出现，是为了缩短编译时间。而普通可执行程序又可以分为静态链和动态链两种形式。因此我们就分开介绍之，原因无他，只是想顺便介绍一下动态链可执行程序和静态链可执行程序在运行时的一些区别。</p>
<p>对于静态链接库的应用，加上-lname，就会链接libname.a这个静态链接库文件。一般静态链接库文件的搜索路径为系统默认的路径，如/usr/lib/和当前路径。你也可以用过-L选项，指定GCC搜索某个特定文件夹。注意-l和-L的参数要加载待编译源码文件之后。</p>
<p>静态链接库既可以在编译时用于生成单个可执行文件，也可以在运行时根据编译或者连接时确定的静态偏移量载入内存中。</p>
<h5>编译静态链接可执行程序</h5>
<p>编译静态链可执行程序,对于gcc，只要加上-static即可。</p>
<p>编译时，程序中若有对库函数的调用，编译器或者连接器就会将库中相应的代码拷贝到目标文件中，生成一个独立的可执行文件。</p>
<h5>编译动态链接可执行程序</h5>
<p>不加-static编译生成的可执行程序都是动态链接的，编译时所做工作很少，仅仅记录了该程序需要什么库函数，以及该库函数在库中到索引。</p>
<p>但对于动态链接程序，在系统启动该可执行程序时，装载器loader必须能找到相应的共享库文件.so文件或者静态链接库文件.a(已经很少使用这种形式了)，并将其载入内存中，一般的，有两种途径可以指定链接库文件的位置，</p>
<ul>
<li>编译动态链接可执行程序时，通过rpath指定，这个可以在编译时增加选项-Wl,-rpath=DIRS.这种方式不需要在运行时做任何修改，该选项会在连接时，写入可执行程序中。</li>
<li>运行时由ld.so指定。默认共享库搜索路径是/usr/local/lib，/usr/lib以及当前目录，你可以通过修改$LD_LIBRARY_PATH变量修改。系统管理员也可以在/etc/profile中修改，以便对所有用户有效。当然修改/etc/ld.so.conf也行，这样所有的程序都将更改寻找链接库文件的路径。</li>
</ul>
<div id="attachment_10953" class="wp-caption alignnone" style="width: 487px"><a href="http://www.lingcc.com/wp-content/uploads/2010/05/confused.jpg"><img class="size-full wp-image-10953" title="很晕吧" src="http://www.lingcc.com/wp-content/uploads/2010/05/confused.jpg" alt="" width="477" height="358" /></a><p class="wp-caption-text">很晕吧</p></div>
<h4>静态链接库的常用操作</h4>
<h5>制作静态链接库</h5>
<p><code>$ar rcs liba.a a.o b.o c.o a_header.h b_header.h</code></p>
<p>上面命令，将a.o, b.o, c.o, a_header.h, b_header.h作成静态链接库liba.a.</p>
<ul>
<li>选项r：将 .o , .h文件插入到liba.a文件中</li>
<li>c:创建一个压缩文件。</li>
<li>s：将.o文件的索引信息写入压缩文件中，或者升级已有索引。这和执行 ranlib liba.a的效果过一样。索引信息会存在压缩包的一个符号文件夹内，连接器可以通过名称找到位置，这样可以加速连接时间。</li>
</ul>
<h5>解压静态链接库</h5>
<p><code>$ar xv liba.a</code></p>
<p>该命令会把liba.a中所有的文件解压缩到当前目录下。</p>
<ul>
<li>x：解压缩该压缩包</li>
<li>v：可视化，解压缩同时输出到屏幕</li>
</ul>
<h5>查看内容</h5>
<p><code>$nm --print-armap liba.a</code></p>
<p>该命令查看liba.a中包含哪些文件，每个文件中包含哪些函数。</p>
<ul>
<li>在列出压缩包中所有文件中的符号，同时包含索引：每个元素到符号的映射</li>
</ul>
<h5>实践：</h5>
<p>本文不再给出具体实践，可以参考<a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html" target="_blank">An Introduction to GCC &#8211; Shared libraries and static libraries</a></p>
<h4>参考：</h4>
<ol>
<li><a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html">http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html</a></li>
<li><a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html"></a><a href="http://en.wikipedia.org/wiki/Static_library">http://en.wikipedia.org/wiki/Static_library</a></li>
<li><a href="http://cpp.codenewbie.com/articles/cpp/1444/Static_Link_Librarys-Page_1.html">http://cpp.codenewbie.com/articles/cpp/1444/Static_Link_Librarys-Page_1.html</a></li>
<li><a href="http://tldp.org/HOWTO/Program-Library-HOWTO/static-libraries.html">http://tldp.org/HOWTO/Program-Library-HOWTO/static-libraries.html</a></li>
<li><a href="http://www.faqs.org/docs/linux_scratch/chapter05/whystatic.html">http://www.faqs.org/docs/linux_scratch/chapter05/whystatic.html</a></li>
<li><a href="http://en.wikipedia.org/wiki/Dynamic-link_library">http://en.wikipedia.org/wiki/Dynamic-link_library</a></li>
<li><a href="http://www.ibm.com/developerworks/linux/library/l-dynamic-libraries/index.html" target="_blank">http://www.ibm.com/developerworks/linux/library/l-dynamic-libraries/index.html</a></li>
</ol>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F03%2F08%2F10709%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GNU工具链学习笔记</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F08%2F10609%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC中的pie和fpie选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gcc和Open64中的-fPIC选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F11%2F11300%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">软链接和硬链接</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F02%2F19%2F9897%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F25%2F10951%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">经验之谈:做好预防措施,保护好自己的电脑的13个Tips</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/07/10916/' rel='bookmark' title='期待未来-一张趣图'>期待未来-一张趣图</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/07/16/11081/' rel='bookmark' title='多面体模型是编译器循环优化的未来吗？'>多面体模型是编译器循环优化的未来吗？</a></li>
<li><a href='http://www.lingcc.com/2008/08/27/9982/' rel='bookmark' title='zz Linux下的段错误的原因及调试'>zz Linux下的段错误的原因及调试</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/05/25/10951/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>走进Debian和Gentoo中的系统初始化过程</title>
		<link>http://www.lingcc.com/2010/05/19/10892/</link>
		<comments>http://www.lingcc.com/2010/05/19/10892/#comments</comments>
		<pubDate>Wed, 19 May 2010 12:04:30 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[Linux系统]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sysinit]]></category>
		<category><![CDATA[启动项]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10892</guid>
		<description><![CDATA[介绍Linux系统的头号进程init和启动过程，以及Gentoo，Debian系统下，如何配置启动项。<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F21%2F11673%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Debian和Gentoo系统中Emacs 23不能使用ibus解决方法</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gcc和Open64中的-fPIC选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F02%2F27%2F9904%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">gentoo的相关配置-make.conf</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F28%2F9963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F21%2F10761%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gentoo安装texlive2009–字体</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/05/10894/' rel='bookmark' title='龙芯电脑常见问题'>龙芯电脑常见问题</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2009/11/20/10065/' rel='bookmark' title='Gcc和Open64中的-fPIC选项'>Gcc和Open64中的-fPIC选项</a></li>
<li><a href='http://www.lingcc.com/2011/11/26/11814/' rel='bookmark' title='How start_kernel get start?'>How start_kernel get start?</a></li>
<li><a href='http://www.lingcc.com/2010/04/21/10761/' rel='bookmark' title='Gentoo安装texlive2009&#8211;字体'>Gentoo安装texlive2009&#8211;字体</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>今天需要对Debian中的默认启动程序做配置，就顺便重新认识一下Linux下的启动过程，并总结对比Debian和Gentoo。</p>
<h4>Init创世纪！</h4>
<p>再来回顾一下Linux PC的启动过程</p>
<ol>
<li>BIOS检测硬件，并查找硬盘MBR(Master Boor Record)上的指令</li>
<li>MBR指向GRUB，LILO之类的boot loader</li>
<li>Grub查询载入操作系统内核的位置，并载入指定的内核</li>
<li>内核载入之后启动init进程。</li>
<li>init启动脚本/etc/rc.d/rc.sysinit, 接着根据运行级别不同，启动指定的进程。</li>
</ol>
<p>init是系统中所有进程的父进程，它确保所有的文件系统(/etc/fstab中指定的)都已经正确挂在，接着就执行/etc/init.d下的一系列脚本来启动服务。接着init就会激活终端，并将进程agetty和他绑定。agetty确保用户能在终端登录。</p>
<p>实际上init会根据不同的运行级别来启动不同的进程。这个运行级别的控制在/etc/inittab中。<span id="more-10892"></span></p>
<h4>Debian</h4>
<p>Debian通过执行init程序启动，配置文件为/etc/inittab,这个文件会指定init执行/etc/init.d/rcS脚本，该脚本又通过子进程执行/etc/rcS.d/目录下的脚本，如检测挂载文件系统，转载内核模块，启动网络服务，设置时钟还有其他初始化工作。接着，为了兼容性，会执行/etc/rc.boot/目录下，所有文件名不含”.”的文件。</p>
<p>启动过程之后，init程序执行默认运行级别中的起动机脚本，运行级别会在/etc/inittab文件中指定。Linux有7个运行级别.分别是</p>
<ul>
<li>0 系统挂起</li>
<li>1 单用户模式</li>
<li>2-5 各种多用户模式</li>
<li>6 系统重启</li>
</ul>
<p>Debian系统默认运行级别的id=2,也就说/etc/rc2.d下的脚本会在多用户状态下运行。事实上，在任一个/etc/rcN.d/目录下的文件都是一个到/etc/init.d/的符号链接。rcN.d/目录下文件命名方式决定了哪个脚本将会运行，”K”开头的在进入该运行级别时默认在执行，执行相应的脚本，会杀掉该服务。而所有S开头的，则在进入运行级别时，会被执行。字母之后的两位数字指定启动的顺序，较小的数字将先被执行。</p>
<h4>Gentoo</h4>
<p>Gentoo的init配置文件也是/etc/inittab,在该文件中前三行：<br />
<code><br />
id:3:initdefault:<br />
si::sysinit:/sbin/rc sysinit<br />
rc::bootwait:/sbin/rc boot</code></p>
<p>第一行:指定gentoo的默认运行级别是3，接下来两行表明gentoo的runlevel首先开始于sysinit，接着是boot。Gentoo使用字符串，而非简单的数字标记运行级，有sysinit, boot, default, nonetwork, single, shutdown六个runlevel，简单明了。</p>
<p>这些runlevel对应于/etc/runlevels/下的文件夹，每个文件夹中都是一些符号链接，指向/etc/init.d/下的脚本。系统启动的时候就是通过执行这些软连接启动相应的进程。</p>
<p>如果想在开机时启动哪个进程，只需要将该进程的软连接添加到对应的/etc/runlevels/文件夹下即可。</p>
<p>Gentoo提供了一个程序rc-update，可以很方便的管理启动项：<br />
<code><br />
#rc-update add xxx default<br />
#rc-update del xxx default<br />
#rc-update show</code></p>
<p>第一行将xxx启动项添加到default运行级，第二行从default runlevel中删除xxx，第三行查看现在的启动项。</p>
<p>参考:<br />
<a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&amp;chap=4">http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&amp;chap=4</a><br />
<a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&amp;chap=4">http://www.yolinux.com/TUTORIALS/LinuxTutorialInitProcess.html</a><br />
<a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&amp;chap=4">http://en.wikipedia.org/wiki/Linux_startup_process</a><br />
<a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&amp;chap=4">http://www.debian-administration.org/article/An_introduction_to_run-levels</a></p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F21%2F11673%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Debian和Gentoo系统中Emacs 23不能使用ibus解决方法</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F11%2F20%2F10065%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gcc和Open64中的-fPIC选项</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F02%2F27%2F9904%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">gentoo的相关配置-make.conf</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F28%2F9963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">gentoo如何处理被屏蔽(masked)的包   by 杨珂 转自linuxsir</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F21%2F10761%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F19%2F10892%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Gentoo安装texlive2009–字体</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/05/10894/' rel='bookmark' title='龙芯电脑常见问题'>龙芯电脑常见问题</a></li>
<li><a href='http://www.lingcc.com/2009/12/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</a></li>
<li><a href='http://www.lingcc.com/2010/01/05/10588/' rel='bookmark' title='用crossdev装龙芯的n32 gnu交叉工具链'>用crossdev装龙芯的n32 gnu交叉工具链</a></li>
<li><a href='http://www.lingcc.com/2009/11/20/10065/' rel='bookmark' title='Gcc和Open64中的-fPIC选项'>Gcc和Open64中的-fPIC选项</a></li>
<li><a href='http://www.lingcc.com/2011/11/26/11814/' rel='bookmark' title='How start_kernel get start?'>How start_kernel get start?</a></li>
<li><a href='http://www.lingcc.com/2010/04/21/10761/' rel='bookmark' title='Gentoo安装texlive2009&#8211;字体'>Gentoo安装texlive2009&#8211;字体</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/05/19/10892/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>前瞻-拿起SIMD的武器I</title>
		<link>http://www.lingcc.com/2010/05/10/10928/</link>
		<comments>http://www.lingcc.com/2010/05/10/10928/#comments</comments>
		<pubDate>Mon, 10 May 2010 14:27:28 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[后端优化与处理器]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[mit]]></category>
		<category><![CDATA[mmx]]></category>
		<category><![CDATA[SIMD]]></category>
		<category><![CDATA[sse]]></category>
		<category><![CDATA[vectorization]]></category>
		<category><![CDATA[多媒体处理]]></category>
		<category><![CDATA[多核]]></category>
		<category><![CDATA[并行]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[数据安全]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[科学计算]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10928</guid>
		<description><![CDATA[上篇文章《前瞻-主流处理器中的数据并行支持(SIMD)》 介绍了当今主流CPU中的SIMD扩展，本文将介绍前人是物和利用SIMD来做优化的，下篇&#60;前瞻-拿起SIMD的武器II&#62;将探讨如何使用CPU的向量指令为程序做优化 已有在SIMD上的优化工作： 正如之前提到的，SIMD对具有以下特性的程序性能提升明显：天然数据并行，访存模式重复、在局部数据上重复操作、控制流数据无关。很多应用有这方面的特性，并能通过使用SIMD扩展提高性能，但实际仅有小部分从中获益，接下来将介绍在单核处理器上，利用Intel的SIMD扩展针对某些应用提升性能的研究，如多媒体，数据安全，数据库和一些科学计算应用。 多媒体处理 多媒体处理需要软件和硬件的很多支持。如MPEG-1，MPEG-2，MPEG-4，MPEG-7，H.263,JPEG2000等需要实时做复杂的媒体处理.3D图像和立体视频处理都需要更强劲的实时处理.因为各种媒体都需要不同的处理方式，技术支持、算法和硬件，因此针对他们的SIMD扩展改进也很不同。 离散小波变换(DWT)主要用于很多图像/视频压缩(如JPEG2000和MPEG-4)，已经有学者使用SIMD扩展减少二维和三维小波变换的执行时间。最新的研究结果显示，使用MMX为一层二维DWT实现提升策略相对于C语言实现在奔四单核处理器上，性能提升4倍.使用SSE实现Daub-4则比C语言版本提升2.5倍.而且，当发生64k别名时(???),相对于没有发生时，有明显的高加速比，这是因为MMX和SSE大大降低了访存(四分之一).也有人在卫星图像处理中使用MMX扩展，并对一些常用操作分别用MMX汇编和C语言实现并做成库，也为很多数字图像处理程序带来很大性能提升。 几何结构处理也是天生的并行任务，因为每个定点都能独立处理。有人在SIMD-PF中使用了Intel SSE，可以一次并行处理四个定点。试验结果显示，SSE为几何结构处理流水线带来了显著的性能提升，加速高达3.0x到3.8x.定点在主存中的分布对SIMD-PF的性能影响很大，预取的影响也不能忽略。 SIMD扩展还用于在其他多媒体应用优化中，如快速傅立叶变换、H.264编解码。其中H.264编解码中，作者首先在奔四单核处理器上使用SIMD扩展获得3x加速，后采用多线程在多核上运行，加速高达4.6x. 与此同时，也有芯片厂商根据实际应用，提出了几个新指令，这些新指令用于加速绝对差值求和运算(Sum-of-Absolute Difference,SAD).使用这些新指令，相对C语言能为SAD带来10x-14x的加速，而MMX的加速只有4x-7x。这些指令用于生成图像柱状图时，与C语言相比，有8x和11x的加速，而MMX只有3x和4x。 数据安全 目前的数据加密技术和工具在健壮性和性能上都无法满足下一代信息技术(个人移动通信，电子商务和互联网)的需求。现在的加解密算法通常是一个串行的数据操作序列，加密和哈希运算往往是瓶颈。椭圆曲线密码体制因安全性高，密钥长度短，计算速度快而受欢迎，也有使用SIMD扩展加速椭圆曲线密码体制的研究工作，在奔三处理器上，使用SIMD 得到了4.4x的加速. 安全哈希算法(SHA):SHA-1,SHA-256,SHA-384,SHA-512.也有人在调研之后，表示SIMD能大大提升其性能。ASE加密算法已经有了SIMD扩展加速版本，加速1.7x 数据库 随着数据库的普及和数据量的增加，高速数据库管理系统的需求越来越大。许多数据库查询，数据仓库和数据挖掘都依赖数据和计算，因此需要很高的处理能力。现在使用SIMD加速查询的研究还不多，但已经有人开始注意到可以使用SIMD实现很多数据库中的操作，如顺序扫描，聚合索引查找和链接等，使用SIMD扩展，取得的加速从10%到4x不等。 科学计算应用 虽然SIMD扩展大量用于多媒体应用加速，但针对科学计算的SIMD扩展研究还很少，而且都处于起步阶段。 DNA和蛋白质序列的比较和对齐在分子生物学，生物信息学中都很重要。其中最重要的字符串匹配操作是Smith-Waterman算法(SW)，但因为它是个计算密集算法，所以很多研究者都选择使用启发式策略来避免使用该算法，不过有人利用Intel的SIMD扩展(MMX和SSE)加速了该算法。 矩阵计算是很多科学计算应用，尤其是数值算法的核心。对矩阵乘的改进会给科学计算带来性能提升。有人使用SIMD扩展在奔三处理器上实现了矩阵乘，比常用算法快2.09x.另外一个比较典型的是线性方程求解，有人使用Intel的SSE改写LU分解算法，能轻松获得2.5x的加速.另外使用Intel的C编译器，添加几个特殊数据结构和相关的intrinsic调用后，也能提升80%的性能。 多项式求根算法是计算密集的，将其并行化也能获得可观的收益，有人选了4种常用多项式求根算法，使用C++，汇编语言和SIMD指令获得3x以上的加速. 其他科学计算，如标准化交叉相关，寻找数组中的最大/最小值.也有人针对如何方便的使用SIMD，并和原有C/C++兼容，并给出了具体应用实现，见《SIMD Correlator librart for GNSS software receivers》。 相关文章： 前瞻-主流处理器中的数据并行支持(SIMD) 前瞻-拿起SIMD的武器II 并行计算前景- 应用和小矮人 Open64课程-简介，概述和中间表示 小例子&#8211;回眸一笑百媚生 探秘CPU性能测试：Spec CPU2000之整点篇<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F02%2F11605%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">SIMD硬件的发展</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F01%2F11600%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">通用微处理中的SIMD指令扩展</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F12%2F10931%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">前瞻-拿起SIMD的武器II</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F20%2F10372%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Expected unqualified-id before﻿ 查错</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F03%2F11619%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">自动向量化</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/04/10878/' rel='bookmark' title='前瞻-主流处理器中的数据并行支持(SIMD)'>前瞻-主流处理器中的数据并行支持(SIMD)</a></li>
<li><a href='http://www.lingcc.com/2010/05/12/10931/' rel='bookmark' title='前瞻-拿起SIMD的武器II'>前瞻-拿起SIMD的武器II</a></li>
<li><a href='http://www.lingcc.com/2009/11/22/10090/' rel='bookmark' title='并行计算前景- 应用和小矮人'>并行计算前景- 应用和小矮人</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2010/01/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</a></li>
<li><a href='http://www.lingcc.com/2010/04/14/10736/' rel='bookmark' title='探秘CPU性能测试：Spec CPU2000之整点篇'>探秘CPU性能测试：Spec CPU2000之整点篇</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>上篇文章<span style="color: #000000;"><a href="http://www.lingcc.com/2010/05/04/10878/" target="_blank">《</a></span><span style="color: #000000;"><a href="http://www.lingcc.com/2010/05/04/10878/" target="_blank">前瞻-主流处理器中的数据并行支持(SIMD)》</a> 介绍了当今主流CPU中的SIMD扩展，本文将介绍前人是物和利用SIMD来做优化的，下篇&lt;<a href="http://www.lingcc.com/2010/05/12/10931/">前瞻-拿起SIMD的武器II</a>&gt;将探讨如何使用CPU的向量指令为程序做优化</span></p>
<h4>已有在SIMD上的优化工作：</h4>
<p>正如之前提到的，SIMD对具有以下特性的程序性能提升明显：天然数据并行，访存模式重复、在局部数据上重复操作、控制流数据无关。很多应用有这方面的特性，并能通过使用SIMD扩展提高性能，但实际仅有小部分从中获益，接下来将介绍在单核处理器上，利用Intel的SIMD扩展针对某些应用提升性能的研究，如多媒体，数据安全，数据库和一些科学计算应用。</p>
<h5><a name="_5810484889520076_477723367654_1559512633830309"></a>多媒体处理</h5>
<p>多媒体处理需要软件和硬件的很多支持。如MPEG-1，MPEG-2，MPEG-4，MPEG-7，H.263,JPEG2000等需要实时做复杂的媒体处理.3D图像和立体视频处理都需要更强劲的实时处理.因为各种媒体都需要不同的处理方式，技术支持、算法和硬件，因此针对他们的SIMD扩展改进也很不同。<span id="more-10928"></span><br />
离散小波变换(DWT)主要用于很多图像/视频压缩(如JPEG2000和MPEG-4)，已经有学者使用SIMD扩展减少二维和三维小波变换的执行时间。最新的研究结果显示，使用MMX为一层二维DWT实现提升策略相对于C语言实现在奔四单核处理器上，性能提升4倍.使用SSE实现Daub-4则比C语言版本提升2.5倍.而且，当发生64k别名时(???),相对于没有发生时，有明显的高加速比，这是因为MMX和SSE大大降低了访存(四分之一).也有人在卫星图像处理中使用MMX扩展，并对一些常用操作分别用MMX汇编和C语言实现并做成库，也为很多数字图像处理程序带来很大性能提升。<br />
几何结构处理也是天生的并行任务，因为每个定点都能独立处理。有人在SIMD-PF中使用了Intel SSE，可以一次并行处理四个定点。试验结果显示，SSE为几何结构处理流水线带来了显著的性能提升，加速高达3.0x到3.8x.定点在主存中的分布对SIMD-PF的性能影响很大，预取的影响也不能忽略。<br />
SIMD扩展还用于在其他多媒体应用优化中，如快速傅立叶变换、H.264编解码。其中H.264编解码中，作者首先在奔四单核处理器上使用SIMD扩展获得3x加速，后采用多线程在多核上运行，加速高达4.6x.<br />
与此同时，也有芯片厂商根据实际应用，提出了几个新指令，这些新指令用于加速绝对差值求和运算(Sum-of-Absolute Difference,SAD).使用这些新指令，相对C语言能为SAD带来10x-14x的加速，而MMX的加速只有4x-7x。这些指令用于生成图像柱状图时，与C语言相比，有8x和11x的加速，而MMX只有3x和4x。</p>
<h5><a name="_43172942148112503_25010120611_5354417450726032"></a>数据安全</h5>
<p>目前的数据加密技术和工具在健壮性和性能上都无法满足下一代信息技术(个人移动通信，电子商务和互联网)的需求。现在的加解密算法通常是一个串行的数据操作序列，加密和哈希运算往往是瓶颈。椭圆曲线密码体制因安全性高，密钥长度短，计算速度快而受欢迎，也有使用SIMD扩展加速椭圆曲线密码体制的研究工作，在奔三处理器上，使用SIMD 得到了4.4x的加速.<br />
安全哈希算法(SHA):SHA-1,SHA-256,SHA-384,SHA-512.也有人在调研之后，表示SIMD能大大提升其性能。ASE加密算法已经有了SIMD扩展加速版本，加速1.7x</p>
<h5><a name="_659544001197848_4105998532982"></a>数据库</h5>
<p>随着数据库的普及和数据量的增加，高速数据库管理系统的需求越来越大。许多数据库查询，数据仓库和数据挖掘都依赖数据和计算，因此需要很高的处理能力。现在使用SIMD加速查询的研究还不多，但已经有人开始注意到可以使用SIMD实现很多数据库中的操作，如顺序扫描，聚合索引查找和链接等，使用SIMD扩展，取得的加速从10%到4x不等。</p>
<h5><a name="_41587631762723754_6645359694957733"></a>科学计算应用</h5>
<p>虽然SIMD扩展大量用于多媒体应用加速，但针对科学计算的SIMD扩展研究还很少，而且都处于起步阶段。<br />
DNA和蛋白质序列的比较和对齐在分子生物学，生物信息学中都很重要。其中最重要的字符串匹配操作是Smith-Waterman算法(SW)，但因为它是个计算密集算法，所以很多研究者都选择使用启发式策略来避免使用该算法，不过有人利用Intel的SIMD扩展(MMX和SSE)加速了该算法。<br />
矩阵计算是很多科学计算应用，尤其是数值算法的核心。对矩阵乘的改进会给科学计算带来性能提升。有人使用SIMD扩展在奔三处理器上实现了矩阵乘，比常用算法快2.09x.另外一个比较典型的是线性方程求解，有人使用Intel的SSE改写LU分解算法，能轻松获得2.5x的加速.另外使用Intel的C编译器，添加几个特殊数据结构和相关的intrinsic调用后，也能提升80%的性能。<br />
多项式求根算法是计算密集的，将其并行化也能获得可观的收益，有人选了4种常用多项式求根算法，使用C++，汇编语言和SIMD指令获得3x以上的加速.<br />
其他科学计算，如标准化交叉相关，寻找数组中的最大/最小值.也有人针对如何方便的使用SIMD，并和原有C/C++兼容，并给出了具体应用实现，见《SIMD Correlator librart for GNSS software receivers》。</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F02%2F11605%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">SIMD硬件的发展</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F01%2F11600%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">通用微处理中的SIMD指令扩展</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F12%2F10931%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">前瞻-拿起SIMD的武器II</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F20%2F10372%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Expected unqualified-id before﻿ 查错</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F03%2F11619%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F10%2F10928%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">自动向量化</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/04/10878/' rel='bookmark' title='前瞻-主流处理器中的数据并行支持(SIMD)'>前瞻-主流处理器中的数据并行支持(SIMD)</a></li>
<li><a href='http://www.lingcc.com/2010/05/12/10931/' rel='bookmark' title='前瞻-拿起SIMD的武器II'>前瞻-拿起SIMD的武器II</a></li>
<li><a href='http://www.lingcc.com/2009/11/22/10090/' rel='bookmark' title='并行计算前景- 应用和小矮人'>并行计算前景- 应用和小矮人</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2010/01/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</a></li>
<li><a href='http://www.lingcc.com/2010/04/14/10736/' rel='bookmark' title='探秘CPU性能测试：Spec CPU2000之整点篇'>探秘CPU性能测试：Spec CPU2000之整点篇</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/05/10/10928/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>龙芯电脑常见问题</title>
		<link>http://www.lingcc.com/2010/05/05/10894/</link>
		<comments>http://www.lingcc.com/2010/05/05/10894/#comments</comments>
		<pubDate>Wed, 05 May 2010 12:50:49 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[IT职业和生活]]></category>
		<category><![CDATA[Linux系统]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[discover]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[pmon]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[USE]]></category>
		<category><![CDATA[zh_CN]]></category>
		<category><![CDATA[链接]]></category>
		<category><![CDATA[龙芯]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10894</guid>
		<description><![CDATA[root密码多少？ loongson 如何添加新用户？ adduser username 怎么修改IP？ vim /etc/network/interfaces 如何重启网络？ /etc/init.d/networking restart 如何启动ssh？ /etc/init.d/ssh start 为啥root账户在/目录下修改，都提示 read only filesystem？因为根分区在挂载时以只读挂载.可以执行 mount / -o remount,rw. 如果以后都想要root在/下可写，可以修改/etc/init.d/discover，把倒数第二行mount的命令注掉即可。 如何修改默认启动项？到/etc/rc2.d/目录下，S开头的文件都是正常启动时要开启的，删除该文件，则不会启动。如果想添加启动项，将/etc/init.d/下的对应启动项做个软链接到/etc/rc2.d/下即可，链接文件名要S开头,加两位数字，加名称，两位数字代表启动顺序，启动时按照从小到大启动。 如何进入pmon命令行，不一样的机器不一样，看看启动时的提示，如果没有提示，试试DEL键，空格键，F12键 为啥我的pmon不自动加载boot.cfg,而是直接启动了某个默认内核？因为pmon可以设置直接启动某个内核。具体的设置可以在pmon命令行中输入set al+回车 可以查看装载的内核，set karg 查看内核启动参数。这些和boot.cfg中的kernel和args两行的作用相同。如果想修改之，可以使用set al +/dev/fs/…/vmlinx的形式直接覆盖原来的参数，也可以使用eset al修改之，注意执行eset al之后，记得按向右方向键，以便看到完整的参数。set karg也一样。 有办法让pmon设置加载boot.cfg文件吗？肯定有，因为既然能从加载boot.cfg设置为自动载入内核，就肯定能设置回去。不过抱歉，我还不知道怎么设置。更换pmon？ 命令行时，VIM或者其他命令执行时，命令提示老是输出方块/中文，怎么改成英文？export LC_ALL=C ; export LC_LANG=C. 因为系统默认的是中文环境。如果想以后都改成英文，并对所有用户有效，修改/etc/profile将最后几个变量的”zh_CN.UTF-8&#8243;改为C 为何每次ssh连接到某台机器时，都要等上几秒才能提示输入密码？这是因为ssh服务器端会反向查找DNS，可以修改服务器端/etc/hosts，增加cliet的ip地址。这样就快了。 相关文章： 走进Debian和Gentoo中的系统初始化过程 为龙芯电脑安装操作系统常见问题 export命令有何玄机 暴力了一把 How start_kernel get start? 最近用hg的一点记录<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F09%2F19%2F11208%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC即将支持龙芯3A</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F06%2F28%2F10983%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯N32系统上的Squirrelfish性能</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">暴力了一把</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F09%2F11055%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯中科公司招聘JAVA虚拟机开发工程师</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F08%2F15%2F11127%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于龙芯公司的小道消息</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/19/10892/' rel='bookmark' title='走进Debian和Gentoo中的系统初始化过程'>走进Debian和Gentoo中的系统初始化过程</a></li>
<li><a href='http://www.lingcc.com/2010/03/25/10717/' rel='bookmark' title='为龙芯电脑安装操作系统常见问题'>为龙芯电脑安装操作系统常见问题</a></li>
<li><a href='http://www.lingcc.com/2010/10/14/11316/' rel='bookmark' title='export命令有何玄机'>export命令有何玄机</a></li>
<li><a href='http://www.lingcc.com/2010/01/12/10645/' rel='bookmark' title='暴力了一把'>暴力了一把</a></li>
<li><a href='http://www.lingcc.com/2011/11/26/11814/' rel='bookmark' title='How start_kernel get start?'>How start_kernel get start?</a></li>
<li><a href='http://www.lingcc.com/2009/12/24/10414/' rel='bookmark' title='最近用hg的一点记录'>最近用hg的一点记录</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<ol>
<li>root密码多少？ loongson</li>
<li>如何添加新用户？ adduser username</li>
<li>怎么修改IP？ vim /etc/network/interfaces</li>
<li>如何重启网络？ /etc/init.d/networking restart</li>
<li>如何启动ssh？ /etc/init.d/ssh start</li>
<li>为啥root账户在/目录下修改，都提示 read only filesystem？因为根分区在挂载时以只读挂载.可以执行 mount / -o remount,rw. 如果以后都想要root在/下可写，可以修改/etc/init.d/discover，把倒数第二行mount的命令注掉即可。<span id="more-10894"></span></li>
<li>如何修改默认启动项？到/etc/rc2.d/目录下，S开头的文件都是正常启动时要开启的，删除该文件，则不会启动。如果想添加启动项，将/etc/init.d/下的对应启动项做个软链接到/etc/rc2.d/下即可，链接文件名要S开头,加两位数字，加名称，两位数字代表启动顺序，启动时按照从小到大启动。</li>
<li>如何进入pmon命令行，不一样的机器不一样，看看启动时的提示，如果没有提示，试试DEL键，空格键，F12键</li>
<li>为啥我的pmon不自动加载boot.cfg,而是直接启动了某个默认内核？因为pmon可以设置直接启动某个内核。具体的设置可以在pmon命令行中输入set al+回车 可以查看装载的内核，set karg 查看内核启动参数。这些和boot.cfg中的kernel和args两行的作用相同。如果想修改之，可以使用set al +/dev/fs/…/vmlinx的形式直接覆盖原来的参数，也可以使用eset al修改之，注意执行eset al之后，记得按向右方向键，以便看到完整的参数。set karg也一样。</li>
<li>有办法让pmon设置加载boot.cfg文件吗？肯定有，因为既然能从加载boot.cfg设置为自动载入内核，就肯定能设置回去。不过抱歉，我还不知道怎么设置。更换pmon？</li>
<li>命令行时，VIM或者其他命令执行时，命令提示老是输出方块/中文，怎么改成英文？export LC_ALL=C ; export LC_LANG=C. 因为系统默认的是中文环境。如果想以后都改成英文，并对所有用户有效，修改/etc/profile将最后几个变量的”zh_CN.UTF-8&#8243;改为C</li>
<li>为何每次ssh连接到某台机器时，都要等上几秒才能提示输入密码？这是因为ssh服务器端会反向查找DNS，可以修改服务器端/etc/hosts，增加cliet的ip地址。这样就快了。</li>
</ol>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F09%2F19%2F11208%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC即将支持龙芯3A</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F06%2F28%2F10983%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯N32系统上的Squirrelfish性能</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F12%2F10645%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">暴力了一把</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F07%2F09%2F11055%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">龙芯中科公司招聘JAVA虚拟机开发工程师</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F08%2F15%2F11127%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F05%2F10894%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">关于龙芯公司的小道消息</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/05/19/10892/' rel='bookmark' title='走进Debian和Gentoo中的系统初始化过程'>走进Debian和Gentoo中的系统初始化过程</a></li>
<li><a href='http://www.lingcc.com/2010/03/25/10717/' rel='bookmark' title='为龙芯电脑安装操作系统常见问题'>为龙芯电脑安装操作系统常见问题</a></li>
<li><a href='http://www.lingcc.com/2010/10/14/11316/' rel='bookmark' title='export命令有何玄机'>export命令有何玄机</a></li>
<li><a href='http://www.lingcc.com/2010/01/12/10645/' rel='bookmark' title='暴力了一把'>暴力了一把</a></li>
<li><a href='http://www.lingcc.com/2011/11/26/11814/' rel='bookmark' title='How start_kernel get start?'>How start_kernel get start?</a></li>
<li><a href='http://www.lingcc.com/2009/12/24/10414/' rel='bookmark' title='最近用hg的一点记录'>最近用hg的一点记录</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/05/05/10894/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>前瞻-全时优化和LLVM-2</title>
		<link>http://www.lingcc.com/2010/04/29/10728/</link>
		<comments>http://www.lingcc.com/2010/04/29/10728/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 04:14:19 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[LLVM]]></category>
		<category><![CDATA[编译前沿]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[编译理论实践和应用]]></category>
		<category><![CDATA[elf]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[JIT]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[SSA]]></category>
		<category><![CDATA[x86]]></category>
		<category><![CDATA[中间表示]]></category>
		<category><![CDATA[全时优化]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[空闲时优化]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[编译器架构]]></category>
		<category><![CDATA[编译器设计]]></category>
		<category><![CDATA[虚拟机]]></category>
		<category><![CDATA[过程间优化]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10728</guid>
		<description><![CDATA[上篇文章，以论文为主要依据，介绍了LLVM的概况和中间表示，本篇关注论文的后半部分内容&#8211;架构设计和LLVM的整体评测： LLVM的架构设计： 总览 LLVM的架构设计以让传统的链接时，安装时，运行时和空闲时代码转换都能透明地在LLVM中间表示上展开为目的。上图就是LLVM的高层设计架构。包括静态的编译器前端用于生成LLVM中间表示；连接器用于做连接时优化，尤其是过程间优化。连接器的输出被JIT或者机器代码生成器生成机器代码。在机器代码生成时，可以通过插入低代价的抽样指令来测量运行时的profile，检测热代码，并将空闲时进行优化。 作者认为LLVM的这种架构具有五个优点，这些优点现阶段的编译器或虚拟机等都无法完全具备，它们是： 提供程序的高层信息 离线代码生成器 用户级的profiling和优化 透明的运行时模型 统一的全程序编译 作者比较了如今存在的一些系统，分析它们是否具备以上5点： 传统的源码级编译器：能提供2和4，但很难提供1，3，5.虽然也能提供过程间优化，但需要修改Makefile 一些商用编译器能够在链接时部分支持1和5，这也是用过将它们的中间表示信息输出到目标文件中。但无法在空闲时使用这些信息 高层虚拟机，如JVM和CLI能提供3，部分支持1. CLI部分支持5，因为它支持多语言代码，但很多底层系统代码只能作为不可控代码直接运行。 透明的二进制运行时优化系统，如Dynamo和Transmeta能提供2，4，5，但不能提供1，而且对3的支持只在运行时。 静态profile制导优化（PGO），能提供3代价是不再对其他阶段透明。另外PGO也有缺点：应用开发者很少用它；使用PGO意味着训练用的输入需要严格和用户行为一致；profiling信息是完全静态的。 当然LLVM也有自己的缺点，作者在文中提到两点：1，源程序语言相关优化需要在前端生成LLVM中间表示之前完成；2，编程语言需不需要一个庞大的运行时系统还有争议。 编译时：外部前端和静态优化 外部静态LLVM编译器(即前端)将源语言程序转换为LLVM虚拟指令集。每种静态编译器都要完成三个关键任务：进行语言相关优化，如使用高层函数优化闭包(closures); 将源程序转换为LLVM代码，并综合尽量多的LLVM类型信息，如指针、结构体和数组信息；启动LLVM的全局或过程间优化。其中第二个任务是外部编译器必须要完成的。LLVM的优化都被写成库的形式，方便前端使用。前端无需构建SSA，可以使用一个栈存放变量，于是就能用栈来实现SSA的构建了。对于所谓的高层语言相关优化，LLVM的观点是：将LLVM优化扩展到特定的转换要好过在编码时为特定语言投入大量的精力。 连接时和过程间优化 LLVM中，连接时是绝大部分分析和转换可以实现的首个编译阶段。LLVM现在包含一些过程间优化，包括：内容相关指针分析；调用图构建；定义-引用分析和过程间转换(内联，死全局变量删除、死参数删除、死类型删除、常数传播、数据越界检查删除、简单结构体域重排、自动存储分配等).LLVM中提供的编译和运行时优化器能加快过程间分析速度。编译时，汇总每个函数的过程间信息，并附在LLVM 代码中。链接时，过程间优化器以这些信息作为输入，而非重新从源码中得到信息。这种技术有效的缩短了编译实践，而且在链接时之前，并未破坏源码的结构。 离线和实时代码生成器 代码生成器用于运行代码前将LLVM中间表示转换为目标平台的机器语言(目前LLVM支持X86和Sparc V9平台).有两种方式实现这种转换，一是在链接时或安装时代码生成器静态地生成高效本地码，这时可以使用代价高的代码生成技术。如果用户打算使用运行时和离线优化器，LLVM中间表示将会附在可执行文件中，并且代码生成器会插入低代价的指令来识别常被执行到的代码区间。另外，LLVM还有一个实时执行引擎，直接在运行时启动代码转换器。 运行时程序行为采集和重优化 LLVM设计的目标之一是开发一种全新的普通应用运行时优化架构。程序执行中，识别最常被执行的路径，通常是热循环。识别出热循环后，复制热区域代码，并使用LLVM代码生成器，优化并生成机器码，并在原始代码和新机器码之间插入一个分支指令。这种机制很强大，理由有三：本地代码生成恩公使用经典算法来产生高性能代码；因为本地代码生成器和运行时优化器都是LLVM的一部分，因此能很好的协同工作，让运行时优化起从代码生成器中得到很好支持；运行时优化起能从LLVM的中间表示中得到高层信息以便实施高度优化。 用户行为信息制导的离线重优化 因为LLVM中间表示能保存，使得应用程序的空闲时离线优化能透明地在用户系统上进行。该优化器可以简单修改连接时过程间优化器来得到，只需要把重点放在目标机相关和反馈信息指导优化即可。 LLVM的评测和应用 评测LLVM 作者评测了LLVM的四个方面：语言无关类型系统的完备性；高级语言特性到LLVM中间表示转换如何实现；LLVM中间表示的复杂度；LLVM的编译速度。 类型系统完备性方面，LLVM使用流敏感，域敏感和内容敏感的指针分析算法来保证LLVM类型系统的可靠性。 高级语言特性方面，作者给出了C++中的隐式调用、模板、基类、虚函数表、例外如何使用LLVM中间表示表达。 LLVM中间表示的复杂度方面，作者对比了GCC3.3 O3下生成X86，Sparc可执行文件和LLVM中间表示文件的大小，结果显示LLVM中间表示大小和X86可执行文件大小相当，明显小于Sparc的可执行文件，作者相信这是LLVM的优势，因为LLVM中间表示使用无限多的寄存器，丰富的类型信息，控制流信息和数据流信息(SSA),而可执行代码没有这些信息。 LLVM的编译速度方面，作者给出了LLVM上几个过程间优化：DGE(aggressive Dead Global variable and function Elimination),DAE(aggressive Dead Argument and return value Elimination),inline转换时间并和GCC O3的编译时间对比，结果显示LLVM做以上三个过程间优化的编译时间要大大短于GCC O3的编译时间，而且GCC O3还没有过程间优化，作者也给出了LLVM的优化效果。 LLVM的应用 <a href='http://www.lingcc.com/2010/04/29/10728/'>[...]</a><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F03%2F10884%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">安装LLVM2.7 step by step</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F20%2F11361%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM居然开始做广告了！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM 2.7 发布</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F12%2F08%2F11882%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">你好，LLVM 3.0</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/04/07/10721/' rel='bookmark' title='前瞻-全时优化和LLVM-1'>前瞻-全时优化和LLVM-1</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/12/28/10469/' rel='bookmark' title='Open64课程-结语'>Open64课程-结语</a></li>
<li><a href='http://www.lingcc.com/2009/11/19/10024/' rel='bookmark' title='Open64课程-编译过程'>Open64课程-编译过程</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>上篇文章，以论文为主要依据，介绍了LLVM的概况和中间表示，本篇关注论文的后半部分内容&#8211;架构设计和LLVM的整体评测：</p>
<h3>LLVM的架构设计：</h3>
<h4>总览</h4>
<p><a href="http://www.lingcc.com/wp-content/uploads/2010/04/llvm-arch.jpg"><img class="alignnone size-medium wp-image-10729" title="llvm-arch" src="http://www.lingcc.com/wp-content/uploads/2010/04/llvm-arch-300x65.jpg" alt="" width="300" height="65" /></a></p>
<p>LLVM的架构设计以让传统的链接时，安装时，运行时和空闲时代码转换都能透明地在LLVM中间表示上展开为目的。上图就是LLVM的高层设计架构。包括静态的编译器前端用于生成LLVM中间表示；连接器用于做连接时优化，尤其是过程间优化。连接器的输出被JIT或者机器代码生成器生成机器代码。在机器代码生成时，可以通过插入低代价的抽样指令来测量运行时的profile，检测热代码，并将空闲时进行优化。</p>
<p><span id="more-10728"></span></p>
<p>作者认为LLVM的这种架构具有五个优点，这些优点现阶段的编译器或虚拟机等都无法完全具备，它们是：</p>
<ol>
<li>提供程序的高层信息</li>
<li>离线代码生成器</li>
<li>用户级的profiling和优化</li>
<li>透明的运行时模型</li>
<li>统一的全程序编译</li>
</ol>
<p>作者比较了如今存在的一些系统，分析它们是否具备以上5点：</p>
<ul>
<li>传统的源码级编译器：能提供2和4，但很难提供1，3，5.虽然也能提供过程间优化，但需要修改Makefile</li>
<li>一些商用编译器能够在链接时部分支持1和5，这也是用过将它们的中间表示信息输出到目标文件中。但无法在空闲时使用这些信息</li>
<li>高层虚拟机，如JVM和CLI能提供3，部分支持1. CLI部分支持5，因为它支持多语言代码，但很多底层系统代码只能作为不可控代码直接运行。</li>
<li>透明的二进制运行时优化系统，如Dynamo和Transmeta能提供2，4，5，但不能提供1，而且对3的支持只在运行时。</li>
<li>静态profile制导优化（PGO），能提供3代价是不再对其他阶段透明。另外PGO也有缺点：应用开发者很少用它；使用PGO意味着训练用的输入需要严格和用户行为一致；profiling信息是完全静态的。</li>
</ul>
<p>当然LLVM也有自己的缺点，作者在文中提到两点：1，源程序语言相关优化需要在前端生成LLVM中间表示之前完成；2，编程语言需不需要一个庞大的运行时系统还有争议。</p>
<h4>编译时：外部前端和静态优化</h4>
<p>外部静态LLVM编译器(即前端)将源语言程序转换为LLVM虚拟指令集。每种静态编译器都要完成三个关键任务：进行语言相关优化，如使用高层函数优化闭包(closures); 将源程序转换为LLVM代码，并综合尽量多的LLVM类型信息，如指针、结构体和数组信息；启动LLVM的全局或过程间优化。其中第二个任务是外部编译器必须要完成的。LLVM的优化都被写成库的形式，方便前端使用。前端无需构建SSA，可以使用一个栈存放变量，于是就能用栈来实现SSA的构建了。对于所谓的高层语言相关优化，LLVM的观点是：将LLVM优化扩展到特定的转换要好过在编码时为特定语言投入大量的精力。</p>
<h4>连接时和过程间优化</h4>
<p>LLVM中，连接时是绝大部分分析和转换可以实现的首个编译阶段。LLVM现在包含一些过程间优化，包括：内容相关指针分析；调用图构建；定义-引用分析和过程间转换(内联，死全局变量删除、死参数删除、死类型删除、常数传播、数据越界检查删除、简单结构体域重排、自动存储分配等).LLVM中提供的编译和运行时优化器能加快过程间分析速度。编译时，汇总每个函数的过程间信息，并附在LLVM 代码中。链接时，过程间优化器以这些信息作为输入，而非重新从源码中得到信息。这种技术有效的缩短了编译实践，而且在链接时之前，并未破坏源码的结构。</p>
<h4>离线和实时代码生成器</h4>
<p>代码生成器用于运行代码前将LLVM中间表示转换为目标平台的机器语言(目前LLVM支持X86和Sparc V9平台).有两种方式实现这种转换，一是在链接时或安装时代码生成器静态地生成高效本地码，这时可以使用代价高的代码生成技术。如果用户打算使用运行时和离线优化器，LLVM中间表示将会附在可执行文件中，并且代码生成器会插入低代价的指令来识别常被执行到的代码区间。另外，LLVM还有一个实时执行引擎，直接在运行时启动代码转换器。</p>
<h4>运行时程序行为采集和重优化</h4>
<p>LLVM设计的目标之一是开发一种全新的普通应用运行时优化架构。程序执行中，识别最常被执行的路径，通常是热循环。识别出热循环后，复制热区域代码，并使用LLVM代码生成器，优化并生成机器码，并在原始代码和新机器码之间插入一个分支指令。这种机制很强大，理由有三：本地代码生成恩公使用经典算法来产生高性能代码；因为本地代码生成器和运行时优化器都是LLVM的一部分，因此能很好的协同工作，让运行时优化起从代码生成器中得到很好支持；运行时优化起能从LLVM的中间表示中得到高层信息以便实施高度优化。</p>
<h4>用户行为信息制导的离线重优化</h4>
<p>因为LLVM中间表示能保存，使得应用程序的空闲时离线优化能透明地在用户系统上进行。该优化器可以简单修改连接时过程间优化器来得到，只需要把重点放在目标机相关和反馈信息指导优化即可。</p>
<h3>LLVM的评测和应用</h3>
<h4>评测LLVM</h4>
<p>作者评测了LLVM的四个方面：语言无关类型系统的完备性；高级语言特性到LLVM中间表示转换如何实现；LLVM中间表示的复杂度；LLVM的编译速度。</p>
<p>类型系统完备性方面，LLVM使用流敏感，域敏感和内容敏感的指针分析算法来保证LLVM类型系统的可靠性。</p>
<p>高级语言特性方面，作者给出了C++中的隐式调用、模板、基类、虚函数表、例外如何使用LLVM中间表示表达。</p>
<p>LLVM中间表示的复杂度方面，作者对比了GCC3.3 O3下生成X86，Sparc可执行文件和LLVM中间表示文件的大小，结果显示LLVM中间表示大小和X86可执行文件大小相当，明显小于Sparc的可执行文件，作者相信这是LLVM的优势，因为LLVM中间表示使用无限多的寄存器，丰富的类型信息，控制流信息和数据流信息(SSA),而可执行代码没有这些信息。</p>
<p>LLVM的编译速度方面，作者给出了LLVM上几个过程间优化：DGE(aggressive Dead Global variable and function Elimination),DAE(aggressive Dead Argument and return value Elimination),inline转换时间并和GCC O3的编译时间对比，结果显示LLVM做以上三个过程间优化的编译时间要大大短于GCC O3的编译时间，而且GCC O3还没有过程间优化，作者也给出了LLVM的优化效果。</p>
<h4>LLVM的应用</h4>
<p>LLVM中已经实现的几种技术：如数据结构体分析(Data Structure Analysis)和自动查询分配(Automatic Poll Allocation)都得益于LLVM的架构。</p>
<p>SAFECode:一个安全的低级中间表示和运行环境。该中间表示基于LLVM中间表示，目的是增强程序的存储安全。除了运行时优化外，SAFECode几乎使用了LLVM架构中的所有结构。</p>
<p>虚拟指令集计算机的外部指令系统设计：虚拟指令集处理器可以使用两个完全不同指令集。外在的虚拟指令级和隐藏的内部实现指令集。LLVM的中间表示就能作为一种外部虚拟指令集。</p>
<h3>与LLVM相关的工作:</h3>
<p>高层语言虚拟机，如SmallTalk，Self，JVM和CLI，需要特定的对象模型和运行时系统支持，但因为太高层，其他语言(如C++)可能很难在该虚拟机上运行。为了可移植性，中间表示需要严格的类型安全，这也限制了对多语言的支持。类型安全的检测也使得很多优化无法进行。</p>
<p>虽然微软的CLI有些支持不同语言的特性。但CLI支持多语言的unmanaged方式使得，部分语言不能用CLI的中间表示完整表达，优化机会也就随之丧失。</p>
<p>Omniware虚拟机和LLVM比较像，因为都实现抽象的低层RISC指令级。但Omniware缺乏高层的类型信息。</p>
<p>Kistler和Franz给出了一个编译器架构，初始代码生成很简单，依靠程序运行行为指导接下来的优化。但不能支持任意语言，而且也没有透明的运行时系统。</p>
<p>类型化的中间表示方面，也有很多相关工作。但多数都为了类型安全，提取高层语言信息。LLVM则重点放在在静态编译优化之外使得经典的程序分析和优化算法能够实现。</p>
<p>统一、通用的中间表示方面也有了不少研究。但几乎都失败了。这些中间表示大多从AST级抽取信息并尽量支持所有源语言特性。LLVM的中间表示更像汇编，使用很小的类型集和低层操作。</p>
<p>过程间优化方面，有的为给定处理器做基于汇编的优化；有些从静态编译器中得到附加信息。但这些都没有考虑运行时和离线优化支持。</p>
<p>也有一些系统提供透明的运行时优化。但这些系统都只是努力的优化机器码。LLVM则是以提供类型，数据流和精确控制流图为目标。</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F03%2F10884%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">安装LLVM2.7 step by step</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F20%2F11361%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM居然开始做广告了！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM 2.7 发布</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F12%2F08%2F11882%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F29%2F10728%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">你好，LLVM 3.0</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/04/07/10721/' rel='bookmark' title='前瞻-全时优化和LLVM-1'>前瞻-全时优化和LLVM-1</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/12/28/10469/' rel='bookmark' title='Open64课程-结语'>Open64课程-结语</a></li>
<li><a href='http://www.lingcc.com/2009/11/19/10024/' rel='bookmark' title='Open64课程-编译过程'>Open64课程-编译过程</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/04/29/10728/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>LLVM 2.7 发布</title>
		<link>http://www.lingcc.com/2010/04/28/10807/</link>
		<comments>http://www.lingcc.com/2010/04/28/10807/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 04:26:39 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[LLVM]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[clang]]></category>
		<category><![CDATA[全时优化]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[过程间优化]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10807</guid>
		<description><![CDATA[LLVM新版本相对于2.6增加了很多新特性并对很多功能做了改进.包括生成代码质量显著提高、生成调试信息的改进以及核心架构生的很多新特性。最令人兴奋的特性是Clang(LLVM的前端)能自举。自举是任何编译器实际开发中最令人兴奋的里程碑，而且也标志着Clang对复杂的C++标准大部分支持。 LLVM是苹果公司主导开发的下一代编译器，目标是能实现全时优化，即在编译时静态分析源代码实现优化；链接时分析所有源码文件做更加激进有效的过程间优化；运行时使用实时编译进行实时优化，并采集使用信息；空闲时利用使用信息实现反馈优化。但目前LLVM还很不完善，很多功能还亟待开发和完善。目前LLVM仅支持C语言和部分C++. LLVM已经应用在不少场合。如，Google用它作为一个Python解释器的底层实现(Unladen Swallow)。苹果公司用它实现Mac OS中OpenCL的底层支持。 Chris Lattner 声明 LLVM 2.7发布的邮件 LLVM 2.7 release notes 相关文章： Google的野心&#8211;Native Client+LLVM 前瞻-LLVM大事记(2004-2010) 前瞻-全时优化和LLVM-1 前瞻-全时优化和LLVM-2 安装LLVM2.7 step by step AMD intern and full time compiler position based on OpenCL and LLVM<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F03%2F10573%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">过程间分析(InterProcedural Analysis)很好很强大</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F14%2F11333%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Clang可以编译Chromium了</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F17%2F10657%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">前瞻- 编译器的bug就不能少点？</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F20%2F11361%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM居然开始做广告了！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F03%2F10884%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">安装LLVM2.7 step by step</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/06/02/10955/' rel='bookmark' title='Google的野心&#8211;Native Client+LLVM'>Google的野心&#8211;Native Client+LLVM</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2010/04/07/10721/' rel='bookmark' title='前瞻-全时优化和LLVM-1'>前瞻-全时优化和LLVM-1</a></li>
<li><a href='http://www.lingcc.com/2010/04/29/10728/' rel='bookmark' title='前瞻-全时优化和LLVM-2'>前瞻-全时优化和LLVM-2</a></li>
<li><a href='http://www.lingcc.com/2010/05/03/10884/' rel='bookmark' title='安装LLVM2.7 step by step'>安装LLVM2.7 step by step</a></li>
<li><a href='http://www.lingcc.com/2011/03/04/11545/' rel='bookmark' title='AMD intern and full time compiler position based on OpenCL and LLVM'>AMD intern and full time compiler position based on OpenCL and LLVM</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>LLVM新版本相对于2.6增加了很多新特性并对很多功能做了改进.包括生成代码质量显著提高、生成调试信息的改进以及核心架构生的很多新特性。最令人兴奋的特性是Clang(LLVM的前端)能自举。自举是任何编译器实际开发中最令人兴奋的里程碑，而且也标志着Clang对复杂的C++标准大部分支持。</p>
<p>LLVM是苹果公司主导开发的下一代编译器，目标是能实现全时优化，即在编译时静态分析源代码实现优化；链接时分析所有源码文件做更加激进有效的过程间优化；运行时使用实时编译进行实时优化，并采集使用信息；空闲时利用使用信息实现反馈优化。但目前LLVM还很不完善，很多功能还亟待开发和完善。目前LLVM仅支持C语言和部分C++.</p>
<p>LLVM已经应用在不少场合。如，Google用它作为一个Python解释器的底层实现(Unladen Swallow)。苹果公司用它实现Mac OS中OpenCL的底层支持。</p>
<p><a href="http://lists.cs.uiuc.edu/pipermail/llvm-announce/2010-April/000034.html" target="_blank">Chris Lattner 声明 LLVM 2.7发布的邮件 </a><br />
<a href="http://llvm.org/releases/2.7/docs/ReleaseNotes.html" target="_blank"> LLVM 2.7 release notes</a></p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F03%2F10573%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">过程间分析(InterProcedural Analysis)很好很强大</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F14%2F11333%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Clang可以编译Chromium了</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F17%2F10657%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">前瞻- 编译器的bug就不能少点？</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F20%2F11361%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM居然开始做广告了！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F03%2F10884%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">安装LLVM2.7 step by step</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/06/02/10955/' rel='bookmark' title='Google的野心&#8211;Native Client+LLVM'>Google的野心&#8211;Native Client+LLVM</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2010/04/07/10721/' rel='bookmark' title='前瞻-全时优化和LLVM-1'>前瞻-全时优化和LLVM-1</a></li>
<li><a href='http://www.lingcc.com/2010/04/29/10728/' rel='bookmark' title='前瞻-全时优化和LLVM-2'>前瞻-全时优化和LLVM-2</a></li>
<li><a href='http://www.lingcc.com/2010/05/03/10884/' rel='bookmark' title='安装LLVM2.7 step by step'>安装LLVM2.7 step by step</a></li>
<li><a href='http://www.lingcc.com/2011/03/04/11545/' rel='bookmark' title='AMD intern and full time compiler position based on OpenCL and LLVM'>AMD intern and full time compiler position based on OpenCL and LLVM</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/04/28/10807/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>来仔细看看GCC 4.5.0</title>
		<link>http://www.lingcc.com/2010/04/16/10746/</link>
		<comments>http://www.lingcc.com/2010/04/16/10746/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 04:39:51 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[GCC]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[amd]]></category>
		<category><![CDATA[builtin]]></category>
		<category><![CDATA[compiler infrastructure]]></category>
		<category><![CDATA[elf]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[USE]]></category>
		<category><![CDATA[x86]]></category>
		<category><![CDATA[内建函数]]></category>
		<category><![CDATA[并行]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[编程技术]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[过程间优化]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10746</guid>
		<description><![CDATA[距离GCC 4.4的发布一年之久，GNU终于发布GCC 4.5了。新版本带来了很多新特性，包括使用MPC库在编译时完成复杂的算术计算，C++0x支持增强，使用部分Graphite完成自动并行化，支持新的ARM处理器，Intel Atom优化和调优支持，以及AMD Orochi优化支持等。今年稍晚发布的Fedora 14,Ubuntu 10.10,OpenSUSE 11.3，都将有GCC4.5，估计Gentoo马上就会有支持了，磨拳擦掌准备试用喽：）详细支持如下： 总体说明： 编译GCC需要MPC库 故纸堆里的旧系统和很久没有更新和测试的系统在GCC4.5中被标记为待放弃，包括IRIX, Solaris 7, Tru64 UNIX V5.1. GCC4.4中标记为待放弃的支持被放弃 移除Itanium 1变种支持，但Itanium2编译的程序能在Itanium1上正确执行 GCC生成的调试信息包括了更多DWARF 3的特性，甚至包含了DWARF4的一些特性.GDB7.0之前的版本将无法使用这些特性.所以调试GCC4.5编译的程序需要使用GDB7.0及以上版本.也可以使用选项 -gdwarf-s  -gstrict-dwarf来禁止生成DWARF4信息，或者-gdwarf-2 -gstrict-dwarf让GCC严格执行DWARF2标准. X86上，浮点运算在GCC4.5上使用严格C99语法编译时，可能会运行变慢。这是为了和标准一致，可以通过选项-fexcess-precision=fast来避免严格的标准限制。 noinline属性不再能阻止整个函数拷贝。但可以通过新的属性noclone做到。 改进： -save-temps可以增加参数，该功能让用户可以在并行编译的时候得到编译器的中间文件，但不会在不同的文件夹中使用相同的文件名从而干扰比起。 调试信息目标文件也都被放在了同个文件夹下，而不是当前工作目录，这样用户可以在并行编译的时候得到调试信息。 集成了MPC库，这样可以让GCC在编译时更精确的评估复杂的算术运算。GCC也可以通过它，对于常数作参数的数学运算类内建函数调用，直接在编译时使用相等的返回值来代替之。包括下列内建函数：cacos, cacosh, casin, casinh, catan, catanh, ccos, ccosh, cexp, clog, cpow, csin, csinh, csqrt, ctan和ctanh。 新的链接时优化器(-flto),打开此选项后，GCC会针对每个输入文件，产生bytecode的表示形式，并将其写入每个目标文件的特定ELF区內。链接时，从这些ELF区內读取函数体，并将其实体化为转换单元。这样就可以使得过程间优化能在不同的文件间进行(甚至不同语言间),进而可能提升性能。使用此功能需要在编译时和链接时都增加-flto选项。如果不需要程序输出任何符号，可以联合-fwhopr和-fwhole-program来让过程间优化器执行更加激进的优化。 增强自动并行化，现在支持外层循环的并行化。 自动并行化能作为Graphite的一部分来打开。在选项-ftree-parallelize-loops=的基础上增加-floop-parallelize-all能打开基于Graphite的优化。(注:Graphite是GCC中使用多面体模型做循环优化的部分) 重写基于严格指针的优化架构，会提高生成代码的效率。基于严格指针的优化在打开-fno-strict-aliasing后可用。 增加关于函数传参的新优化。试图改变函数原型，避免无用传递，仅传递结构体中特定部分，并将引用传参改为值传参。-O2，-Os及以上级别默认开启此优化。 优化异常控制代码。 新语言支持和特定语言改进 所有语言：-fshow-colum选项默认打开，错误信息现在有列信息。 C类语言：若#include的文件未找到，编译器会立即退出；增加一个新内建函数__builtin_unreachable()；增加-Wlogical-op选项，对可能存在的逻辑错误，报警告；嵌入式汇编增加goto特性，允许汇编中的语句直接跳到C中的标号处；C++0x原始strings(raw string)支持；deprecatd树形现在可以增加可选字符串参数,如__attribute__((deprecated(“text string”))),这样，deprecation警告会和字符串一同打印。 <a href='http://www.lingcc.com/2010/04/16/10746/'>[...]</a><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F27%2F11679%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC几个选项学习</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F09%2F16%2F11210%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC Internal 中文文档上线</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F11%2F29%2F11859%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC如何进出GIMPLE中间表示</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F09%2F19%2F11208%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC即将支持龙芯3A</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2010/01/22/10668/' rel='bookmark' title='WebKit和Firefox的JavaScript性能对比'>WebKit和Firefox的JavaScript性能对比</a></li>
<li><a href='http://www.lingcc.com/2009/12/16/10317/' rel='bookmark' title='Open64课程&#8212;代码生成(CG)'>Open64课程&#8212;代码生成(CG)</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2010/01/08/10609/' rel='bookmark' title='GCC中的pie和fpie选项'>GCC中的pie和fpie选项</a></li>
<li><a href='http://www.lingcc.com/2009/12/14/10295/' rel='bookmark' title='open64课程&#8211;过程间分析优化(IPA)'>open64课程&#8211;过程间分析优化(IPA)</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>距离GCC 4.4的发布一年之久，GNU终于发布GCC 4.5了。新版本带来了很多新特性，包括使用MPC库在编译时完成复杂的算术计算，C++0x支持增强，使用部分Graphite完成自动并行化，支持新的ARM处理器，Intel Atom优化和调优支持，以及AMD Orochi优化支持等。今年稍晚发布的Fedora 14,Ubuntu 10.10,OpenSUSE 11.3，都将有GCC4.5，估计Gentoo马上就会有支持了，磨拳擦掌准备试用喽：）详细支持如下：</p>
<h4>总体说明：</h4>
<ul>
<li>编译GCC需要MPC库</li>
<li>故纸堆里的旧系统和很久没有更新和测试的系统在GCC4.5中被标记为待放弃，包括IRIX, Solaris 7, Tru64 UNIX V5.1.</li>
<li>GCC4.4中标记为待放弃的支持被放弃</li>
<li>移除Itanium 1变种支持，但Itanium2编译的程序能在Itanium1上正确执行</li>
<li>GCC生成的调试信息包括了更多DWARF 3的特性，甚至包含了DWARF4的一些特性.GDB7.0之前的版本将无法使用这些特性.所以调试GCC4.5编译的程序需要使用GDB7.0及以上版本.也可以使用选项 -gdwarf-s  -gstrict-dwarf来禁止生成DWARF4信息，或者-gdwarf-2 -gstrict-dwarf让GCC严格执行DWARF2标准.</li>
<li>X86上，浮点运算在GCC4.5上使用严格C99语法编译时，可能会运行变慢。这是为了和标准一致，可以通过选项-fexcess-precision=fast来避免严格的标准限制。</li>
<li>noinline属性不再能阻止整个函数拷贝。但可以通过新的属性noclone做到。</li>
</ul>
<p><span id="more-10746"></span></p>
<h4>改进：</h4>
<ul>
<li>-save-temps可以增加参数，该功能让用户可以在并行编译的时候得到编译器的中间文件，但不会在不同的文件夹中使用相同的文件名从而干扰比起。</li>
<li>调试信息目标文件也都被放在了同个文件夹下，而不是当前工作目录，这样用户可以在并行编译的时候得到调试信息。</li>
<li>集成了MPC库，这样可以让GCC在编译时更精确的评估复杂的算术运算。GCC也可以通过它，对于常数作参数的数学运算类内建函数调用，直接在编译时使用相等的返回值来代替之。包括下列内建函数：cacos, cacosh, casin, casinh, catan, catanh, ccos, ccosh, cexp, clog, cpow, csin, csinh, csqrt, ctan和ctanh。</li>
<li>新的链接时优化器(-flto),打开此选项后，GCC会针对每个输入文件，产生bytecode的表示形式，并将其写入每个目标文件的特定ELF区內。链接时，从这些ELF区內读取函数体，并将其实体化为转换单元。这样就可以使得过程间优化能在不同的文件间进行(甚至不同语言间),进而可能提升性能。使用此功能需要在编译时和链接时都增加-flto选项。如果不需要程序输出任何符号，可以联合-fwhopr和-fwhole-program来让过程间优化器执行更加激进的优化。</li>
<li>增强自动并行化，现在支持外层循环的并行化。</li>
<li>自动并行化能作为Graphite的一部分来打开。在选项-ftree-parallelize-loops=的基础上增加-floop-parallelize-all能打开基于Graphite的优化。(注:Graphite是GCC中使用多面体模型做循环优化的部分)</li>
<li>重写基于严格指针的优化架构，会提高生成代码的效率。基于严格指针的优化在打开-fno-strict-aliasing后可用。</li>
<li>增加关于函数传参的新优化。试图改变函数原型，避免无用传递，仅传递结构体中特定部分，并将引用传参改为值传参。-O2，-Os及以上级别默认开启此优化。</li>
<li>优化异常控制代码。</li>
</ul>
<h4>新语言支持和特定语言改进</h4>
<ul>
<li>所有语言：-fshow-colum选项默认打开，错误信息现在有列信息。</li>
<li>C类语言：若#include的文件未找到，编译器会立即退出；增加一个新内建函数__builtin_unreachable()；增加-Wlogical-op选项，对可能存在的逻辑错误，报警告；嵌入式汇编增加goto特性，允许汇编中的语句直接跳到C中的标号处；C++0x原始strings(raw string)支持；deprecatd树形现在可以增加可选字符串参数,如__attribute__((deprecated(“text string”))),这样，deprecation警告会和字符串一同打印。</li>
<li>其他针对各个语言的详细细节请参考官方release。</li>
</ul>
<h4>其他改进：</h4>
<ul>
<li>插件支持：可以不通过改变编译器代码来扩展编译器功能。-fplugin=file.so能指定GCC载入动态链接文件file.so，并将其作为编译器的一部分执行。更多的细节请参考相关文档。</li>
<li>安装文件夹稍有变动。</li>
</ul>
<p>参考：</p>
<p>http://gcc.gnu.org/gcc-4.5/changes.html</p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F06%2F27%2F11679%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC几个选项学习</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F09%2F16%2F11210%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC Internal 中文文档上线</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F11%2F29%2F11859%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC如何进出GIMPLE中间表示</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F09%2F19%2F11208%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F16%2F10746%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">GCC即将支持龙芯3A</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2010/01/22/10668/' rel='bookmark' title='WebKit和Firefox的JavaScript性能对比'>WebKit和Firefox的JavaScript性能对比</a></li>
<li><a href='http://www.lingcc.com/2009/12/16/10317/' rel='bookmark' title='Open64课程&#8212;代码生成(CG)'>Open64课程&#8212;代码生成(CG)</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2010/01/08/10609/' rel='bookmark' title='GCC中的pie和fpie选项'>GCC中的pie和fpie选项</a></li>
<li><a href='http://www.lingcc.com/2009/12/14/10295/' rel='bookmark' title='open64课程&#8211;过程间分析优化(IPA)'>open64课程&#8211;过程间分析优化(IPA)</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/04/16/10746/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>前瞻-全时优化和LLVM-1</title>
		<link>http://www.lingcc.com/2010/04/07/10721/</link>
		<comments>http://www.lingcc.com/2010/04/07/10721/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 14:30:56 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[LLVM]]></category>
		<category><![CDATA[编译前沿]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[编译理论实践和应用]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[JIT]]></category>
		<category><![CDATA[MPI]]></category>
		<category><![CDATA[N64]]></category>
		<category><![CDATA[Open64]]></category>
		<category><![CDATA[SSA]]></category>
		<category><![CDATA[中间表示]]></category>
		<category><![CDATA[全时优化]]></category>
		<category><![CDATA[工具链]]></category>
		<category><![CDATA[性能]]></category>
		<category><![CDATA[空闲时优化]]></category>
		<category><![CDATA[编程技术]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[编译器设计]]></category>
		<category><![CDATA[虚拟机]]></category>
		<category><![CDATA[过程间优化]]></category>
		<category><![CDATA[运行时技术]]></category>
		<category><![CDATA[链接]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10721</guid>
		<description><![CDATA[读论文&#60;LLVM: A Compilation Framework for Lifelong Program Analysis &#38; Transformation&#62; CGO 04 1，写在前面的话 全时优化(LifeLong Optimization)对于每个编译爱好者来说，太有魅力了。我在起初也是被这个题目所吸引打算一探究竟。本文是04年LLVM的最早两位开发者Chris Lattner和Vikram Adve所写，发表在04年的CGO上， 先来说说LLVM的历史。2000年LLVM开始开发，2005年Apple雇了Chris Lattner，LLVM也相当于成了Apple的官方支持的编译器。Apple已经将它用在OpenCL的流水线优化，Xcode已经能使用llvm-gcc编译代码。可以说05年之前LLVM一直都是学术界的东西，05年之后用于工业界.而这篇文章写在04年.本博最近听过一个关于LLVM的讨论会，会中有资深人士提到LLVM现在越来越像一个普通的编译器。说这番话的意思是，我们可以从这篇文章里找到LLVM的架构设计和早期的一些实现思想，但请不要迷信LLVM现在有多么神奇，每个架构都会有它的优缺点。 这篇文章，我现在已经读完了理论和介绍部分，性能评测部分还没有读。所以标题里面加了个1，因为接下来，还想作几件事，一是读完文章，二是跟踪一下Chris Lattner最近几年的文章，三是尝试将Open64和LLVM做个对比，最后看看代码。所以敬请期待之后的系列文章。 2.总览 先来解释Lifetime:文中分为编译时，链接时，安装时，运行时，空闲时五个阶段。这五个阶段都存在着优化机会：编译时的普通静态优化；链接时的过程间优化；安装时的目标机相关优化；运行时的动态优化和空闲时的profile制导优化。LLVM最早的设计就是针对以上几种优化进行的。 既然需要运行时和空闲时优化，就必须有必要的运行时环境和profile插装方式。因此注定LLVM的中间表示将占据非常重要的位置。编译和链接是为了生成中间表示，运行和空闲时则需要对中间表示的解释和执行。因此LLVM用上了目前编译所开发的所有技术:静态编译优化，JIT，虚拟机，解释器，运行时技术等等。也注定了LLVM要有一整套的工具链和环境来完成上述工作。 作者给出了LLVM架构设计中由于支持全时优化的五个特性，并支持现阶段，并无任何一种系统能同时具备这五个特性，不管是编译器，虚拟机还是其他系统。这五个特性是： 保持程序信息不变 离线本地代码生成 基于用户的profile和优化 透明的运行时模型 统一的全程序编译。 作者从两个角度来论述LLVM对全时优化的支持，一是LLVM的中间表示设计；二是LLVM的整体架构设计。 3.中间表示 LLVM的中间表示采取类RISC指令集，但包含关键的高层类型信息，精确控制流图和数据流图。LLVM的中间表示的几个特性：低层，语言无关的类型系 统；提供保存类型信息又能做类型转换和底层地址运算的指令；两个底层例外处理指令。LLVM中间表示之所以能做到与源程序独立，是因为它使用了比汇编稍大 的底层指令级及存储模型但并不暴露任何实际运行时需求和源程序语义需求。这种中间表示也决定了LLVM的局限性，对于源源转换之类的优化，LLVM就无法 直接在中间表示发力。 作者主要从五个方面介绍了LLVM中间表示的特点：指令集、语言无关的类型信息、存储模型、例外处理截止和三种中间表示形式相互透明(普通文本，二进制和内存中) 指令集： LLVM的中间表示采用原始处理器中的关键操作，回避物理寄存器、流水线、底层调用转换等细节，但为虚拟寄存器提供了集中类型(布尔型、整型、浮点型、指针),这些虚拟寄存器都采用SSA的形式。LLVM中有31个指令，多数采用了类型重载，且多为三地址形式.LLVM的每个虚拟寄存器都使用SSA的形式，而存储位置则不是SSA，这是因为存储可能存在别名。虚拟寄存器采用SSA能带来精确的定义-使用关系。另外LLVM也简化了控制流图，每个函数都转化为基本块的集合。每个基本块都有LLVM指令序列组成，结束基本块都有一个退出指令，如return，unwind，invoke。 语言无关的类型信息： LLVM中每个SSA 虚拟寄存器和存储对象都有和其关联的类型，所有的操作也都有严格的类型规则。LLVM的类型系统包括了如下类型:void,bool, signed/unsigned int(8bit to 64bit),single float,double float和四种衍生类型：pointer,array,structure和function。作者认为很多高层的类型都能使用这些类型表示。如C++中的类继承就能使用structure,function和function pointer array 来表示；而且作者也认为以上这些类型基本胜任经典的语言无关的程序分析和优化。因为LLVM的中间表示层次低，就需要支持弱类型语言，因此为提高在LLVM程序中声明类型的可靠性，LLVM使用一些指针分析算法来来判断所访问的内存与指针的类型是否可以可靠的相互转换。LLVM的类型转换仅能通过cast指令从一种类型转换为另一种类型。LLVM的指针算术运算通过getelementptr来实现，该指令力保在做地址运算时指令安全。load和store指令则只负责取和存。 精确存储分配和统一存储模型： LLVM通过三个指令实现存储操作：malloc，free和alloca。malloc负责在堆上分配带类型的存储位置；free负责释放malloc分配的存储空间；alloca和malloc相似，它分配的是在当前栈帧內分配存储而非堆，该内存将在函数返回时自动收回。LLVM中所有地址对象都被精确分配地址。全局变量和函数定义都被分配一个对象地址。这使得一个 统一的存储模型被建立。 函数调用和例外处理： <a href='http://www.lingcc.com/2010/04/07/10721/'>[...]</a><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F20%2F11361%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM居然开始做广告了！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM 2.7 发布</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F03%2F10884%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">安装LLVM2.7 step by step</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F12%2F08%2F11882%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">你好，LLVM 3.0</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
<h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/04/29/10728/' rel='bookmark' title='前瞻-全时优化和LLVM-2'>前瞻-全时优化和LLVM-2</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2009/11/19/10024/' rel='bookmark' title='Open64课程-编译过程'>Open64课程-编译过程</a></li>
<li><a href='http://www.lingcc.com/2009/12/14/10295/' rel='bookmark' title='open64课程&#8211;过程间分析优化(IPA)'>open64课程&#8211;过程间分析优化(IPA)</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>读论文&lt;<a href="http://llvm.org/pubs/2004-01-30-CGO-LLVM.html" target="_blank">LLVM: A Compilation Framework for Lifelong Program Analysis &amp; Transformation</a>&gt; CGO 04</p>
<h3>1，写在前面的话</h3>
<p>全时优化(LifeLong Optimization)对于每个编译爱好者来说，太有魅力了。我在起初也是被这个题目所吸引打算一探究竟。本文是04年LLVM的最早两位开发者Chris Lattner和Vikram Adve所写，发表在04年的CGO上，</p>
<p>先来说说LLVM的历史。2000年LLVM开始开发，2005年Apple雇了Chris Lattner，LLVM也相当于成了Apple的官方支持的编译器。Apple已经将它用在OpenCL的流水线优化，Xcode已经能使用llvm-gcc编译代码。可以说05年之前LLVM一直都是学术界的东西，05年之后用于工业界.而这篇文章写在04年.本博最近听过一个关于LLVM的讨论会，会中有资深人士提到LLVM现在越来越像一个普通的编译器。说这番话的意思是，我们可以从这篇文章里找到LLVM的架构设计和早期的一些实现思想，但请不要迷信LLVM现在有多么神奇，每个架构都会有它的优缺点。</p>
<p>这篇文章，我现在已经读完了理论和介绍部分，性能评测部分还没有读。所以标题里面加了个1，因为接下来，还想作几件事，一是读完文章，二是跟踪一下Chris Lattner最近几年的文章，三是尝试将Open64和LLVM做个对比，最后看看代码。所以敬请期待之后的系列文章。<br />
<span id="more-10721"></span></p>
<h3>2.总览</h3>
<p>先来解释Lifetime:文中分为编译时，链接时，安装时，运行时，空闲时五个阶段。这五个阶段都存在着优化机会：编译时的普通静态优化；链接时的过程间优化；安装时的目标机相关优化；运行时的动态优化和空闲时的profile制导优化。LLVM最早的设计就是针对以上几种优化进行的。</p>
<p>既然需要运行时和空闲时优化，就必须有必要的运行时环境和profile插装方式。因此注定LLVM的中间表示将占据非常重要的位置。编译和链接是为了生成中间表示，运行和空闲时则需要对中间表示的解释和执行。因此LLVM用上了目前编译所开发的所有技术:静态编译优化，JIT，虚拟机，解释器，运行时技术等等。也注定了LLVM要有一整套的工具链和环境来完成上述工作。</p>
<p>作者给出了LLVM架构设计中由于支持全时优化的五个特性，并支持现阶段，并无任何一种系统能同时具备这五个特性，不管是编译器，虚拟机还是其他系统。这五个特性是：</p>
<ol>
<li>保持程序信息不变</li>
<li>离线本地代码生成</li>
<li>基于用户的profile和优化</li>
<li>透明的运行时模型</li>
<li>统一的全程序编译。</li>
</ol>
<p>作者从两个角度来论述LLVM对全时优化的支持，一是LLVM的中间表示设计；二是LLVM的整体架构设计。</p>
<h3>3.中间表示</h3>
<p>LLVM的中间表示采取类RISC指令集，但包含关键的高层类型信息，精确控制流图和数据流图。LLVM的中间表示的几个特性：低层，语言无关的类型系 统；提供保存类型信息又能做类型转换和底层地址运算的指令；两个底层例外处理指令。LLVM中间表示之所以能做到与源程序独立，是因为它使用了比汇编稍大 的底层指令级及存储模型但并不暴露任何实际运行时需求和源程序语义需求。这种中间表示也决定了LLVM的局限性，对于源源转换之类的优化，LLVM就无法 直接在中间表示发力。</p>
<p>作者主要从五个方面介绍了LLVM中间表示的特点：指令集、语言无关的类型信息、存储模型、例外处理截止和三种中间表示形式相互透明(普通文本，二进制和内存中)</p>
<h4>指令集：</h4>
<p>LLVM的中间表示采用原始处理器中的关键操作，回避物理寄存器、流水线、底层调用转换等细节，但为虚拟寄存器提供了集中类型(布尔型、整型、浮点型、指针),这些虚拟寄存器都采用SSA的形式。LLVM中有31个指令，多数采用了类型重载，且多为三地址形式.LLVM的每个虚拟寄存器都使用SSA的形式，而存储位置则不是SSA，这是因为存储可能存在别名。虚拟寄存器采用SSA能带来精确的定义-使用关系。另外LLVM也简化了控制流图，每个函数都转化为基本块的集合。每个基本块都有LLVM指令序列组成，结束基本块都有一个退出指令，如return，unwind，invoke。</p>
<h4>语言无关的类型信息：</h4>
<p>LLVM中每个SSA 虚拟寄存器和存储对象都有和其关联的类型，所有的操作也都有严格的类型规则。LLVM的类型系统包括了如下类型:void,bool, signed/unsigned int(8bit to 64bit),single float,double float和四种衍生类型：pointer,array,structure和function。作者认为很多高层的类型都能使用这些类型表示。如C++中的类继承就能使用structure,function和function pointer array 来表示；而且作者也认为以上这些类型基本胜任经典的语言无关的程序分析和优化。因为LLVM的中间表示层次低，就需要支持弱类型语言，因此为提高在LLVM程序中声明类型的可靠性，LLVM使用一些指针分析算法来来判断所访问的内存与指针的类型是否可以可靠的相互转换。LLVM的类型转换仅能通过cast指令从一种类型转换为另一种类型。LLVM的指针算术运算通过getelementptr来实现，该指令力保在做地址运算时指令安全。load和store指令则只负责取和存。</p>
<h4>精确存储分配和统一存储模型：</h4>
<p>LLVM通过三个指令实现存储操作：malloc，free和alloca。malloc负责在堆上分配带类型的存储位置；free负责释放malloc分配的存储空间；alloca和malloc相似，它分配的是在当前栈帧內分配存储而非堆，该内存将在函数返回时自动收回。LLVM中所有地址对象都被精确分配地址。全局变量和函数定义都被分配一个对象地址。这使得一个 统一的存储模型被建立。</p>
<h4>函数调用和例外处理：</h4>
<p>对于普通的函数调用，LLVM提供了一个带类型的call指令。LLVM有个与众不同的特性使得低级中间表示能处理高级程序例外，这种特性基于invoke和unwind两个指令实现。这两个指令共同支持了基于栈弹出的抽象例外处理模型。详细的机制论述请参考论文，作者用了将近一页的篇幅来论述。</p>
<h4>普通文本、二进制和内存中的表示形式：</h4>
<p>LLVM的中间表示是首个能同时等价的在二进制，普通文本和内存中(如编译器内部)表示的。指令集最初的设计就考虑到要能高效的即可作为一个中间表示，又能作为离线代码表示和编译器内部表示，并且在三者之间转换时无需任何语义变化。这三者之间的等价转换使得LLVM调试很方便。</p>
<p><em><span style="color: #000000;"><strong>正所谓，中间表示很重要，编译架构也得牛，眼高手低要不得，关键还得看评测。敬请关注下文 LLVM的架构介绍及整体评测。</strong></span></em></p>
<div style=float:left><!-- JiaThis Button BEGIN -->
<div id="jiathis_style_32x32">
	<a class="jiathis_button_qzone"></a>
	<a class="jiathis_button_tsina"></a>
	<a class="jiathis_button_tqq"></a>
	<a class="jiathis_button_renren"></a>
	<a class="jiathis_button_kaixin001"></a>
	<a href="http://www.jiathis.com/share/" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" src="http://v2.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END --></div><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F10%2F20%2F11361%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM居然开始做广告了！</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F28%2F10807%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">LLVM 2.7 发布</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F03%2F10884%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">安装LLVM2.7 step by step</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F12%2F08%2F11882%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F04%2F07%2F10721%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">你好，LLVM 3.0</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table><p><h3>相关文章：</h3><ul>
<li><a href='http://www.lingcc.com/2010/04/29/10728/' rel='bookmark' title='前瞻-全时优化和LLVM-2'>前瞻-全时优化和LLVM-2</a></li>
<li><a href='http://www.lingcc.com/2010/04/30/10822/' rel='bookmark' title='前瞻-LLVM大事记(2004-2010)'>前瞻-LLVM大事记(2004-2010)</a></li>
<li><a href='http://www.lingcc.com/2009/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
<li><a href='http://www.lingcc.com/2009/11/19/10024/' rel='bookmark' title='Open64课程-编译过程'>Open64课程-编译过程</a></li>
<li><a href='http://www.lingcc.com/2009/12/14/10295/' rel='bookmark' title='open64课程&#8211;过程间分析优化(IPA)'>open64课程&#8211;过程间分析优化(IPA)</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/04/07/10721/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

