xref: /csrg-svn/sys/tahoe/math/Kmodf.s (revision 45761)
1*45761Sbostic/*-
2*45761Sbostic * Copyright (c) 1985 The Regents of the University of California.
3*45761Sbostic * All rights reserved.
4*45761Sbostic *
5*45761Sbostic * This code is derived from software contributed to Berkeley by
6*45761Sbostic * Computer Consoles Inc.
7*45761Sbostic *
8*45761Sbostic * %sccs.include.redist.c%
9*45761Sbostic *
10*45761Sbostic *	@(#)Kmodf.s	7.1 (Berkeley) 12/06/90
11*45761Sbostic */
1224141Ssam
1325693Ssam#include "../tahoe/SYS.h"
1445701Sbostic#include "../math/fp.h"
1524141Ssam
1624141Ssam/*
1725664Ssam *  float Kmodf (value, iptr, hfs)
1825664Ssam *  float value, *iptr;
1925664Ssam *  int hfs;
2025664Ssam *
2125664Ssam *  Modf returns the fractional part of "value",
2225664Ssam *  and stores the integer part indirectly through "iptr".
2325664Ssam */
2424141Ssam	.text
2525664SsamENTRY(Kmodf, R8|R7|R6|R5|R4|R3|R2)
2624141Ssam /*
2724141Ssam * Some initializations:
2824141Ssam */
2924141Ssam	clrl	r3
3024141Ssam	movl	4(fp),r0	/* fetch operand to r0. */
3124141Ssam	movl	8(fp),r1
3224141Ssam	movl	12(fp),r6	/* fetch addr of int to r6. */
3324141Ssam /*
3425664Ssam  * get exponent
3525664Ssam  */
3624141Ssam	andl3	$EXPMASK,r0,r2	/* r2 will hold the exponent. */
3724141Ssam	shrl	$EXPSHIFT,r2,r2
3824141Ssam	subl2	$BIAS,r2	/* unbias it.  */
3924141Ssam	jleq	allfrac		/* it's int part is  zero. */
4024141Ssam	cmpl	r2,$56
4124141Ssam	jgeq	allint		/* it's fraction part is zero. */
4224141Ssam /*
4325664Ssam  * get fraction
4425664Ssam  */
4524141Ssam	movl	r0,r4		/* remember the original number. */
4624141Ssam	movl	r1,r5
4724141Ssam	bbc	$31,r0,positive	/* if negative remember it. */
4824141Ssam	incl	r3
4924141Ssampositive:
5024141Ssam				/* clear the non fraction parts. */
5124141Ssam	andl2	$(0!(EXPMASK | SIGNBIT)),r0
5224141Ssam				/* add the hidden bit. */
5324141Ssam	orl2	$(0!CLEARHID),r0
5424141Ssam
5524141Ssam	cmpl	r2,$HID_POS	/* see if there are bits to clear only in r0 */
5624141Ssam	jgtr	in_r1		/* some bytes in r1	*/
5724141Ssam	jeql	onlyallr0	/* all r0 must be cleared. */
5824141Ssam	mnegl	r2,r7		/* r7 - loop counter. */
5924141Ssam	movl	$CLEARHID,r8	/* first bit to clear. */
6024141Ssam1:
6124141Ssam	andl2	r8,r0		/* clear int. bits from fraction part. */
6224141Ssam	shar	$1,r8,r8
6324141Ssam	aoblss	$0,r7,1b
6424141Ssam1:
6524141Ssam	andl2	r8,r4		/* clear frac bits for int calculation: */
6624141Ssam	shar	$1,r8,r8
6724141Ssam	cmpl	$0xffffffff,r8
6824141Ssam	jneq	1b
6924141Ssam	clrl	r5
7024141Ssam	jmp	norm
7124141Ssam
7224141Ssamonlyallr0:
7324141Ssam	clrl	r0
7424141Ssam	clrl	r5
7524141Ssam	jmp 	norm
7624141Ssam
7724141Ssamin_r1:
7824141Ssam	clrl	r0
7924141Ssam	subl3	r2,$HID_POS,r7
8024141Ssam	movl	$0x7fffffff,r8
8124141Ssam1:
8224141Ssam	andl2	r8,r1
8324141Ssam	shar	$1,r8,r8
8424141Ssam	orl2	$0x80000000,r8
8524141Ssam	aoblss	$0,r7,1b
8624141Ssam1:
8724141Ssam	andl2	r8,r5
8824141Ssam	shar	$1,r8,r8
8924141Ssam	cmpl	$0xffffffff,r8
9024141Ssam	jneq	1b
9124141Ssamnorm:
9224141Ssam	addl2	$BIAS,r2	/* fnorm expects it biased. */
9324141Ssam	pushl	16(fp)		/* hfs */
9425664Ssam	callf	$8,_Kfnorm	/* normelize fraction part. */
9524141Ssam	cmpl	$0,r0
9624141Ssam	jeql	1f
9724141Ssam	bbc	$0,r3,1f
9824141Ssam	orl2	$0x80000000,r0
9924141Ssam1:
10024141Ssam	movl	r4,(r6)		/* put int part in place. */
10124141Ssam	movl	r5,4(r6)
10224141Ssam	ret
10324141Ssam
10424141Ssamallint:
10524141Ssam	movl	r0,(r6)		/* copy the argument to the int addr. */
10624141Ssam	movl	r1,4(r6)
10724141Ssam	clrl	r0		/* clear the fraction part. */
10824141Ssam	clrl	r1
10924141Ssam	ret
11024141Ssam
11124141Ssamallfrac:
11224141Ssam				/* the fraction is ready in r0. */
11324141Ssam	clrl	(r6)		/* zero the int part. */
11424141Ssam	clrl	4(r6)
11524141Ssam	ret
11624141Ssam
11724141Ssamret_zero:
11824141Ssam	clrl	(r6)
11924141Ssam 	clrl	4(r6)
12024141Ssam	clrl	r0
12124141Ssam	clrl	r1
12224141Ssam	ret
123