泡泡网CPU频道 PCPOP首页      /      CPU     /      评测    /    正文

微软是祸首? Intel游戏落败深入分析

       微软在它的编译器的默认选项没有发挥处理器的性能,特别是对Pentium 4不利,而且微软的技术文档也在一定程度上误导了程序员。

{imageTitle}

    这位名叫Levichi的程序员在仔细阅读了一篇测评文章后,进行了深入的分析,通过对Battlefield 2进行了反编译,得出了两个结论:

1、 游戏是使用Visual Studio 2003 C++编译的
2 、编译采用了混合模式(blended mode),几乎没有任何优化。

     在微软MSDN网站上,对混合模式是这样描述的:

{imageTitle}

When no /Gx option is specified, the compiler defaults to /GB, "blended" optimization mode. In both the 2002 and 2003 releases of Visual C++ .NET, /GB is equivalent to /G6, which is said to optimize code for the Intel Pentium Pro, Pentium II, and Pentium III.

       当不使用/Gx选项时,编译器缺省使用/GB 混合模式。在Visual C++ .NET 2002和2003中,/GB等价于/G6,为Pentium Pro、Pentium II和Pentium III优化。

{imageTitle}

      微软推荐程序员为Pentium 4和Athlon系统编程时使用/G7。MSDN网站是如此描述的:

    The performance improvement achieved by compiling an application with /G7 varies, but when comparing to code generated by Visual C++ .NET 2002, it''s not unusual to see 5-10 percent reduction in execution time for typical programs, and even 10-15 percent for programs that contain a lot of floating-point code. The range of improvement can vary greatly, and in some cases users will see over 20 percent improvement when compiling with /G7 and running on the latest generation processors. Using /G7 does not mean that the compiler will produce code that only runs on the Intel Pentium 4 and AMD Athlon processors. Code compiled with /G7 will continue to run on older generations of these processors, although there might be some minor performance penalty. In addition, we''ve observed some cases where compiling with /G7 produces code that runs slower on the AMD Athlon.

     编译中使用/G7选项带来的性能提高情况不同,但是相对于Visual C++ .NET 2002产生的代码,这个选项通常对于典型程序可以缩短5-10%的执行时间,对于含有大量浮点运算的代码,甚至可以缩短10-15%。使用/G7选项编译带来的性能提高幅度变化很大,在最新的处理器上运行,在某些情况下可能有超过20%的提升。

{imageTitle}

     使用/G7选项并不意味着编译器产生的代码只能在Intel的Pentium 4和AMD的Athlon处理器上运行,仍然能够在以前的处理器上使用,只是性能会稍有损失。此外,我们注意到在某些情况下使用/G7选项产生的代码在AMD Athlon处理器上运行要慢一点。

      但是微软的这段描述也不确切,AMD的Athlon可能指的是32位的K7系列,如Athlon XP和更早的产品。而现在的90nm制程的Athlon 64系列支持全部的SSE、SSE 2和SSE 3指令集。

     在MSDN的文档中还暗示着,使用/G7选项产生的序列可能包含更多的指令,避免使用高延迟指令,在Pentium 4处理器上运行效率更高,就如同IMUL。

    我们回到Levichi的邮件:

... it would be logical to at least compile the game code with /G6 and /arch:SSE switches. That however, is not the case. I have checked it and the code uses only FPU, which is known to work slower on Pentium 4s. Moreover it uses pretty inefficient integer code too. Even /G6 would help a lot by enabling the compiler to generate conditional moves instead of many conditional branches, which are known to penalize NetBurst architecture so much.

    理论上讲,编译游戏时至少应该使用/G6和/arch:SSE选项,但事实并非如此。我检查了代码,只使用了Pentium 4上缓慢的浮点运算单元,此外还使用了效率低下的整数运算。/G6选项能够使编译器产生条件转移语句而不是条件分支,后者在NetBurst架构上会损失很多性能。

0人已赞

关注我们

泡泡网

手机扫码关注