| double floating point compare routine
|
| written by Olaf Flebbe (flebbe@tat.physik.uni-tuebingen.de)
| Based on a 68k floating point packet from Kai-Uwe Bloem, itself based
| on a 80x86 floating point packet from comp.os.minix, written by P.Housel
| 
| Revision 2.0: olaf 12-92.
|

	.text
	.even
	.globl	___eqdf2, ___nedf2
	.globl	___gtdf2, ___ledf2
	.globl	___gedf2, ___ltdf2
	.globl	__cmpdf2, ___cmpdf2
	
__cmpdf2:
___cmpdf2:
___eqdf2:
___nedf2:
	moveml	sp@(4),d0-d1/a0-a1		| get numbers to compare with
	tstl	d0		| check sign bit
	bpl	1f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

1:	exg	a0,d0
	exg	a1,d1
	tstl	d0		| check sign bit
	bpl	2f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

2:	cmpl	d1,a1
	bne	4f
	cmpl	d0,a0
	bne	4f
	bclr	#31,d0
	cmpl	#0x7ff00000,d0		| NaN is not equal NaN !
	bgt	4f
	blt	3f
	tstl	d1
	bne	4f
3:	clrl	d0
	rts

4:	moveql	#1,d0
	rts

___gtdf2:
	moveml	sp@(4),d0-d1/a0-a1		| get numbers to compare with
	tstl	d0		| check sign bit
	bpl	1f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

1:	exg	a0,d0
	exg	a1,d1
	tstl	d0		| check sign bit
	bpl	2f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

2:	exg	a0,d0
	exg	a1,d1
	cmpl	a0,d0
	bgt	4f		| d0 > a0 Test if NaN (should be false!)
	blt	3f		| 
	cmpl	a1,d1
	bhi	4f
3:	clrl	d0		| Test is false.
	rts
4:	bclr	#31,d0		
	cmpl	#0x7ff00000,d0	| First operand == NaN =?
	bgt	3b
	blt	5f		| It is finite!
	tstl	d1
	bne	3b		| It *is* a NaN
5:	moveql	#1,d0		| Test True
	rts

___ledf2:
	moveml	sp@(4),d0-d1/a0-a1		| get numbers to compare with
	tstl	d0		| check sign bit
	bpl	1f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

1:	exg	a0,d0
	exg	a1,d1
	tstl	d0		| check sign bit
	bpl	2f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

2:	cmpl	d0,a0
	blt	4f
	bgt	3f
	cmpl	d1,a1
	bls	4f	        | <= !
3:	moveql	#1,d0		| Test is false
	rts
4:	bclr	#31,d0		
	cmpl	#0x7ff00000,d0	| First operand == NaN =?
	bgt	3b
	blt	5f		| It is finite!
	tstl	d1
	bne	3b		| It *is* a NaN
5:	clrl	d0		| Test true
	rts

___gedf2:
	moveml	sp@(4),d0-d1/a0-a1		| get numbers to compare with
	tstl	d0		| check sign bit
	bpl	1f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

1:	exg	a0,d0
	exg	a1,d1
	tstl	d0		| check sign bit
	bpl	2f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

2:	exg	a0,d0
	exg	a1,d1
	cmpl	a0,d0
	bgt	4f
	blt	3f
	cmpl	a1,d1
	beq	4f		| >= !
	bhi	4f
3:	moveql	#-1,d0		| False
	rts
4:	bclr	#31,d0		
	cmpl	#0x7ff00000,d0	| First operand == NaN =?
	bgt	3b
	blt	5f		| It is finite!
	tstl	d1
	bne	3b		| It *is* a NaN
5:	clrl	d0		| Test True
	rts

___ltdf2:
	moveml	sp@(4),d0-d1/a0-a1		| get numbers to compare with
	tstl	d0		| check sign bit
	bpl	1f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

1:	exg	a0,d0
	exg	a1,d1
	tstl	d0		| check sign bit
	bpl	2f
	negl	d1		| negate
	negxl	d0
	bchg	#31,d0		| toggle sign bit

2:	cmpl	d0,a0
	blt	4f
	bgt	3f
	cmpl	d1,a1
	beq	3f
	bls	4f
3:	clrl	d0
	rts
4:	bclr	#31,d0		
	cmpl	#0x7ff00000,d0	| First operand == NaN =?
	bgt	3b
	blt	5f		| It is finite!
	tstl	d1
	bne	3b		| It *is* a NaN
5:	moveql	#-1,d0		| Test True
	rts
