The International Simutrans Forum

 

Author Topic: 64-bit compatibility  (Read 3454 times)

0 Members and 1 Guest are viewing this topic.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
64-bit compatibility
« on: May 13, 2009, 01:54:27 PM »
I am considering compiling a 64-bit version of Simutrans-Experimental for the Windows platform if I can, and I am wondering whether the base Simutrans code has any problems for 64-bit compatibility. In particular, I notice that there is a possible problem with the pointer hashtable: the hashing function just returns a 32-bit unsigned integer cast of the pointer, which works on 32-bit systems, but not on 64-bit systems, since 64-bit systems (using 64-bit applications) have 64-bit pointers.

Are there any other issues like this, does anyone know? Are there serious migration issues to a fully 64-bit build?

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10636
  • Languages: De,EN,JP
Re: 64-bit compatibility
« Reply #1 on: May 14, 2009, 08:48:49 AM »
A hastable cannot fail. Double keys are no problem, since anyway this value will be divided by 111 and the remaning number is taken for hashing. For the actual comparison long is used, which should be large enough for a point on any system according to C++99 standards, as far as I know.

The most serious issue may be the different systax for default int and long types of MSVC and gcc. What size is int on MSVC 64bit?

For simutrans using 64Bit is not helpful, since there will be a lot misalignments of structures. Also the map will be 30% more memory consuming (meaning more meory to be streamed through the processore, i.e. slow total speed).

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: 64-bit compatibility
« Reply #2 on: May 14, 2009, 11:57:44 AM »
Ahh, so you're saying that it will work better when compiled as 32-bit? The main reason that I am looking into it was because some 64-bit Linux users reported instability with Simutrans-Experimental...

Edit: Incidentally, in Windows and Linux (GCC), int is 32-bit on a 64-bit platform. There are some platforms on which int is 64-bit. The real problem is not so much int as long, which is 32-bit on Windows 32-and 64-bit, but 64-bit on Linux (GCC) 64-bit, while being 32-bit on Linux (GCC) 32-bit.
« Last Edit: May 14, 2009, 12:12:59 PM by jamespetts »

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10636
  • Languages: De,EN,JP
Re: 64-bit compatibility
« Reply #3 on: May 14, 2009, 12:44:42 PM »
long must be 64 bit on Windows64 (unfourtunately only the german page clear states this?). Everything else is a violation of the standard. I rather suspect int to be different. Since size_t returns a 64 bit values long must be 64bit. (Since you can define arrays >4GB with x64 architekture compilers).

On DOS, long could be even 16 bit, since the maximum size of a segment was 65536 bytes, and thus sizeof(void*)>sizeof(long). But for all flat memory models (as used with todays architectures) the definition that sizeof(DATA)<=largest long number automatically implies that on 64Bit OS long is 64bit.
« Last Edit: May 14, 2009, 12:51:06 PM by prissi »

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: 64-bit compatibility
« Reply #4 on: May 14, 2009, 12:53:17 PM »
The information on 64-bit types I obtained here.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10636
  • Languages: De,EN,JP
Re: 64-bit compatibility
« Reply #5 on: May 14, 2009, 07:33:46 PM »
Wonderful, Microsoft seems to indeed to violate the C++ standard that requires size_t<=long ... The only portable way seems to be to cast to size_t then. (http://www.viva64.com/content/articles/64-bit-development/?f=Optimization.html&lang=en&content=64-bit-development)

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: 64-bit compatibility
« Reply #6 on: May 14, 2009, 08:38:58 PM »
Casting - that's not good for performance, is it?

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10636
  • Languages: De,EN,JP
Re: 64-bit compatibility
« Reply #7 on: May 14, 2009, 08:47:05 PM »
Casting to size_t is actually a no-op, since the data are identical.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20774
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: 64-bit compatibility
« Reply #8 on: May 14, 2009, 08:54:13 PM »
Ahh, I see, interesting.