Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/BASM    [ Add a report in this area ]  
Report #:  98613   Status: Closed
MOVQ is translated to MOVD
Project:  Delphi Build #:  16.0.4256.43595
Version:    16.0 Submitted By:   Christian Budde
Report Type:  Basic functionality failure Date Reported:  9/6/2011 2:01:41 PM
Severity:    Commonly encountered problem Last Updated: 9/5/2012 8:09:32 PM
Platform:    All versions Internal Tracking #:   287471
Resolution: Fixed (Resolution Comments) Resolved in Build: : 17.0.4625.53395
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 11
Description
While porting the assmenbler optimizations of the GR32 project I found out, that the assembler opcode MOVQ is translated by the new delphi compiler (Windows 64-Bit!) to MOVD, which results in a different output.

If specified a "QWORD PTR" it seems to work fine though. This however is different to the 32-Bit compiler, where it is not necessary.
Steps to Reproduce:
By USc:
- dcc64 QC98613.dpr
- execute QC98613.exe

expected: output is PASS
actual: output is FAIL

See under the debugger that MOVQ [RCX], MM0 is encoded as 0F7E01 instead of 0F7F01

program QC98613;

{$APPTYPE CONSOLE}

{$IFDEF CPUX64}
procedure FillPointerWithData_MMX(var X; Value: Integer);
asm
  MOVD       MM0, EDX
  PUNPCKLDQ  MM0, MM0

  MOVQ       [RCX], MM0 //-> gets encoded as 0F7E01 movd [rcx],mm0
  //DB $0F, $7F, $01 //-> this is the correct sequence

  EMMS
end;

var
  Data: array [0..1] of Integer;
const
  CValue: Integer = $ABEEF;
begin
  FillPointerWithData_MMX(Data, CValue);
  if (Data[0] = CValue) and (Data[1] = CValue) then
    WriteLn('PASS')
  else
    WriteLn('FAIL');
{$ELSE}
begin
  WriteLn('PASS');
{$ENDIF}
end.




Original steps:
Use a simple function such as:

procedure FillPointerWithData_MMX(var X; Value: Integer);
asm
        MOVD       MM0, EDX
        PUNPCKLDQ  MM0, MM0
        MOVQ       [RCX], MM0
        EMMS
end;

Call it like:

var
  Data: array [0..1] of Integer;
const
  CValue: Integer = $ABEEF;
begin
  FillPointerWithData_MMX(@Data[0], CValue);
  if (Data[0] <> CValue) or (Data[1] <> CValue) then
    raise Exception.Create('Error');
end.
Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01