Do you perhaps happen to know, what would be the easiest way to modify my AEC-to-x86 compiler (you can run the core of it in browser: https://flatassembler.github.io/compiler ) to be able to target i486? Right now, I think it targets i486, except relying on the fcomip instruction which exists only on i686 and newer. At first I thought I might replace fcomip with something like:
fsubp
fist dword [result]
cmp dword [result],0
But the problem with that is that I'd also need to replace every ja with jg and every jb with jl, which, given the way the compiler is structured, is not a simple task (I'm afraid it's too error-prone). Do you have a better idea?
Is there a way to push FPU flags (ones affected by fcomp) and pop them into CPU flags that would work on both i486 and 64-bit x86 processors?
fcomi(PPro) was replacing (fstsw ax+sahf), and that SSE2ucomisdalso sets FLAGS that way. (And thatfstsw axwas new in 286; 8086 needed to store to memory and reload.) See also http://www.ray.masmcode.com/tutorial/fpuchap7.htm for a very good guide to x87 instructions with examples. – Peter Cordes Jan 08 '23 at 03:09gcc -m32 -march=i486on https://godbolt.org/ (see How to remove "noise" from GCC/clang assembly output?). Anything GCC emits with-march=i486will also work on 64-bit CPUs in 32-bit compat mode. – Peter Cordes Jan 08 '23 at 16:41fcomip. – FlatAssembler May 26 '23 at 15:11fcomipdoes an FP compare, right? So it's the same question as how to do FP compares on CPUs earlier than P6, withoutfcomi[p]. Thus, GCC asm output for something likereturn x > 1.0;will have to do that using earlier instructions: https://godbolt.org/z/KW4PM3osY - GCC13-Osuses the standardsfnswsw/sahf/jp/jnefor an==compare, but-O3just uses bitwise ops on AH instead of SAHF, so that's fun, only needing one branch for predicates that would normally need ajpto rule out unordered. – Peter Cordes May 26 '23 at 15:18