|Re: [eigen] Signed or unsigned indexing|
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
> On Jan 21, 2017, at 10:42 AM, Gael Guennebaud <gael.guennebaud@xxxxxxxxx> wrote:
> I remember we observed a clear speedup when we moved from int to ptrdiff_t in Eigen. That was before we release 2.0, so with much older compilers (gcc 4.2) and older hardware (core2).
I am not sure that you would see that with newer compilers. The reason is that the undefined behavior for overflow with signed integers allows 32-bit signed integers to be implemented as 64-bit signed integers when compiled if the compiler believes that this is useful. I am sure that this optimization was not made on earlier versions of compilers which is why you got a speedup at that time. I have not measured any difference with recent compilers except in very contrived examples like the one that is attached at the end of this email (with a recursive function).
> Actually, both questions are highly related because when you start mixing 32 and 64 bits integers, I have to admit that unsigned types win here because the conversion is a no op in this case, whereas signed types require a special treatment.
Even though I understand your point, I still disagree that unsigned integers win here. Performance is not always about counting operations, but more often about letting the compiler reason about the code. As I said before, a compiler is allowed to change your integer from 32-bit to 64-bit it thinks that it makes a difference. It is not allowed with unsigned integers.. Have a look at the concrete example from bzip2 given by Chandler Carruth at 39:20 on https://www.youtube.com/watch?
|Mail converted by MHonArc 2.6.19+||http://listengine.tuxfamily.org/|