From abbc3fa755801a51a605431bcaff2b35b7edc4b4 Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 14 Sep 2003 11:34:13 +0000 Subject: [PATCH] * moved int64 asm code to int64p.inc * save ebx,esi --- rtl/i386/i386.inc | 40 ++++--- rtl/i386/int64p.inc | 233 ++++++++++++++++++++++++++++++++++++ rtl/inc/int64.inc | 179 ++++----------------------- rtl/inc/system.inc | 7 +- rtl/linux/i386/syscall.inc | 22 ++-- rtl/linux/i386/syscallh.inc | 20 ++-- rtl/powerpc/int64p.inc | 23 ++++ rtl/sparc/int64p.inc | 23 ++++ 8 files changed, 358 insertions(+), 189 deletions(-) create mode 100644 rtl/i386/int64p.inc create mode 100644 rtl/powerpc/int64p.inc create mode 100644 rtl/sparc/int64p.inc diff --git a/rtl/i386/i386.inc b/rtl/i386/i386.inc index 06cd0e6900..0780377215 100644 --- a/rtl/i386/i386.inc +++ b/rtl/i386/i386.inc @@ -31,54 +31,54 @@ asm movl dest,%edi movl source,%esi movl %edi,%eax - movl count,%ebx + movl count,%edx { check for zero or negative count } - cmpl $0,%ebx + cmpl $0,%edx jle .LMoveEnd { Check for back or forward } sub %esi,%eax jz .LMoveEnd { Do nothing when source=dest } jc .LFMove { Do forward, dest0 then + fpc_mul_qword:=fpc_mul_qword+f1; + + f1:=f1 shl 1; + bitpos:=bitpos shl 1; + end; + + { if one of the operands is greater than the result an } + { overflow occurs } + if checkoverflow and (_f1 <> 0) and (f2 <>0) and + ((_f1>fpc_mul_qword) or (f2>fpc_mul_qword)) then + HandleErrorFrame(215,get_frame); + end; + end; + +{ + $Log$ + Revision 1.1 2003-09-14 11:34:13 peter + * moved int64 asm code to int64p.inc + * save ebx,esi + +} diff --git a/rtl/inc/int64.inc b/rtl/inc/int64.inc index b8e99a1f63..fc3f31ab3e 100644 --- a/rtl/inc/int64.inc +++ b/rtl/inc/int64.inc @@ -96,71 +96,17 @@ count_leading_zeros:=r; end; + +{$ifndef FPC_SYSTEM_HAS_DIV_QWORD} function fpc_div_qword(n,z : qword) : qword;[public,alias: 'FPC_DIV_QWORD']; {$ifdef hascompilerproc} compilerproc; {$endif} var shift,lzz,lzn : longint; - { one : qword; } begin fpc_div_qword:=0; if n=0 then HandleErrorFrame(200,get_frame); -{$ifdef i386} - { the following piece of code is taken from the } - { AMD Athlon Processor x86 Code Optimization manual } - asm - movl n+4,%ecx - movl n,%ebx - movl z+4,%edx - movl z,%eax - testl %ecx,%ecx - jnz .Lqworddivbigdivisor - cmpl %ebx,%edx - jae .Lqworddivtwo_divs - divl %ebx - movl %ecx,%edx - leave - ret $16 - - .Lqworddivtwo_divs: - movl %eax,%ecx - movl %edx,%eax - xorl %edx,%edx - divl %ebx - xchgl %ecx,%eax - divl %ebx - movl %ecx,%edx - leave - ret $16 - - .Lqworddivbigdivisor: - movl %ecx,%edi - shrl $1,%edx - rcrl $1,%eax - rorl $1,%edi - rcrl $1,%ebx - bsrl %ecx,%ecx - shrdl %cl,%edi,%ebx - shrdl %cl,%edx,%eax - shrl %cl,%edx - roll $1,%edi - divl %ebx - movl z,%ebx - movl %eax,%ecx - imull %eax,%edi - mull n - addl %edi,%edx - subl %eax,%ebx - movl %ecx,%eax - movl z+4,%ecx - sbbl %edx,%ecx - sbbl $0,%eax - xorl %edx,%edx - leave - ret $16 - end; -{$else i386} lzz:=count_leading_zeros(z); lzn:=count_leading_zeros(n); { if the denominator contains less zeros } @@ -179,9 +125,11 @@ dec(shift); n:=n shr 1; until shift<0; -{$endif i386} end; +{$endif FPC_SYSTEM_HAS_DIV_QWORD} + +{$ifndef FPC_SYSTEM_HAS_MOD_QWORD} function fpc_mod_qword(n,z : qword) : qword;[public,alias: 'FPC_MOD_QWORD']; {$ifdef hascompilerproc} compilerproc; {$endif} var @@ -191,66 +139,6 @@ fpc_mod_qword:=0; if n=0 then HandleErrorFrame(200,get_frame); -{$ifdef i386_not_working_correct} - { the following piece of code is taken from the } - { AMD Athlon Processor x86 Code Optimization manual } - asm - movl n+4,%ecx - movl n,%ebx - movl z+4,%edx - movl z,%eax - testl %ecx,%ecx - jnz .Lqwordmodr_big_divisior - cmpl %ebx,%edx - jae .Lqwordmodr_two_divs - divl %ebx - movl %edx,%eax - movl %ecx,%edx - leave - ret $16 - - .Lqwordmodr_two_divs: - movl %eax,%ecx - movl %edx,%eax - xorl %edx,%edx - divl %ebx - movl %ecx,%eax - divl %ebx - movl %edx,%eax - xorl %edx,%edx - leave - ret $16 - - .Lqwordmodr_big_divisior: - movl %ecx,%edi - shrl $1,%edx - rcrl $1,%eax - rorl $1,%edi - rcrl $1,%ebx - bsrl %ecx,%ecx - shrdl %cl,%edi,%ebx - shrdl %cl,%edx,%eax - shrl %cl,%edx - rorl $1,%edi - divl %ebx - movl z,%ebx - movl %eax,%ecx - imull %eax,%edi - mull n - addl %edi,%edx - subl %eax,%ebx - movl z+4,%ecx - movl n,%eax - sbbl %edx,%ecx - sbbl %edx,%edx - andl %edx,%eax - andl n+4,%edx - addl %ebx,%eax - adcl %ecx,%edx - leave - ret $16 - end; -{$else i386} lzz:=count_leading_zeros(z); lzn:=count_leading_zeros(n); { if the denominator contains less zeros } @@ -270,9 +158,11 @@ n:=n shr 1; until shift<0; fpc_mod_qword:=z; -{$endif i386} end; +{$endif FPC_SYSTEM_HAS_MOD_QWORD} + +{$ifndef FPC_SYSTEM_HAS_DIV_INT64} function fpc_div_int64(n,z : int64) : int64;[public,alias: 'FPC_DIV_INT64']; {$ifdef hascompilerproc} compilerproc; {$endif} var @@ -307,7 +197,10 @@ fpc_div_int64:=q1 div q2; end; end; +{$endif FPC_SYSTEM_HAS_DIV_INT64} + +{$ifndef FPC_SYSTEM_HAS_MOD_INT64} function fpc_mod_int64(n,z : int64) : int64;[public,alias: 'FPC_MOD_INT64']; {$ifdef hascompilerproc} compilerproc; {$endif} var @@ -340,7 +233,10 @@ else fpc_mod_int64:=r; end; +{$endif FPC_SYSTEM_HAS_MOD_INT64} + +{$ifndef FPC_SYSTEM_HAS_MUL_QWORD} { multiplies two qwords the longbool for checkoverflow avoids a misaligned stack } @@ -350,40 +246,7 @@ _f1,bitpos : qword; l : longint; -{$ifdef i386} - r : qword; -{$endif i386} - begin -{$ifdef i386} - if not(checkoverflow) then - begin - { the following piece of code is taken from the } - { AMD Athlon Processor x86 Code Optimization manual } - asm - movl f1+4,%edx - movl f2+4,%ecx - orl %ecx,%edx - movl f2,%edx - movl f1,%eax - jnz .Lqwordmultwomul - mull %edx - jmp .Lqwordmulready - .Lqwordmultwomul: - imul f1+4,%edx - imul %eax,%ecx - addl %edx,%ecx - mull f2 - add %ecx,%edx - .Lqwordmulready: - movl %eax,r - movl %edx,r+4 - end; - fpc_mul_qword:=r; - end - else -{$endif i386} - begin fpc_mul_qword:=0; bitpos:=1; @@ -404,9 +267,11 @@ if checkoverflow and (_f1 <> 0) and (f2 <>0) and ((_f1>fpc_mul_qword) or (f2>fpc_mul_qword)) then HandleErrorFrame(215,get_frame); - end; end; +{$endif FPC_SYSTEM_HAS_MUL_QWORD} + +{$ifndef FPC_SYSTEM_HAS_MUL_INT64} function fpc_mul_int64(f1,f2 : int64;checkoverflow : longbool) : int64;[public,alias: 'FPC_MUL_INT64']; {$ifdef hascompilerproc} compilerproc; {$endif} var @@ -448,6 +313,8 @@ fpc_mul_int64:=q3; end; end; +{$endif FPC_SYSTEM_HAS_MUL_INT64} + procedure qword_str(value : qword;var s : string); @@ -463,6 +330,7 @@ s:=hs; end; + procedure int64_str(value : int64;var s : string); var @@ -480,6 +348,7 @@ qword_str(qword(value),s); end; + procedure fpc_shortstr_qword(v : qword;len : longint;var s : shortstring);[public,alias:'FPC_SHORTSTR_QWORD']; {$ifdef hascompilerproc} compilerproc; {$endif} begin @@ -641,7 +510,11 @@ { $Log$ - Revision 1.21 2003-09-03 14:09:37 florian + Revision 1.22 2003-09-14 11:34:13 peter + * moved int64 asm code to int64p.inc + * save ebx,esi + + Revision 1.21 2003/09/03 14:09:37 florian * arm fixes to the common rtl code * some generic math code fixed * ... diff --git a/rtl/inc/system.inc b/rtl/inc/system.inc index aa056fe50c..8e6a45bc74 100644 --- a/rtl/inc/system.inc +++ b/rtl/inc/system.inc @@ -245,6 +245,7 @@ end; {$i sstrings.inc} { requires sstrings.inc for initval } +{$I int64p.inc} {$I int64.inc} {Requires int64.inc, since that contains the VAL functions for int64 and qword} @@ -767,7 +768,11 @@ end; { $Log$ - Revision 1.42 2003-09-03 14:09:37 florian + Revision 1.43 2003-09-14 11:34:13 peter + * moved int64 asm code to int64p.inc + * save ebx,esi + + Revision 1.42 2003/09/03 14:09:37 florian * arm fixes to the common rtl code * some generic math code fixed * ... diff --git a/rtl/linux/i386/syscall.inc b/rtl/linux/i386/syscall.inc index f38fc83605..e2a5f062bf 100644 --- a/rtl/linux/i386/syscall.inc +++ b/rtl/linux/i386/syscall.inc @@ -19,7 +19,7 @@ {$ASMMODE ATT} -function FpSysCall(sysnr:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL0']; +function FpSysCall(sysnr:TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL0']; asm { load the registers... } @@ -49,7 +49,7 @@ asm .LSyscOK: end; -function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL1']; +function FpSysCall(sysnr,param1 : TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL1']; asm { load the registers... } @@ -80,7 +80,7 @@ asm .LSyscOK: end; -function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL2']; +function FpSysCall(sysnr,param1,param2 : TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL2']; asm { load the registers... } @@ -112,7 +112,7 @@ asm .LSyscOK: end; -function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL3']; +function FpSysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL3']; asm { load the registers... } @@ -145,7 +145,7 @@ asm .LSyscOK: end; -function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL4']; +function FpSysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL4']; asm { load the registers... } @@ -179,7 +179,7 @@ asm .LSyscOK: end; -function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL5']; +function FpSysCall(sysnr,param1,param2,param3,param4,param5 : TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL5']; asm { load the registers... } @@ -216,7 +216,7 @@ end; {$ifdef notsupported} { Only 5 params are pushed, so it'll not work as expected (PFV) } -function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;[public,alias:'FPC_SYSCALL6']; +function FpSysCall(sysnr,param1,param2,param3,param4,param5,param6 : TSysParam):TSysResult; assembler;{$ifndef VER1_0}oldfpccall;{$endif}[public,alias:'FPC_SYSCALL6']; asm { load the registers... } @@ -261,7 +261,7 @@ end; --- Main:The System Call Self --- *****************************************************************************} -Procedure FpSysCall( callnr:TSysParam;var regs : SysCallregs );assembler; +Procedure FpSysCall( callnr:TSysParam;var regs : SysCallregs );assembler;{$ifndef VER1_0}oldfpccall;{$endif} { This function puts the registers in place, does the call, and then copies back the registers as they are after the SysCall. @@ -341,7 +341,11 @@ end; { $Log$ - Revision 1.7 2002-12-24 19:45:59 peter + Revision 1.8 2003-09-14 11:34:13 peter + * moved int64 asm code to int64p.inc + * save ebx,esi + + Revision 1.7 2002/12/24 19:45:59 peter * only set errno when syscall fails Revision 1.6 2002/12/23 21:17:53 peter diff --git a/rtl/linux/i386/syscallh.inc b/rtl/linux/i386/syscallh.inc index 3f32de3665..0394a9931a 100644 --- a/rtl/linux/i386/syscallh.inc +++ b/rtl/linux/i386/syscallh.inc @@ -34,19 +34,23 @@ Type TSysParam = Longint; -function Do_SysCall(sysnr:TSysParam):TSysResult; external name 'FPC_SYSCALL0'; -function Do_SysCall(sysnr,param1:TSysParam):TSysResult; external name 'FPC_SYSCALL1'; -function Do_SysCall(sysnr,param1,param2:TSysParam):TSysResult; external name 'FPC_SYSCALL2'; -function Do_SysCall(sysnr,param1,param2,param3:TSysParam):TSysResult; external name 'FPC_SYSCALL3'; -function Do_SysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult; external name 'FPC_SYSCALL4'; -function Do_SysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; external name 'FPC_SYSCALL5'; +function Do_SysCall(sysnr:TSysParam):TSysResult;{$ifndef VER1_0}oldfpccall;{$endif}external name 'FPC_SYSCALL0'; +function Do_SysCall(sysnr,param1:TSysParam):TSysResult;{$ifndef VER1_0}oldfpccall;{$endif}external name 'FPC_SYSCALL1'; +function Do_SysCall(sysnr,param1,param2:TSysParam):TSysResult; {$ifndef VER1_0}oldfpccall;{$endif}external name 'FPC_SYSCALL2'; +function Do_SysCall(sysnr,param1,param2,param3:TSysParam):TSysResult;{$ifndef VER1_0}oldfpccall;{$endif}external name 'FPC_SYSCALL3'; +function Do_SysCall(sysnr,param1,param2,param3,param4:TSysParam):TSysResult;{$ifndef VER1_0}oldfpccall;{$endif}external name 'FPC_SYSCALL4'; +function Do_SysCall(sysnr,param1,param2,param3,param4,param5:TSysParam):TSysResult; {$ifndef VER1_0}oldfpccall;{$endif}external name 'FPC_SYSCALL5'; {$ifdef notsupported} -function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; external name 'FPC_SYSCALL6'; +function Do_SysCall(sysnr,param1,param2,param3,param4,param5,param6:TSysParam):TSysResult; {$ifndef VER1_0}oldfpccall;{$endif}external name 'FPC_SYSCALL6'; {$endif notsupported} { $Log$ - Revision 1.4 2003-07-06 21:26:10 peter + Revision 1.5 2003-09-14 11:34:13 peter + * moved int64 asm code to int64p.inc + * save ebx,esi + + Revision 1.4 2003/07/06 21:26:10 peter * syscall6 alias fixed Revision 1.3 2002/12/18 20:41:33 peter diff --git a/rtl/powerpc/int64p.inc b/rtl/powerpc/int64p.inc new file mode 100644 index 0000000000..3473efad9e --- /dev/null +++ b/rtl/powerpc/int64p.inc @@ -0,0 +1,23 @@ +{ + $Id$ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by the Free Pascal development team + + This file contains some helper routines for int64 and qword + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{ + $Log$ + Revision 1.1 2003-09-14 11:34:13 peter + * moved int64 asm code to int64p.inc + * save ebx,esi + +} diff --git a/rtl/sparc/int64p.inc b/rtl/sparc/int64p.inc new file mode 100644 index 0000000000..3473efad9e --- /dev/null +++ b/rtl/sparc/int64p.inc @@ -0,0 +1,23 @@ +{ + $Id$ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by the Free Pascal development team + + This file contains some helper routines for int64 and qword + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{ + $Log$ + Revision 1.1 2003-09-14 11:34:13 peter + * moved int64 asm code to int64p.inc + * save ebx,esi + +}