Skip to content
Permalink
Browse files

* intel asm reader: try to read avx512 extensions only if the instru…

…ction supports them

  * cleanup

git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@42656 3ad0048d-3df7-0310-abae-a5850022a9f2
  • Loading branch information...
FPK committed Aug 12, 2019
1 parent 2a30e47 commit febad29d6ce2c713855332803a2a0942786307d3
Showing with 55 additions and 11 deletions.
  1. +1 −1 compiler/scanner.pas
  2. +27 −5 compiler/x86/aasmcpu.pas
  3. +8 −0 compiler/x86/rax86.pas
  4. +6 −5 compiler/x86/rax86int.pas
  5. +13 −0 tests/webtbs/tw35953.pp
@@ -39,7 +39,7 @@ interface


type
tcommentstyle = (comment_none,comment_tp,comment_oldtp,comment_delphi,comment_c, comment_x86OpExt);
tcommentstyle = (comment_none,comment_tp,comment_oldtp,comment_delphi,comment_c);

tscannerfile = class;

@@ -63,13 +63,11 @@ interface
OT_VECTORSAE = $8000000000; { OPTIONAL SAE-FLAG AVX512}
OT_VECTORER = $10000000000; { OPTIONAL ER-FLAG-FLAG AVX512}

OT_VECTOR_EXT = OT_VECTORMASK or OT_VECTORZERO or OT_VECTORBCST or OT_VECTORSAE or OT_VECTORER;

OT_BITSB32 = OT_BITS32 or OT_VECTORBCST;
OT_BITSB64 = OT_BITS64 or OT_VECTORBCST;


OT_VECTOR_EXT_MASK = OT_VECTORMASK or OT_VECTORZERO or OT_VECTORBCST;

OT_BITS80 = $00000010; { FPU only }
OT_FAR = $00000020; { this means 16:16 or 16:32, like in CALL/JMP }
OT_NEAR = $00000040;
@@ -652,6 +650,7 @@ taicpu = class(tai_cpu_abstract_sym)
function spilling_create_store(r:tregister; const ref:treference):Taicpu;

function MemRefInfo(aAsmop: TAsmOp): TInsTabMemRefSizeInfoRec;
function MightHaveExtension(AsmOp : TAsmOp) : Boolean;

procedure InitAsm;
procedure DoneAsm;
@@ -686,8 +685,6 @@ implementation
itcpugas,
cpuinfo;



procedure AddSymbol(symname : string; defined : boolean);
var
EC : PExternChain;
@@ -877,6 +874,31 @@ implementation
result := InsTabMemRefSizeInfoCache^[aAsmop];
end;


function MightHaveExtension(AsmOp : TAsmOp): Boolean;
var
i,j: LongInt;
insentry: pinsentry;
begin
Result:=true;
i:=InsTabCache^[AsmOp];
if i>=0 then
begin
insentry:=@instab[i];
while insentry^.opcode=AsmOp do
begin
for j:=0 to insentry^.ops-1 do
begin
if (insentry^.optypes[j] and OT_VECTOR_EXT)<>0 then
exit;
end;
inc(i);
insentry:=@instab[i];
end;
end;
Result:=false;
end;

{ Operation type for spilling code }
type
toperation_type_table=array[tasmop,0..Max_Operands] of topertype;
@@ -73,6 +73,8 @@ Tx86Instruction=class(TInstruction)
{ opcode adding }
function ConcatInstruction(p : TAsmList) : tai;override;
function getstring: string;
{ returns true, if the opcode might have an extension as used by AVX512 }
function MightHaveExtension : boolean;
end;

const
@@ -2016,4 +2018,10 @@ function Tx86Instruction.getstring: string;
GetString:=s+']';
end;

function Tx86Instruction.MightHaveExtension: boolean;

begin
Result:=aasmcpu.MightHaveExtension(opcode);
end;

end.
@@ -2015,7 +2015,7 @@ tx86intreader = class(tasmreader)
begin
hreg:=actasmregister;

Consume(AS_REGISTER, true);
Consume(AS_REGISTER, MightHaveExtension(actopcode));

while actasmtoken in OPEXT_STARTASMTOKEN do
begin
@@ -2190,7 +2190,7 @@ tx86intreader = class(tasmreader)
if GotPlus or GotStar or BracketlessReference then
Message(asmr_e_invalid_reference_syntax);

Consume(AS_RBRACKET, true);
Consume(AS_RBRACKET, MightHaveExtension(actopcode));
while actasmtoken in OPEXT_STARTASMTOKEN do
begin
consume_voperand_ext(oper);
@@ -2544,7 +2544,7 @@ tx86intreader = class(tasmreader)
{ is it a normal variable ? }
Begin
expr:=actasmpattern;
Consume(AS_ID, true);
Consume(AS_ID, MightHaveExtension(actopcode));

while actasmtoken in OPEXT_STARTASMTOKEN do
begin
@@ -2613,7 +2613,8 @@ tx86intreader = class(tasmreader)
begin
{ save the type of register used. }
tempreg:=actasmregister;
Consume(AS_REGISTER, true);

Consume(AS_REGISTER, MightHaveExtension(actopcode));

if (getregtype(tempreg) in [R_MMREGISTER, R_ADDRESSREGISTER]) then
begin
@@ -2876,7 +2877,7 @@ tx86intreader = class(tasmreader)
Message(asmr_e_too_many_operands)
else
Dec(operandnum);
Consume(AS_COMMA, true);
Consume(AS_COMMA,instr.MightHaveExtension);
end;

{Far constant, i.e. jmp $0000:$11111111.}
@@ -0,0 +1,13 @@
{ %CPU=x86_64,i386 }
{$mode objfpc}{$H+}
{$asmmode INTEL}

function f: longint; assembler;
asm
mov ecx, ebx {shift by initial common exponent e}
vaddpd XMM0 {k1} {z}, XMM0, [RAX + RDI + $10] {1to2}
end;


begin
end.

0 comments on commit febad29

Please sign in to comment.
You can’t perform that action at this time.