* 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_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_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);override;
procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
procedure fixref(list : taasmoutput;var ref : treference);
@ -1138,7 +1138,7 @@ unit cgcpu;
end;
procedure tcgarm.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);
procedure tcgarm.g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);
begin
{ we support only ARM standard calling conventions so this procedure has no use on the ARM }
end;
@ -1273,7 +1273,10 @@ begin
end.
{
$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
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_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;
{# @abstract(Abstract code generator for 64 Bit operations)
@ -854,19 +854,17 @@ implementation
LOC_CREGISTER,
LOC_REGISTER:
begin
{$ifndef cpu64bit}
if (locpara.size in [OS_S64,OS_64]) then
begin
{$ifdef cpu64bit}
ungetregister(list,locpara.register64);
{$else cpu64bit}
getexplicitregister(list,locpara.registerlow);
getexplicitregister(list,locpara.registerhigh);
ungetregister(list,locpara.registerlow);
ungetregister(list,locpara.registerhigh);
{$endif cpu64bit}
cg64.a_load64_reg_ref(list,locpara.register64,ref)
end
else
{$endif cpu64bit}
begin
getexplicitregister(list,locpara.register);
ungetregister(list,locpara.register);
@ -2140,7 +2138,10 @@ finalization
end.
{
$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 registers32 to registersint
* 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 }
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 }
function is_64bitint(def : tdef) : boolean;
@ -234,6 +237,13 @@ implementation
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;
begin
{ generate a unsigned range if high<0 and low>=0 }
@ -845,7 +855,10 @@ implementation
end.
{
$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 registers32 to registersint
* replace some s32bit,u32bit with torddef([su]inttype).def.typ

View File

@ -42,6 +42,8 @@ unit cgcpu;
tcg386 = class(tcgx86)
procedure init_register_allocators;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;
tcg64f386 = class(tcg64f32)
@ -57,7 +59,7 @@ unit cgcpu;
uses
globtype,globals,verbose,systems,cutils,
symdef,symsym,defutil,paramgr,
symdef,symsym,defutil,paramgr,procinfo,
rgcpu,rgx86,tgobj;
@ -111,6 +113,41 @@ unit cgcpu;
result := opsize_2_cgsize[reg2opsize(reg)];
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 ************ }
@ -246,7 +283,10 @@ begin
end.
{
$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
assembler reader related

View File

@ -56,7 +56,7 @@ interface
procedure gen_stackalloc_code(list:Taasmoutput);
procedure gen_stackfree_code(list:Taasmoutput;usesacc,usesacchi:boolean);
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_finalize_code(list:TAAsmoutput;inlined:boolean);
procedure gen_entry_code(list:TAAsmoutput);
@ -1164,14 +1164,8 @@ implementation
while assigned(hp) do
begin
case tvarsym(hp.parasym).localloc.loc of
LOC_REGISTER :
begin
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_REGISTER,
LOC_MMREGISTER,
LOC_FPUREGISTER:
begin
gotregvarparas := true;
@ -1642,7 +1636,7 @@ implementation
end;
procedure gen_restore_used_regs(list:TAAsmoutput;usesacc,usesacchi,usesfpu:boolean);
procedure gen_restore_used_regs(list:TAAsmoutput;const funcretparaloc:tparalocation);
begin
{ Pure assembler routines need to save the registers themselves }
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
push edi,esi,ebp,esp(ignored),ebx,edx,ecx,eax }
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
if current_procinfo.procdef.proccalloption in savestdregs_pocalls then
cg.g_restore_standard_registers(list);
@ -2117,7 +2111,10 @@ implementation
end.
{
$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 registers32 to registersint
* 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_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_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);override;
procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
@ -809,7 +809,7 @@ const
{$warning FIX ME}
end;
procedure tcgppc.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);
procedure tcgppc.g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);
begin
{$warning FIX ME}
end;
@ -2292,7 +2292,10 @@ begin
end.
{
$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
register allocator and may be necessary to indicate a register may not
be reused before some point

View File

@ -761,7 +761,7 @@ implementation
gen_save_used_regs(templist);
aktproccode.insertlistafter(headertai,templist);
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 }
aktfilepos:=entrypos;
gen_stackalloc_code(templist);
@ -1342,7 +1342,10 @@ implementation
end.
{
$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 registers32 to registersint
* 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_overflowCheck(List:TAasmOutput;const Loc:TLocation;def:TDef);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_standard_registers(list:taasmoutput);override;
procedure g_return_from_proc(list:TAasmOutput;parasize:aword);override;
@ -813,7 +813,7 @@ implementation
end;
procedure TCgSparc.g_restore_all_registers(list:TaasmOutput;accused,acchiused:boolean);
procedure TCgSparc.g_restore_all_registers(list:TaasmOutput;const funcretparaloc:tparalocation);
begin
{ The sparc port uses the sparc standard calling convetions so this function has no used }
end;
@ -1107,7 +1107,10 @@ begin
end.
{
$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
* sparc fpu flags branching added
* 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_save_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;
@ -1829,36 +1827,6 @@ unit cgx86;
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 }
procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);
var
@ -1889,7 +1857,10 @@ unit cgx86;
end.
{
$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 ***
Revision 1.104 2004/02/03 19:46:48 jonas

View File

@ -256,6 +256,9 @@ uses
tparalocation = record
size : TCGSize;
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;
case TCGLoc of
LOC_REFERENCE : (reference : tparareference);
@ -265,9 +268,10 @@ uses
1 : (register,registerhigh : tregister);
{ overlay a registerlow }
2 : (registerlow : tregister);
{$ifndef cpu64bit}
{ overlay a 64 Bit register type }
3 : (reg64 : tregister64);
4 : (register64 : tregister64);
3 : (register64 : tregister64);
{$endif cpu64bit}
);
{ it's only for better handling }
LOC_MMXREGISTER,LOC_CMMXREGISTER : (
@ -535,7 +539,10 @@ implementation
end.
{
$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
Revision 1.37 2004/01/15 14:01:32 florian

View File

@ -38,6 +38,8 @@ unit cgcpu;
tcgx86_64 = class(tcgx86)
procedure init_register_allocators;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;
end;
@ -89,6 +91,18 @@ unit cgcpu;
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);
var
ecxpushed : boolean;
@ -220,7 +234,10 @@ begin
end.
{
$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
assembler reader related

View File

@ -30,95 +30,127 @@ unit cpupara;
uses
globtype,
cpubase,
cpubase,cgbase,
symconst,symbase,symtype,symdef,
paramgr;
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)
private
procedure create_funcret_paraloc_info(p : tabstractprocdef; side: tcallercallee);
public
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;
end;
implementation
uses
verbose,
cpuinfo,cgbase,systems,
cutils,verbose,
cpuinfo,systems,
defutil;
const
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);
function getparaloc(p : tdef) : tcgloc;
procedure getvalueparaloc(p : tdef;var loc_lo,loc_hi:tcgloc);
begin
{ Later, the LOC_REFERENCE is in most cases changed into LOC_REGISTER
if push_addr_param for the def is true
}
// !!!!! Fix aggregate types
case p.deftype of
orddef:
getparaloc:=LOC_REGISTER;
floatdef:
case tfloatdef(p).typ of
s80real:
getparaloc:=LOC_REFERENCE;
s32real,
s64real,
s64comp,
s64currency,
s128real:
getparaloc:=LOC_MMREGISTER;
end;
enumdef:
getparaloc:=LOC_REGISTER;
pointerdef:
getparaloc:=LOC_REGISTER;
formaldef:
getparaloc:=LOC_REGISTER;
classrefdef:
getparaloc:=LOC_REGISTER;
recorddef:
getparaloc:=LOC_REFERENCE;
objectdef:
if is_object(p) then
getparaloc:=LOC_REFERENCE
else
getparaloc:=LOC_REGISTER;
stringdef:
if is_shortstring(p) or is_longstring(p) then
getparaloc:=LOC_REFERENCE
else
getparaloc:=LOC_REGISTER;
procvardef:
if (po_methodpointer in tprocvardef(p).procoptions) then
getparaloc:=LOC_REFERENCE
else
getparaloc:=LOC_REGISTER;
filedef:
getparaloc:=LOC_REGISTER;
arraydef:
getparaloc:=LOC_REFERENCE;
setdef:
if is_smallset(p) then
getparaloc:=LOC_REGISTER
else
getparaloc:=LOC_REFERENCE;
variantdef:
getparaloc:=LOC_REFERENCE;
{ avoid problems with errornous definitions }
errordef:
getparaloc:=LOC_REGISTER;
else
internalerror(2002071001);
end;
loc_lo:=LOC_INVALID;
loc_hi:=LOC_INVALID;
case p.deftype of
orddef:
begin
loc_lo:=LOC_REGISTER;
{$warning TODO 128bit also needs lochigh}
end;
floatdef:
begin
case tfloatdef(p).typ of
s80real:
loc_lo:=LOC_REFERENCE;
s32real,
s64real,
s64comp,
s64currency :
loc_lo:=LOC_MMREGISTER;
s128real:
begin
loc_lo:=LOC_MMREGISTER;
loc_hi:=LOC_MMREGISTER;
{$warning TODO float 128bit needs SSEUP lochigh}
end;
end;
end;
recorddef:
begin
if p.size<=16 then
begin
{$warning TODO location depends on the fields}
loc_lo:=LOC_REFERENCE;
end
else
loc_lo:=LOC_REFERENCE;
end;
objectdef:
begin
if is_object(p) then
loc_lo:=LOC_REFERENCE
else
loc_lo:=LOC_REGISTER;
end;
arraydef:
loc_lo:=LOC_REFERENCE;
variantdef:
loc_lo:=LOC_REFERENCE;
stringdef:
if is_shortstring(p) or is_longstring(p) then
loc_lo:=LOC_REFERENCE
else
loc_lo:=LOC_REGISTER;
setdef:
if is_smallset(p) then
loc_lo:=LOC_REGISTER
else
loc_lo:=LOC_REFERENCE;
procvardef:
begin
{ 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;
@ -142,6 +174,34 @@ unit cpupara;
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;
var
hp : tparaitem;
@ -163,61 +223,108 @@ unit cpupara;
begin
pushaddr:=push_addr_param(hp.paratyp,hp.paratype.def,p.proccalloption);
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
paraloc.size:=OS_ADDR;
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
else
subreg:=cgsize2subreg(paraloc.size);
paraloc.alignment:=paraalign;
paraloc.register:=newreg(R_INTREGISTER,paraintsupregs[intparareg],subreg);
inc(intparareg);
end
else if (mmparareg<=high(parammsupregs)) then
else
if (paraloc.loc=LOC_MMREGISTER) and
(mmparareg<=high(parammsupregs)) then
begin
paraloc.register:=newreg(R_MMREGISTER,parammsupregs[mmparareg],R_SUBNONE);
inc(mmparareg);
end
else
begin
paraloc.loc:=LOC_REFERENCE;
paraloc.lochigh:=LOC_INVALID;
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);
varalign:=size_2_align(l);
paraloc.reference.offset:=parasize;
// varalign:=used_align(varalign,paraalign,paraalign);
// parasize:=align(parasize+l,varalign);
varalign:=used_align(varalign,paraalign,paraalign);
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;
hp.paraloc[side]:=paraloc;
hp:=tparaitem(hp.next);
end;
{ Register parameters are assigned from left-to-right, adapt offset
for calleeside to be reversed }
hp:=tparaitem(p.para.first);
while assigned(hp) do
{ Register parameters are assigned from left-to-right, but the
offsets on the stack are right-to-left. There is no need
to reverse the offset, only adapt the calleeside with the
start offset of the first param on the stack }
if side=calleeside then
begin
if (hp.paraloc[side].loc=LOC_REFERENCE) then
hp:=tparaitem(p.para.first);
while assigned(hp) do
begin
l:=push_size(hp.paratyp,hp.paratype.def,p.proccalloption);
// 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
if (hp.paraloc[side].loc=LOC_REFERENCE) then
inc(hp.paraloc[side].reference.offset,target_info.first_parm_offset);
hp:=tparaitem(hp.next);
end;
hp:=tparaitem(hp.next);
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;
end;
@ -227,7 +334,10 @@ begin
end.
{
$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
assembler reader related

View File

@ -26,24 +26,39 @@ unit cpupi;
{$i fpcdefs.inc}
interface
interface
uses
psub,procinfo;
type
tx86_64procinfo = class(tcgprocinfo)
function calc_stackframe_size:longint;override;
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
cprocinfo:=tx86_64procinfo;
end.
{
$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
Revision 1.1 2003/01/05 13:36:54 florian