barotto / IBMulator

The IBM PS/1 emulator.
https://barotto.github.io/IBMulator
GNU General Public License v3.0
112 stars 4 forks source link

NEG Ed fails to compute SF correctly when value is 0x80000000 #59

Closed barotto closed 2 years ago

barotto commented 3 years ago

When IBMulator is compiled with GCC version 6 and later and with optimizations turned on (so not -O0), test386.asm fails the NEG D test for EAX=0x80000000:

17413,17414c17413,17414
< F7 NEG D EAX=80000000 EDX=00000000 PS=0091 EAX=80000000 EDX=00000000 PS=0805 
< F7 NEG D EAX=80000001 EDX=00000000 PS=0805 EAX=7FFFFFFF EDX=00000000 PS=0015 
---
> F7 NEG D EAX=80000000 EDX=00000000 PS=0091 EAX=80000000 EDX=00000000 PS=0885 
> F7 NEG D EAX=80000001 EDX=00000000 PS=0885 EAX=7FFFFFFF EDX=00000000 PS=0015 

The SF is wrongly cleared.

This is the result of UB code.

See this Stack Overflow discussion for details.