www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DMD: slow coping for small static arrays.

reply "Ilya Yaroshenko" <ilyayaroshenko gmail.com> writes:
I have found that DMD can not optimise array coping for small 
static arrays:

Code:
-----------------------------------
size_t[8] foo(size_t[8] x)
{
   size_t[8] ret = void;
   ret[0..3] = x[5..8];
   ret[3..8] = x[0..5];
   return ret;
}
-----------------------------------

DMD (nightly build): http://goo.gl/CAufv8
-----------------------------------
ulong[8] example.foo(ulong[8]):
	push   rbp
	mov    rbp,rsp
	sub    rsp,0x10
	mov    QWORD PTR [rbp-0x8],rdi
	mov    edx,0x18
	lea    rsi,[rbp+0x38]
	call   1a <ulong[8] example.foo(ulong[8])+0x1a>
	mov    edx,0x28
	lea    rsi,[rbp+0x10]
	mov    rax,QWORD PTR [rbp-0x8]
	lea    rdi,[rax+0x18]
	call   30 <ulong[8] example.foo(ulong[8])+0x30>
	mov    rax,QWORD PTR [rbp-0x8]
	mov    rsp,rbp
	pop    rbp
	ret
	add    BYTE PTR [rax],al
	...
-----------------------------------

GDC 4.2: http://goo.gl/RdcjeV
-----------------------------------
uint[8] example.foo(uint[8]):
	movl	4(%esp), %eax
	movl	28(%esp), %edx
	movl	%edx, (%eax)
	movl	32(%esp), %edx
	movl	%edx, 4(%eax)
	movl	36(%esp), %edx
	movl	%edx, 8(%eax)
	movl	8(%esp), %ecx
	movl	%ecx, 12(%eax)
	movl	12(%esp), %ecx
	movl	%ecx, 16(%eax)
	movl	16(%esp), %ecx
	movl	%ecx, 20(%eax)
	movl	20(%esp), %ecx
	movl	%ecx, 24(%eax)
	movl	24(%esp), %ecx
	movl	%ecx, 28(%eax)
	ret	$4
-----------------------------------

Fast coping is important for new N-demensional ranges 
https://github.com/D-Programming-Language/phobos/pull/3397 .

I want to know should I write a work around for DMD OR DMD would 
be fixed during this year?
Jul 19 2015
parent reply "Ilya Yaroshenko" <ilyayaroshenko gmail.com> writes:
 GDC 4.2: http://goo.gl/RdcjeV
GDC 4.9.2
Jul 19 2015
parent reply "Temtaime" <temtaime gmail.com> writes:
On Sunday, 19 July 2015 at 08:09:18 UTC, Ilya Yaroshenko wrote:
 GDC 4.2: http://goo.gl/RdcjeV
GDC 4.9.2
Just use GDC. DMD is a reference compiler, it generates suboptimal code all the time.
Jul 19 2015
parent "jmh530" <john.michael.hall gmail.com> writes:
On Sunday, 19 July 2015 at 09:03:08 UTC, Temtaime wrote:
 On Sunday, 19 July 2015 at 08:09:18 UTC, Ilya Yaroshenko wrote:
 GDC 4.2: http://goo.gl/RdcjeV
GDC 4.9.2
Just use GDC. DMD is a reference compiler, it generates suboptimal code all the time.
I feel like this is not the most helpful comment...
Jul 20 2015