Hi Dennis,

Thanks

I have considered the problem you mentioned before. That is the reason I
just use record, not packed record. I think I should take your suggestion
seriously, so maybe change fReadOnly type from Boolean to Cardinal, and
assign 0 or $FFFF to that value to represent Boolean, to avoid any potential
problem arise and also enjoy the speed improvement.

Best Regards
Leigh



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Dennis Chuah
Sent: Tuesday, June 17, 2003 1:29 PM
To: Multiple recipients of list delphi
Subject: Re: [DUG]: Delphi optimizer


One danger with hand optimising ASM code is illustrated by your example.  In
the generated code:

> mov byte ptr [eax+$304], $0

writes 0 to BYTE location [eax+$304], whereas you

mov [eax+$304], edx

writing a DWORD into location [eax+$304], possibly overwriting memory.

This sort of bugs can be vary hard to track down.  The software would seem
to work for some time, then a bug would appear in a complete unrelated area.

You should therefore write your code like:

xor edx, edx
mov [eax+$2fc], edx
mov [eax+$300], edx
mov byte ptr [eax+$304], $0

which is only a saving of one instruction!

On a Pentium CPU (and the AMD CPU's as well), basic instructions execute in
1 CPU clock cycle.  This means your hand optimised assembler only runs 1
nano second faster than that generated by Delphi.  I won't bother if I were
you.

Dennis.

----- Original Message -----
From: "Leigh Wanstead" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Tuesday, June 17, 2003 11:43 AM
Subject: [DUG]: Delphi optimizer


> Hello everyone,
>
> I was surprised that Delphi 7 generate following asmbler code for this
> pascal code. I have turned on Code generation/Optimization.
>
>   fMyRecord.fLength := 0;
>   fMyRecord.fCount := 0;
>   fMyRecord.fReadOnly := False;
>
> xor edx, edx
> mov [eax+$2fc], edx
>
> xor edx, edx
> mov [eax+$300], edx
>
> mov byte ptr [eax+$304], $0
>
> I think the optimized asm code will look like this.
>
> xor edx, edx
> mov [eax+$2fc], edx
> mov [eax+$300], edx
> mov [eax+$304], edx
>
> I tested the hand written asm code, it is 5 cpu clock cycle faster. I hate
> to put asm in my source code. So the question is how to write delphi code
to
> generate optimize asm code like this one.
>
> I know this slow down may not sound that much, just for research purpose.
>
> I have enclosed delphi sample code for your reference. I look forward to
> hearing from you.
>
> TIA
>
> Best Regards
> Leigh
>
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to