* let all the case code generation work with tconstexprint instead of aint,

so it also works for 32 bit targets and a high level code generator
    (where aint is still 32 bit, but 64 bit operations are not decomposed)

git-svn-id: trunk@41441 -
This commit is contained in:
Jonas Maebe 2019-02-24 19:58:37 +00:00
parent 1d5877ecf0
commit 07bd4ba517
10 changed files with 97 additions and 81 deletions

View File

@ -31,9 +31,9 @@ interface
type
taarch64casenode = class(tcgcasenode)
protected
procedure optimizevalues(var max_linear_list: aint; var max_dist: aword);override;
procedure optimizevalues(var max_linear_list: int64; var max_dist: qword);override;
function has_jumptable: boolean;override;
procedure genjumptable(hp: pcaselabel ;min_, max_: aint);override;
procedure genjumptable(hp: pcaselabel ;min_, max_: int64);override;
end;
@ -56,7 +56,7 @@ implementation
*****************************************************************************}
procedure taarch64casenode.optimizevalues(var max_linear_list: aint; var max_dist: aword);
procedure taarch64casenode.optimizevalues(var max_linear_list: int64; var max_dist: qword);
begin
max_linear_list:=10;
end;
@ -68,7 +68,7 @@ implementation
end;
procedure taarch64casenode.genjumptable(hp: pcaselabel; min_, max_: aint);
procedure taarch64casenode.genjumptable(hp: pcaselabel; min_, max_: int64);
var
last: TConstExprInt;
tablelabel: TAsmLabel;
@ -80,7 +80,7 @@ implementation
procedure genitem(list:TAsmList;t : pcaselabel);
var
i : aint;
i : int64;
begin
if assigned(t^.less) then
genitem(list,t^.less);

View File

@ -41,9 +41,9 @@ interface
end;
tarmcasenode = class(tcgcasenode)
procedure optimizevalues(var max_linear_list:aint;var max_dist:aword);override;
procedure optimizevalues(var max_linear_list:int64;var max_dist:qword);override;
function has_jumptable : boolean;override;
procedure genjumptable(hp : pcaselabel;min_,max_ : aint);override;
procedure genjumptable(hp : pcaselabel;min_,max_ : int64);override;
procedure genlinearlist(hp : pcaselabel);override;
procedure genjmptreeentry(p : pcaselabel;parentvalue : TConstExprInt);override;
end;
@ -136,7 +136,7 @@ implementation
TARMCASENODE
*****************************************************************************}
procedure tarmcasenode.optimizevalues(var max_linear_list:aint;var max_dist:aword);
procedure tarmcasenode.optimizevalues(var max_linear_list:int64;var max_dist:qword);
begin
inc(max_linear_list,2)
end;
@ -148,7 +148,7 @@ implementation
end;
procedure tarmcasenode.genjumptable(hp : pcaselabel;min_,max_ : aint);
procedure tarmcasenode.genjumptable(hp : pcaselabel;min_,max_ : int64);
var
last : TConstExprInt;
tmpreg,
@ -161,22 +161,30 @@ implementation
procedure genitem(list:TAsmList;t : pcaselabel);
var
i : aint;
i : int64;
begin
if assigned(t^.less) then
genitem(list,t^.less);
{ fill possible hole }
for i:=last.svalue+1 to t^._low.svalue-1 do
if cs_create_pic in current_settings.moduleswitches then
list.concat(Tai_const.Create_rel_sym_offset(aitconst_ptr,piclabel,elselabel,picoffset))
else
list.concat(Tai_const.Create_sym(elselabel));
for i:=t^._low.svalue to t^._high.svalue do
if cs_create_pic in current_settings.moduleswitches then
list.concat(Tai_const.Create_rel_sym_offset(aitconst_ptr,piclabel,blocklabel(t^.blockid),picoffset))
else
list.concat(Tai_const.Create_sym(blocklabel(t^.blockid)));
last:=t^._high.svalue;
i:=last+1;
while i<=t^._low-1 do
begin
if cs_create_pic in current_settings.moduleswitches then
list.concat(Tai_const.Create_rel_sym_offset(aitconst_ptr,piclabel,elselabel,picoffset))
else
list.concat(Tai_const.Create_sym(elselabel));
i:=i+1;
end;
i:=t^._low;
while i<=t^._high do
begin
if cs_create_pic in current_settings.moduleswitches then
list.concat(Tai_const.Create_rel_sym_offset(aitconst_ptr,piclabel,blocklabel(t^.blockid),picoffset))
else
list.concat(Tai_const.Create_sym(blocklabel(t^.blockid)));
i:=i+1;
end;
last:=t^._high;
if assigned(t^.greater) then
genitem(list,t^.greater);
end;

View File

@ -31,7 +31,7 @@ interface
type
ti386casenode = class(tx86casenode)
procedure optimizevalues(var max_linear_list:aint;var max_dist:aword);override;
procedure optimizevalues(var max_linear_list:int64;var max_dist:qword);override;
end;
@ -44,7 +44,7 @@ implementation
TI386CASENODE
*****************************************************************************}
procedure ti386casenode.optimizevalues(var max_linear_list:aint;var max_dist:aword);
procedure ti386casenode.optimizevalues(var max_linear_list:int64;var max_dist:qword);
begin
{ a jump table crashes the pipeline! }
if current_settings.optimizecputype=cpu_386 then

View File

@ -33,9 +33,9 @@ uses
type
tcpucasenode = class(tcgcasenode)
protected
procedure optimizevalues(var max_linear_list: aint; var max_dist: aword); override;
procedure optimizevalues(var max_linear_list: int64; var max_dist: qword); override;
function has_jumptable: boolean; override;
procedure genjumptable(hp: pcaselabel; min_, max_: aint); override;
procedure genjumptable(hp: pcaselabel; min_, max_: int64); override;
end;
@ -50,7 +50,7 @@ uses
cgbase, cgutils, cgobj,
defutil,procinfo;
procedure tcpucasenode.optimizevalues(var max_linear_list: aint; var max_dist: aword);
procedure tcpucasenode.optimizevalues(var max_linear_list: int64; var max_dist: qword);
begin
{ give the jump table a higher priority }
max_dist := (max_dist * 3) div 2;
@ -63,7 +63,7 @@ begin
end;
procedure tcpucasenode.genjumptable(hp: pcaselabel; min_, max_: aint);
procedure tcpucasenode.genjumptable(hp: pcaselabel; min_, max_: int64);
var
table: tasmlabel;
last: TConstExprInt;
@ -75,15 +75,23 @@ var
procedure genitem(t: pcaselabel);
var
i: aint;
i: TConstExprInt;
begin
if assigned(t^.less) then
genitem(t^.less);
{ fill possible hole }
for i := last.svalue+1 to t^._low.svalue-1 do
jumpSegment.concat(Tai_const.Create_type_sym(labeltyp,elselabel));
for i := t^._low.svalue to t^._high.svalue do
jumpSegment.concat(Tai_const.Create_type_sym(labeltyp,blocklabel(t^.blockid)));
i:=last+1;
while i<=t^._low-1 do
begin
jumpSegment.concat(Tai_const.Create_type_sym(labeltyp,elselabel));
i:=i+1;
end;
i:= t^._low;
while i<=t^._high do
begin
jumpSegment.concat(Tai_const.Create_type_sym(labeltyp,blocklabel(t^.blockid)));
i:=i+1;
end;
last := t^._high;
if assigned(t^.greater) then
genitem(t^.greater);

View File

@ -82,9 +82,9 @@ interface
function GetBranchLabel(Block: TNode; out _Label: TAsmLabel): Boolean;
function blocklabel(id:longint):tasmlabel;
procedure optimizevalues(var max_linear_list:aint;var max_dist:aword);virtual;
procedure optimizevalues(var max_linear_list:int64;var max_dist:qword);virtual;
function has_jumptable : boolean;virtual;
procedure genjumptable(hp : pcaselabel;min_,max_ : aint); virtual;
procedure genjumptable(hp : pcaselabel;min_,max_ : int64); virtual;
procedure genlinearlist(hp : pcaselabel); virtual;
procedure genlinearcmplist(hp : pcaselabel); virtual;
@ -613,7 +613,7 @@ implementation
end;
procedure tcgcasenode.optimizevalues(var max_linear_list:aint;var max_dist:aword);
procedure tcgcasenode.optimizevalues(var max_linear_list:int64;var max_dist:qword);
begin
{ no changes by default }
end;
@ -626,7 +626,7 @@ implementation
end;
procedure tcgcasenode.genjumptable(hp : pcaselabel;min_,max_ : aint);
procedure tcgcasenode.genjumptable(hp : pcaselabel;min_,max_ : int64);
begin
internalerror(200209161);
end;
@ -827,7 +827,7 @@ implementation
{$endif}
{$endif cpuhighleveltarget}
begin
hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_EQ, aint(t^._low.svalue),hregister, blocklabel(t^.blockid));
hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_EQ, tcgint(t^._low),hregister, blocklabel(t^.blockid));
end;
{ Reset last here, because we've only checked for one value and need to compare
for the next range both the lower and upper bound }
@ -934,7 +934,7 @@ implementation
{$endif}
{$endif cpuhighleveltarget}
begin
hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_lt, aint(t^._low.svalue), hregister,
hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_lt, tcgint(t^._low), hregister,
elselabel);
end;
end;
@ -1026,7 +1026,7 @@ implementation
{$endif}
{$endif cpuhighleveltarget}
begin
hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_le, aint(t^._high.svalue), hregister, blocklabel(t^.blockid));
hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_le, tcgint(t^._high.svalue), hregister, blocklabel(t^.blockid));
end;
last:=t^._high;
@ -1165,8 +1165,8 @@ implementation
distv,
lv,hv,
max_label: tconstexprint;
max_linear_list : aint;
max_dist : aword;
max_linear_list : int64;
max_dist : qword;
ShortcutElse: Boolean;
begin
location_reset(location,LOC_VOID,OS_NO);

View File

@ -31,9 +31,9 @@ interface
type
tgppccasenode = class(tcgcasenode)
protected
procedure optimizevalues(var max_linear_list : aint; var max_dist : aword);override;
procedure optimizevalues(var max_linear_list : int64; var max_dist : qword);override;
function has_jumptable : boolean;override;
procedure genjumptable(hp : pcaselabel;min_,max_ : aint);override;
procedure genjumptable(hp : pcaselabel;min_,max_ : int64);override;
procedure genlinearlist(hp : pcaselabel); override;
end;
@ -57,7 +57,7 @@ implementation
*****************************************************************************}
procedure tgppccasenode.optimizevalues(var max_linear_list : aint; var max_dist : aword);
procedure tgppccasenode.optimizevalues(var max_linear_list : int64; var max_dist : qword);
begin
max_linear_list := 10;
end;
@ -69,7 +69,7 @@ implementation
end;
procedure tgppccasenode.genjumptable(hp : pcaselabel;min_,max_ : aint);
procedure tgppccasenode.genjumptable(hp : pcaselabel;min_,max_ : int64);
var
table : tasmlabel;
last : TConstExprInt;

View File

@ -31,9 +31,9 @@ interface
type
trvcasenode = class(tcgcasenode)
protected
procedure optimizevalues(var max_linear_list : aint; var max_dist : aword);override;
procedure optimizevalues(var max_linear_list : int64; var max_dist : qword);override;
function has_jumptable : boolean;override;
procedure genjumptable(hp : pcaselabel;min_,max_ : aint);override;
procedure genjumptable(hp : pcaselabel;min_,max_ : int64);override;
end;
@ -56,7 +56,7 @@ implementation
*****************************************************************************}
procedure trvcasenode.optimizevalues(var max_linear_list : aint; var max_dist : aword);
procedure trvcasenode.optimizevalues(var max_linear_list : int64; var max_dist : qword);
begin
max_linear_list := 3;
end;
@ -68,7 +68,7 @@ implementation
end;
procedure trvcasenode.genjumptable(hp : pcaselabel;min_,max_ : aint);
procedure trvcasenode.genjumptable(hp : pcaselabel;min_,max_ : int64);
var
table : tasmlabel;
last : TConstExprInt;

View File

@ -34,9 +34,9 @@ unit ncpuset;
type
tcpucasenode = class(tcgcasenode)
protected
procedure optimizevalues(var max_linear_list:aint;var max_dist:aword);override;
procedure optimizevalues(var max_linear_list:int64;var max_dist:qword);override;
function has_jumptable : boolean;override;
procedure genjumptable(hp : pcaselabel;min_,max_ : aint);override;
procedure genjumptable(hp : pcaselabel;min_,max_ : int64);override;
end;
@ -50,7 +50,7 @@ unit ncpuset;
cgbase,cgutils,cgobj,
defutil,procinfo;
procedure tcpucasenode.optimizevalues(var max_linear_list:aint;var max_dist:aword);
procedure tcpucasenode.optimizevalues(var max_linear_list:int64;var max_dist:qword);
begin
{ give the jump table a higher priority }
max_dist:=(max_dist*3) div 2;
@ -63,7 +63,7 @@ unit ncpuset;
end;
procedure tcpucasenode.genjumptable(hp : pcaselabel;min_,max_ : aint);
procedure tcpucasenode.genjumptable(hp : pcaselabel;min_,max_ : int64);
var
base,
table : tasmlabel;
@ -74,22 +74,22 @@ unit ncpuset;
procedure genitem(list:TAsmList;t : pcaselabel);
var
i : aint;
i : TConstExprInt;
begin
if assigned(t^.less) then
genitem(list,t^.less);
{ fill possible hole }
i:=last.svalue+1;
while i<=t^._low.svalue-1 do
i:=last+1;
while i<=t^._low-1 do
begin
list.concat(Tai_const.Create_rel_sym(aitconst_ptr,base,elselabel));
inc(i);
i:=i+1;
end;
i:=t^._low.svalue;
while i<=t^._high.svalue do
i:=t^._low;
while i<=t^._high do
begin
list.concat(Tai_const.Create_rel_sym(aitconst_ptr,base,blocklabel(t^.blockid)));
inc(i);
i:=i+1;
end;
last:=t^._high;
if assigned(t^.greater) then

View File

@ -37,7 +37,7 @@ interface
tx86casenode = class(tcgcasenode)
function has_jumptable : boolean;override;
procedure genjumptable(hp : pcaselabel;min_,max_ : aint);override;
procedure genjumptable(hp : pcaselabel;min_,max_ : int64);override;
procedure genlinearlist(hp : pcaselabel);override;
procedure genjmptreeentry(p : pcaselabel;parentvalue : TConstExprInt);override;
end;
@ -66,7 +66,7 @@ implementation
end;
procedure tx86casenode.genjumptable(hp : pcaselabel;min_,max_ : aint);
procedure tx86casenode.genjumptable(hp : pcaselabel;min_,max_ : int64);
var
table : tasmlabel;
last : TConstExprInt;
@ -78,30 +78,30 @@ implementation
labeltyp: taiconst_type;
AlmostExhaustive: Boolean;
lv, hv: TConstExprInt;
ExhaustiveLimit, Range, x, oldmin : aint;
ExhaustiveLimit, Range, x, oldmin : int64;
const
ExhaustiveLimitBase = 32;
procedure genitem(list:TAsmList;t : pcaselabel);
var
i : aint;
i : TConstExprInt;
begin
if assigned(t^.less) then
genitem(list,t^.less);
{ fill possible hole }
i:=last.svalue+1;
while i<=t^._low.svalue-1 do
i:=last+1;
while i<=t^._low-1 do
begin
list.concat(Tai_const.Create_type_sym(labeltyp,elselabel));
inc(i);
i:=i+1;
end;
i:=t^._low.svalue;
while i<=t^._high.svalue do
i:=t^._low;
while i<=t^._high do
begin
list.concat(Tai_const.Create_type_sym(labeltyp,blocklabel(t^.blockid)));
inc(i);
i:=i+1;
end;
last:=t^._high;
if assigned(t^.greater) then

View File

@ -32,8 +32,8 @@ interface
type
tx8664casenode = class(tx86casenode)
procedure optimizevalues(var max_linear_list:aint;var max_dist:aword);override;
procedure genjumptable(hp : pcaselabel;min_,max_ : aint);override;
procedure optimizevalues(var max_linear_list:int64;var max_dist:qword);override;
procedure genjumptable(hp : pcaselabel;min_,max_ : int64);override;
end;
@ -53,7 +53,7 @@ implementation
TX8664CASENODE
*****************************************************************************}
procedure tx8664casenode.optimizevalues(var max_linear_list:aint;var max_dist:aword);
procedure tx8664casenode.optimizevalues(var max_linear_list:int64;var max_dist:qword);
begin
inc(max_linear_list,9);
end;
@ -61,7 +61,7 @@ implementation
{ Always generate position-independent jump table, it is twice less in size at a price
of two extra instructions (which shouldn't cause more slowdown than pipeline trashing) }
procedure tx8664casenode.genjumptable(hp : pcaselabel; min_,max_ : aint);
procedure tx8664casenode.genjumptable(hp : pcaselabel; min_,max_ : int64);
var
last: TConstExprInt;
tablelabel: TAsmLabel;
@ -80,22 +80,22 @@ implementation
procedure genitem(t : pcaselabel);
var
i : aint;
i : TConstExprInt;
begin
if assigned(t^.less) then
genitem(t^.less);
{ fill possible hole }
i:=last.svalue+1;
while i<=t^._low.svalue-1 do
i:=last+1;
while i<=t^._low-1 do
begin
jtlist.concat(Tai_const.Create_rel_sym(jtitemconsttype,tablelabel,elselabel));
inc(i);
i:=i+1;
end;
i:=t^._low.svalue;
while i<=t^._high.svalue do
i:=t^._low;
while i<=t^._high do
begin
jtlist.concat(Tai_const.Create_rel_sym(jtitemconsttype,tablelabel,blocklabel(t^.blockid)));
inc(i);
i:=i+1;
end;
last:=t^._high;
if assigned(t^.greater) then