Re: [eigen] find command or equivalent

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


interesting, here is how this is compiled by gcc 4.5:

..L418:
	leaq	(%rsi,%rdx), %rcx
	addq	$1, %rax
	addq	$4, %rdx
	cmpq	%rbx, %rax
	movss	(%rcx), %xmm0
	movaps	%xmm0, %xmm1
	movaps	%xmm0, %xmm3
	cmpnltss	%xmm2, %xmm1
	movaps	%xmm1, %xmm0
	andps	%xmm1, %xmm3
	andnps	%xmm4, %xmm0
	orps	%xmm3, %xmm0
	movss	%xmm0, (%rcx)
	jne	.L418

where %xmm2 contains 0.0001, and %xmm4 is initialized to zero
(xorps	%xmm4, %xmm4).

- Since GCC knows that %xmm4 == 0, it should be able to optimize away
these two instructions which have no effect:
	andnps	%xmm4, %xmm0
	orps	%xmm3, %xmm0

- It is also weird that it generates packet instructions while the
loop is not vectorized (andss, andnss, orss would be enough).

- there are too many movaps instructions.

here is what gcc should be able to easily generate:

..L418:
	leaq	(%rsi,%rdx), %rcx
	addq	$1, %rax
	addq	$4, %rdx
	cmpq	%rbx, %rax
	movss	(%rcx), %xmm0
	movaps	%xmm0, %xmm1
	cmpnltss	%xmm2, %xmm1
	andss	%xmm1, %xmm0
	movss	%xmm0, (%rcx)
	jne	.L418

maybe it is worth a bug report ?

gael

On Fri, Sep 3, 2010 at 9:19 AM, Gael Guennebaud
<gael.guennebaud@xxxxxxxxx> wrote:
> you can do:
>
> A = (A.array()<0.0001).select(0,A);
>
> where the "select" method mimics the c++ ?: operator.
>
> gael
>
>
> On Fri, Sep 3, 2010 at 6:40 AM, Suresh Kumar
> <suresh.amritapuri@xxxxxxxxx> wrote:
>> Hi
>> I want to replace all elements of a matrix, which are less than a threshold
>> by zero. How to do it without writing a nested for loop?
>> I am looking for something like this in matlab. A(A < 0.001) = 0 where A is
>> a matrix.
>> Thanks
>> suresh
>>
>> --
>> R Suresh Kumar,
>> http://www.ee.ucr.edu/~sramachandranna
>> --
>> Dhyaana–moolam Guror murtih
>> Puja-moolam Guroh padam
>> Mantra – moolam Guror vakyam
>> Moksha – moolam Guroh krpa.
>>
>



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