Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/BASM    [ Add a report in this area ]  
Report #:  101019   Status: Open
x64: CALL and JMP QWORD PTR are encoded with superfluous REX.W prefixes
Project:  Delphi Build #:  16.0.4316.44803
Version:    16.0 Submitted By:   Blaise Thorn
Report Type:  Minor failure / Design problem Date Reported:  11/14/2011 5:06:55 PM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   288791
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
The emitted REX prefix 48h does nothing in these cases, and, ergo, it is completely unnecessary.
Steps to Reproduce:
{ Run this under the x64 debugger.
  Expected encoding for "call qword ptr [@pHalt]": FF15 00000000
  Actual encoding: 48 FF15 00000000
  The same goes for "jmp qword ptr [@pHalt]".
}
{$DebugInfo off}
asm

int 3

call qword ptr [@pHalt]
@pHalt:

dq offset System.@Halt0
end.


Automatable steps by USc:
- dcc64 QC101019.dpr
- execute QC101019.exe

expected: output is PASS
actual: output is
FAIL - I=1 Value=48 ExpectedValue=FF
FAIL - I=2 Value=FF ExpectedValue=15
FAIL - I=3 Value=15 ExpectedValue=00

program QC101019;

{$APPTYPE CONSOLE}

uses
  System.SysUtils;

var
  Expected: Integer = 0;
  Counter: Integer = 0;

procedure TestProc;
asm
  call qword ptr [@pHalt]
@pHalt:
  dq offset System.@Halt0
end;

procedure DoTest;
const
  ExpectedData: array [1..6] of Byte = ($FF, $15, $00, $00, $00, $00);
var
  P, Q: ^Byte;
  Value, ExpectedValue: Byte;
  I: Integer;
begin
  Expected := Length(ExpectedData);
  P := @TestProc;
  Q := @ExpectedData;
  for I := Low(ExpectedData) to High(ExpectedData) do
    begin
      Value := P^;
      ExpectedValue := Q^;
      if Value = ExpectedValue then
        Inc(Counter)
      else
         WriteLn('FAIL - I=', I, ' Value=', IntToHex(Value, 2), ' ExpectedValue=', IntToHex(ExpectedValue, 2));
      Inc(P);
      Inc(Q);
    end;
end;

begin
  try
    DoTest;
    if Expected = Counter then
      WriteLn('PASS')
  except
    on E: TObject do
      WriteLn('FAIL - Exception=', E.ClassName);
  end;
end.
Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01