This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Error at division by constant zero


Well, I did not state my point clearly enough.

>From the external point of view it is best to keep the 
operation, either as instruction or as libcall.

But the decision whether it is one or the other should be
based on the same rules as for a division by a dynamic value.

In the current code (3.0.4) the decision for a constant 0 is based
on whether there is a shift instruction, wheras the decision
for a variable is based on a divide instruction. This discrepancy
is the mistake I see in the source.

	Erwin

Erwin Unruh, Fujitsu Siemens Computers, C/C++ compiler group


> -----Original Message-----
> From: Andrew Haley [mailto:aph@cambridge.redhat.com]
> Sent: Freitag, 23. August 2002 11:13
> To: Unruh, Erwin
> Cc: gcc@gcc.gnu.org; yasir999@hotmail.com
> Subject: Error at division by constant zero
> 
> 
> Unruh, Erwin writes:
> 
>  > When dividing an integer by constant zero, the GCC does 
> emit a library call to
>  > the corresponding routine. On Sparc this is .rem or .div, 
> on Linux this might be
>  > __modsi3 or __divsi3.
>  > 
>  > I think this is an error in expand_divmod. 
> EXACT_POWER_OF_2_OR_ZERO_P gives
>  > true. So we think we could use a shift optab.
> 
> For division by zero?  How?
> 
> Division by zero is an undefined operation in C - see ISO 9899 Section
> 6.3.5.  So, in theory we can do anything.  But, what is the most
> useful "anything" we can do?  We have chosen to preserve division by
> zero so that if the processor has a divide overflow trap we'll get one
> at runtime.  Also, some languages (such as Java) can trap divide
> overlows overflow and we need that behaviour.
> 
> Andrew.
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]