- This topic has 9 replies, 2 voices, and was last updated 6 years, 6 months ago by HeDiBo.
-
AuthorPosts
-
March 21, 2018 at 12:25 pm #37784HeDiBoParticipant
I had a nasty bug in acPNG when running as 64 bit program.
Delphi XE4 for WIN32 generates this code:
Code:acPNG.pas.2889: MaxInSample := (1 shl SourceBPS) – 1;
008A5F03 8A4DE7 mov cl,[ebp-$19]
008A5F06 B001 mov al,$01
008A5F08 D2E0 shl al,cl
008A5F0A 48 dec eax
008A5F0B 8845E9 mov [ebp-$17],alBut when generating for WIN64 it generates this code:
Code:acPNG.pas.2889: MaxInSample := (1 shl SourceBPS) – 1;
0000000000B37A45 B001 mov al,$01
0000000000B37A47 480FB64D27 movzx rcx,byte ptr [rbp+$27]
0000000000B37A4C 80E107 and cl,$07
0000000000B37A4F D3E0 shl eax,cl
0000000000B37A51 80E801 sub al,$01
0000000000B37A54 884529 mov [rbp+$29],alI think that's not correct (the pascal source does not limit the shift to max 7 bits). But there we have it. Maybe you can figure out how to make this module behave with WIN64
March 24, 2018 at 9:07 am #57728SupportKeymasterHello!
Max value of SourceBPS is 8 there, min value is 0
I have checked the code in x32 and x64, all results were equal and there was not overflow or range errors.
Do you have problems with this code? Maybe you can give me the Png-file which can't be processed? I will test why it happens.
March 24, 2018 at 5:10 pm #57745HeDiBoParticipant'Support' wrote:Hello!
Max value of SourceBPS is 8 there, min value is 0
I have checked the code in x32 and x64, all results were equal and there was not overflow or range errors.
Do you have problems with this code? Maybe you can give me the Png-file which can't be processed? I will test why it happens.
I didn't say there was an overflow or range error. In my 64 bit delphi (Delphi XE4) the code generated is simply wrong.
This is the stack trace:
acPNG.MulDiv16(0,0,0)
acPNG.TColorManager.RowConvertIndexed8((…),$5710618,40,128)
acPNG.TColorManager.ConvertRow((…),$5710618,40,128)
acPNG.TPNGGraphic.LoadIDAT((no value))
acPNG.TPNGGraphic.LoadFromStream($82D5BD0)
sGraphUtils.LoadBmpFromPngStream($53C8E40,$82D5BD0)
acAlphaImageList.TsAlphaImageList.GenerateStdList
acAlphaImageList.TsAlphaImageList.Loaded
System.Classes.NotifyGlobalLoading
System.Classes.InitInheritedComponent($531DEB0,TClass($6F1738))
Vcl.Forms.TCustomForm.Create($53B74E0)
Vcl.Forms.TApplication.CreateForm(TComponentClass($927278),(no value))
ac64BitBug.ac64BitBug
:00007FFCDD051FE4 ; C:WINDOWSSystem32KERNEL32.DLL
:00007FFCDD35EFC1 ;
This is a sample project, As soon as image 1 is loaded, the DIvision by Zero exception occurs.
[attachment=8702:ac64BitBug.zip]
March 24, 2018 at 6:34 pm #57747SupportKeymasterThank you for the demo.
Really, I see that old x64 compilers has this bug.
I will search a better solution.
This solution is the best, I think (2 shl (n-1)-1), but I will check it: https://stackoverflo…on-in-delphi-xe
March 24, 2018 at 9:50 pm #57748HeDiBoParticipant'Support' wrote:Thank you for the demo.
Really, I see that old x64 compilers has this bug.
I will search a better solution.
This solution is the best, I think (2 shl (n-1)-1), but I will check it: https://stackoverflo…on-in-delphi-xe
Thanks!
Will you report here when you think you programmed around this Delphi bug? I'll try it again then.
March 27, 2018 at 2:21 pm #57762HeDiBoParticipantIn AC 13.04 the 64 bit code changed to:
Code:acPNG.pas.2891: MaxInSample := byte(integer(1 shl SourceBPS) – 1);
000000000084CEC9 C7C001000000 mov eax,$00000001
000000000084CECF 480FB64D27 movzx rcx,byte ptr [rbp+$27]
000000000084CED4 80E11F and cl,$1f
000000000084CED7 D3E0 shl eax,cl
000000000084CED9 80E801 sub al,$01
000000000084CEDC 884529 mov [rbp+$29],alAnd that seems to work
PS. Is there anyway you can eliminate the generated tabs in the code text? They're always wrong 😰
April 1, 2018 at 7:21 am #57757SupportKeymasterThis is how it looks in the my editor.
[attachment=8714:Code.png]
Please, show how it looks on your side.
April 1, 2018 at 4:46 pm #57799HeDiBoParticipant'Support' wrote:This is how it looks in the my editor.
[attachment=8714:Code.png]
Please, show how it looks on your side.
Sorry, I didn't mean in the Delphi editor, but in the [code}..[/code] part on this website.
April 13, 2018 at 4:08 pm #57833SupportKeymasterHello!
I understand now, but can't change it in the form engine, unfortunately.
May 16, 2018 at 11:04 am #57961HeDiBoParticipant'Support' wrote:Thank you for the demo.
Really, I see that old x64 compilers has this bug.
I will search a better solution.
This solution is the best, I think (2 shl (n-1)-1), but I will check it: https://stackoverflo…on-in-delphi-xe
The problem is solved. But the change in the source code is not marked with a comment, explaining the need for the used construct. That's important to prevent forgetting where it's for or for a third person maintaining the code in the future.
-
AuthorPosts
- You must be logged in to reply to this topic.