#369 fild/fistp memory copying doesn't work on non-i386 platforms

open
nobody
5
2012-09-07
2012-01-09
Nikolay Nikolov
No

The DOS version of the Free Pascal Compiler ( http://www.freepascal.org/ ) wouldn't run on non-i386 versions of DOSBox, so today I spent some time debugging DOSBox until I found the problem. Apparently FPC (and FPC-compiled programs) uses the FPU to copy memory blocks via the fild & fistp instructions, and since DOSBox converts int64 to double, some precision is lost and the data is garbled.

Here's how it looks:
http://vogons.zetafleet.com/viewtopic.php?t=24499&sid=9ae1bdc243d05d347f08553e7ad73c44

The reason some people are experiencing problems and others aren't is because dosbox on i386 uses the native x87 FPU and works fine. However 64-bit linux distros ship a 64-bit DOSBox, which doesn't work.

The problem affects not only Free Pascal, but also programs, compiled with it. Here's the code that breaks:
http://svn.freepascal.org/svn/fpc/trunk/rtl/i386/fastmove.inc
(procedures Forwards_IA32_3 and Backwards_IA32_3)

Apparently this weird method of copying data was the fastest way to copy data on the original Intel Pentium and Pentium MMX, so I it's probably also used in a lot of games from the Pentium era (and maybe other compilers as well).

Discussion