Re: [eigen] Signed or unsigned indexing |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: Re: [eigen] Signed or unsigned indexing*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Sat, 21 Jan 2017 22:56:09 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=6wWcxDb1CSxTkV/EagrFLdS4DIIejaQo5bCbts4+c/Q=; b=U5ll9CVDBfqslyVGJ2dNMT0VmgmNCvMFg7Bv9y8o1Vzo2Nt0kjKe6gP5PWucmjiRqe 0Xvw3KU8q0VvP4FOwxXX4BcNhMqfHo1rzbo7hMm3/cESkw6hoZit9izXD2+0hcZ5aj9s D+puV+8+x48R+rgk+Jm7KhullBsWs1Xw3uUaah9KaYf6hkVfwh5R8Cd4rvvW0+LkTuA+ 5jNts24yl1mBHrQ5/TfClVUjRo6GU3vEkV1yihV6snAiT4KJGHxjuJF56q8HF/INMy3j S2IncMlV4VYoM7nQrgJ/flmzFQIaNk8OdtBwEpCpXfDrjadq6MN1/pj5I6dc8SjSlypx H/Vg==

On Sat, Jan 21, 2017 at 12:40 PM, Francois Fayard <fayard@xxxxxxxxxxxxx> wrote:

> 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).

That's easy to check, I simply measured:

EIGEN_DONT_INLINE

void foo(MatrixXf &A, MatrixXf &B, Index i, Index j, Index n, Index m)

{

A.block(i, j, n, m) += B.block(i+1, j+1, n, m);

}

and got 15% of speed difference between int and ptrdiff_t using either gcc6 or clang3.9.

> 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?v=yG1OZ69H_-o

I measured the conversion of 1000 integers from 'int' or 'unsigned int' to 'long' and observe 25% of speed difference using either clang or gcc (in favour of unsigned int). But, when used to index another buffer, like data[indices[i]] as in sparse stuff, I cannot see any difference anymore.

gael

**Follow-Ups**:**Re: [eigen] Signed or unsigned indexing***From:*fayard

**References**:**[eigen] Signed or unsigned indexing***From:*Henrik Mannerström

**Re: [eigen] Signed or unsigned indexing***From:*Benoit Jacob

**Re: [eigen] Signed or unsigned indexing***From:*Francois Fayard

**Re: [eigen] Signed or unsigned indexing***From:*Mark Borgerding

**Re: [eigen] Signed or unsigned indexing***From:*Martin Beeger

**Re: [eigen] Signed or unsigned indexing***From:*François Fayard

**Re: [eigen] Signed or unsigned indexing***From:*Gael Guennebaud

**Re: [eigen] Signed or unsigned indexing***From:*Francois Fayard

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] eigen 3.3.1 upgrade** - Next by Date:
**[eigen] unsubscribe** - Previous by thread:
**Re: [eigen] Signed or unsigned indexing** - Next by thread:
**Re: [eigen] Signed or unsigned indexing**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |