!@(#)RELEASE VERSION WorkShop Compilers 5.0 98/12/15
!
! @(#)libm.m4 1.1 97/09/10 SMI
!
! Copyright 09/10/97 Sun Microsystems, Inc.  All Rights Reserved.
!

	.inline	sqrtf,1
	fsqrts	%f1,%f0
	.end

	.inline	sqrt,1
	fsqrtd	%f0,%f0
	.end

	.inline	ceil,1
	sethi	%hi(0x43300000),%o0
	sllx	%o0,32,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f2
	fabsd	%f0,%f4
	fsubd	%f2,%f2,%f6
	fcmpd	%fcc0,%f4,%f2
	fbl,pt	%fcc0,1f
	nop
	faddd	%f0,%f6,%f0
	ba	4f
	nop
1:
	fcmpd	%fcc1,%f0,%f6
	fbg,pt	%fcc1,2f
	nop
	fbe,pn	%fcc1,4f
	nop
	fnegd	%f2,%f2
2:
	faddd	%f0,%f2,%f4
	fsubd	%f4,%f2,%f4
	fcmpd	%fcc0,%f4,%f0
	fbge,pt	%fcc0,3f
	nop
	sethi	%hi(0x3ff00000),%o0
	st	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f2
	faddd	%f4,%f2,%f4
3:
	fabsd	%f4,%f0
	fbge,pt	%fcc1,4f
	nop
	fnegd	%f0,%f0
4:
	.end

	.inline	floor,1
	sethi	%hi(0x43300000),%o0
	sllx	%o0,32,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f2
	fabsd	%f0,%f4
	fsubd	%f2,%f2,%f6
	fcmpd	%fcc0,%f4,%f2
	fbl,pt	%fcc0,1f
	nop
	faddd	%f0,%f6,%f0
	ba	4f
	nop
1:
	fcmpd	%fcc1,%f0,%f6
	fbg,pt	%fcc1,2f
	nop
	fbe,pn	%fcc1,4f
	nop
	fnegd	%f2,%f2
2:
	faddd	%f0,%f2,%f4
	fsubd	%f4,%f2,%f4
	fcmpd	%fcc0,%f4,%f0
	fble,pt	%fcc0,3f
	nop
	sethi	%hi(0x3ff00000),%o0
	st	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f2
	fsubd	%f4,%f2,%f4
3:
	fabsd	%f4,%f0
	fbge,pt	%fcc1,4f
	nop
	fnegd	%f0,%f0
4:
	.end

	.inline	ilogb,1
	st	%f0,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0x7ff00000),%o1
	andcc	%o0,%o1,%o0
	bne,pt	%icc,2f
	nop
	sethi	%hi(0x43500000),%o0
	sllx	%o0,32,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f2
	fmuld	%f0,%f2,%f0
	st	%f0,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	andcc	%o0,%o1,%o0
	bne,pt	%icc,1f
	nop
	sethi	%hi(0x80000001),%o0
	or	%o0,%lo(0x80000001),%o0
	ba	4f
	nop
1:
	srl	%o0,20,%o0
	sub	%o0,0x435,%o0
	ba	4f
	nop
2:
	subcc	%o1,%o0,%g0
	bne,pt	%icc,3f
	nop
	sethi	%hi(0x7fffffff),%o0
	or	%o0,%lo(0x7fffffff),%o0
	ba	4f
	nop
3:
	srl	%o0,20,%o0
	sub	%o0,0x3ff,%o0
4:
	.end

	.inline	rint,1
	sethi	%hi(0x43300000),%o0
	sllx	%o0,32,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f2
	fabsd	%f0,%f4
	fsubd	%f2,%f2,%f6
	fcmpd	%fcc0,%f4,%f2
	fbl,pt	%fcc0,1f
	nop
	faddd	%f0,%f6,%f0
	ba	4f
	nop
1:
	fcmpd	%fcc1,%f0,%f6
	fbg,pt	%fcc1,2f
	nop
	fbe,pn	%fcc1,4f
	nop
	fnegd	%f2,%f2
2:
	faddd	%f0,%f2,%f4
	fcmpd	%fcc0,%f4,%f2
	fbe,pn	%fcc0,3f
	nop
	fsubd	%f4,%f2,%f0
	ba	4f
	nop
3:
	fabsd	%f6,%f0
	fbge,pt	%fcc1,4f
	nop
	fnegd	%f0,%f0
4:
	.end

	.inline	min_subnormal,1
	or	%g0,1,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f0
	.end

	.inline	min_subnormalf,1
	or	%g0,1,%o0
	st	%o0,[%sp+0x87f]
	ld	[%sp+0x87f],%f0
	.end

	.inline	max_subnormal,1
	xnor	%g0,%g0,%o0
	srlx	%o0,12,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f0
	.end

	.inline	max_subnormalf,1
	xnor	%g0,%g0,%o0
	srl	%o0,9,%o0
	st	%o0,[%sp+0x87f]
	ld	[%sp+0x87f],%f0
	.end

	.inline	min_normal,1
	sethi	%hi(0x00100000),%o0
	sllx	%o0,32,%o0
        stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f0
	.end

	.inline	min_normalf,1
	sethi	%hi(0x00800000),%o0
	st	%o0,[%sp+0x87f]
	ld	[%sp+0x87f],%f0
	.end

	.inline	max_normal,1
	sethi	%hi(0x80100000),%o1
	sllx	%o1,32,%o1
	xnor	%g0,%g0,%o0
	andn	%o0,%o1,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f0
	.end

	.inline	max_normalf,1
	sethi	%hi(0x7f7ffc00),%o0
	or	%o0,0x3ff,%o0
	st	%o0,[%sp+0x87f]
	ld	[%sp+0x87f],%f0
	.end

	.inline	__infinity,1
	sethi	%hi(0x7ff00000),%o0
	sllx	%o0,32,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f0
	.end

	.inline	infinity,1
	sethi	%hi(0x7ff00000),%o0
	sllx	%o0,32,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f0
	.end

	.inline	infinityf,1
	sethi	%hi(0x7f800000),%o0
	st	%o0,[%sp+0x87f]
	ld	[%sp+0x87f],%f0
	.end

	.inline	signaling_nan,1
	sethi	%hi(0x7ff00000),%o0
	sllx	%o0,32,%o0
	or	%o0,0x1,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f0
	.end

	.inline	signaling_nanf,1
	sethi	%hi(0x7f800000),%o0
	or	%o0,1,%o0
	st	%o0,[%sp+0x87f]
	ld	[%sp+0x87f],%f0
	.end

	.inline	quiet_nan,1
	xnor	%g0,%g0,%o0
	srlx	%o0,1,%o0
	stx	%o0,[%sp+0x87f]
	ldd	[%sp+0x87f],%f0
	.end

	.inline	quiet_nanf,1
	xnor	%g0,%g0,%o0
	srl	%o0,1,%o0
	st	%o0,[%sp+0x87f]
	ld	[%sp+0x87f],%f0
	.end

	.inline	__swapEX,1
	and	%o0,0x1f,%o1
	sll	%o1,5,%o1
	.volatile
	st	%fsr,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	andn	%o0,0x3e0,%o2
	or	%o1,%o2,%o1
	st	%o1,[%sp+0x87f]
	ld	[%sp+0x87f],%fsr
	srl	%o0,5,%o0
	and	%o0,0x1f,%o0
	.nonvolatile
	.end

	.inline	_QgetRD,0
	st	%fsr,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	srl	%o0,30,%o0
	.end

	.inline	_QgetRP,0
	or	%g0,%g0,%o0
	.end

	.inline	__swapRD,1
	and	%o0,0x3,%o0
	sll	%o0,30,%o1
	.volatile
	st	%fsr,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0xc0000000),%o4
	andn	%o0,%o4,%o2
	or	%o1,%o2,%o1
	st	%o1,[%sp+0x87f]
	ld	[%sp+0x87f],%fsr
	srl	%o0,30,%o0
	and	%o0,0x3,%o0
	.nonvolatile
	.end

!
! On the SPARC, __swapRP is a no-op; always return 0 for backward compatibility
!
	.inline	__swapRP,1
	or	%g0,%g0,%o0
	.end

	.inline	__swapTE,1
	and	%o0,0x1f,%o0
	sll	%o0,23,%o1
	.volatile
	st	%fsr,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0x0f800000),%o4
	andn	%o0,%o4,%o2
	or	%o1,%o2,%o1
	st	%o1,[%sp+0x87f]
	ld	[%sp+0x87f],%fsr
	srl	%o0,23,%o0
	and	%o0,0x1f,%o0
	.nonvolatile
	.end

	.inline	fp_class,1
	fabsd	%f0,%f0
	std	%f0,[%sp+0x87f]
	ldx	[%sp+0x87f],%o0
	orcc	%g0,%o0,%g0
	be,pn	%xcc,2f
	nop
	sethi	%hi(0x7ff00000),%o1
	sllx	%o1,32,%o1
	andcc	%o0,%o1,%g0
	bne,pt	%xcc,1f
	nop
	or	%g0,1,%o0
	ba	2f
	nop
1:
	subcc	%o0,%o1,%g0
	bge,pn	%xcc,1f
	nop
	or	%g0,2,%o0
	ba	2f
	nop
1:
	andncc	%o0,%o1,%o0
	bne,pn	%xcc,1f
	nop
	or	%g0,3,%o0
	ba	2f
	nop
1:
	sethi	%hi(0x00080000),%o1
	sllx	%o1,32,%o1
	andcc	%o0,%o1,%g0
	or	%g0,4,%o0
	bne,pt	%xcc,2f
	nop
	or	%g0,5,%o0
2:
	.end

	.inline	fp_classf,1
	fabss	%f1,%f1
	st	%f1,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	orcc	%g0,%o0,%g0
	be,pn	%icc,2f
	nop
1:
	sethi	%hi(0x7f800000),%o1
	andcc	%o0,%o1,%g0
	bne,pt	%icc,1f
	nop
	or	%g0,1,%o0
	ba	2f
	nop
1:
	subcc	%o0,%o1,%g0
	bge,pn	%icc,1f
	nop
	or	%g0,2,%o0
	ba	2f
	nop
1:
	bg,pn	%icc,1f
	nop
	or	%g0,3,%o0
	ba	2f
	nop
1:
	sethi	%hi(0x00400000),%o1
	andcc	%o0,%o1,%g0
	or	%g0,4,%o0
	bne,pt	%icc,2f
	nop
	or	%g0,5,%o0
2:
	.end

	.inline	copysign,2
	fabsd	%f0,%f0
	st	%f0,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	st	%f2,[%sp+0x887]
	ld	[%sp+0x887],%o1
	srl	%o1,31,%o1
	sll	%o1,31,%o1
	or	%o0,%o1,%o0
	st	%o0,[%sp+0x87f]
	ld	[%sp+0x87f],%f0
	.end

	.inline	copysignf,2
	fabss	%f1,%f1
	st	%f1,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	st	%f3,[%sp+0x887]
	ld	[%sp+0x887],%o1
	srl	%o1,31,%o1
	sll	%o1,31,%o1
	or	%o0,%o1,%o0
	st	%o0,[%sp+0x87f]
	ld	[%sp+0x87f],%f0
	.end

	.inline	finite,1
	fabsd	%f0,%f0
	st	%f0,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0x7ff00000),%o1
	sub	%o0,%o1,%o0
	srl	%o0,31,%o0
	.end

	.inline	finitef,1
	fabss	%f1,%f1
	st	%f1,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0x7f800000),%o1
	sub	%o0,%o1,%o0
	srl	%o0,31,%o0
	.end

	.inline	signbit,1
	st	%f0,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	srl	%o0,31,%o0
	.end

	.inline	signbitf,1
	st	%f1,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	srl	%o0,31,%o0
	.end

	.inline	isinf,1
	fabsd	%f0,%f0
	std	%f0,[%sp+0x87f]
	ldx	[%sp+0x87f],%o0
	sethi	%hi(0x7ff00000),%o1
	sllx	%o1,32,%o1
	sub	%o0,%o1,%o0
	sub	%g0,%o0,%o1
	or	%o0,%o1,%o0
	xnor	%o0,%g0,%o0
	srlx	%o0,63,%o0
	.end

	.inline	isinff,1
	fabss	%f1,%f1
	st	%f1,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0x7f800000),%o1
	sub	%o0,%o1,%o0
	sub	%g0,%o0,%o1
	or	%o0,%o1,%o0
	xnor	%o0,%g0,%o0
	srl	%o0,31,%o0
	.end

	.inline	isnan,1
	fabsd	%f0,%f0
	std	%f0,[%sp+0x87f]
	ldx	[%sp+0x87f],%o0
	sethi	%hi(0x7ff00000),%o1
	sllx	%o1,32,%o1
	sub	%o1,%o0,%o0
	srlx	%o0,63,%o0
	.end

	.inline	isnanf,1
	fabss	%f1,%f1
	st	%f1,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0x7f800000),%o1
	sub	%o1,%o0,%o0
	srl	%o0,31,%o0
	.end

	.inline	isnormal,1
	fabsd	%f0,%f0
	st	%f0,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0x7ff00000),%o1
	sub	%o0,%o1,%o2
	sethi	%hi(0x00100000),%o1
	sub	%o0,%o1,%o1
	andn	%o2,%o1,%o0
	srl	%o0,31,%o0
	.end

	.inline	isnormalf,1
	fabss	%f1,%f1
	st	%f1,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0x7f800000),%o1
	sub	%o0,%o1,%o2
	sethi	%hi(0x00800000),%o1
	sub	%o0,%o1,%o1
	andn	%o2,%o1,%o0
	srl	%o0,31,%o0
	.end

	.inline	issubnormal,1
	fabsd	%f0,%f0
	std	%f0,[%sp+0x87f]
	ldx	[%sp+0x87f],%o0
	sethi	%hi(0x00100000),%o1
	sllx	%o1,32,%o1
	sub	%o0,%o1,%o1
	sub	%g0,%o0,%o2
	or	%o0,%o2,%o0
	and	%o0,%o1,%o0
	srlx	%o0,63,%o0
	.end

	.inline	issubnormalf,1
	fabss	%f1,%f1
	st	%f1,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sethi	%hi(0x00800000),%o1
	sub	%o0,%o1,%o1
	sub	%g0,%o0,%o2
	or	%o0,%o2,%o0
	and	%o0,%o1,%o0
	srl	%o0,31,%o0
	.end

	.inline	iszero,1
	fabsd	%f0,%f0
	std	%f0,[%sp+0x87f]
	ldx	[%sp+0x87f],%o0
	sub	%g0,%o0,%o1
	or	%o0,%o1,%o0
	xnor	%o0,%g0,%o0
	srlx	%o0,63,%o0
	.end

	.inline	iszerof,1
	fabss	%f1,%f1
	st	%f1,[%sp+0x87f]
	ld	[%sp+0x87f],%o0
	sub	%g0,%o0,%o1
	or	%o0,%o1,%o0
	xnor	%o0,%g0,%o0
	srl	%o0,31,%o0
	.end

	.inline	abs,1
	subcc	%g0,%o0,%g0
	ble,pt	%icc,1f
	nop
	sub	%g0,%o0,%o0
1:
	.end

	.inline	fabs,1
	fabsd	%f0,%f0
	.end

	.inline	fabsf,1
	fabss	%f1,%f0
	.end
