mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 14:09:20 +02:00
+ integer division-by-zero detection support for ppc
+ compilerproc FPC_DIVBYZERO
This commit is contained in:
parent
80429f91a1
commit
c2efd86268
@ -31,6 +31,7 @@ interface
|
|||||||
|
|
||||||
type
|
type
|
||||||
tppcmoddivnode = class(tmoddivnode)
|
tppcmoddivnode = class(tmoddivnode)
|
||||||
|
function pass_1: tnode;override;
|
||||||
procedure pass_2;override;
|
procedure pass_2;override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ implementation
|
|||||||
aasmbase,aasmcpu,aasmtai,
|
aasmbase,aasmcpu,aasmtai,
|
||||||
defutil,
|
defutil,
|
||||||
cgbase,cgobj,pass_1,pass_2,
|
cgbase,cgobj,pass_1,pass_2,
|
||||||
ncon,
|
ncon,procinfo,
|
||||||
cpubase,cpuinfo,
|
cpubase,cpuinfo,
|
||||||
ncgutil,cgcpu,cg64f32,rgobj;
|
ncgutil,cgcpu,cg64f32,rgobj;
|
||||||
|
|
||||||
@ -65,11 +66,20 @@ implementation
|
|||||||
TPPCMODDIVNODE
|
TPPCMODDIVNODE
|
||||||
*****************************************************************************}
|
*****************************************************************************}
|
||||||
|
|
||||||
|
function tppcmoddivnode.pass_1: tnode;
|
||||||
|
begin
|
||||||
|
result := inherited pass_1;
|
||||||
|
if not assigned(result) then
|
||||||
|
include(current_procinfo.flags,pi_do_call);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure tppcmoddivnode.pass_2;
|
procedure tppcmoddivnode.pass_2;
|
||||||
const
|
const
|
||||||
{ signed overflow }
|
{ signed overflow }
|
||||||
divops: array[boolean, boolean] of tasmop =
|
divops: array[boolean, boolean] of tasmop =
|
||||||
((A_DIVWU,A_DIVWUO_),(A_DIVW,A_DIVWO_));
|
((A_DIVWU,A_DIVWUO_),(A_DIVW,A_DIVWO_));
|
||||||
|
zerocond: tasmcond = (dirhint: DH_Plus; simple: true; cond:C_NE; cr: RS_CR1);
|
||||||
var
|
var
|
||||||
power : longint;
|
power : longint;
|
||||||
op : tasmop;
|
op : tasmop;
|
||||||
@ -77,6 +87,7 @@ implementation
|
|||||||
divider,
|
divider,
|
||||||
resultreg : tregister;
|
resultreg : tregister;
|
||||||
size : Tcgsize;
|
size : Tcgsize;
|
||||||
|
hl : tasmlabel;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
secondpass(left);
|
secondpass(left);
|
||||||
@ -124,6 +135,9 @@ implementation
|
|||||||
{ load divider in a register if necessary }
|
{ load divider in a register if necessary }
|
||||||
location_force_reg(exprasmlist,right.location,
|
location_force_reg(exprasmlist,right.location,
|
||||||
def_cgsize(right.resulttype.def),true);
|
def_cgsize(right.resulttype.def),true);
|
||||||
|
if (right.nodetype <> ordconstn) then
|
||||||
|
exprasmlist.concat(taicpu.op_reg_reg_const(A_CMPWI,NR_CR1,
|
||||||
|
right.location.register,0));
|
||||||
divider := right.location.register;
|
divider := right.location.register;
|
||||||
|
|
||||||
{ needs overflow checking, (-maxlongint-1) div (-1) overflows! }
|
{ needs overflow checking, (-maxlongint-1) div (-1) overflows! }
|
||||||
@ -153,6 +167,13 @@ implementation
|
|||||||
{ set result location }
|
{ set result location }
|
||||||
location.loc:=LOC_REGISTER;
|
location.loc:=LOC_REGISTER;
|
||||||
location.register:=resultreg;
|
location.register:=resultreg;
|
||||||
|
if right.nodetype <> ordconstn then
|
||||||
|
begin
|
||||||
|
objectlibrary.getlabel(hl);
|
||||||
|
exprasmlist.concat(taicpu.op_cond_sym(A_BC,zerocond,hl));
|
||||||
|
cg.a_call_name(exprasmlist,'FPC_DIVBYZERO');
|
||||||
|
cg.a_label(exprasmlist,hl);
|
||||||
|
end;
|
||||||
cg.g_overflowcheck(exprasmlist,location,resulttype.def);
|
cg.g_overflowcheck(exprasmlist,location,resulttype.def);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -513,7 +534,11 @@ begin
|
|||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.37 2003-12-31 18:12:23 jonas
|
Revision 1.38 2004-01-01 17:58:16 jonas
|
||||||
|
+ integer division-by-zero detection support for ppc
|
||||||
|
+ compilerproc FPC_DIVBYZERO
|
||||||
|
|
||||||
|
Revision 1.37 2003/12/31 18:12:23 jonas
|
||||||
* (64 bit int) shl/shr (value > 63) := 0
|
* (64 bit int) shl/shr (value > 63) := 0
|
||||||
|
|
||||||
Revision 1.36 2003/12/28 23:49:30 jonas
|
Revision 1.36 2003/12/28 23:49:30 jonas
|
||||||
|
@ -277,6 +277,7 @@ procedure fpc_largeset_contains_sets(set1,set2 : pointer; size: longint); compil
|
|||||||
{$endif LARGESETS}
|
{$endif LARGESETS}
|
||||||
|
|
||||||
procedure fpc_rangeerror; compilerproc;
|
procedure fpc_rangeerror; compilerproc;
|
||||||
|
procedure fpc_divbyzero; compilerproc;
|
||||||
procedure fpc_overflow; compilerproc;
|
procedure fpc_overflow; compilerproc;
|
||||||
//procedure fpc_iocheck(addr : longint); compilerproc;
|
//procedure fpc_iocheck(addr : longint); compilerproc;
|
||||||
procedure fpc_iocheck; compilerproc;
|
procedure fpc_iocheck; compilerproc;
|
||||||
@ -309,7 +310,11 @@ function fpc_qword_to_double(q: qword): double; compilerproc;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.50 2003-10-25 22:52:07 florian
|
Revision 1.51 2004-01-01 17:58:16 jonas
|
||||||
|
+ integer division-by-zero detection support for ppc
|
||||||
|
+ compilerproc FPC_DIVBYZERO
|
||||||
|
|
||||||
|
Revision 1.50 2003/10/25 22:52:07 florian
|
||||||
* fixed copy(<dynarray>, ...)
|
* fixed copy(<dynarray>, ...)
|
||||||
|
|
||||||
Revision 1.49 2003/10/04 23:40:42 florian
|
Revision 1.49 2003/10/04 23:40:42 florian
|
||||||
|
@ -512,6 +512,10 @@ begin
|
|||||||
HandleErrorFrame(201,get_frame);
|
HandleErrorFrame(201,get_frame);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure fpc_divbyzero;[public,alias:'FPC_DIVBYZERO']; {$ifdef hascompilerproc} compilerproc; {$endif}
|
||||||
|
begin
|
||||||
|
HandleErrorFrame(200,get_frame);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure fpc_overflow;[public,alias:'FPC_OVERFLOW']; {$ifdef hascompilerproc} compilerproc; {$endif}
|
procedure fpc_overflow;[public,alias:'FPC_OVERFLOW']; {$ifdef hascompilerproc} compilerproc; {$endif}
|
||||||
begin
|
begin
|
||||||
@ -853,7 +857,11 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.47 2003-11-03 09:42:28 marco
|
Revision 1.48 2004-01-01 17:58:16 jonas
|
||||||
|
+ integer division-by-zero detection support for ppc
|
||||||
|
+ compilerproc FPC_DIVBYZERO
|
||||||
|
|
||||||
|
Revision 1.47 2003/11/03 09:42:28 marco
|
||||||
* Peter's Cardinal<->Longint fixes patch
|
* Peter's Cardinal<->Longint fixes patch
|
||||||
|
|
||||||
Revision 1.46 2003/10/29 18:23:45 jonas
|
Revision 1.46 2003/10/29 18:23:45 jonas
|
||||||
|
Loading…
Reference in New Issue
Block a user