Skip to main content
gamedev.net
🔒 Locked

Asm Float Comparisons

Started by jonbell 5 replies 250+ views
Original Post
jonbell
jonbell
How do I compare 2 floats which I have pushed onto the FPU stack? Do floating point operations alter the same flags as integer operations?
sbennett
sbennett
Second question first: No.

Use some variant of FCOM, and then FNSTSW to store the status word into (eg) EAX. Then test EAX for whatever bit pattern. I think the relevant bit patterns are in the MASM docs, but I can''t remember them now.
Jan Wassenberg
Jan Wassenberg
If you''re willing to assume Pentium Pro CPU or above, what you want is fcomi.
fcomi st0, st_i => ZF = (st0 == st_i), CF = (st0 < st_i), PF = error (NaN etc.; FPUCW.IM = 1)

HTH
Jan
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
jonbell
jonbell
What processors are considered pentium pro? (P2 and above?)

Also what if I don''t want to assume that, what instruction do i need then?
q2guy
q2guy
A pentium pro+ is considered Pentium Pro,Pentium II,Pentium III,Pentium IV
Jan Wassenberg
Jan Wassenberg
> A pentium pro+ is considered Pentium Pro,Pentium II,Pentium III,Pentium IV <
hehe. I think he meant non-Intel CPUs
This and all other Pentium Pro features are supported on Athlons; I dunno about Transmeta and Cyrix (in case anyone cares )

You can test if the processor supports fcomi:

mov eax, 1
cpuid
mov [feat_flags], edx

bits 0 and 15 must be set.

500x5
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
jonbell
jonbell
whats the compare instruction to compare 2 floats on 386 and above? There must be one.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.