Such a small benchmark
Bert Freudenberg
bert at isg.cs.uni-magdeburg.de
Wed Oct 16 19:49:10 UTC 2002
On Wed, 16 Oct 2002, Viktor wrote:
> > I know that many fortran compilers would just optimize the whole loop
> > away. Are you certain that the compiled C program wasn't also
> > similiarily affected?
> >
> > --
> > Travis Griggs
>
> No, I supposed such optimizations, but I was wrong.
If you look closely, it does, partially.
> Here is disassembled code:
>
> 436: void CSelfDlg::OnBuildObject()
> 437: {
> 0040EF40 53 push ebx
> 0040EF41 55 push ebp
> 0040EF42 56 push esi
> 0040EF43 8B 35 28 40 41 00 mov esi,dword ptr
> [__imp__GetTickCount at 0 (00414028)]
> 0040EF49 57 push edi
> 0040EF4A 8B D9 mov ebx,ecx
> 0040EF4C FF D6 call esi
> 438: DWORD BegTime = ::GetTickCount();
> 439: DWORD *Array = new DWORD [1];
> 0040EF4E 6A 04 push 4
> 0040EF50 8B E8 mov ebp,eax
> 0040EF52 E8 A5 31 00 00 call operator new (004120fc)
> 0040EF57 8B F8 mov edi,eax
> 0040EF59 83 C4 04 add esp,4
> 0040EF5C B8 80 96 98 00 mov eax,989680h
> 0040EF61 8B 0F mov ecx,dword ptr [edi]
> 440: for (DWORD Index = 0; Index < 10000000; Index++)
> 0040EF63 48 dec eax
> 441: {
> 442: Array [0] = 3;
> 0040EF64 B9 03 00 00 00 mov ecx,3
> 0040EF69 75 F8 jne CSelfDlg::OnBuildObject+23h
> (0040ef63)
> 0040EF6B 89 0F mov dword ptr [edi],ecx
> 443: };
> 444: DWORD TotalTime = ::GetTickCount() - BegTime;
> 0040EF6D FF D6 call esi
> 0040EF6F 8B F0 mov esi,eax
> 445: delete Array;
> 0040EF71 57 push edi
> 0040EF72 2B F5 sub esi,ebp
> 0040EF74 E8 77 31 00 00 call operator delete (004120f0)
> 0040EF79 83 C4 04 add esp,4
Essentially, the above is:
mov ecx,Array[0]
label: dec eax
mov ecx,3
jne label
mov Array[0],ecx
The compiler did put the array element into a register. This saves a
memory write for each step.
--Bert
More information about the Squeak-dev
mailing list
|