Hi,
I have little experience with 64 bit programming, since my main platform is still 32 bit. I did some tests now on my 64 bit linux box and it seems, that the same code compiled to 64 bit is about twice as SLOW as on 32 bit windows!
I am a little bit puzzled now, because I expected it to be faster (or as least equal). I tweaked a little bit and changed some variables in tight loops explicitly from Int to Int32. This seems to increase the speed at about 10-20%, but still the code is much slower as on 32 bit. Has anybody an explanation of this ? And if my feeling is right, that 32 bit operations are faster than 64bit operations on a 64bit machine, doesn't it make sense to define Int to be 32 bit on both platforms (even if this breaks some code) ?
that the same code compiled to 64 bit is about twice as SLOW as on 32 bit windows!
Using 64bit has several impacts (not nim specific): 1- there are more registers available which should increase performance as the 32bit x86 has only a few registers available (this is x86 specific). 2-64bit operations are available which speed up 64bit computations if you use them. 3-All x86-64 CPU have SSE2(? from memory), so the compiler can generate better code for floating point that 'base' x86 4-integers and pointers use two times more memory and cache which reduce performance. 5-code which has hand coded assembly language for x86 but not for x86-64 revert to generic C code which is slower usually.
I guess that you're seeing the effect of (4), so you should use int32 instead of int, maybe using 32bit integer index instead of pointer, checking that the order of elements in the generated struct doesn't have too much padding would help too.
On Linux, they're creating a new ABI named "x32" to have 32bit pointers on userspace programs but with the CPU in 64bit mode: this will allow to have the 'best of both world' from a performance point of view: more registers and 32bit pointers (for application using less than 4GB of RAM).. Note that this ABI isn't available yet (it has been included in the kernel very recently).
yes that's what I have thought of - using Int32 instead of Int and Int32 indexes. But there is a problem, that many [] expect a Int index not a Int32 index:
var data: array[0..5, int]
var x: Int32 = 0
echo data[x]
this does not compile under 64 bit - I think nimrod is a little bit strict here, because 0..5 could be any from Int8 up
Unsigned integers have recently been added and so this part of the language is still in flux; I haven't even implemented yet the design I have in mind... ;-)
Thanks for posting these results, I'll take them into consideration.
hey your work is great! I saw the improvements with closures and unsigned ints. Can't wait for 0.9
Besides that there are still things missing in nimrod, I haven't had so much with fun with programming since a long time.