From 07a21319b94efe4be5efc2730d3eaef4a242c099 Mon Sep 17 00:00:00 2001 From: mazen Date: Wed, 22 Jan 2003 20:45:15 +0000 Subject: [PATCH] * making math code in RTL compiling. *NB : This does NOT mean necessary that it will generate correct code! --- compiler/ncgcal.pas | 12 ++- compiler/sparc/cpunode.pas | 10 ++- compiler/sparc/ncpuadd.pas | 16 +++- compiler/sparc/ncpucnv.pas | 8 +- rtl/sparc/math.inc | 174 +++++++++++++++++++------------------ 5 files changed, 123 insertions(+), 97 deletions(-) diff --git a/compiler/ncgcal.pas b/compiler/ncgcal.pas index 25ba5a418a..fb38326cd4 100644 --- a/compiler/ncgcal.pas +++ b/compiler/ncgcal.pas @@ -1052,16 +1052,16 @@ implementation cg.a_call_ref(exprasmlist,href); cg.free_scratch_reg(exprasmlist,tmpreg); end; - +{$ifndef SPARC}{We don't need that on SPARC arch!} { push base pointer ?} { never when inlining, since if necessary, the base pointer } { can/will be gottten from the current procedure's symtable } - { (JM) } + { (JM)} if not inlined then if (lexlevel>=normal_function_level) and assigned(tprocdef(procdefinition).parast) and ((tprocdef(procdefinition).parast.symtablelevel)>normal_function_level) then load_framepointer; - +{$endif SPARC} rg.saveregvars(exprasmlist,regs_to_push); {$ifdef dummy} @@ -1572,7 +1572,11 @@ begin end. { $Log$ - Revision 1.34 2003-01-17 12:03:45 daniel + Revision 1.35 2003-01-22 20:45:15 mazen + * making math code in RTL compiling. + *NB : This does NOT mean necessary that it will generate correct code! + + Revision 1.34 2003/01/17 12:03:45 daniel * Optalign conditional code adapted to record Tregister Revision 1.33 2003/01/08 18:43:56 daniel diff --git a/compiler/sparc/cpunode.pas b/compiler/sparc/cpunode.pas index 632aa990bf..04a1f697a8 100644 --- a/compiler/sparc/cpunode.pas +++ b/compiler/sparc/cpunode.pas @@ -28,14 +28,18 @@ the behaviour of such a unit having just a USES clause!} implementation uses ncgbas,ncgflw,ncgcnv,ncgld,ncgmem,ncgcon,{ncgset,} - ncpuadd,ncpucall,{n386con,n386cnv,n386flw,}ncpumat,{n386mem,} - {n386set,}ncpuinln,{n386opt,}ncpucnv, + ncpuadd,ncpucall,{n386con,n386flw,}ncpumat,{n386mem,} + ncgset,ncpuinln,{n386opt,}ncpucnv, { this not really a node } {ncpuobj,}rgcpu; end. { $Log$ - Revision 1.6 2002-12-21 23:21:47 mazen + Revision 1.7 2003-01-22 20:45:15 mazen + * making math code in RTL compiling. + *NB : This does NOT mean necessary that it will generate correct code! + + Revision 1.6 2002/12/21 23:21:47 mazen + added support for the shift nodes + added debug output on screen with -an command line option diff --git a/compiler/sparc/ncpuadd.pas b/compiler/sparc/ncpuadd.pas index ebd4fddd47..c3dc52666e 100644 --- a/compiler/sparc/ncpuadd.pas +++ b/compiler/sparc/ncpuadd.pas @@ -905,10 +905,16 @@ procedures } orddef: if is_boolean(left.resulttype.def)and is_boolean(right.resulttype.def) then{handling boolean expressions} - second_addboolean + begin + second_addboolean; + exit; + end else if is_64bitint(left.resulttype.def) then{64bit operations} - second_add64bit; + begin + second_add64bit; + exit; + end; stringdef: InternalError(20020726);//second_addstring; setdef: @@ -1040,7 +1046,11 @@ begin end. { $Log$ - Revision 1.7 2003-01-20 22:21:36 mazen + Revision 1.8 2003-01-22 20:45:15 mazen + * making math code in RTL compiling. + *NB : This does NOT mean necessary that it will generate correct code! + + Revision 1.7 2003/01/20 22:21:36 mazen * many stuff related to RTL fixed Revision 1.6 2003/01/08 18:43:58 daniel diff --git a/compiler/sparc/ncpucnv.pas b/compiler/sparc/ncpucnv.pas index 54bccac9ed..08a12e7218 100644 --- a/compiler/sparc/ncpucnv.pas +++ b/compiler/sparc/ncpucnv.pas @@ -246,7 +246,7 @@ procedure TSparctypeconvnode.second_int_to_real; tempconst.free; location.register := rg.getregisterfpu(exprasmlist); {$WARNING FIXME what really should be done?} - exprasmlist.concat(taicpu.op_reg_ref(A_LD,location.register,ref)); + exprasmlist.concat(taicpu.op_Ref_Reg(A_LDF,Ref,location.register)); tg.ungetiftemp(exprasmlist,ref); exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUB,location.register,location.register,tmpfpureg)); rg.ungetregisterfpu(exprasmlist,tmpfpureg); @@ -388,7 +388,11 @@ begin end. { $Log$ - Revision 1.10 2003-01-20 22:21:36 mazen + Revision 1.11 2003-01-22 20:45:15 mazen + * making math code in RTL compiling. + *NB : This does NOT mean necessary that it will generate correct code! + + Revision 1.10 2003/01/20 22:21:36 mazen * many stuff related to RTL fixed Revision 1.9 2002/12/05 14:28:03 florian diff --git a/rtl/sparc/math.inc b/rtl/sparc/math.inc index f75c0ab70a..f32ed77d24 100644 --- a/rtl/sparc/math.inc +++ b/rtl/sparc/math.inc @@ -15,6 +15,89 @@ **********************************************************************} +{**************************************************************************** + Int to real helpers + ****************************************************************************} + +const + longint_to_real_helper: int64 = $4330000080000000; + cardinal_to_real_helper: int64 = $430000000000000; + int_to_real_factor: double = double(high(cardinal))+1.0; + +function fpc_int64_to_double(i: int64): double; compilerproc; +{assembler;} +{ input: high(i) in r3, low(i) in r4 } +{ output: double(i) in f0 } +var + temp: packed record + case byte of + 0: (l1,l2: cardinal); + 1: (d: double); + end; +begin{asm} +(* lis r0,0x4330 + stw r0,temp + xoris r3,r3,0x8000 + stw r3,4+temp + {$ifndef macos} + lis r3,longint_to_real_helper@ha + lfd f1,longint_to_real_helper@l(r3) + {$else} + lfd f1,longint_to_real_helper(r2) + {$endif} + lfd f0,temp + stw r4,4+temp + fsub f0,f0,f1 + {$ifndef macos} + lis r4,cardinal_to_real_helper@ha + lfd f1,cardinal_to_real_helper@l(r4) + lis r3,int_to_real_factor@ha + lfd f3,temp + lfd f2,int_to_real_factor@l(r3) + {$else} + lfd f1,cardinal_to_real_helper(r2) + lfd f3,temp + lfd f2,int_to_real_factor(r2) + {$endif} + fsub f3,f3,f1 + fmadd f1,f0,f2,f3*) +end{ ['R0','R3','R4','F0','F1','F2','F3']}; + + +function fpc_qword_to_double(q: qword): double; compilerproc; +{assembler;} +{ input: high(q) in r3, low(q) in r4 } +{ output: double(q) in f0 } +var + temp: packed record + case byte of + 0: (l1,l2: cardinal); + 1: (d: double); + end; +begin{asm} +(* lis r0,0x4330 + stw r0,temp + stw r3,4+temp + lfd f0,temp + {$ifndef macos} + lis r3,cardinal_to_real_helper@ha + lfd f1,cardinal_to_real_helper@l(r3) + {$else} + lfd f1,cardinal_to_real_helper(r2) + {$endif} + stw r4,4+temp + fsub f0,f0,f1 + lfd f3,temp + {$ifndef macos} + lis r3,int_to_real_factor@ha + lfd f2,int_to_real_factor@l(r3) + {$else} + lfd f2,int_to_real_factor(r2) + {$endif} + fsub f3,f3,f1 + fmadd f1,f0,f2,f3*) +end{ ['R0','R3','F0','F1','F2','F3']}; + {**************************************************************************** EXTENDED data type routines @@ -137,7 +220,7 @@ {**************************************************************************** Longint data type routines ****************************************************************************} - + {$define FPC_SYSTEM_HAS_POWER_INT64} function power(bas,expo : Int64) : Int64; begin if bas=0 then @@ -198,93 +281,14 @@ end; -{**************************************************************************** - Int to real helpers - ****************************************************************************} - -const - longint_to_real_helper: int64 = $4330000080000000; - cardinal_to_real_helper: int64 = $430000000000000; - int_to_real_factor: double = double(high(cardinal))+1.0; - -function fpc_int64_to_double(i: int64): double; compilerproc; -{assembler;} -{ input: high(i) in r3, low(i) in r4 } -{ output: double(i) in f0 } -var - temp: packed record - case byte of - 0: (l1,l2: cardinal); - 1: (d: double); - end; -begin{asm} -(* lis r0,0x4330 - stw r0,temp - xoris r3,r3,0x8000 - stw r3,4+temp - {$ifndef macos} - lis r3,longint_to_real_helper@ha - lfd f1,longint_to_real_helper@l(r3) - {$else} - lfd f1,longint_to_real_helper(r2) - {$endif} - lfd f0,temp - stw r4,4+temp - fsub f0,f0,f1 - {$ifndef macos} - lis r4,cardinal_to_real_helper@ha - lfd f1,cardinal_to_real_helper@l(r4) - lis r3,int_to_real_factor@ha - lfd f3,temp - lfd f2,int_to_real_factor@l(r3) - {$else} - lfd f1,cardinal_to_real_helper(r2) - lfd f3,temp - lfd f2,int_to_real_factor(r2) - {$endif} - fsub f3,f3,f1 - fmadd f1,f0,f2,f3*) -end{ ['R0','R3','R4','F0','F1','F2','F3']}; - - -function fpc_qword_to_double(q: qword): double; compilerproc; -{assembler;} -{ input: high(q) in r3, low(q) in r4 } -{ output: double(q) in f0 } -var - temp: packed record - case byte of - 0: (l1,l2: cardinal); - 1: (d: double); - end; -begin{asm} -(* lis r0,0x4330 - stw r0,temp - stw r3,4+temp - lfd f0,temp - {$ifndef macos} - lis r3,cardinal_to_real_helper@ha - lfd f1,cardinal_to_real_helper@l(r3) - {$else} - lfd f1,cardinal_to_real_helper(r2) - {$endif} - stw r4,4+temp - fsub f0,f0,f1 - lfd f3,temp - {$ifndef macos} - lis r3,int_to_real_factor@ha - lfd f2,int_to_real_factor@l(r3) - {$else} - lfd f2,int_to_real_factor(r2) - {$endif} - fsub f3,f3,f1 - fmadd f1,f0,f2,f3*) -end{ ['R0','R3','F0','F1','F2','F3']}; - { $Log$ - Revision 1.2 2003-01-20 22:21:36 mazen + Revision 1.3 2003-01-22 20:45:15 mazen + * making math code in RTL compiling. + *NB : This does NOT mean necessary that it will generate correct code! + + Revision 1.2 2003/01/20 22:21:36 mazen * many stuff related to RTL fixed Revision 1.1 2002/12/24 21:30:20 mazen