View Issue Details

IDProjectCategoryView StatusLast Update
0035953FPCCompilerpublic2019-08-15 01:51
ReporterDo-wan KimAssigned ToJ. Gareth Moreton 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1Product Build42655 
Target VersionFixed in Version3.3.1 
Summary0035953: Error in inline assembly code after r42655.
DescriptionI got following error with fpc trunk r42655.

---------------------------------------------------------------------

Hint: (11030) Start of reading config file C:\development\fpc\bin\i386-win32\fpc.cfg
Hint: (11031) End of reading config file C:\development\fpc\bin\i386-win32\fpc.cfg
Free Pascal Compiler version 3.3.1-r42655 [2019/08/12] for i386
Copyright (c) 1993-2019 by Florian Klaempfl and others
(1002) Target OS: Win32 for i386
(3104) Compiling assembler_test.lpr
F:\delphiprj-new\lr_proj\test\assembler_test.lpr(55,20) Error: (7049) Assembler syntax error in operand
assembler_test.lpr(67) Fatal: (10026) There were 1 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: C:\development\fpc\bin\i386-win32\ppc386.exe returned an error exitcode
Steps To ReproduceThis code from MPArith library.
------------------------------------------------
program assembler_test;

{$mode objfpc}{$H+}
{$asmmode INTEL}

{$R *.res}


function __gcd32: longint; assembler;
{-Calculate GCD of unsigned (A,B) in (eax,edx)}
asm
        push ebx
        {done if A=B, otherwise if A<B then swap A and B}
        cmp eax,edx
        jz @@x
        jae @@1
        xchg eax,edx

{here eax >= edx. Calculate odd parts a,b with A=a*2^e(a), B=b*2^e(b)}
@@1: bsf ecx, edx {if B=0 return A}
        jz @@x

        bsf ebx, eax {ebx=e(a), A cannot be zero}
        shr edx, cl {edx=b}
        xchg ebx, ecx
        shr eax, cl {eax=a}

        cmp ebx,ecx {ebx = e = min(e(a),e(b)}
        jb @@2
        mov ebx,ecx

@@2: cmp eax,edx {compare a and b}
        jz @@4 {done if equal}

{in the main loop both a and b are always odd}
{therefore for |a-b| is even and non-zero}
        push esi
@@3: mov esi, eax {eax=a, edx=b}
        {calculate max(a,b) and min(a,b) without branches}
        {see H.S.Warren, Hacker's Delight, Revision 1/4/07}
        {http://www.hackersdelight.org/revisions.pdf}
        sub esi, edx {esi=a-b}
        sbb ecx, ecx {if a>=b then ecx=0 else ecx=-1}
        and esi, ecx {if a>=b then esi=0 else esi=a-b}
        add edx, esi {if a>=b then edx=b else edx=a, i.e. edx=min(a,b)}
        sub eax, esi {if a>=b then eax=a else eax=a-(a-b)=b=max(a,b)}
        sub eax, edx {a'=max(a,b)-min(a,b), b'=min(a,b)}
        bsf ecx, eax {a'=|a-b| is even, divide out powers of 2}
        shr eax, cl
        cmp eax, edx {compare new a and new b}
        jnz @@3 {and repeat loop if not equal}

        pop esi

@@4: mov ecx, ebx {shift by initial common exponent e} // <---- Error: (7049) Assembler syntax error in operand
        shl eax, cl
@@x: pop ebx

end;


begin

  __gcd32;
end.
TagsNo tags attached.
Fixed in Revision42656
FPCOldBugId
FPCTarget-
Attached Files
  • assembler_test.lpr (1,986 bytes)
  • rax86int.pas-35953.patch (438 bytes)
    Index: compiler/x86/rax86int.pas
    ===================================================================
    --- compiler/x86/rax86int.pas	(revision 42655)
    +++ compiler/x86/rax86int.pas	(working copy)
    @@ -2714,7 +2714,7 @@
     
                 else
                   begin
    -                Message(asmr_e_syn_operand);
    +                //Message(asmr_e_syn_operand);
                     RecoverConsume(true);
                     break;
                   end;
    

Activities

Do-wan Kim

2019-08-12 03:17

reporter  

assembler_test.lpr (1,986 bytes)

Do-wan Kim

2019-08-12 05:55

reporter   ~0117647

Temporary fix.

rax86int.pas-35953.patch (438 bytes)
Index: compiler/x86/rax86int.pas
===================================================================
--- compiler/x86/rax86int.pas	(revision 42655)
+++ compiler/x86/rax86int.pas	(working copy)
@@ -2714,7 +2714,7 @@
 
             else
               begin
-                Message(asmr_e_syn_operand);
+                //Message(asmr_e_syn_operand);
                 RecoverConsume(true);
                 break;
               end;

Do-wan Kim

2019-08-12 16:39

reporter   ~0117655

Thank you!

J. Gareth Moreton

2019-08-12 22:56

developer   ~0117659

Last edited: 2019-08-12 22:56

View 2 revisions

This fix is only temporary, so it needs to be followed up, since that may be a legitimate error at other times. I will see if I can fix it myself.

rd0x

2019-08-13 09:20

reporter   ~0117660

Last edited: 2019-08-13 09:22

View 2 revisions

I don't think that Florian just applied the patch, see https://github.com/graemeg/freepascal/commit/febad29d6ce2c713855332803a2a0942786307d3
It also includes a test based on the instruction above but no idea where to check if the test passes. (Does a website for this exists?)

J. Gareth Moreton

2019-08-13 22:03

developer   ~0117663

I'll do some investigations and close it again if all is well - I was under the assumption that this report was marked as 'fixed' based on the patch supplied, since there's no other information to indicate otherwise.

Sven Barth

2019-08-14 13:28

manager   ~0117669

@J. Gareth Moreton: The "Fixed in Revision" field is set with that you can look at the changes: https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&revision=42656

J. Gareth Moreton

2019-08-15 01:51

developer   ~0117676

Apologies - the error message wasn't commented out in the trunk and the root issue is actually fixed. I apologise for my misinterpretation - re-closing this issue as it is fixed.

Issue History

Date Modified Username Field Change
2019-08-12 03:15 Do-wan Kim New Issue
2019-08-12 03:17 Do-wan Kim File Added: assembler_test.lpr
2019-08-12 05:55 Do-wan Kim File Added: rax86int.pas-35953.patch
2019-08-12 05:55 Do-wan Kim Note Added: 0117647
2019-08-12 12:54 Florian Assigned To => Florian
2019-08-12 12:54 Florian Status new => resolved
2019-08-12 12:54 Florian Resolution open => fixed
2019-08-12 12:54 Florian Fixed in Version => 3.3.1
2019-08-12 12:54 Florian Fixed in Revision => 42656
2019-08-12 12:54 Florian FPCTarget => -
2019-08-12 16:39 Do-wan Kim Status resolved => closed
2019-08-12 16:39 Do-wan Kim Note Added: 0117655
2019-08-12 22:56 J. Gareth Moreton Assigned To Florian => J. Gareth Moreton
2019-08-12 22:56 J. Gareth Moreton Status closed => feedback
2019-08-12 22:56 J. Gareth Moreton Resolution fixed => reopened
2019-08-12 22:56 J. Gareth Moreton Note Added: 0117659
2019-08-12 22:56 J. Gareth Moreton Note Edited: 0117659 View Revisions
2019-08-12 22:58 J. Gareth Moreton Status feedback => assigned
2019-08-13 09:20 rd0x Note Added: 0117660
2019-08-13 09:22 rd0x Note Edited: 0117660 View Revisions
2019-08-13 22:03 J. Gareth Moreton Note Added: 0117663
2019-08-14 13:28 Sven Barth Note Added: 0117669
2019-08-15 01:51 J. Gareth Moreton Status assigned => closed
2019-08-15 01:51 J. Gareth Moreton Resolution reopened => fixed
2019-08-15 01:51 J. Gareth Moreton Note Added: 0117676