Array reverse

2012-11-23 Thread bearophile
I've seen a difference in the performance of std.algorithm.reverse applied on an array compared to home-made code, so I have written a little test. Below you see the code, and the asm of the functions, compiled with DMD 2.060, 32 bit (-O -release -inline). Feel free to recompile the code you

Re: Array reverse

2012-11-23 Thread monarch_dodra
On Friday, 23 November 2012 at 09:14:20 UTC, bearophile wrote: I've seen a difference in the performance of std.algorithm.reverse applied on an array compared to home-made code, so I have written a little test. Below you see the code, and the asm of the functions, compiled with DMD 2.060, 32

Re: Array reverse

2012-11-23 Thread Walter Bright
On 11/23/2012 1:14 AM, bearophile wrote: Feel free to recompile the code yourself to see if I have done some mistake :-) You've got array bounds checking turned on for algorithm.reverse, and you avoided that in your code by using unchecked pointers.

Re: Array reverse

2012-11-27 Thread bearophile
Walter Bright: Sorry for the late reply. You've got array bounds checking turned on for algorithm.reverse, and you avoided that in your code by using unchecked pointers. Right, sorry. This is compiled with the latest DMD 2.061alpha with -O -release -inline -noboundscheck. I have used the sa

Re: Array reverse

2012-11-27 Thread bearophile
monarch_dodra: Could you maybe also add this in your study? void reverseArr(T)(T[] arr) { for (auto x = arr.ptr, y = &arr[$ - 1]; x < y; ) swap(*x++, *y--); } This is the full program: import core.stdc.stdio: printf; import std.algorithm: reverse, swap; void reverseArr(T)(T[] a

Re: Array reverse

2012-11-28 Thread David Nadlinger
On Wednesday, 28 November 2012 at 00:19:33 UTC, bearophile wrote: dpaste is currently down and I don't have gdc2/dc2 installed here, so I can't show the asm from those other compilers. fwiw, here is what LDC produces: --- _D4test18__T10reverseArrTiZ10reverseArrFAiZv: lea RAX, QWORD