龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

Viusal C++.NET的优化代码(3)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
func(int *pi, int *pj) { *pj = g; h = *pi; } 当不使用"/GL"选项时,生成了如下代码: sub esp, 8 lea eax, DWORD PTR _j$[esp+8] push eax lea ecx, DWORD PTR _i$[esp+12] push ecx mov DWORD P
  func(int *pi, int *pj)
  {
  *pj = g;
  h = *pi;
  }

  当不使用"/GL"选项时,生成了如下代码:

  sub esp, 8
  lea eax, DWORD PTR _j$[esp+8]
  push eax
  lea ecx, DWORD PTR _i$[esp+12]
  push ecx
  mov DWORD PTR _i$[esp+16], 0
  mov DWORD PTR _j$[esp+16], 1
  mov DWORD PTR ?g@@3HA, 5
  mov DWORD PTR ?h@@3HA, 6
  call ?func@@YAXPAH0@Z
  mov eax, DWORD PTR _i$[esp+16]
  mov edx, DWORD PTR ?g@@3HA
  mov ecx, DWORD PTR ?h@@3HA
  add edx, eax
  add ecx, eax
  mov DWORD PTR ?g@@3HA, edx
  mov DWORD PTR ?h@@3HA, ecx
  xor eax, eax
  add esp, 16
  ret 0

  当使用了"/GL"时,你会看到下面的代码,现在的代码短多了。注意编译这个例子时同样要注意关掉内联优化。

  sub esp, 8
  lea ecx, DWORD PTR _j$[esp+8]
  lea edx, DWORD PTR _i$[esp+8]
  mov DWORD PTR _i$[esp+8], 0
  mov DWORD PTR ?g@@3HA, 5
  mov DWORD PTR ?h@@3HA, 6
  call ?func@@YAXPAH0@Z
  mov DWORD PTR ?g@@3HA, 5
  xor eax, eax
  add esp, 8

精彩图集

赞助商链接