VC and BCB optimization code test (1)

zhaozj2021-02-16  65

Tools: VC Version 7.0BCB Version 6.0 Compile Options: Maximum Speed ​​Optimization, (VC 7.0 Turn off Auto Internal Function Options) Continental Tools: W32DASM

Benchmark test procedure: void test () {INT A = 0, B = 1, c = 4; for (int i = 0; i

INT main () {__ASM {MOV EDX, EDX NOP}; test ();

For the purpose, the test program has an optimization capability of useless functions. Since Test does not return any values, no external variables, therefore, this is an invalid function, an excellent compiler can optimize it.

VC compile results: // ----------------------------------------- ------ main () ---------------------------------------------------------------------------------------------------- ), very good !!!: 00401003 C3 RET / / ------------------------------------- ------------ Main () finished --------------

BCB compile results: // ------------------------------------------- -------- Main () --------------: 00401184 89D2 MOV EDX, EDX: 00401186 90 NOP: 00401187 E8DCFFFFF CALL 00401168 // Call Test (), BAD! !! :(: 0040118C 33c0 xor Eax, Eax: 0040118E C3 RET / / --------------------------------- ---------------- Main () finished -------

As seen from the above results, VC is in this manifestation, quite good, BCB is a bit garbage

VC VS BCB === 1: 0

Benchmark detector int@global = 0; int test () {INT A = 0, B = 3, c = 4; for (int i = 0; i

INT main () {__ASM {MOV EDX, EDX NOP}; return test ();

OBJECTIVE: Testing the optimization capabilities of invalid variables in functions, A is useless variables, and excellent compilers should optimize it.

VC test results: // ------------------------------------------ ---- Main () --------------------: 00401000 8BD2 MOV EDX, EDX: 00401002 90 NOP: 00401003 A1C0724000 MOV EAX, DWORD PTR [004072C0]: 00401008 83C007 Add Eax, 00000007 // !!!!!!!!! Horror !!!!: 0040100B A3C0724000 MOV DWORD PTR [004072C0], EAX: 00401010 C3 RET / / ----------- ------------------------------------ - main () finished --------- ---

BCB test results / / -------------------------------------------------------------------------------------------------------- -main () -------------------: 0040118C 89D2 MOV EDX, EDX: 0040118E 90 NOP: 0040118F E8D4FFFFFF CALL 00401168 / / BAD: 00401194 C3 RET / / ------------------------------------------ Main () finished --- ------- // ----------------------------------------- --- Test () -------------------------------------------------------------------- 0000000004 // c = 4: 00401173 33c0 xor Eax, EAX // i = 0: 00401175 EB07 JMP 0040117E: 00401177 FF05A4204000 Inc DWORD PTR [004020A4] // global: 0040117d 40 Inc EAX / / I // No a; good !!!: 0040117E 8D1C11 LEA EBX, DWORD PTR [ECX EBX] // EBX = B C = 7: 00401181 3BC3 CMP EAX, EBX: 00401183 7CF2 JL 00401177: 00401185 A1A4204000 MOV EAX, DWORD PTR [004020A4]: 0040118A 5B POP EBX: 0040118B C3 RET / / -------------------------- ------------------ Test () finished -------------- Result summary: VC in this performance is not It doesn't feel horrible, it actually optimizes the program logically, directly calculating the value of Global, then directly embed Main (), the compiler shown here is quite smart! ! !

BC's performance is quite a rules compared to VC! First, the main () function called Test () in Test (), BCB exhibits some advanced optimization means, first, without multiple calculation of condition variables B C, but calculates in EDX after calculating it, avoiding At each cycle, the condition variables are calculated. Secondly, optimize the invalid variable A, in general, it is still a strong man, but it is better than the VC, it is really a heaven and earth. The execution of the VC is more than one quantity than the BCB!

It is a horror. It seems that after joining MS from Anders, the progress of the VC in the compiler technology is crazy, but the BCB is too much ~~~ 55555 ~~~~ However, from a side body show, can Manual optimization can be manually optimized, because you can't know if each compiler can have enough intelligence ~~~

Original: http://purec.binghua.com/article/showArticle.asp? ArticleId = 230

转载请注明原文地址:https://www.9cbs.com/read-20846.html

New Post(0)