<?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/%e5%86%85%e5%bb%ba%e5%87%bd%e6%95%b0/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>来仔细看看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>小例子&#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="乱扯计算" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2010%2F12%2F31%2F11470%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/29/7110199.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;">乱扯计算</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="除夕夜看春晚？你OUT了！搞ACM，挣奖金吧。" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2012%2F01%2F15%2F11952%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/2012/01/15/13984937.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;">除夕夜看春晚？你OUT了！搞ACM，挣奖金吧。</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="JAVA虚拟机入门" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fwww.lingcc.com%2F2011%2F05%2F08%2F11580%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/05/08/7999970.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;">JAVA虚拟机入门</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="MSI推出阴离子笔电及搭载Turbo Battery Technology的节电本" 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%2F29%2F9907%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/7115676.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;">MSI推出阴离子笔电及搭载Turbo Battery Technology的节电本</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%2F09%2F18%2F11235%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/17/23191912.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;">推荐个演讲-马云的</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="百度IM内测版界面曝光" 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%2F29%2F9908%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/7115680.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;">百度IM内测版界面曝光</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%2F12%2F31%2F11470%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/29/7110199.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;">乱扯计算</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%2F01%2F11%2F10639%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/7114940.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;">令人振奋的第六感技术</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="MSI推出阴离子笔电及搭载Turbo Battery Technology的节电本" 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%2F29%2F9907%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/7115676.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;">MSI推出阴离子笔电及搭载Turbo Battery Technology的节电本</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%2F03%2F13%2F9949%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/7115493.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;">职场男装搭配颜色合身要领</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>
	</channel>
</rss>

