﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-岁月流转，往昔空明-文章分类-Tips，Tricks</title><link>http://www.cppblog.com/lingjingqiu/category/359.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 17:10:00 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 17:10:00 GMT</pubDate><ttl>60</ttl><item><title>希望自己写SIMD优化的朋友注意了。</title><link>http://www.cppblog.com/lingjingqiu/articles/1373.html</link><dc:creator>空明流转</dc:creator><author>空明流转</author><pubDate>Mon, 28 Nov 2005 13:03:00 GMT</pubDate><guid>http://www.cppblog.com/lingjingqiu/articles/1373.html</guid><wfw:comment>http://www.cppblog.com/lingjingqiu/comments/1373.html</wfw:comment><comments>http://www.cppblog.com/lingjingqiu/articles/1373.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/lingjingqiu/comments/commentRss/1373.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lingjingqiu/services/trackbacks/1373.html</trackback:ping><description><![CDATA[昨天在写MatrixMultiply&nbsp;SIMD优化的时候，由于SSE的资料较多，我想都没想就写了一组SSE加速的程序。结果晚上做Profiler的时候，发现SSE算法的速度太慢，结果见下。 
<P></P>
<P>进程/线程优先级最高<BR>D3DX为D3DX9.LIB链接<BR>vc71-Release默认优化。<BR>SSE的测试数据是128bit对齐，使用movaps指令读取。<BR>预先预热了缓存<BR>Athlon&nbsp;XP&nbsp;1800+，&nbsp;512M，&nbsp;WD800JB</P>
<P>前面的数字是RDTSC测试出来的。</P>
<P>8255127&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatrixMultiply&nbsp;&nbsp;&nbsp;D3DX<BR>8079411&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MatrixMultiply&nbsp;&nbsp;&nbsp;3DNow<BR>101563037&nbsp;&nbsp;MatrixMultiply&nbsp;&nbsp;&nbsp;SSE<BR>250227542&nbsp;&nbsp;MatrixMultiply&nbsp;&nbsp;&nbsp;C</P>
<P>423771291&nbsp;&nbsp;Normalize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SSE<BR>31882680&nbsp;&nbsp;&nbsp;&nbsp;Normalize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3DNow<BR>51605359&nbsp;&nbsp;&nbsp;&nbsp;Normalize&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D3DX</P>
<P>从以上数据我们可以看出，Matrix的乘法运算中，C的速度是最慢的，sse次之。<BR>但是两者与3DNow相差了一个数量级的性能。接下来的Normalize测试也可以看出这一点。</P>
<P>ps，不要怀疑代码的质量，因为这三段代码的相关代码都经过类比的测试，大致可以认为这里面所有的代码质量是类似的。（最关键的是，不是我写的，哈哈！）</P>
<P>所以结论很简单，就是，如果你要针对不同CPU做优化，最好送佛送到西，每一种指令集都进行优化，还有就是不要想当然的认为优化的结果一定就很好，因为CPU对常规指令的执行进行了充分的优化，再加上乱序执行的方式，对于小函数来说，SIMD的额外成本太高了，最明显的就是DotProduct。</P>
<P>所以希望大家测试以后再决定优化的启用。<BR></P><img src ="http://www.cppblog.com/lingjingqiu/aggbug/1373.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lingjingqiu/" target="_blank">空明流转</a> 2005-11-28 21:03 <a href="http://www.cppblog.com/lingjingqiu/articles/1373.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>