[Issue 10287] std.random.uniform is very slow with dmd
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 6 17:54:28 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10287
--- Comment #1 from bearophile_hugs at eml.cc 2013-06-06 17:54:27 PDT ---
This alternative version of the program is handy to produce a more readable asm
output:
import core.stdc.stdio: printf;
import core.stdc.stdlib: atoi;
import std.random: Xorshift, uniform;
uint randomSum(in uint n, Xorshift rng) {
uint total = 0;
for (uint i = 0; i < n; i++)
total += uniform(0, 10, rng);
return total;
}
void main(in string[] args) {
immutable uint N = (args.length == 2) ?
atoi((args[1] ~ '\0').ptr) :
1_000;
auto rng = Xorshift(0);
immutable result = randomSum(N, rng);
printf("%u\n", result);
}
LDC2 produces for the randomSum() function (the inner loop is 26 instructions
long, with no call instructions):
__D4temp9randomSumFxkS3std6random38__T14XorshiftEngineTkVi128Vi11Vi8Vi19Z14XorshiftEngineZk:
pushl %ebp
pushl %ebx
pushl %edi
pushl %esi
pushl %eax
xorl %eax, %eax
cmpl $0, 40(%esp)
je LBB0_5
leal 24(%esp), %ecx
movl 8(%ecx), %esi
movl (%ecx), %eax
movl 4(%ecx), %edx
movl 12(%ecx), %ebp
xorl %ebx, %ebx
movl $0, (%esp)
.align 16, 0x90
LBB0_2:
movl %esi, %edi
movl %edx, %ecx
movl %ebp, %esi
movl %eax, %ebp
shll $11, %ebp
xorl %eax, %ebp
movl %esi, %eax
shrl $19, %eax
xorl %esi, %eax
xorl %ebp, %eax
shrl $8, %ebp
xorl %eax, %ebp
cmpl $-7, %esi
movl %edi, %edx
movl %ecx, %eax
ja LBB0_2
movl %esi, %eax
movl $671088641, %edx
mull %edx
shrl $26, %edx
addl %edx, (%esp)
incl %ebx
cmpl 40(%esp), %ebx
movl %edi, %edx
movl %ecx, %eax
jne LBB0_2
leal 24(%esp), %eax
movl %ebp, 12(%eax)
movl %ecx, (%eax)
movl %edi, 4(%eax)
movl %esi, 8(%eax)
movl (%esp), %eax
LBB0_5:
addl $4, %esp
popl %esi
popl %edi
popl %ebx
popl %ebp
ret $20
Maybe it's also a matter of missed inlining.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list