VOGONS


First post, by benjaminhei

User metadata
Rank Newbie
Rank
Newbie

Using this simple Basic program (compiled with Firstbasic, similar to Turbobasic) on DOSBox, the addition and modulo operations (maybe others as well) give wrong results when using over 15 digits on ARM processors (Snapdragon 410 and Cortex-A7).

The same program gives perfect results on Intel processors (N270 and i7).

Anybody any idea what this can be?

cls
defqud x,y,z '64 bit integer
x=435165264000000000 'age of universe in sec
for y=1 to 16
mtimer ‘starting the microtimer
z=(x+y) mod 16
print using "#####"; mtimer; y; z; : print " "; : print using ",&"; x+y
next y
end

Reply 1 of 5, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

probably the C fpu core vs the ASM (86) fpu core. The former has 64 bit as internal accuracy, while the latter has 80 bit.
Or a bug in the C fpu core.

Water flows down the stream
How to ask questions the smart way!

Reply 3 of 5, by Joey_sw

User metadata
Rank Oldbie
Rank
Oldbie

Intel use 80bits internally: https://en.wikipedia.org/wiki/Extended_precision
ARM based CPU usually shy away from using 80bits and using 64 bits instead: https://en.wikipedia.org/wiki/Double_precision

I would suspect that somehow the operations are not done in pure integer,
but may be converted into floating point operations somehow along the way.

To test it, try value less than 2^52 (double precision accuracy limit) and value greater than that.
In your example the x(+y) was 59 bits.

Last edited by Joey_sw on 2016-05-06, 09:47. Edited 1 time in total.

-fffuuu

Reply 4 of 5, by Scali

User metadata
Rank l33t
Rank
l33t

Doesn't look like there's a fix for it already.
If I look at the FMUL implementation here: http://svn.code.sf.net/p/dosbox/code-0/dosbox … _instructions.h
It just does a mul-operation in C, which won't have more precision than your CPU is capable of, so it won't go beyond double precision on most non-x86 CPUs.
In the case of extended precision, the instructions should be emulated entirely, using integer mathematics.
In BOCHS this is done already, so you could take that code, see eg floatx80_mul(): http://bochs.sourceforge.net/cgi-bin/topper.p … -bin/lxr/source

http://scalibq.wordpress.com/just-keeping-it- … ro-programming/

Reply 5 of 5, by benjaminhei

User metadata
Rank Newbie
Rank
Newbie

thanks for dosbox and thanks for all the inspiration here which finally helped me to confirm that the problem is the 64 bit fpu emulation on arm processors versus the 80 bit on intel. I solved the problem for now by setting the fpu bit in the emulated bios data area to 0. the firstbasic/turbobasic compiler realises at the start of the program that there is no fpu and uses his own emulation which is 80 bit.

a simpler method of deactivating the fpu is 'set 87=no' in the autoexec.bat of dosbox.

Nevertheless an 80 bit fpu arm emulation for dosbox would be highly appreciated because the solution is 10 times slower.