; Virtual instructions for FPU comparisons (all x87 models).
; Written by X-Calibre, 2000

; This will add the following conditional jumps to your macro assembler:

; fjg	-	jump if greater
; fjl	-	jump if less
; fje	-	jump if equal
; fjne	-	jump if not equal
; fjge	-	jump if greater or equal
; fjle	-	jump if less or equal
; fjnc	-	jump if non-comparable

; Some info on how the flags work:

; C3     C2     C1     C0     Meaning

; 0      0      ?      0      ST > source
; 0      0      ?      1      ST < source
; 1      0      ?      0      ST = source
; 1      1      ?      1      ST not comparable to source

;  15                    8
; +-----------------------+
; ¦  ¦C3¦  ¦  ¦  ¦C2¦C1¦C0¦<-- Coprocessor
; +-----------------------+

;   7                    0
; +-----------------------+
; ¦SF¦ZF¦  ¦AF¦  ¦PF¦  ¦CF¦<-- Processor
; +-----------------------+

.data?
FPUStatusWord	WORD	?

GetFlags	MACRO
	push	eax
	fstsw	[FPUStatusWord]
	mov		ah, BYTE PTR [FPUStatusWord+1]
	sahf
	pop		eax
ENDM

fjg		MACRO	target
	GetFlags
	ja		target
ENDM

fjl		MACRO	target
	GetFlags
	jb		target
ENDM

fje		MACRO	target
	GetFlags
	je		target
ENDM

fjne	MACRO	target
	GetFlags
	jne		target
ENDM

fjge	MACRO	target
	GetFlags
	jae		target
ENDM

fjle	MACRO	target
	GetFlags
	jbe		target
ENDM

fjnc	MACRO	target	; This is "Jump if not comparable"
	GetFlags
	jp		target
ENDM

