* first try to get cpupara working for x86_64

This commit is contained in:
peter 2004-02-04 22:01:13 +00:00
parent 8012731ede
commit 8c5b0f7d82
13 changed files with 353 additions and 170 deletions

View File

@ -92,7 +92,7 @@ unit cgcpu;
procedure g_save_standard_registers(list : taasmoutput);override; procedure g_save_standard_registers(list : taasmoutput);override;
procedure g_restore_standard_registers(list : taasmoutput);override; procedure g_restore_standard_registers(list : taasmoutput);override;
procedure g_save_all_registers(list : taasmoutput);override; procedure g_save_all_registers(list : taasmoutput);override;
procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);override; procedure g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);override;
procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel); procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
procedure fixref(list : taasmoutput;var ref : treference); procedure fixref(list : taasmoutput;var ref : treference);
@ -1138,7 +1138,7 @@ unit cgcpu;
end; end;
procedure tcgarm.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean); procedure tcgarm.g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);
begin begin
{ we support only ARM standard calling conventions so this procedure has no use on the ARM } { we support only ARM standard calling conventions so this procedure has no use on the ARM }
end; end;
@ -1273,7 +1273,10 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.43 2004-01-29 17:09:32 florian Revision 1.44 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.43 2004/01/29 17:09:32 florian
* handling of floating point references fixed * handling of floating point references fixed
Revision 1.42 2004/01/28 15:36:47 florian Revision 1.42 2004/01/28 15:36:47 florian

View File

@ -440,7 +440,7 @@ unit cgobj;
} }
procedure g_restore_standard_registers(list:Taasmoutput);virtual;abstract; procedure g_restore_standard_registers(list:Taasmoutput);virtual;abstract;
procedure g_save_all_registers(list : taasmoutput);virtual;abstract; procedure g_save_all_registers(list : taasmoutput);virtual;abstract;
procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);virtual;abstract; procedure g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);virtual;abstract;
end; end;
{# @abstract(Abstract code generator for 64 Bit operations) {# @abstract(Abstract code generator for 64 Bit operations)
@ -854,19 +854,17 @@ implementation
LOC_CREGISTER, LOC_CREGISTER,
LOC_REGISTER: LOC_REGISTER:
begin begin
{$ifndef cpu64bit}
if (locpara.size in [OS_S64,OS_64]) then if (locpara.size in [OS_S64,OS_64]) then
begin begin
{$ifdef cpu64bit}
ungetregister(list,locpara.register64);
{$else cpu64bit}
getexplicitregister(list,locpara.registerlow); getexplicitregister(list,locpara.registerlow);
getexplicitregister(list,locpara.registerhigh); getexplicitregister(list,locpara.registerhigh);
ungetregister(list,locpara.registerlow); ungetregister(list,locpara.registerlow);
ungetregister(list,locpara.registerhigh); ungetregister(list,locpara.registerhigh);
{$endif cpu64bit}
cg64.a_load64_reg_ref(list,locpara.register64,ref) cg64.a_load64_reg_ref(list,locpara.register64,ref)
end end
else else
{$endif cpu64bit}
begin begin
getexplicitregister(list,locpara.register); getexplicitregister(list,locpara.register);
ungetregister(list,locpara.register); ungetregister(list,locpara.register);
@ -2140,7 +2138,10 @@ finalization
end. end.
{ {
$Log$ $Log$
Revision 1.154 2004-02-03 22:32:53 peter Revision 1.155 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.154 2004/02/03 22:32:53 peter
* renamed xNNbittype to xNNinttype * renamed xNNbittype to xNNinttype
* renamed registers32 to registersint * renamed registers32 to registersint
* replace some s32bit,u32bit with torddef([su]inttype).def.typ * replace some s32bit,u32bit with torddef([su]inttype).def.typ

View File

@ -163,6 +163,9 @@ interface
{# Returns true, if def is a double type } {# Returns true, if def is a double type }
function is_double(def : tdef) : boolean; function is_double(def : tdef) : boolean;
{# Returns true, if def is an extended type }
function is_extended(def : tdef) : boolean;
{# Returns true, if def is a 64 bit integer type } {# Returns true, if def is a 64 bit integer type }
function is_64bitint(def : tdef) : boolean; function is_64bitint(def : tdef) : boolean;
@ -234,6 +237,13 @@ implementation
end; end;
function is_extended(def : tdef) : boolean;
begin
result:=(def.deftype=floatdef) and
(tfloatdef(def).typ=s80real);
end;
function range_to_basetype(low,high:TConstExprInt):tbasetype; function range_to_basetype(low,high:TConstExprInt):tbasetype;
begin begin
{ generate a unsigned range if high<0 and low>=0 } { generate a unsigned range if high<0 and low>=0 }
@ -845,7 +855,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.9 2004-02-03 22:32:53 peter Revision 1.10 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.9 2004/02/03 22:32:53 peter
* renamed xNNbittype to xNNinttype * renamed xNNbittype to xNNinttype
* renamed registers32 to registersint * renamed registers32 to registersint
* replace some s32bit,u32bit with torddef([su]inttype).def.typ * replace some s32bit,u32bit with torddef([su]inttype).def.typ

View File

@ -42,6 +42,8 @@ unit cgcpu;
tcg386 = class(tcgx86) tcg386 = class(tcgx86)
procedure init_register_allocators;override; procedure init_register_allocators;override;
class function reg_cgsize(const reg: tregister): tcgsize; override; class function reg_cgsize(const reg: tregister): tcgsize; override;
procedure g_save_all_registers(list : taasmoutput);override;
procedure g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);override;
end; end;
tcg64f386 = class(tcg64f32) tcg64f386 = class(tcg64f32)
@ -57,7 +59,7 @@ unit cgcpu;
uses uses
globtype,globals,verbose,systems,cutils, globtype,globals,verbose,systems,cutils,
symdef,symsym,defutil,paramgr, symdef,symsym,defutil,paramgr,procinfo,
rgcpu,rgx86,tgobj; rgcpu,rgx86,tgobj;
@ -111,6 +113,41 @@ unit cgcpu;
result := opsize_2_cgsize[reg2opsize(reg)]; result := opsize_2_cgsize[reg2opsize(reg)];
end;} end;}
procedure tcg386.g_save_all_registers(list : taasmoutput);
begin
list.concat(Taicpu.Op_none(A_PUSHA,S_L));
tg.GetTemp(list,POINTER_SIZE,tt_noreuse,current_procinfo.save_regs_ref);
a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_STACK_POINTER_REG,current_procinfo.save_regs_ref);
end;
procedure tcg386.g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);
var
href : treference;
begin
a_load_ref_reg(list,OS_ADDR,OS_ADDR,current_procinfo.save_regs_ref,NR_STACK_POINTER_REG);
tg.UnGetTemp(list,current_procinfo.save_regs_ref);
if funcretparaloc.loc=LOC_REGISTER then
begin
if funcretparaloc.size in [OS_64,OS_S64] then
begin
reference_reset_base(href,NR_STACK_POINTER_REG,20);
a_load_reg_ref(list,OS_32,OS_32,NR_FUNCTION_RETURN64_HIGH_REG,href);
reference_reset_base(href,NR_STACK_POINTER_REG,28);
a_load_reg_ref(list,OS_32,OS_32,NR_FUNCTION_RETURN64_LOW_REG,href);
end
else
begin
reference_reset_base(href,NR_STACK_POINTER_REG,28);
a_load_reg_ref(list,OS_32,OS_32,NR_FUNCTION_RETURN_REG,href);
end;
end;
list.concat(Taicpu.Op_none(A_POPA,S_L));
{ We add a NOP because of the 386DX CPU bugs with POPAD }
list.concat(taicpu.op_none(A_NOP,S_L));
end;
{ ************* 64bit operations ************ } { ************* 64bit operations ************ }
@ -246,7 +283,10 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.44 2004-01-14 23:39:05 florian Revision 1.45 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.44 2004/01/14 23:39:05 florian
* another bunch of x86-64 fixes mainly calling convention and * another bunch of x86-64 fixes mainly calling convention and
assembler reader related assembler reader related

View File

@ -56,7 +56,7 @@ interface
procedure gen_stackalloc_code(list:Taasmoutput); procedure gen_stackalloc_code(list:Taasmoutput);
procedure gen_stackfree_code(list:Taasmoutput;usesacc,usesacchi:boolean); procedure gen_stackfree_code(list:Taasmoutput;usesacc,usesacchi:boolean);
procedure gen_save_used_regs(list:TAAsmoutput); procedure gen_save_used_regs(list:TAAsmoutput);
procedure gen_restore_used_regs(list:TAAsmoutput;usesacc,usesacchi,usesfpu:boolean); procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tparalocation);
procedure gen_initialize_code(list:TAAsmoutput;inlined:boolean); procedure gen_initialize_code(list:TAAsmoutput;inlined:boolean);
procedure gen_finalize_code(list:TAAsmoutput;inlined:boolean); procedure gen_finalize_code(list:TAAsmoutput;inlined:boolean);
procedure gen_entry_code(list:TAAsmoutput); procedure gen_entry_code(list:TAAsmoutput);
@ -1164,14 +1164,8 @@ implementation
while assigned(hp) do while assigned(hp) do
begin begin
case tvarsym(hp.parasym).localloc.loc of case tvarsym(hp.parasym).localloc.loc of
LOC_REGISTER : LOC_REGISTER,
begin LOC_MMREGISTER,
gotregvarparas := true;
{ cg.a_load_param_reg will first allocate and then deallocate paraloc }
{ register (if the parameter resides in a register) and then allocate }
{ the regvar (which is currently not allocated) }
cg.a_loadany_param_reg(list,hp.paraloc[calleeside],tvarsym(hp.parasym).localloc.register,nil);
end;
LOC_FPUREGISTER: LOC_FPUREGISTER:
begin begin
gotregvarparas := true; gotregvarparas := true;
@ -1642,7 +1636,7 @@ implementation
end; end;
procedure gen_restore_used_regs(list:TAAsmoutput;usesacc,usesacchi,usesfpu:boolean); procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tparalocation);
begin begin
{ Pure assembler routines need to save the registers themselves } { Pure assembler routines need to save the registers themselves }
if (po_assembler in current_procinfo.procdef.procoptions) then if (po_assembler in current_procinfo.procdef.procoptions) then
@ -1651,7 +1645,7 @@ implementation
{ for the save all registers we can simply use a pusha,popa which { for the save all registers we can simply use a pusha,popa which
push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax } push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
if (po_saveregisters in current_procinfo.procdef.procoptions) then if (po_saveregisters in current_procinfo.procdef.procoptions) then
cg.g_restore_all_registers(list,usesacc,usesacchi) cg.g_restore_all_registers(list,funcretparaloc)
else else
if current_procinfo.procdef.proccalloption in savestdregs_pocalls then if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
cg.g_restore_standard_registers(list); cg.g_restore_standard_registers(list);
@ -2117,7 +2111,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.187 2004-02-03 22:32:54 peter Revision 1.188 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.187 2004/02/03 22:32:54 peter
* renamed xNNbittype to xNNinttype * renamed xNNbittype to xNNinttype
* renamed registers32 to registersint * renamed registers32 to registersint
* replace some s32bit,u32bit with torddef([su]inttype).def.typ * replace some s32bit,u32bit with torddef([su]inttype).def.typ

View File

@ -97,7 +97,7 @@ unit cgcpu;
procedure g_save_standard_registers(list:Taasmoutput);override; procedure g_save_standard_registers(list:Taasmoutput);override;
procedure g_restore_standard_registers(list:Taasmoutput);override; procedure g_restore_standard_registers(list:Taasmoutput);override;
procedure g_save_all_registers(list : taasmoutput);override; procedure g_save_all_registers(list : taasmoutput);override;
procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);override; procedure g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);override;
procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel); procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
@ -809,7 +809,7 @@ const
{$warning FIX ME} {$warning FIX ME}
end; end;
procedure tcgppc.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean); procedure tcgppc.g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);
begin begin
{$warning FIX ME} {$warning FIX ME}
end; end;
@ -2292,7 +2292,10 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.157 2004-02-03 19:49:24 jonas Revision 1.158 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.157 2004/02/03 19:49:24 jonas
- removed mov "reg, reg" optimizations, as they are removed by the - removed mov "reg, reg" optimizations, as they are removed by the
register allocator and may be necessary to indicate a register may not register allocator and may be necessary to indicate a register may not
be reused before some point be reused before some point

View File

@ -761,7 +761,7 @@ implementation
gen_save_used_regs(templist); gen_save_used_regs(templist);
aktproccode.insertlistafter(headertai,templist); aktproccode.insertlistafter(headertai,templist);
aktfilepos:=exitpos; aktfilepos:=exitpos;
gen_restore_used_regs(aktproccode,usesacc,usesacchi,usesfpu); gen_restore_used_regs(aktproccode,procdef.funcret_paraloc[calleeside]);
{ Add stack allocation code after header } { Add stack allocation code after header }
aktfilepos:=entrypos; aktfilepos:=entrypos;
gen_stackalloc_code(templist); gen_stackalloc_code(templist);
@ -1342,7 +1342,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.183 2004-02-03 22:32:54 peter Revision 1.184 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.183 2004/02/03 22:32:54 peter
* renamed xNNbittype to xNNinttype * renamed xNNbittype to xNNinttype
* renamed registers32 to registersint * renamed registers32 to registersint
* replace some s32bit,u32bit with torddef([su]inttype).def.typ * replace some s32bit,u32bit with torddef([su]inttype).def.typ

View File

@ -79,7 +79,7 @@ interface
procedure g_flags2reg(list:TAasmOutput;Size:TCgSize;const f:tresflags;reg:TRegister);override; procedure g_flags2reg(list:TAasmOutput;Size:TCgSize;const f:tresflags;reg:TRegister);override;
procedure g_overflowCheck(List:TAasmOutput;const Loc:TLocation;def:TDef);override; procedure g_overflowCheck(List:TAasmOutput;const Loc:TLocation;def:TDef);override;
procedure g_stackframe_entry(list:TAasmOutput;localsize:LongInt);override; procedure g_stackframe_entry(list:TAasmOutput;localsize:LongInt);override;
procedure g_restore_all_registers(list:TAasmOutput;accused,acchiused:boolean);override; procedure g_restore_all_registers(list:TAasmOutput;const funcretparaloc:tparalocation);override;
procedure g_restore_frame_pointer(list:TAasmOutput);override; procedure g_restore_frame_pointer(list:TAasmOutput);override;
procedure g_restore_standard_registers(list:taasmoutput);override; procedure g_restore_standard_registers(list:taasmoutput);override;
procedure g_return_from_proc(list:TAasmOutput;parasize:aword);override; procedure g_return_from_proc(list:TAasmOutput;parasize:aword);override;
@ -813,7 +813,7 @@ implementation
end; end;
procedure TCgSparc.g_restore_all_registers(list:TaasmOutput;accused,acchiused:boolean); procedure TCgSparc.g_restore_all_registers(list:TaasmOutput;const funcretparaloc:tparalocation);
begin begin
{ The sparc port uses the sparc standard calling convetions so this function has no used } { The sparc port uses the sparc standard calling convetions so this function has no used }
end; end;
@ -1107,7 +1107,10 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.77 2004-01-12 22:11:38 peter Revision 1.78 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.77 2004/01/12 22:11:38 peter
* use localalign info for alignment for locals and temps * use localalign info for alignment for locals and temps
* sparc fpu flags branching added * sparc fpu flags branching added
* moved powerpc copy_valye_openarray to generic * moved powerpc copy_valye_openarray to generic

View File

@ -127,8 +127,6 @@ unit cgx86;
procedure g_return_from_proc(list : taasmoutput;parasize : aword);override; procedure g_return_from_proc(list : taasmoutput;parasize : aword);override;
procedure g_save_standard_registers(list:Taasmoutput);override; procedure g_save_standard_registers(list:Taasmoutput);override;
procedure g_restore_standard_registers(list:Taasmoutput);override; procedure g_restore_standard_registers(list:Taasmoutput);override;
procedure g_save_all_registers(list : taasmoutput);override;
procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);override;
procedure g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);override; procedure g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);override;
@ -1829,36 +1827,6 @@ unit cgx86;
end; end;
procedure tcgx86.g_save_all_registers(list : taasmoutput);
begin
list.concat(Taicpu.Op_none(A_PUSHA,S_L));
tg.GetTemp(list,POINTER_SIZE,tt_noreuse,current_procinfo.save_regs_ref);
a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_ESP,current_procinfo.save_regs_ref);
end;
procedure tcgx86.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);
var
href : treference;
begin
a_load_ref_reg(list,OS_ADDR,OS_ADDR,current_procinfo.save_regs_ref,NR_ESP);
tg.UnGetTemp(list,current_procinfo.save_regs_ref);
if acchiused then
begin
reference_reset_base(href,NR_ESP,20);
list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EDX,href));
end;
if accused then
begin
reference_reset_base(href,NR_ESP,28);
list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EAX,href));
end;
list.concat(Taicpu.Op_none(A_POPA,S_L));
{ We add a NOP because of the 386DX CPU bugs with POPAD }
list.concat(taicpu.op_none(A_NOP,S_L));
end;
{ produces if necessary overflowcode } { produces if necessary overflowcode }
procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef); procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);
var var
@ -1889,7 +1857,10 @@ unit cgx86;
end. end.
{ {
$Log$ $Log$
Revision 1.105 2004-02-04 19:22:27 peter Revision 1.106 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.105 2004/02/04 19:22:27 peter
*** empty log message *** *** empty log message ***
Revision 1.104 2004/02/03 19:46:48 jonas Revision 1.104 2004/02/03 19:46:48 jonas

View File

@ -256,6 +256,9 @@ uses
tparalocation = record tparalocation = record
size : TCGSize; size : TCGSize;
loc : TCGLoc; loc : TCGLoc;
{ Location type of registerhigh, for x86_64 this can
be different from loc when pushing structures of 16 bytes }
lochigh : TCGLoc;
alignment : byte; alignment : byte;
case TCGLoc of case TCGLoc of
LOC_REFERENCE : (reference : tparareference); LOC_REFERENCE : (reference : tparareference);
@ -265,9 +268,10 @@ uses
1 : (register,registerhigh : tregister); 1 : (register,registerhigh : tregister);
{ overlay a registerlow } { overlay a registerlow }
2 : (registerlow : tregister); 2 : (registerlow : tregister);
{$ifndef cpu64bit}
{ overlay a 64 Bit register type } { overlay a 64 Bit register type }
3 : (reg64 : tregister64); 3 : (register64 : tregister64);
4 : (register64 : tregister64); {$endif cpu64bit}
); );
{ it's only for better handling } { it's only for better handling }
LOC_MMXREGISTER,LOC_CMMXREGISTER : ( LOC_MMXREGISTER,LOC_CMMXREGISTER : (
@ -535,7 +539,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.38 2004-01-30 13:42:03 florian Revision 1.39 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.38 2004/01/30 13:42:03 florian
* fixed more alignment issues * fixed more alignment issues
Revision 1.37 2004/01/15 14:01:32 florian Revision 1.37 2004/01/15 14:01:32 florian

View File

@ -38,6 +38,8 @@ unit cgcpu;
tcgx86_64 = class(tcgx86) tcgx86_64 = class(tcgx86)
procedure init_register_allocators;override; procedure init_register_allocators;override;
class function reg_cgsize(const reg: tregister): tcgsize; override; class function reg_cgsize(const reg: tregister): tcgsize; override;
procedure g_save_all_registers(list : taasmoutput);override;
procedure g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);override;
procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override; procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
end; end;
@ -89,6 +91,18 @@ unit cgcpu;
end; end;
procedure tcgx86_64.g_save_all_registers(list : taasmoutput);
begin
{$warning todo tcgx86_64.g_save_all_registers}
end;
procedure tcgx86_64.g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);
begin
{$warning todo tcgx86_64.g_restore_all_registers}
end;
procedure tcgx86_64.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean); procedure tcgx86_64.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
var var
ecxpushed : boolean; ecxpushed : boolean;
@ -220,7 +234,10 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.9 2004-01-14 23:39:05 florian Revision 1.10 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.9 2004/01/14 23:39:05 florian
* another bunch of x86-64 fixes mainly calling convention and * another bunch of x86-64 fixes mainly calling convention and
assembler reader related assembler reader related

View File

@ -30,95 +30,127 @@ unit cpupara;
uses uses
globtype, globtype,
cpubase, cpubase,cgbase,
symconst,symbase,symtype,symdef, symconst,symbase,symtype,symdef,
paramgr; paramgr;
type type
{ Returns the location for the nr-st 32 Bit int parameter
if every parameter before is an 32 Bit int parameter as well
and if the calling conventions for the helper routines of the
rtl are used.
}
tx86_64paramanager = class(tparamanager) tx86_64paramanager = class(tparamanager)
private
procedure create_funcret_paraloc_info(p : tabstractprocdef; side: tcallercallee);
public
function getintparaloc(calloption : tproccalloption; nr : longint) : tparalocation;override; function getintparaloc(calloption : tproccalloption; nr : longint) : tparalocation;override;
function get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;override;
function get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;override;
function get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;override;
function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override; function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
end; end;
implementation implementation
uses uses
verbose, cutils,verbose,
cpuinfo,cgbase,systems, cpuinfo,systems,
defutil; defutil;
const const
paraintsupregs : array[0..5] of tsuperregister = (RS_RDI,RS_RSI,RS_RDX,RS_RCX,RS_R8,RS_R9); paraintsupregs : array[0..5] of tsuperregister = (RS_RDI,RS_RSI,RS_RDX,RS_RCX,RS_R8,RS_R9);
parammsupregs : array[0..7] of tsuperregister = (RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3,RS_XMM4,RS_XMM5,RS_XMM6,RS_XMM7); parammsupregs : array[0..7] of tsuperregister = (RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3,RS_XMM4,RS_XMM5,RS_XMM6,RS_XMM7);
function getparaloc(p : tdef) : tcgloc; procedure getvalueparaloc(p : tdef;var loc_lo,loc_hi:tcgloc);
begin begin
{ Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER loc_lo:=LOC_INVALID;
if push_addr_param for the def is true loc_hi:=LOC_INVALID;
} case p.deftype of
// !!!!! Fix aggregate types orddef:
case p.deftype of begin
orddef: loc_lo:=LOC_REGISTER;
getparaloc:=LOC_REGISTER; {$warning TODO 128bit also needs lochigh}
floatdef: end;
case tfloatdef(p).typ of floatdef:
s80real: begin
getparaloc:=LOC_REFERENCE; case tfloatdef(p).typ of
s32real, s80real:
s64real, loc_lo:=LOC_REFERENCE;
s64comp, s32real,
s64currency, s64real,
s128real: s64comp,
getparaloc:=LOC_MMREGISTER; s64currency :
end; loc_lo:=LOC_MMREGISTER;
enumdef: s128real:
getparaloc:=LOC_REGISTER; begin
pointerdef: loc_lo:=LOC_MMREGISTER;
getparaloc:=LOC_REGISTER; loc_hi:=LOC_MMREGISTER;
formaldef: {$warning TODO float 128bit needs SSEUP lochigh}
getparaloc:=LOC_REGISTER; end;
classrefdef: end;
getparaloc:=LOC_REGISTER; end;
recorddef: recorddef:
getparaloc:=LOC_REFERENCE; begin
objectdef: if p.size<=16 then
if is_object(p) then begin
getparaloc:=LOC_REFERENCE {$warning TODO location depends on the fields}
else loc_lo:=LOC_REFERENCE;
getparaloc:=LOC_REGISTER; end
stringdef: else
if is_shortstring(p) or is_longstring(p) then loc_lo:=LOC_REFERENCE;
getparaloc:=LOC_REFERENCE end;
else objectdef:
getparaloc:=LOC_REGISTER; begin
procvardef: if is_object(p) then
if (po_methodpointer in tprocvardef(p).procoptions) then loc_lo:=LOC_REFERENCE
getparaloc:=LOC_REFERENCE else
else loc_lo:=LOC_REGISTER;
getparaloc:=LOC_REGISTER; end;
filedef: arraydef:
getparaloc:=LOC_REGISTER; loc_lo:=LOC_REFERENCE;
arraydef: variantdef:
getparaloc:=LOC_REFERENCE; loc_lo:=LOC_REFERENCE;
setdef: stringdef:
if is_smallset(p) then if is_shortstring(p) or is_longstring(p) then
getparaloc:=LOC_REGISTER loc_lo:=LOC_REFERENCE
else else
getparaloc:=LOC_REFERENCE; loc_lo:=LOC_REGISTER;
variantdef: setdef:
getparaloc:=LOC_REFERENCE; if is_smallset(p) then
{ avoid problems with errornous definitions } loc_lo:=LOC_REGISTER
errordef: else
getparaloc:=LOC_REGISTER; loc_lo:=LOC_REFERENCE;
else procvardef:
internalerror(2002071001); begin
end; { This is a record < 16 bytes }
if (po_methodpointer in tprocvardef(p).procoptions) then
begin
loc_lo:=LOC_REGISTER;
loc_hi:=LOC_REGISTER;
end
else
loc_lo:=LOC_REGISTER;
end;
else
begin
{ default for pointers,enums,etc }
loc_lo:=LOC_REGISTER;
end;
end;
end;
function tx86_64paramanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
begin
result:=[RS_RAX,RS_RCX,RS_RDX,RS_RSI,RS_RDI,RS_R8,RS_R9,RS_R10,RS_R11];
end;
function tx86_64paramanager.get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;
begin
result:=[RS_XMM0..RS_XMM15];
end;
function tx86_64paramanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
begin
result:=[RS_ST0..RS_ST7];
end; end;
@ -142,6 +174,34 @@ unit cpupara;
end; end;
procedure tx86_64paramanager.create_funcret_paraloc_info(p : tabstractprocdef; side: tcallercallee);
var
paraloc : tparalocation;
begin
{ Function return }
fillchar(paraloc,sizeof(tparalocation),0);
paraloc.size:=def_cgsize(p.rettype.def);
{ Return in FPU register? }
if is_extended(p.rettype.def) then
begin
paraloc.loc:=LOC_FPUREGISTER;
paraloc.register:=NR_FPU_RESULT_REG;
end
else
{ Return in register? }
if not ret_in_param(p.rettype.def,p.proccalloption) then
begin
paraloc.loc:=LOC_REGISTER;
paraloc.register:=NR_FUNCTION_RETURN_REG;
end
else
begin
paraloc.loc:=LOC_REFERENCE;
end;
p.funcret_paraloc[side]:=paraloc;
end;
function tx86_64paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint; function tx86_64paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
var var
hp : tparaitem; hp : tparaitem;
@ -163,61 +223,108 @@ unit cpupara;
begin begin
pushaddr:=push_addr_param(hp.paratyp,hp.paratype.def,p.proccalloption); pushaddr:=push_addr_param(hp.paratyp,hp.paratype.def,p.proccalloption);
if pushaddr then if pushaddr then
paraloc.size:=OS_ADDR
else
paraloc.size:=def_cgsize(hp.paratype.def);
paraloc.alignment:=paraalign;
if (intparareg<=high(paraintsupregs)) and
not(
((hp.paratype.def.deftype in [floatdef,recorddef,arraydef]) and
(not pushaddr))
) then
begin begin
paraloc.size:=OS_ADDR;
paraloc.loc:=LOC_REGISTER; paraloc.loc:=LOC_REGISTER;
if paraloc.size=OS_NO then paraloc.lochigh:=LOC_INVALID;
end
else
begin
paraloc.size:=def_cgsize(hp.paratype.def);
getvalueparaloc(hp.paratype.def,paraloc.loc,paraloc.lochigh);
end;
paraloc.alignment:=paraalign;
{ Location low }
if (paraloc.loc=LOC_REGISTER) and
(intparareg<=high(paraintsupregs)) then
begin
if (paraloc.size=OS_NO) or (paraloc.lochigh<>LOC_INVALID) then
subreg:=R_SUBWHOLE subreg:=R_SUBWHOLE
else else
subreg:=cgsize2subreg(paraloc.size); subreg:=cgsize2subreg(paraloc.size);
paraloc.alignment:=paraalign;
paraloc.register:=newreg(R_INTREGISTER,paraintsupregs[intparareg],subreg); paraloc.register:=newreg(R_INTREGISTER,paraintsupregs[intparareg],subreg);
inc(intparareg); inc(intparareg);
end end
else if (mmparareg<=high(parammsupregs)) then else
if (paraloc.loc=LOC_MMREGISTER) and
(mmparareg<=high(parammsupregs)) then
begin begin
paraloc.register:=newreg(R_MMREGISTER,parammsupregs[mmparareg],R_SUBNONE);
inc(mmparareg);
end end
else else
begin begin
paraloc.loc:=LOC_REFERENCE; paraloc.loc:=LOC_REFERENCE;
paraloc.lochigh:=LOC_INVALID;
if side=callerside then if side=callerside then
paraloc.reference.index:=NR_STACK_POINTER_REG paraloc.reference.index:=NR_STACK_POINTER_REG
else else
paraloc.reference.index:=NR_FRAME_POINTER_REG; paraloc.reference.index:=NR_FRAME_POINTER_REG;
l:=push_size(hp.paratyp,hp.paratype.def,p.proccalloption); l:=push_size(hp.paratyp,hp.paratype.def,p.proccalloption);
// varalign:=size_2_align(l); varalign:=size_2_align(l);
paraloc.reference.offset:=parasize; paraloc.reference.offset:=parasize;
// varalign:=used_align(varalign,paraalign,paraalign); varalign:=used_align(varalign,paraalign,paraalign);
// parasize:=align(parasize+l,varalign); parasize:=align(parasize+l,varalign);
end;
{ Location High if required }
if (paraloc.lochigh<>LOC_INVALID) then
begin
if (paraloc.lochigh=LOC_REGISTER) and
(intparareg<=high(paraintsupregs)) then
begin
paraloc.registerhigh:=newreg(R_INTREGISTER,paraintsupregs[intparareg],R_SUBWHOLE);
inc(intparareg);
end
else
if (paraloc.lochigh=LOC_MMREGISTER) and
(mmparareg<=high(parammsupregs)) then
begin
paraloc.registerhigh:=newreg(R_MMREGISTER,parammsupregs[mmparareg],R_SUBNONE);
inc(mmparareg);
end
else
begin
{ Release when location low has already registers
assigned }
if paraloc.loc=LOC_REGISTER then
dec(intparareg);
if paraloc.loc=LOC_MMREGISTER then
dec(mmparareg);
{ Overwrite with LOC_REFERENCE }
paraloc.loc:=LOC_REFERENCE;
paraloc.lochigh:=LOC_INVALID;
fillchar(paraloc.reference,sizeof(paraloc.reference),0);
if side=callerside then
paraloc.reference.index:=NR_STACK_POINTER_REG
else
paraloc.reference.index:=NR_FRAME_POINTER_REG;
l:=push_size(hp.paratyp,hp.paratype.def,p.proccalloption);
varalign:=size_2_align(l);
paraloc.reference.offset:=parasize;
varalign:=used_align(varalign,paraalign,paraalign);
parasize:=align(parasize+l,varalign);
end;
end; end;
hp.paraloc[side]:=paraloc; hp.paraloc[side]:=paraloc;
hp:=tparaitem(hp.next); hp:=tparaitem(hp.next);
end; end;
{ Register parameters are assigned from left-to-right, adapt offset { Register parameters are assigned from left-to-right, but the
for calleeside to be reversed } offsets on the stack are right-to-left. There is no need
hp:=tparaitem(p.para.first); to reverse the offset, only adapt the calleeside with the
while assigned(hp) do start offset of the first param on the stack }
if side=calleeside then
begin begin
if (hp.paraloc[side].loc=LOC_REFERENCE) then hp:=tparaitem(p.para.first);
while assigned(hp) do
begin begin
l:=push_size(hp.paratyp,hp.paratype.def,p.proccalloption); if (hp.paraloc[side].loc=LOC_REFERENCE) then
// varalign:=used_align(size_2_align(l),paraalign,paraalign);
// l:=align(l,varalign);
hp.paraloc[side].reference.offset:=parasize-hp.paraloc[side].reference.offset-l;
if side=calleeside then
inc(hp.paraloc[side].reference.offset,target_info.first_parm_offset); inc(hp.paraloc[side].reference.offset,target_info.first_parm_offset);
hp:=tparaitem(hp.next);
end; end;
hp:=tparaitem(hp.next);
end; end;
{ We need to return the size allocated } { Create Function result paraloc }
create_funcret_paraloc_info(p,side);
{ We need to return the size allocated on the stack }
result:=parasize; result:=parasize;
end; end;
@ -227,7 +334,10 @@ begin
end. end.
{ {
$Log$ $Log$
Revision 1.6 2004-01-14 23:39:05 florian Revision 1.7 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.6 2004/01/14 23:39:05 florian
* another bunch of x86-64 fixes mainly calling convention and * another bunch of x86-64 fixes mainly calling convention and
assembler reader related assembler reader related

View File

@ -26,24 +26,39 @@ unit cpupi;
{$i fpcdefs.inc} {$i fpcdefs.inc}
interface interface
uses uses
psub,procinfo; psub,procinfo;
type type
tx86_64procinfo = class(tcgprocinfo) tx86_64procinfo = class(tcgprocinfo)
function calc_stackframe_size:longint;override;
end; end;
implementation implementation
uses
cutils,
tgobj;
function tx86_64procinfo.calc_stackframe_size:longint;
begin
{ RSP should be aligned on 16 bytes }
result:=Align(tg.direction*tg.lasttemp,16);
end;
begin begin
cprocinfo:=tx86_64procinfo; cprocinfo:=tx86_64procinfo;
end. end.
{ {
$Log$ $Log$
Revision 1.2 2003-12-24 00:33:10 florian Revision 1.3 2004-02-04 22:01:13 peter
* first try to get cpupara working for x86_64
Revision 1.2 2003/12/24 00:33:10 florian
* x86-64 compilation fixed * x86-64 compilation fixed
Revision 1.1 2003/01/05 13:36:54 florian Revision 1.1 2003/01/05 13:36:54 florian