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 SSE2ucomisd
also sets FLAGS that way. (And thatfstsw ax
was new in 286; 8086 needed to store to memory and reload.) See also ray.masmcode.com/tutorial/fpuchap7.htm for a very good guide to x87 instructions with examples.gcc -m32 -march=i486
on godbolt.org (see How to remove "noise" from GCC/clang assembly output?). Anything GCC emits with-march=i486
will also work on 64-bit CPUs in 32-bit compat mode.fcomip
.fcomip
does 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: godbolt.org/z/KW4PM3osY - GCC13-Os
uses the standardsfnswsw
/sahf
/jp
/jne
for an==
compare, but-O3
just uses bitwise ops on AH instead of SAHF, so that's fun, only needing one branch for predicates that would normally need ajp
to rule out unordered.