<?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; builtin</title>
	<atom:link href="http://www.lingcc.com/tag/builtin/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>前瞻-拿起SIMD的武器II</title>
		<link>http://www.lingcc.com/2010/05/12/10931/</link>
		<comments>http://www.lingcc.com/2010/05/12/10931/#comments</comments>
		<pubDate>Wed, 12 May 2010 14:17:39 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[后端优化与处理器]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[3dnow]]></category>
		<category><![CDATA[avx]]></category>
		<category><![CDATA[Backend 编译器后端]]></category>
		<category><![CDATA[builtin]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[MIPS]]></category>
		<category><![CDATA[mmx]]></category>
		<category><![CDATA[MPI]]></category>
		<category><![CDATA[SIMD]]></category>
		<category><![CDATA[sse]]></category>
		<category><![CDATA[sse2]]></category>
		<category><![CDATA[sse3]]></category>
		<category><![CDATA[vectorization]]></category>
		<category><![CDATA[windows]]></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=10931</guid>
		<description><![CDATA[上篇文章《前瞻-主流处理器中的数据并行支持(SIMD)&#62;和《前瞻-拿起SIMD的武器I》分别介绍了当今主流CPU中的SIMD扩展 ，以及前人是如何利用SIMD来做优化的，本文&#60;前瞻-拿起SIMD的武器II&#62;将探讨如何使用CPU的向量指令为程序做优化 如何实现？ 编程环境 在现在CPU设计中都加入SIMD扩展并不是解决应用性能问题的好方法。如果没有很好的利用途径，再强大的SIMD扩展指令集都是徒劳。接下来，我们从编译器技术和编程方法论上探讨如何使用SIMD指令来实现应用加速。 编译器的局限 尽管现在SIMD扩展在大部分处理器中都已具备，但目前编译器仍难生成基于SIMD指令的高效代码序列，因为从以控制流为主体的C语言中自动抽象并行化很难。仅仅有几个商业编译器能自动产生SIMD并行，但往往需要很高的代价，结构也很不令人满意。这一块依然是研究开发的热点。SWAR(SIMD within a register)是曾经比较典型的比那一起。一开始作为一个兼容面向多种处理器，之后又转化为一个能识别简单高层并行语言SWARC(一个为使用SIMD指令而生的数据并行C语言).但是，因为SIMD指令的限制，数据并行语言的成功取决于应用领域中高效的并行方法和能很好描述这种应用的语言。SWARC在语言设计阶段，缺乏对特定并行方法的假设使得它使用范围很有限。 也有人针对图像处理任务，提出了一种对C语言的并行扩展和对应的SIMD编译器，并用它实现SIMD加速。作者使用这种语言实现了图像滤波器，并使用SIMD编译器在奔腾处理器上得到了图像滤波器的高效代码序列。通过与最新C编译器中编译得到的代码对比，SIMD编译器得到的代码有4x的加速.也有人专门就如何降低用户学习新编程语言的复杂性进行研究，并提出了一个编程语言原型和相应的编译器。自动向量化的工作也有人在继续奋斗。有人提供了在编译C代码时自动使用SIMD指令代替的技术，使用它让跨平台的源代码使用SIMD指令。这种技术基于经典的代码树结构，并在其上收集数据流图信息以便生成SIMD指令，对目前的主流处理器，这样实现还行，但是很多新的SIMD结构都在趋于提供较高层的并行了。 在某些应用中，通过使用编译器内部的函数来插入一组SIMD指令实现数据在寄存器中的重排，可以实现更高度的并行。这种编译器内部函数都对应一个或多个特定的SIMD指令，通过插入这些函数，程序员告诉编译器需要选择哪个SIMD指令，编译器则负责寄存器分配和指令调度。最近有人描述了SIMD指令如何从常规代码中产生，如何决定SIMD操作的书讯，并每个SIMD指令组。在该提议中，独立的存储访问都组织称SIMD操作，SIMD数据流图根据访存的数据依赖构建，接着SIMD操作的顺序复制到数据六图中。这种机制并不依赖特定的体系结构，在SSE实现该提议，对于某些应用核心，加速比达到35%。 另外也有人研究了使用SIMD并行操作和使用串行操作的能耗问题。通过比较多个benchmark，作者的结论是：使用SIMD指令能节省72%的能耗，提升76%的性能。 编程方法论 虽然没有编译器令人满意的支持，但SIMD依然是有效的提升性能的方法，接下来介绍三种使用SIMD扩展的途径。 汇编语言：这是最高效的使用方式，因为这种编程方式能直接从硬件平台获得性能。但很容易出错，而且可移植性不强。 共享库：这些库通常处理器生产商提供的，但这些库只能覆盖特等的函数，而且只能用在特定的处理器上。比如，Intel的汇编库就提供了很多常用信号处理，向量计算和图像处理的汇编函数库供C函数调用,但通常，这种方式会造成库中的可用函数和目标应用需要的不匹配。 向量化编译器：最理想的情况下，高级语言编译器能自动识别代码中的并行部分，并生成相应的SIMD指令串。但是虽然现在有很多自动SIMD向量化的提议，但成功的很少。值得一提的是Intel C++ Compiler中的intrinsic支持，把括MMX，SSE，SSE2的SIMD指令支持，C++ SIMD向量类，还有一个自动的向量化工具能自动从循环中得到SIMD并行。它为Microsoft Windows和Linux操作系统环境带来明显性能提升。ICC的二进制文件，在Windows环境下能与Visual C++二进制兼容，在Linux能与GCC相应版本的二进制兼容。现在通过intrinsic库和C++来编程要比汇编语言容易的多，因为不再需要维护寄存器，可以方便的开发较大的软件，但因为编译器要完成寄存器分配和指令调度，所以相对于汇编，性能可能会有下降，但并不绝对。 GNU Gcc 4.2也支持了包括AtliVec,SSE2和3DNow！在内的一些多媒体扩展。 数据对齐 对齐就是把数据和代码放在主存中能让硬件更高效访问的地址的技术，也就是存储地址的一种属性。一个地址是X对齐的，如果它的地址能表示为Xn+0的形式。其中X是2的某次幂，n为任意整数。一个存储向量数据的内存块，若其边界是非对齐的，那访问它的开销将会非常大，因为需要使用数据重排机制。这种机制通常需要产生很多额外的存储访问。为了避免这种过高代价，已经有了一些技术，如循环分割，动态/静态对齐检测。很多CPU，如基于Alpha, IA-64, IA-32,MIPS和SuperH的结构，都禁止访问非对齐数据，如果程序请求访问了非对齐的数据，则抛出异常。 数据对齐是开发自动使用SIMD扩展必须要解决的基础问题之一。掌控对齐会大大增加自动向量化的难度，并限制其应用范围。为了能对向量数据高效存储，存储访问必须正确对齐。 选择合适的SIMD扩展 SIMD扩展在现在的PC中几乎都有，为啥不用呢？但，再者之前，得先回答几个问题： 现在的代码能从MMX，SSE,SSE2或SSE3中获益吗？ 代码是整点运算还是浮点？ 需要什么样的编程技术？ 如何组织数据类型，如何对齐？ 另外，为了能从SIMD扩展中获得最大收益，下面几点一定要好好评估： 计算敏感的程序段 足够给程序性能产生影响的程序段 几乎没有数据依赖控制流图的程序段 需要浮点运算的程序段 使用少量指令就能编写的计算代码段 需要额外调整才能高效利用cache结构的代码段 一款商业软件Intel VTune能较好到检测出可以并行的程序段。协助程序员优化性能。 总的来说，一个能做SIMD优化的程序段，应该是循环体较小，循环操作一个数组，该数组由8、16或者32位对齐整数，单精度32位浮点，或双精度64位浮点组成。再加上使用尽可能少的数据类型，更长的向量数据，并且小心的控制内存访问。能做到这些，SIMD扩展就能为你的程序带来不小的性能提升了：） 个人总计： 至此，对目前最低级的并行&#8211;单指令多数据并行。算是有了点认识。SIMD几乎所有的主流CPU上都有，从Alpha的MVI，IBM PowerPC上的AltiVec和SPE，HP PA-RISC 多媒体加速扩展(MAX), Intel的MMX，iwMMX，SSE，SSE2，SSE3，SSSE3；AMD的3DNow!, ARC的ARC视频处理子系统，SPARC的VIS， Sun的MAJC， <a href='http://www.lingcc.com/2010/05/12/10931/'>[...]</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%2F02%2F11605%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F12%2F10931%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%2F12%2F10931%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%2F09%2F14%2F11718%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F12%2F10931%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Some notes about IBM  XL C Compiler</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%2F10%2F10928%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F12%2F10931%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">前瞻-拿起SIMD的武器I</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%2F12%2F10931%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  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/01/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</a></li>
<li><a href='http://www.lingcc.com/2010/05/10/10928/' rel='bookmark' title='前瞻-拿起SIMD的武器I'>前瞻-拿起SIMD的武器I</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/2010/04/14/10736/' rel='bookmark' title='探秘CPU性能测试：Spec CPU2000之整点篇'>探秘CPU性能测试：Spec CPU2000之整点篇</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<h4><span style="font-weight: normal;">上篇文章</span><a href="http://www.lingcc.com/2010/05/04/10878/" target="_blank"><span style="font-weight: normal;">《</span></a><a href="http://www.lingcc.com/2010/05/04/10878/" target="_blank"><span style="font-weight: normal;">前瞻-主流处理器中的数据并行支持(SIMD)</span></a><span style="font-weight: normal;">&gt;和《</span><a href="http://www.lingcc.com/2010/05/10/10928/" target="_blank"><span style="font-weight: normal;">前瞻-拿起SIMD的武器I</span></a><span style="font-weight: normal;">》分别介绍了当今主流CPU中的SIMD扩展 ，以及前人是如何利用SIMD来做优化的，本文&lt;前</span><span style="font-weight: normal;">瞻-拿起SIMD的武器II</span><span style="font-weight: normal;">&gt;将探讨如何使用CPU的向量指令为程序做优化</span></h4>
<h3>如何实现？</h3>
<h4><a name="_3698829783465135"></a>编程环境</h4>
<p>在现在CPU设计中都加入SIMD扩展并不是解决应用性能问题的好方法。如果没有很好的利用途径，再强大的SIMD扩展指令集都是徒劳。接下来，我们从编译器技术和编程方法论上探讨如何使用SIMD指令来实现应用加速。<span id="more-10931"></span></p>
<h4><a name="_42636573218531726"></a>编译器的局限</h4>
<p>尽管现在SIMD扩展在大部分处理器中都已具备，但目前编译器仍难生成基于SIMD指令的高效代码序列，因为从以控制流为主体的C语言中自动抽象并行化很难。仅仅有几个商业编译器能自动产生SIMD并行，但往往需要很高的代价，结构也很不令人满意。这一块依然是研究开发的热点。SWAR(SIMD within a register)是曾经比较典型的比那一起。一开始作为一个兼容面向多种处理器，之后又转化为一个能识别简单高层并行语言SWARC(一个为使用SIMD指令而生的数据并行C语言).但是，因为SIMD指令的限制，数据并行语言的成功取决于应用领域中高效的并行方法和能很好描述这种应用的语言。SWARC在语言设计阶段，缺乏对特定并行方法的假设使得它使用范围很有限。<br />
也有人针对图像处理任务，提出了一种对C语言的并行扩展和对应的SIMD编译器，并用它实现SIMD加速。作者使用这种语言实现了图像滤波器，并使用SIMD编译器在奔腾处理器上得到了图像滤波器的高效代码序列。通过与最新C编译器中编译得到的代码对比，SIMD编译器得到的代码有4x的加速.也有人专门就如何降低用户学习新编程语言的复杂性进行研究，并提出了一个编程语言原型和相应的编译器。自动向量化的工作也有人在继续奋斗。有人提供了在编译C代码时自动使用SIMD指令代替的技术，使用它让跨平台的源代码使用SIMD指令。这种技术基于经典的代码树结构，并在其上收集数据流图信息以便生成SIMD指令，对目前的主流处理器，这样实现还行，但是很多新的SIMD结构都在趋于提供较高层的并行了。<br />
在某些应用中，通过使用编译器内部的函数来插入一组SIMD指令实现数据在寄存器中的重排，可以实现更高度的并行。这种编译器内部函数都对应一个或多个特定的SIMD指令，通过插入这些函数，程序员告诉编译器需要选择哪个SIMD指令，编译器则负责寄存器分配和指令调度。最近有人描述了SIMD指令如何从常规代码中产生，如何决定SIMD操作的书讯，并每个SIMD指令组。在该提议中，独立的存储访问都组织称SIMD操作，SIMD数据流图根据访存的数据依赖构建，接着SIMD操作的顺序复制到数据六图中。这种机制并不依赖特定的体系结构，在SSE实现该提议，对于某些应用核心，加速比达到35%。<br />
另外也有人研究了使用SIMD并行操作和使用串行操作的能耗问题。通过比较多个benchmark，作者的结论是：使用SIMD指令能节省72%的能耗，提升76%的性能。</p>
<h4>编程方法论</h4>
<p>虽然没有编译器令人满意的支持，但SIMD依然是有效的提升性能的方法，接下来介绍三种使用SIMD扩展的途径。</p>
<ol>
<li><a name="__7473931998985098"></a>汇编语言：这是最高效的使用方式，因为这种编程方式能直接从硬件平台获得性能。但很容易出错，而且可移植性不强。</li>
<li>共享库：这些库通常处理器生产商提供的，但这些库只能覆盖特等的函数，而且只能用在特定的处理器上。比如，Intel的汇编库就提供了很多常用信号处理，向量计算和图像处理的汇编函数库供C函数调用,但通常，这种方式会造成库中的可用函数和目标应用需要的不匹配。</li>
<li>向量化编译器：最理想的情况下，高级语言编译器能自动识别代码中的并行部分，并生成相应的SIMD指令串。但是虽然现在有很多自动SIMD向量化的提议，但成功的很少。值得一提的是Intel C++ Compiler中的intrinsic支持，把括MMX，SSE，SSE2的SIMD指令支持，C++ SIMD向量类，还有一个自动的向量化工具能自动从循环中得到SIMD并行。它为Microsoft Windows和Linux操作系统环境带来明显性能提升。ICC的二进制文件，在Windows环境下能与Visual C++二进制兼容，在Linux能与GCC相应版本的二进制兼容。现在通过intrinsic库和C++来编程要比汇编语言容易的多，因为不再需要维护寄存器，可以方便的开发较大的软件，但因为编译器要完成寄存器分配和指令调度，所以相对于汇编，性能可能会有下降，但并不绝对。 GNU Gcc 4.2也支持了包括AtliVec,SSE2和3DNow！在内的一些多媒体扩展。</li>
</ol>
<h4><a name="_8764728304827076"></a>数据对齐</h4>
<p>对齐就是把数据和代码放在主存中能让硬件更高效访问的地址的技术，也就是存储地址的一种属性。一个地址是X对齐的，如果它的地址能表示为Xn+0的形式。其中X是2的某次幂，n为任意整数。一个存储向量数据的内存块，若其边界是非对齐的，那访问它的开销将会非常大，因为需要使用数据重排机制。这种机制通常需要产生很多额外的存储访问。为了避免这种过高代价，已经有了一些技术，如循环分割，动态/静态对齐检测。很多CPU，如基于Alpha, IA-64, IA-32,MIPS和SuperH的结构，都禁止访问非对齐数据，如果程序请求访问了非对齐的数据，则抛出异常。</p>
<p>数据对齐是开发自动使用SIMD扩展必须要解决的基础问题之一。掌控对齐会大大增加自动向量化的难度，并限制其应用范围。为了能对向量数据高效存储，存储访问必须正确对齐。</p>
<h4>选择合适的SIMD扩展</h4>
<p>SIMD扩展在现在的PC中几乎都有，为啥不用呢？但，再者之前，得先回答几个问题：</p>
<ol>
<li>现在的代码能从MMX，SSE,SSE2或SSE3中获益吗？</li>
<li>代码是整点运算还是浮点？</li>
<li>需要什么样的编程技术？</li>
<li>如何组织数据类型，如何对齐？</li>
</ol>
<p>另外，为了能从SIMD扩展中获得最大收益，下面几点一定要好好评估：</p>
<ol>
<li>计算敏感的程序段</li>
<li>足够给程序性能产生影响的程序段</li>
<li>几乎没有数据依赖控制流图的程序段</li>
<li>需要浮点运算的程序段</li>
<li>使用少量指令就能编写的计算代码段</li>
<li>需要额外调整才能高效利用cache结构的代码段</li>
</ol>
<p>一款商业软件Intel VTune能较好到检测出可以并行的程序段。协助程序员优化性能。</p>
<p>总的来说，一个能做SIMD优化的程序段，应该是循环体较小，循环操作一个数组，该数组由8、16或者32位对齐整数，单精度32位浮点，或双精度64位浮点组成。再加上使用尽可能少的数据类型，更长的向量数据，并且小心的控制内存访问。能做到这些，SIMD扩展就能为你的程序带来不小的性能提升了：）</p>
<p>个人总计：</p>
<p>至此，对目前最低级的并行&#8211;单指令多数据并行。算是有了点认识。SIMD几乎所有的主流CPU上都有，从Alpha的MVI，IBM PowerPC上的AltiVec和SPE，HP PA-RISC 多媒体加速扩展(MAX), Intel的MMX，iwMMX，SSE，SSE2，SSE3，SSSE3；AMD的3DNow!, ARC的ARC视频处理子系统，SPARC的VIS， Sun的MAJC， ARM的NEON， MIPS的MDMX和MIPS-3D， Cell的SPU， Philips的Xetal 到GPU上SIMD的普遍使用，从64位到128位，256位的数据并行。SIMD的硬件支持越来约强大。</p>
<p>另一方面，高品质的多媒体处理需求，也使得我们的计算机应用中数据处理越来越庞大。但唯独编译器很难为SIMD加速做贡献。SIMD的并行需要很弱的数据依赖，数据流的统一。而这种统一很难靠编译器来提取。高效的方式还得靠人工来做。人工来做，就意味着人要了解他要优化的这个算法，哪里数据计算比较多，哪里跳转，控制语句比较多。能不能使用SIMD优化，如何使用SIMD优化。</p>
<p>SIMD的硬件支持因为各个CPU厂商的设计目标不同，而且还有知识产权的问题。这样SIMD标准很难统一起来。针对每一个特定的CPU型号，都要做特定的SIMD优化，这也给软件的可移植性带来了挑战。</p>
<p>编译器能提取数据依赖吗？编译器能为程序员做点什么？编译器能在多大程度上协助程序员的工作？主流编译器已经有了对MMX，SSE，SSE2的intrinsic支持，编程在稍微损失性能的条件下编程更加容易了。Intel的VTune能帮助我们更好的发现并行机会。但很明显，这些还不够。幸好，GCC也引入了<a href="http://gcc.gnu.org/wiki/Graphite" target="_blank">Graphite</a>，或许在不久的将来，会有一些机会吧。现在影响SIMD，最多的不是找到一系列指令串来操作数据，而是如何高效的把数据组织成一个向量数据，在计算完成以后，高效的把这些数据都拿出来。</p>
<p>未来，我们还有很多值得期待，还有许多可以努力！</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%2F12%2F10931%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%2F12%2F10931%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%2F09%2F14%2F11718%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F12%2F10931%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Some notes about IBM  XL C Compiler</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%2F10%2F10928%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F05%2F12%2F10931%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">前瞻-拿起SIMD的武器I</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%2F12%2F10931%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  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/01/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</a></li>
<li><a href='http://www.lingcc.com/2010/05/10/10928/' rel='bookmark' title='前瞻-拿起SIMD的武器I'>前瞻-拿起SIMD的武器I</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/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/12/10931/feed/</wfw:commentRss>
		<slash:comments>6</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%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%2F2011%2F03%2F28%2F11567%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 4.6的新特性</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  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%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%2F2011%2F03%2F28%2F11567%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 4.6的新特性</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  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>小例子&#8211;回眸一笑百媚生</title>
		<link>http://www.lingcc.com/2010/01/21/10663/</link>
		<comments>http://www.lingcc.com/2010/01/21/10663/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 11:32:58 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[编译技术]]></category>
		<category><![CDATA[编译理论实践和应用]]></category>
		<category><![CDATA[amd]]></category>
		<category><![CDATA[builtin]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[MIPS]]></category>
		<category><![CDATA[mmx]]></category>
		<category><![CDATA[SIMD]]></category>
		<category><![CDATA[sse]]></category>
		<category><![CDATA[sse2]]></category>
		<category><![CDATA[sse3]]></category>
		<category><![CDATA[内建函数]]></category>
		<category><![CDATA[并行]]></category>
		<category><![CDATA[并行计算]]></category>
		<category><![CDATA[编译器]]></category>
		<category><![CDATA[龙芯]]></category>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10663</guid>
		<description><![CDATA[这两天在折腾小例子，用来表现对语言做某种扩展后将可更高效的编程。我那蹩脚的coding技术捉襟见肘。一个小例子要言简意赅，写在半页ppt里，要有对比，有突出，又要很直观。尝试了很多次。写小例子很能考察编程能力，指针，静态，数组，寄存器变量，各个类型长度等等。要达到瞄一眼就能印象深刻，被震撼的感觉，难！ 眼见为实，看下面的小例子，简单的写个循环: [code lang="cpp"] ip (short int* fb, short int* bb,short int* res) { int i=0; for (; i&#38;lt; 8; i++) res[i] = fb[i] + bb[i]+1; }[/code] 在龙芯上用simd(单指令多数据，一条指令可以存多个数据)来实现的话，需要这么写，别忘了包含loongson.h头文件，这段代码在gcc4.3之后才支持： [code lang="cpp"] #include &#34;loongson.h&#34; typedef union {int8x8_t v; int8_t a[8]; } i8x8_t; ip (int8_t* fb, int8_t* bb, int8_t* res) { i8x8_t i_ls; i_ls.a[0] = 1; i_ls.a[1] = <a href='http://www.lingcc.com/2010/01/21/10663/'>[...]</a><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="iPhone SDK 正式登场！" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F07%2F9931%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/30/7115388.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">iPhone SDK 正式登场！</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="百度Hi策略的猜想" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F10%2F9937%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/31/20239408.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">百度Hi策略的猜想</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="如何打领带五种方法加视频" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F02%2F04%2F9892%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/30/7115617.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">如何打领带五种方法加视频</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="关于并行貌似正确的废话-程序语言发展的启示" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F06%2F13%2F10970%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/30/7111620.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">关于并行貌似正确的废话-程序语言发展的启示</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="说说静态单赋值（SSA,Static Single-Assignment)" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F08%2F13%2F11685%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/08/13/22609462.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">说说静态单赋值（SSA,Static Single-Assignment)</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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/12/10931/' rel='bookmark' title='前瞻-拿起SIMD的武器II'>前瞻-拿起SIMD的武器II</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/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2010/01/07/10594/' rel='bookmark' title='使用crossdev安装龙芯的O32 gnu交叉工具链'>使用crossdev安装龙芯的O32 gnu交叉工具链</a></li>
<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/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>这两天在折腾小例子，用来表现对语言做某种扩展后将可更高效的编程。我那蹩脚的coding技术捉襟见肘。一个小例子要言简意赅，写在半页ppt里，要有对比，有突出，又要很直观。尝试了很多次。写小例子很能考察编程能力，指针，静态，数组，寄存器变量，各个类型长度等等。要达到瞄一眼就能印象深刻，被震撼的感觉，难！</p>
<p>眼见为实，看下面的小例子，简单的写个循环:</p>
<p>[code lang="cpp"]<br />
ip (short int* fb, short int* bb,short int* res)<br />
{<br />
int i=0;<br />
for (; i&amp;lt; 8; i++)<br />
res[i] = fb[i] + bb[i]+1;<br />
}[/code]</p>
<p>在龙芯上用simd(单指令多数据，一条指令可以存多个数据)来实现的话，需要这么写，别忘了包含loongson.h头文件，这段代码在gcc4.3之后才支持：<span id="more-10663"></span></p>
<p>[code lang="cpp"]<br />
#include &quot;loongson.h&quot;<br />
typedef union {int8x8_t v; int8_t a[8]; } i8x8_t;<br />
ip (int8_t* fb,  int8_t* bb, int8_t* res) {<br />
i8x8_t i_ls;<br />
i_ls.a[0] = 1;<br />
i_ls.a[1] = 1;<br />
i_ls.a[2] = 1;<br />
i_ls.a[3] = 1;<br />
i_ls.a[4] = 1;<br />
i_ls.a[5] = 1;<br />
i_ls.a[6] = 1;<br />
i_ls.a[7] = 1;</p>
<p>i8x8_t* fb_ls = ( i8x8_t* ) malloc( sizeof( i8x8_t ));<br />
i8x8_t* bb_ls = ( i8x8_t* ) malloc( sizeof( i8x8_t ));<br />
i8x8_t* res_ls = ( i8x8_t* ) malloc( sizeof( i8x8_t ));<br />
memcpy(( void* )fb_ls, ( void* )fb, sizeof( i8x8_t ));<br />
memcpy(( void* )bb_ls, ( void* )bb, sizeof( i8x8_t ));</p>
<p>res_ls-&amp;gt;v= paddb_u( fb_ls-&amp;gt;v, bb_ls-&amp;gt;v );  //内建函数<br />
res_ls-&amp;gt;v= paddb_u( res_ls-&amp;gt;v, i_ls.v );   //内建函数</p>
<p>memcpy(( void* )res, ( void* )res_ls, sizeof( i8x8_t ));</p>
<p>free fb_ls;<br />
free bb_ls;<br />
free res_ls;<br />
}[/code]</p>
<p>需要如下选项编译:</p>
<p>[code lang="cpp"]<br />
$mipsel-unknown-linux-gnu-gcc -march=loongson2f  test.c  -flax-vector-conversions<br />
[/code]</p>
<p>-flax-vector-conversions 允许宽松的向量类型转换。<br />
使用simd扩展能很好的利用硬件资源，现在intel的cpu已经有了mmx，sse，sse2，sse3，AMD的也有3dNox!，这些都是类似上面的操作。龙芯上从2E开始就有了多媒体指令的支持。<br />
多媒体指令的使用，头疼的不在运算部分，而是怎么拼数据的问题。要切分，要对齐，要放到合适的地方，算完还要取出来。不过加速是肯定的。<br />
不仅仅可以用编译器内建函数使用simd，还有更直接的嵌入汇编，请看下面一段程序：</p>
<p>[code lang="cpp"]<br />
#define       LEN 1000000<br />
void main()<br />
{<br />
float a[LEN] __attribute__((aligned(8))) ;//设定8字节地址对齐<br />
float b[LEN] __attribute__((aligned(8))) ;<br />
int j,i;<br />
for(j = 0 ; j &amp;lt; LEN ; j++){       //初始化<br />
a[j] = 1.2345 + j;<br />
b[j] = 6.5432 + j;<br />
}<br />
for(i=0;i&amp;lt;100;i++)<br />
for( j = 0 ; j &amp;lt; LEN ; j++){<br />
a[j] = a[j] + b[j];<br />
}<br />
}<br />
[/code]</p>
<p>龙芯上，对最后一个双层循环嵌入汇编：</p>
<p>[code lang="cpp"]<br />
#define LEN 1000000<br />
void main()<br />
{<br />
//不对齐的话,下面的 ldc1会产生不对齐的异常,提示总线错误<br />
float a[LEN] __attribute__((aligned(8))) ;<br />
float b[LEN] __attribute__((aligned(8))) ;<br />
int j , i;<br />
for(j = 0 ; j &amp;lt; LEN ; j++){ // 初始化<br />
a[j] = 1.2345 + j;<br />
b[j] = 6.5432 + j;<br />
}<br />
for(i=0;i &amp;lt; 100 ;i++)<br />
__asm__(<br />
&quot;.set noreorder\n&quot;<br />
&quot;.set arch=loongson2f\n&quot;<br />
&quot;1:\n&quot;<br />
&quot;slti $8,%2,2\n&quot; // 判断待操作的数据是否小于 2<br />
&quot;bnez $8,2f\n&quot;<br />
&quot;addiu %2,-2\n&quot; //利用延时槽<br />
&quot;ldc1 $f0,0(%0)\n&quot;//在龙芯的世界里,字 32 位,双字 64 位<br />
&quot;ldc1 $f2,0(%1)\n&quot;//ldc1 读取两个 float,利用 64 位的总线宽度<br />
&quot;add.ps $f0,$f0,$f2\n&quot;// add.ps 指令并行做了两对 float 的加法<br />
&quot;sdc1 $f0,0(%0)\n&quot;<br />
&quot;addiu %0,8\n&quot;<br />
&quot;b 1b\n&quot;<br />
&quot;addiu %1,8\n&quot; // 延时槽<br />
//程序执行到此表示待操作的数据小于 2,为 0 或 1<br />
&quot;2:\n&quot;<br />
&quot;beq %2,$0,3f\n&quot;<br />
//这个延时槽没有合适的指令填充,用 nop 填充<br />
&quot;nop\n&quot;<br />
&quot;lwc1 $f0,0(%0)\n&quot;<br />
&quot;lwc1 $f2,0(%1)\n&quot;<br />
&quot;add $f0,$f0,$f2\n&quot;<br />
&quot;swc1 $f0,0(%0)\n&quot;<br />
&quot;3:\n&quot;<br />
&quot;.set reorder\n&quot;<br />
::&quot;r&quot;(a),&quot;r&quot;(b),&quot;r&quot;(LEN)<br />
:&quot;$8&quot;,&quot;$f0&quot;,&quot;$f2&quot;,&quot;memory&quot;<br />
);<br />
}<br />
[/code]</p>
<p>参考：</p>
<p>http://dev.lemote.com/files/document/loongson/SIMD指令使用手册v0.1.pdf</p>
<p>http://gcc.gnu.org/onlinedocs/gcc/MIPS-Loongson-Built_002din-Functions.html#MIPS-Loongson-Built_002din-Functions</p>
<p>http://gcc.gnu.org/viewcvs/trunk/gcc/testsuite/gcc.target/mips/loongson-simd.c?revision=142875&#038;view=co</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="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="经验之谈:做好预防措施,保护好自己的电脑的13个Tips" style="text-decoration: none !important; cursor: pointer !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%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/30/7115636.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">经验之谈:做好预防措施,保护好自己的电脑的13个Tips</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="百度Hi策略的猜想" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F10%2F9937%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/07/31/20239408.png" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">百度Hi策略的猜想</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="zzMozilla的疯狂构想 Firefox 4将开拓浏览器新疆界" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F31%2F9966%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/06/05/11067795.gif" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">zzMozilla的疯狂构想 Firefox 4将开拓浏览器新疆界</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="百度聊天工具&quot;百度hi&quot;功能一览及评价" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2008%2F03%2F01%2F9914%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/04/30/7115293.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">百度聊天工具&quot;百度hi&quot;功能一览及评价</font>
                    </a>
                </td>
                <td width="102" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="Some notes about IBM  XL C Compiler" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F09%2F14%2F11718%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2010%2F01%2F21%2F10663%2F">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 96px !important; height: 96px !important;" src="http://static.wumii.com/site_images/2011/09/14/30937598.jpg" width="96px" height="96px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 102px !important; font: 12px/15px arial !important; height: 60px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">Some notes about IBM  XL C Compiler</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" 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/12/10931/' rel='bookmark' title='前瞻-拿起SIMD的武器II'>前瞻-拿起SIMD的武器II</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/12/29/10503/' rel='bookmark' title='GCC初窥'>GCC初窥</a></li>
<li><a href='http://www.lingcc.com/2010/01/07/10594/' rel='bookmark' title='使用crossdev安装龙芯的O32 gnu交叉工具链'>使用crossdev安装龙芯的O32 gnu交叉工具链</a></li>
<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/2009/11/18/10000/' rel='bookmark' title='Open64课程-简介，概述和中间表示'>Open64课程-简介，概述和中间表示</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2010/01/21/10663/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>GCC初窥</title>
		<link>http://www.lingcc.com/2009/12/29/10503/</link>
		<comments>http://www.lingcc.com/2009/12/29/10503/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 12:44:03 +0000</pubDate>
		<dc:creator>erlv</dc:creator>
				<category><![CDATA[GCC]]></category>
		<category><![CDATA[编译技术]]></category>
		<category><![CDATA[编译理论实践和应用]]></category>
		<category><![CDATA[3dnow]]></category>
		<category><![CDATA[amd]]></category>
		<category><![CDATA[builtin]]></category>
		<category><![CDATA[compiler infrastructure]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[elf]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[ld]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[LLVM]]></category>
		<category><![CDATA[MIPS]]></category>
		<category><![CDATA[MPI]]></category>
		<category><![CDATA[N64]]></category>
		<category><![CDATA[Open64]]></category>
		<category><![CDATA[portage]]></category>
		<category><![CDATA[spec]]></category>
		<category><![CDATA[SSA]]></category>
		<category><![CDATA[sse]]></category>
		<category><![CDATA[windows]]></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>

		<guid isPermaLink="false">http://www.lingcc.com/?p=10503</guid>
		<description><![CDATA[这是gcc maillist中某国际友人 laurent@guerby.net 做的2个小时报告的ppt，报告题目为。最近一直想深入了解gcc，而这个ppt基本包含本博想了解的内容，所以将其翻译并分享到这里。翻译过程中，很多地方可能有错，请大家不吝赐教。

什么是GCC
GCC--GNU Compiler Collection,即GNU 编译器集合。GCC即可作为本地编译器也能作为交叉编译器，它支持很多高级语言和多个编译和目标平台。GCC的网址 http://gcc.gnu.org.它是FSF基金会版权所有的自由软件.<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%2F16%2F11210%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%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%2F03%2F28%2F11567%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">仔细端详GCC 4.6的新特性</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%2F27%2F11679%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%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%2F2011%2F11%2F29%2F11859%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%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%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</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/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</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/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/2010/04/16/10746/' rel='bookmark' title='来仔细看看GCC 4.5.0'>来仔细看看GCC 4.5.0</a></li>
<li><a href='http://www.lingcc.com/2010/01/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>这是gcc maillist中某国际友人 laurent@guerby.net 做的2个小时报告的ppt，报告题目为GCC Toulibre 20091216。最近一直想深入了解gcc，而这个ppt基本包含本博想了解的内容，所以将其翻译并分享到这里。翻译过程中，很多地方可能有错，请大家不吝赐教。原版的ppt见文末。</p>
<ul>
<li>什么是GCC</li>
</ul>
<p>GCC&#8211;GNU Compiler Collection,即GNU 编译器集合。GCC即可作为本地编译器也能作为交叉编译器，它支持很多高级语言和多个编译和目标平台。GCC的网址 <a href="http://gcc.gnu.org">http://gcc.gnu.org</a>.它是FSF基金会版权所有的自由软件.<span id="more-10503"></span></p>
<ul>
<li>GCC支持的语言</li>
</ul>
<p>已经在代码树中：c(gcc),c++(g++),Java(gcj),Ada(GNAT),Objective-C(gobjc),Objective-C++(gobjc++),Fortran(gfortran),不在代码树中,但已经支持的Modula-2,Modula-3,Pascal(gpc),PL/1,D(gdc),Mercury,VHDL(ghdl).</p>
<ul>
<li>GCC支持的目标平台</li>
</ul>
<p>已经在代码树中的,可以在gcc-4.5/gcc/config子文件夹中找到,包括:alpha,arc,arm,avr,bfin,cris,crx,fr30,frv,h8300,i386,ia64,iq2000,lm32,m32c,m32r,m68hc11,m68k,mcore,mep,mips,mmix,mn10300,moxie,pa,pdp11,picochip,rs6000,rx,s390,score,sh,soft-fp,sparc,spu,stormy16,v850,vax,vms,xtensa<br />
不在代码数中但已经支持的,可在GNU_Compiler_Collection的Wikipedia中找到,包括PDP-10和Z8000等14中终端.</p>
<ul>
<li>gcc易编译</li>
</ul>
<p>至少对于本地编译gcc,仅需以下几步<br />
<code><br />
$ tar xfj gcc-4.4.2.tar.bz2<br />
$ mkdir build &amp;&amp; cd build<br />
$ ../gcc-4.4.2/configure –prefix=/opt/gcc<br />
$ make bootstrap &amp;&amp; make install<br />
$ make -k check<br />
</code></p>
<ul>
<li>gcc编译很快</li>
</ul>
<p>具体速度依赖编译所用机器,在2&#215;4个核的X86_64上仅需15分钟.在ARM Cortex A8@800Mhz上需要大约7小时.编译需要约512M内存.注意,对于开发版的GCC,因为需要很多内建的检测,所以编译会较慢.</p>
<ul>
<li>自举</li>
</ul>
<p>编译器是用程序语言编写并被编译成机器码以便执行的,所以使用特定编程语言写出的编译器是能够编译它自己的(译者注:写编译器的语言和编译器编译的语言要相同),这就是编译器的自举.GCC的自举过程为首先系统编译器编译生成stage1,而后stage1被用来编译它自己生成stage2.接着stage2被用来编译生成stage3,其中stage2和stage3生成的要完全相同.(译者注:现在一个简单的make命令，将自动完成make bootstrap)</p>
<ul>
<li>编译前的准备工作.</li>
</ul>
<p>目前多数发布的是4.3或4.4.在debian或者ubuntu上可以使用命令<br />
<code><br />
$apt-get build-dep gcc<br />
</code><br />
来得到编译环境.在windowss上也能通过Cygwin或Mingw得到</p>
<ul>
<li>生成一个交叉编译器</li>
</ul>
<p>生成一个交叉编译器更难,因为GCC,GNU libc和Linux内核都需要链接并依赖彼此的头文件和常量.另外你可能还需要代码树之外的补丁.推荐使用预编译好的工具链,如gcc-avr或者是Crosstool-ng之类的工具.</p>
<ul>
<li>GCC项目历史</li>
</ul>
<p>1985年Richard Stallman开始了GCC作为GNU C编译器的项目；<br />
1991年GCC 1.x=&gt;GCC 2.x;<br />
1997年EGCS启动;<br />
1999年EGCS成为官方GCC2.95,GCC引入委员会;<br />
2001年GCC 3.x;<br />
2005年GCC4.x,并6个月至1年发布一次.</p>
<ul>
<li>贡献者</li>
</ul>
<p>下面数据基于快速修改记录处理(quick ChangeLog parsing)生成.依次为:年份==修改记录===邮件数<br />
1998 == 1685 == 107<br />
1999 == 2629 == 196<br />
2000 == 5588 == 326<br />
2001 == 6356 == 355<br />
2002 == 7259 == 371<br />
2003 == 10440 == 443<br />
2004 == 12857 == 440<br />
2005 == 11657 == 407<br />
2006 == 9221 == 356<br />
2007 == 8611 == 366<br />
2008 == 7789 == 357<br />
2009 == 9028 == 341</p>
<ul>
<li>基于GCC的有偿工作</li>
</ul>
<p>有Redhat,Novell等系统集成商,AdaCore,CodeSourcery等开发工具提供商,IBM,AMD,Intel,ST半导体等芯片提供商,Google(15人为C++支持工作,15人为GCC架构工作),还有科研机构如INRIA Saclay等.</p>
<ul>
<li>gcc是个相当大的项目</li>
</ul>
<p>gcc-4.5-20091210/gcc除去测试集,使用SLOCCOUNT计数,并按语言分组(按比例从大到小):ANSI C:1067922(67.18%);Ada:485301(30.53%);asm:30379(1.91%);更多的统计数据如下:<br />
31006 == 108 == asm<br />
170569 == 62 == texi<br />
189382 == 999 == ads<br />
230459 == 714 == h<br />
300237 == 229 == md<br />
707707 == 871 == adb<br />
1365750 == 772 == c<br />
共识别3033097行</p>
<ul>
<li>GCC中的选项</li>
</ul>
<p>-O0=&gt;无优化,和其他编译器有不同<br />
-O1=&gt;优化,但最小化编译时间<br />
-O2=&gt;有更多耗时的优化<br />
-O3=&gt;非常耗时的优化,如自动内联和向量化<br />
-Os=&gt;代码大小优化<br />
怎样得到-O1具体的优化选项?<br />
<code><br />
$gcc -Q --help=optimizers -O1<br />
</code><br />
输出结果:<br />
<code><br />
The following options control optimizations:<br />
-falign-jumps              [disabled]<br />
-falign-labels             [disabled]<br />
-falign-loops              [enabled]<br />
...<br />
</code><br />
4.3约140个,4.4约160个,4.5约180。这样我们就能查看gcc中O0,O1,O2,O3,Os中所有相关的优化选项。<br />
目标机相关的指令有哪些?运行命令<br />
<code><br />
$ gcc -Q --target-help<br />
Target specific options:<br />
-m128bit-long-double sizeof(long double) is 16<br />
-m32 Generate 32bit i386 code<br />
-m3dnow Support 3DNow! built-in functions<br />
-m64 Generate 64bit x86-64 code<br />
....<br />
</code><br />
此外还有一些选项,如<br />
-march=&#8230;. =&gt; 选择一个指令集(注意,得到的可执行代码可能不能运行)<br />
-mtune=&#8230; =&gt; 在指定的指令集中,针对某个目标机做 优化(atom,core2,opteron等)<br />
-native  =&gt;自动检测当前处理器</p>
<ul>
<li>如何找到有趣的选项</li>
</ul>
<p>在<a href="http://www.spec.org">http://www.spec.org</a>上找SPECint和SPECfp的详细结果,测量峰值时使用的选项都在文档中,或者使用自动调优工具,如Acovea,  <a href="http://www.coyotegulch.com/products/acovea/">http://www.coyotegulch.com/products/acovea/</a></p>
<ul>
<li>内建功能(Builtins)</li>
</ul>
<p>gcc特用的,但一些其他编译器有提供的功能.这些功能很有趣,因为都是机器无关的.<br />
例如:<br />
<code><br />
int __builtin_ffs(unsigned int x)<br />
</code><br />
返回1+x的最小指数(?),或者当x为0时返回0<br />
还有一些机器相关的内联汇编,如asm(“fsinx %1,%0&#8243;:”=f” (result):”f”(angle));</p>
<ul>
<li>GCC如何工作?</li>
</ul>
<p><code><br />
$ls -l /usr/bin/gcc-4.1<br />
-rwxr-xr-x 1 root root 205952 2006-12-11 00:12 /usr/bin/gcc<br />
</code><br />
可以看到,gcc程序很小,这仅仅是一个驱动器.它将根据命令行调用很多程序来完成任务.真正的编译器如下:<br />
<code><br />
5.3M /usr/lib/gcc/x86_64-linux-gnu/4.1.2/cc1<br />
5.8M/usr/lib/gcc/x86_64-linux-gnu/4.1.2/cc1plus<br />
7.7M /usr/lib/gcc/x86_64-linux-gnu/4.1.2/gnat1<br />
5.2M /usr/lib/gcc/x86_64-linux-gnu/4.1.2/jc1<br />
</code><br />
因此真正的顺序是:gcc=&gt;xx1=&gt;as或ld.(译者注:请参见本文末尾的gcc -v helloworld.c)</p>
<ul>
<li>Binutils是什么?</li>
</ul>
<p>GCC指示一个文本文件到文本文件的转换器,Binutils做生成可执行机器码的工作.<br />
运行命令<br />
<code><br />
$gcc -S file.c<br />
</code><br />
将只生成汇编文件file.s</p>
<ul>
<li>GCC的内部架构</li>
</ul>
<p>前端:每种编程语言有一个前端,包含该编程语言的词法分析，语法分析和语义分析，并将其翻译成统一的中间代码表示，接着该中间表示将会lower成GIMPLE。<br />
中端:操作GIMPLE，依次做机器无关和机器相关的转换和优化。<br />
后端:使用目标机器描述生成目标机器汇编文件。<br />
RTL即寄存器转换语言。在优化时，可能需要对程序遍历数以百遍。</p>
<ul>
<li>目标机器描述</li>
</ul>
<p>这是一个模式匹配引擎，它描述每个机器指令的作用。它是一个包含分段C语言代码的文本文件。如gcc/config/i386/i386.md.机器描述的质量将影响最终生成的目标代码的质量。仅需对每个目标机创建一个描述，就能将所有的语言移植到该机器上。</p>
<ul>
<li>关于Moxie</li>
</ul>
<p>Moxie的博客   <a href="http://moxielogic.org/blog/">http://moxielogic.org/blog/</a>。已有贡献，简化虚拟指令系统结构设计，为整个GNU工具链做贡献，现在已经可以运行Binutils，GCC，qemu和Linux。gcc/config/moxie/*.md有560行，gcc/config/moxie/*少于2000行。</p>
<ul>
<li>中间代码形式</li>
</ul>
<p>对于代码：<br />
<code><br />
int f(int x, int y) {<br />
int tmp;<br />
tmp=x;<br />
if (x&gt;0) tmp=-x;<br />
return tmp+y;<br />
}<br />
</code><br />
<code><br />
$ gcc -S -O3 -fdump-tree-all t.c</code><br />
得到共100多个文件。<br />
例如t.c.003t.original内容如下：<br />
<code><br />
f (int x, int y)<br />
{<br />
int D.2705;<br />
int tmp;<br />
tmp = x;<br />
if (x &gt; 0) goto ; else goto ;<br />
:<br />
tmp = -x;<br />
:<br />
D.2705 = tmp + y;<br />
return D.2705;<br />
}</code><br />
t.c.024t.ssa如下<br />
<code><br />
f (int x, int y) {<br />
int tmp;<br />
int D.2705;<br />
: tmp_3 = x_2(D);<br />
if (x_2(D) &gt; 0) goto ;<br />
else     goto ;<br />
:<br />
tmp_4 = -x_2(D);<br />
:<br />
# tmp_1 = PHI<br />
D.2705_6 = tmp_1 + y_5(D);<br />
return D.2705_6;<br />
}</code></p>
<ul>
<li>GCC与GDB</li>
</ul>
<p>使用选项-g生成调试信息。在汇编文集中插入很多运行无关的代码,如DWARF(和ELF).GDB通过读入这些代码来映射运行中每个点的行号，内存你和寄存器。GCC甚至可以在优化时生产调试信息，但是所生成的信息将很难跟踪。</p>
<ul>
<li>GCC和GDB中的bug</li>
</ul>
<p>GCC可能产生错误的调试信息，GDB可能错误的读入调试信息，用户界面可能和GDB通信时出错，因此在实际中，需要在这几个项目中获得帮助来搞定bug，希望这些项目之间有更好的沟通。</p>
<ul>
<li>GCC中的bug</li>
</ul>
<p>GCC每次发布都伴随着数以百计的已知bug(其他的编译器也一样),GCC中紧急bug类型(bugzilla中的关键字):wrong-code,accepts-invalid,编译器内部出错时很容易找出、ice-on-valid、ice-on-invalid、wrong-debug、missed-optimization、rejects-valid、memory-hog、compile-time-hog、assemble-failure、build</p>
<ul>
<li>如何报告GCC bug</li>
</ul>
<p>链接：<a href="http://gcc.gnu.org/bugs">http://gcc.gnu.org/bugs</a> 是个很好的必读资源，包含通常的非gcc bug。 若真是bug，可以运行<br />
<code><br />
$gcc -v -save-temps -O1 myfile.c</code><br />
生成myfile.i文件，通常情况下，添加这两个附件并连同平台名称和编译器输出就足够了。出错和不出错的版本信息也很有帮助。</p>
<ul>
<li>GCC4.5的新特性</li>
</ul>
<p>在链接  <a href="http://gcc.gnu.org/gcc-4.5/changes.html">http://gcc.gnu.org/gcc-4.5/changes.html</a>中能找到，具体如下<br />
第一，增加一个全新的链接时优化器(-flto),使用这一选项时，GCC能够为每个输入文件得到一个bytecode表示，并将它写入每个目标文件的特定ELF段中。当目标文件需要链接在一起时，所有的函数体将从这些ELF段中读出，并将其作为转换单元的一部分表示。这将使得过程间优化能在不同的文件间进行(甚至不同的语言间),为生成代码的性能提升提供可能。为使用链接时优化器，-flto选项需要在编译时和最终链接过程中指定，若程序不需要任何符号输出，将-flto和-fwhopr以及-fwhole-program一起使用可以让过程间优化器使用更激进的假设进而提升性能；第二，自动并行化可以作为Graphite的一部分打开，在打开-ftree-parallelize-loops=的同时，指定-floop-parallelize-all可以打开基于Graphite的优化；第三，现在可以在不修改源码的前提下扩展编译器。新加入的选项-fplugin=file.so告诉编译器载入共享目标文件file.so，并将它作为编译器的一部分运行。内部的文档描述了插件和编译器之间交互的细节以及如何交互。见  <a href="http://gcc.gnu.org/wiki/GCC_PluginAPI">http://gcc.gnu.org/wiki/GCC_PluginAPI</a></p>
<ul>
<li>如何提问和贡献</li>
</ul>
<p><a href="http://gcc.gnu.org/">http://gcc.gnu.org/</a> 有详细的用户手册。gcc-help@gcc.gnu.org 是gcc帮助用的邮件列表<br />
IRC用户帮助 =&gt; irc.freenode.org #gcc<br />
http://gcc.gnu.org/ml =&gt;邮件列表归档<br />
gcc-patches@gcc.gnu.org  补丁<br />
gcc@gcc.gnu.org<br />
gcc-testresults@gcc.gnu.org<br />
IRC开发频道 =&gt; irc.oftc.net #gcc</p>
<ul>
<li>GCC外的其他编译器</li>
</ul>
<p>自由的:LLVM和Open64，有插件时变得很有趣。<br />
非自由的:ICC（Intel),XLC(IBM)&#8230;<br />
评测编译器很难，最好基于你自己的代码，做自己的设置。当心bug和技术支持。如果你想做多平台，那GCC是很难搞定的。</p>
<ul>
<li>GCC编译农场(GCC Compile Farm)</li>
</ul>
<p>链接<a href=" http://gcc.gnu.org/wiki/CompileFarm"> http://gcc.gnu.org/wiki/CompileFarm</a>。 目的:为自由软件开发者提供方便访问且多样的体系结构用来编译和测试(并不局限于GCC).由FSF法国提供支持。很多研究所，个人和公司提供机器，主机和帮助。AMD和Genesi贡献了机器。</p>
<ul>
<li>结论</li>
</ul>
<p>GCC是一个庞大的老项目，但是它依旧活力十足，并有很多公司提供支持。学习GCC非常艰巨。即便高质量到Bug报告也是对GCC的贡献。</p>
<div id="__ss_2780061" style="width: 425px; text-align: left;"><a style="font: 14px Helvetica,Arial,Sans-serif; display: block; margin: 12px 0 3px 0; text-decoration: underline;" title="Gcc Toulibre 20091216" href="http://www.slideshare.net/erlv/gcc-toulibre-20091216">Gcc Toulibre 20091216</a><object style="margin: 0px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=gcc-toulibre-20091216-091227020235-phpapp02&amp;stripped_title=gcc-toulibre-20091216" /><param name="allowfullscreen" value="true" /><embed style="margin: 0px;" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=gcc-toulibre-20091216-091227020235-phpapp02&amp;stripped_title=gcc-toulibre-20091216" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size: 11px; font-family: tahoma,arial; height: 26px; padding-top: 2px;">View more <a style="text-decoration: underline;" href="http://www.slideshare.net/">documents</a> from <a style="text-decoration: underline;" href="http://www.slideshare.net/erlv">erlv</a>.</div>
</div>
<p>附：在译者电脑上运行gcc -v helloworld.c的输出。<br />
<code><br />
$ gcc -v helloworld.c<br />
Using built-in specs.<br />
Target: i686-pc-linux-gnu<br />
Configured with: /var/tmp/portage/sys-devel/gcc-4.4.2/work/gcc-4.4.2/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.4.2 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.4.2 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.4.2/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.4.2/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld --with-python-dir=/share/gcc-data/i686-pc-linux-gnu/4.4.2/python --disable-libgcj --with-arch=i686 --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.4.2 p1.0'<br />
Thread model: posix<br />
gcc version 4.4.2 (Gentoo 4.4.2 p1.0)<br />
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i686'<br />
/usr/libexec/gcc/i686-pc-linux-gnu/4.4.2/cc1 -quiet -v helloworld.c -D_FORTIFY_SOURCE=2 -quiet -dumpbase helloworld.c -mtune=generic -march=i686 -auxbase helloworld -version -o /tmp/ccRoxwan.s<br />
ignoring nonexistent directory "/usr/local/include"<br />
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../../i686-pc-linux-gnu/include"<br />
#include "..." search starts here:<br />
#include &lt;...&gt; search starts here:<br />
/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/include<br />
/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/include-fixed<br />
/usr/include<br />
End of search list.<br />
GNU C (Gentoo 4.4.2 p1.0) version 4.4.2 (i686-pc-linux-gnu)<br />
compiled by GNU C version 4.4.2, GMP version 4.3.1, MPFR version 2.4.1-p1.<br />
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072<br />
Compiler executable checksum: bfddefec40932d7559ac2c097447ec05<br />
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i686'<br />
/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../../i686-pc-linux-gnu/bin/as -V -Qy -o /tmp/cc0ViYlD.o /tmp/ccRoxwan.s<br />
GNU assembler version 2.18 (i686-pc-linux-gnu) using BFD version (GNU Binutils) 2.18<br />
COMPILER_PATH=/usr/libexec/gcc/i686-pc-linux-gnu/4.4.2/:/usr/libexec/gcc/i686-pc-linux-gnu/4.4.2/:/usr/libexec/gcc/i686-pc-linux-gnu/:/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/:/usr/lib/gcc/i686-pc-linux-gnu/:/usr/libexec/gcc/i686-pc-linux-gnu/4.4.2/:/usr/libexec/gcc/i686-pc-linux-gnu/:/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/:/usr/lib/gcc/i686-pc-linux-gnu/:/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../../i686-pc-linux-gnu/bin/<br />
LIBRARY_PATH=/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/:/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/:/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../../i686-pc-linux-gnu/lib/:/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../:/lib/:/usr/lib/<br />
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i686'<br />
/usr/libexec/gcc/i686-pc-linux-gnu/4.4.2/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../crt1.o /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../crti.o /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/crtbegin.o -L/usr/lib/gcc/i686-pc-linux-gnu/4.4.2 -L/usr/lib/gcc/i686-pc-linux-gnu/4.4.2 -L/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../../i686-pc-linux-gnu/lib -L/usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../.. /tmp/cc0ViYlD.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/crtend.o /usr/lib/gcc/i686-pc-linux-gnu/4.4.2/../../../crtn.o<br />
</code></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%2F09%2F16%2F11210%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%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%2F03%2F28%2F11567%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">仔细端详GCC 4.6的新特性</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%2F27%2F11679%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%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%2F2011%2F11%2F29%2F11859%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%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%2F2012%2F01%2F15%2F11963%2F&from=http%3A%2F%2Fwww.lingcc.com%2F2009%2F12%2F29%2F10503%2F">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Open64、LLVM、GCC源代码行数对比</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/31/10534/' rel='bookmark' title='Gentoo中的交叉编译利器&#8211;crossdev'>Gentoo中的交叉编译利器&#8211;crossdev</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/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/2010/04/16/10746/' rel='bookmark' title='来仔细看看GCC 4.5.0'>来仔细看看GCC 4.5.0</a></li>
<li><a href='http://www.lingcc.com/2010/01/21/10663/' rel='bookmark' title='小例子&#8211;回眸一笑百媚生'>小例子&#8211;回眸一笑百媚生</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.lingcc.com/2009/12/29/10503/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

