Saleem Abdulrasool
2014-Sep-09 01:18 UTC
[LLVMdev] [Compiler-RT] [ARM] Where __aeabi_[il]div0 builtins should be implemented?
On Mon, Sep 8, 2014 at 1:19 AM, Renato Golin <renato.golin at linaro.org> wrote:> > Why not adjust this instead? > > I was just being conservative. I don't know what else depends on this > library and I don't want to change things outside of my scope. >The current implementations actually return 0. Can you point out where that doesn't hold please? If you look at the generated code, in reality, the function is to spec as `bx lr'. The intent is that it provides a hook where you can break (without changing any state) OR replace it with the implementation that you prefer.> Since returning zero is consistent with the EABI, I don't think we > should deviate from that norm, not without a lot of thought, at least.Yes, although the current implementation also is consistent with EABI.> > We could use __rt_raise(2, 2), which would need to call signal as well, > so > > you end up growing a dependency on the target environment's libc > > implementation. I think that expanding the responsibility of compiler-rt > > from supporting the code generation from the compiler to integrating into > > the target environment's libc can be problematic. > > I wasn't proposing we signal, but that we return zero, instead of the > argument. >Fair enough. However, the point is that emulating GCC's behavior of the exception is what I was referring to.> Today we return either zero (in divmod/div/mod) or the argument (when > calling div0 directly), and that's just wrong.Quoting the RTABI: 1. int __aeabi_idiv0(int return_value); long long __aeabi_ldiv0(long long return_value); The *div0 functions: Return the value passed to them as a parameter. Is my copy out of date?> > Why 0 and not infinity? Or some other value? > > Because 0 is what it was before. > > cheers, > --renato >-- Saleem Abdulrasool compnerd (at) compnerd (dot) org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140908/c55283f0/attachment.html>
Renato Golin
2014-Sep-09 08:37 UTC
[LLVMdev] [Compiler-RT] [ARM] Where __aeabi_[il]div0 builtins should be implemented?
On 9 September 2014 02:18, Saleem Abdulrasool <compnerd at compnerd.org> wrote:> The current implementations actually return 0. Can you point out where that > doesn't hold please?With the current implementation... int foo(int a) { return __aeabi_idiv0(a); } returns 'a', while: int bar(int a) { return __aeabi_idiv(a, 0); } returns zero.> Quoting the RTABI: > > int __aeabi_idiv0(int return_value); > long long __aeabi_ldiv0(long long return_value); > > The *div0 functions: > > Return the value passed to them as a parameter. > > Is my copy out of date?As I said before, all three behaviours are allowed by the RTABI (exception, constant, parameter), but we now have two different behaviours in compiler-rt. This is a regression. We must make it consistent to what there was there before (return zero). If you *really* want to make it return the parameter or signal, we should discuss this properly, on another thread, but right now, division by zero in compiler-rt has to return zero. --renato
Saleem Abdulrasool
2014-Sep-10 05:39 UTC
[LLVMdev] [Compiler-RT] [ARM] Where __aeabi_[il]div0 builtins should be implemented?
On Tue, Sep 9, 2014 at 1:37 AM, Renato Golin <renato.golin at linaro.org> wrote:> On 9 September 2014 02:18, Saleem Abdulrasool <compnerd at compnerd.org> > wrote: > > The current implementations actually return 0. Can you point out where > that > > doesn't hold please? > > With the current implementation... > > int foo(int a) { > return __aeabi_idiv0(a); > } > > returns 'a', while: > > int bar(int a) { > return __aeabi_idiv(a, 0); > } > > returns zero. > > > > Quoting the RTABI: > > > > int __aeabi_idiv0(int return_value); > > long long __aeabi_ldiv0(long long return_value); > > > > The *div0 functions: > > > > Return the value passed to them as a parameter. > > > > Is my copy out of date? > > As I said before, all three behaviours are allowed by the RTABI > (exception, constant, parameter), but we now have two different > behaviours in compiler-rt. This is a regression. > > We must make it consistent to what there was there before (return > zero). If you *really* want to make it return the parameter or signal, > we should discuss this properly, on another thread, but right now, > division by zero in compiler-rt has to return zero.Oh! I think I see what the confusion is all about. __aeabi_[il]div0 are *NOT* division routines. They are handlers for the error case of division by zero. They do not perform a division by zero, they effectively are meant to trap the fact that a division by zero has occurred.> > --renato >-- Saleem Abdulrasool compnerd (at) compnerd (dot) org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140909/abf9b13e/attachment.html>