Division by zero

2007-02-09 Thread Jie Zhang
Hi, Division by zero is undefined. We chose to keep it: http://gcc.gnu.org/ml/gcc-patches/2001-06/msg01068.html But now gcc seems to optimize it away. For the following function: $ cat t.c #include void foo (int rc) { int x = rc / INT_MAX; x = 4 / x; } $ gcc -O2 -S t.c $ cat t.s

Re: Division by zero

2007-02-09 Thread Ian Lance Taylor
"Jie Zhang" <[EMAIL PROTECTED]> writes: > But now gcc seems to optimize it away. For the following function: > > $ cat t.c > #include > void foo (int rc) > { > int x = rc / INT_MAX; > x = 4 / x; > } I believe we still keep division by zero in

Re: Division by zero

2007-02-10 Thread Robert Dewar
Ian Lance Taylor wrote: "Jie Zhang" <[EMAIL PROTECTED]> writes: But now gcc seems to optimize it away. For the following function: $ cat t.c #include void foo (int rc) { int x = rc / INT_MAX; x = 4 / x; } I believe we still keep division by zero in general. In your

Re: Division by zero

2007-02-10 Thread Jie Zhang
oo (int rc) >> { >> int x = rc / INT_MAX; >> x = 4 / x; >> } > > I believe we still keep division by zero in general. In your example > it gets optimized away because it is dead code. Nothing uses x. And it is certainly reasonable to do this optimization given

Re: Division by zero

2007-02-10 Thread Steven Bosscher
On 2/10/07, Jie Zhang <[EMAIL PROTECTED]> wrote: The code I posted in my first email is from libgloss/libnosys/_exit.c. It's used to cause an exception deliberately. From your replies, it seems it should find another way to do that. Maybe you can use __builtin_trap() ? Gr. Steven

Re: Division by zero

2007-02-10 Thread Robert Dewar
Jie Zhang wrote: The code I posted in my first email is from libgloss/libnosys/_exit.c. It's used to cause an exception deliberately. From your replies, it seems it should find another way to do that. Any code that tries to raise an exception deliberately is certainly depending on undefined be

Re: Division by zero

2007-02-10 Thread Jie Zhang
On 2/10/07, Robert Dewar <[EMAIL PROTECTED]> wrote: Jie Zhang wrote: > The code I posted in my first email is from libgloss/libnosys/_exit.c. > It's used to cause an exception deliberately. From your replies, it > seems it should find another way to do that. Any code that tries to raise an exce

Re: Division by zero

2007-02-10 Thread Jie Zhang
On 2/10/07, Steven Bosscher <[EMAIL PROTECTED]> wrote: On 2/10/07, Jie Zhang <[EMAIL PROTECTED]> wrote: > The code I posted in my first email is from libgloss/libnosys/_exit.c. > It's used to cause an exception deliberately. From your replies, it > seems it should find another way to do that. Ma

Re: Division by zero

2007-02-10 Thread Paolo Bonzini
I'm going to use an asm (). Yeah, an asm volatile ("" : : "r" (x) : ) should please GCC and still be portable to different platforms. Paolo

Re: Division by zero

2007-02-10 Thread Jie Zhang
On 2/11/07, Paolo Bonzini <[EMAIL PROTECTED]> wrote: > I'm going to use an asm (). Yeah, an asm volatile ("" : : "r" (x) : ) should please GCC and still be portable to different platforms. I thought using an asm () for each port to cause an exception specific for that port. Such that divide-b

Re: Division by zero

2007-02-12 Thread Bernd Jendrissek
gt; > >> $ cat t.c > >> #include > >> void foo (int rc) > >> { > >> int x = rc / INT_MAX; > >> x = 4 / x; > >> } > > > > I believe we still keep division by zero in general. In your example > > it gets optimized aw

Division by zero on A53 which does not raise an exception

2022-11-28 Thread Stephen Smith via Gcc
I am working on a project which is using an A53 core. The core does not raise an exception if there is a division by zero (for either integer or floating point division). The designers chose to set status bits for the floating point case but not raise an exception.With the integer

Re: Division by zero on A53 which does not raise an exception

2022-11-29 Thread Richard Biener via Gcc
On Tue, Nov 29, 2022 at 5:39 AM Stephen Smith via Gcc wrote: > > I am working on a project which is using an A53 core. The core does not > raise an exception if there is a division by zero (for either integer or > floating point division). > > The designers chose to set s

Re: Division by zero on A53 which does not raise an exception

2022-11-29 Thread Szabolcs Nagy via Gcc
The 11/28/2022 21:37, Stephen Smith via Binutils wrote: > I am working on a project which is using an A53 core. The core does not > raise an exception if there is a division by zero (for either integer or > floating point division). floating-point division by zero signals the FE_