[eigen] Re: sse4 and integer multiplication |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] Re: sse4 and integer multiplication
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Tue, 24 Nov 2009 15:26:39 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=z2XxVd8wgasI2EpqLWx+O91R63Gu60ZuVEB5Y9aZpsc=; b=wg8W/aU9oF9NRzBvWo0+dmwURtBw0xBw6G+PRqLzhrqItnp0n7kGDQH3OQs+//pDM8 3sxrQ/DOSEI/9eL6c/Wkn37MCaCcJnWbFPVAXxnuxbjSvQR1y8UgG8VUeqpQZ4cvXwTQ qKvrM4JP68aFkxT9pC33OSnt9jN4HVUD4QPvA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=ox6eHeeTbDPhH7QMIh9ddwvAc28f3MGLoxT7YRJtUr52U8v2tygNneUPuTh4/4JxOW IAMXP18QmyZ1LVn+tA+D3saftuYHNDw9PYaFYmNz/mgF6LZF2Q4ZmBdhFOaMlUKq509d enIABKY0Y+YX7WqlXT1jmbgQKtYaYg7KCmp2w=
oooh.... it was able to optimize integer multiplications by 3/5/9 as
LEA (load effective address) instructions ??!!
This reminds me very vague memories...
Benoit
2009/11/24 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
> Hi,
>
> i just added SSE4 integer mul support. It is an improvement over the
> current vectorized integer multiplication where SSE4 is available, but
> i am puzzled: here is my benchmark:
>
>
>
> #include <Eigen/Dense>
> using namespace Eigen;
> using namespace std;
>
> EIGEN_DONT_INLINE void foo()
> {
> // i was wondering if the cpu could be clever enough to
> // optimize when the ints are 0 or 1; it's not so easy to
> // ensure that we don't end up with only 0 and 1...
>
> Vector4i v(5,-7,11,13);
> Vector4i w(9,3,-5,-7);
>
> for(int i = 0; i<100000000; i++)
> {
> EIGEN_ASM_COMMENT("begin");
> v = v.cwise()*v;
> v = v.cwise()*w;
> EIGEN_ASM_COMMENT("end");
> }
> cout << v << endl;
> }
>
> int main()
> {
> foo();
> }
>
>
>
> OK so i'm puzzled because the fastest is... with no vectorization at all.
>
> No vectorization: 0.57 sec
> With SSE4.1: 0.81 sec
> With SSE2: 1.21 sec
>
> So i did what i usually do in such circumstances: dump the assembly
> and go whine until daddy Gael takes care of me.
>
> Without vec:
>
> imull %edx, %edx
> imull %eax, %eax
> leal 0(,%rdx,8), %edi
> imull %ebx, %ebx
> leal (%rax,%rax,4), %eax
> imull %ecx, %ecx
> subl %edi, %edx
> negl %eax
> leal (%rbx,%rbx,8), %ebx
> leal (%rcx,%rcx,2), %ecx
>
> With SSE4.1:
>
> movdqa %xmm1, %xmm0
> pmulld %xmm1, %xmm0
> pmulld (%rdx), %xmm0
> movdqa %xmm0, %xmm1
> movdqa %xmm0, (%rbp)
>
> Cheers,
> Benoit
>