1/*- 2 * Copyright (c) 1985 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Computer Consoles Inc. 7 * 8 * %sccs.include.redist.c% 9 * 10 * @(#)Kmodf.s 7.1 (Berkeley) 12/06/90 11 */ 12 13#include "../tahoe/SYS.h" 14#include "../math/fp.h" 15 16/* 17 * float Kmodf (value, iptr, hfs) 18 * float value, *iptr; 19 * int hfs; 20 * 21 * Modf returns the fractional part of "value", 22 * and stores the integer part indirectly through "iptr". 23 */ 24 .text 25ENTRY(Kmodf, R8|R7|R6|R5|R4|R3|R2) 26 /* 27 * Some initializations: 28 */ 29 clrl r3 30 movl 4(fp),r0 /* fetch operand to r0. */ 31 movl 8(fp),r1 32 movl 12(fp),r6 /* fetch addr of int to r6. */ 33 /* 34 * get exponent 35 */ 36 andl3 $EXPMASK,r0,r2 /* r2 will hold the exponent. */ 37 shrl $EXPSHIFT,r2,r2 38 subl2 $BIAS,r2 /* unbias it. */ 39 jleq allfrac /* it's int part is zero. */ 40 cmpl r2,$56 41 jgeq allint /* it's fraction part is zero. */ 42 /* 43 * get fraction 44 */ 45 movl r0,r4 /* remember the original number. */ 46 movl r1,r5 47 bbc $31,r0,positive /* if negative remember it. */ 48 incl r3 49positive: 50 /* clear the non fraction parts. */ 51 andl2 $(0!(EXPMASK | SIGNBIT)),r0 52 /* add the hidden bit. */ 53 orl2 $(0!CLEARHID),r0 54 55 cmpl r2,$HID_POS /* see if there are bits to clear only in r0 */ 56 jgtr in_r1 /* some bytes in r1 */ 57 jeql onlyallr0 /* all r0 must be cleared. */ 58 mnegl r2,r7 /* r7 - loop counter. */ 59 movl $CLEARHID,r8 /* first bit to clear. */ 601: 61 andl2 r8,r0 /* clear int. bits from fraction part. */ 62 shar $1,r8,r8 63 aoblss $0,r7,1b 641: 65 andl2 r8,r4 /* clear frac bits for int calculation: */ 66 shar $1,r8,r8 67 cmpl $0xffffffff,r8 68 jneq 1b 69 clrl r5 70 jmp norm 71 72onlyallr0: 73 clrl r0 74 clrl r5 75 jmp norm 76 77in_r1: 78 clrl r0 79 subl3 r2,$HID_POS,r7 80 movl $0x7fffffff,r8 811: 82 andl2 r8,r1 83 shar $1,r8,r8 84 orl2 $0x80000000,r8 85 aoblss $0,r7,1b 861: 87 andl2 r8,r5 88 shar $1,r8,r8 89 cmpl $0xffffffff,r8 90 jneq 1b 91norm: 92 addl2 $BIAS,r2 /* fnorm expects it biased. */ 93 pushl 16(fp) /* hfs */ 94 callf $8,_Kfnorm /* normelize fraction part. */ 95 cmpl $0,r0 96 jeql 1f 97 bbc $0,r3,1f 98 orl2 $0x80000000,r0 991: 100 movl r4,(r6) /* put int part in place. */ 101 movl r5,4(r6) 102 ret 103 104allint: 105 movl r0,(r6) /* copy the argument to the int addr. */ 106 movl r1,4(r6) 107 clrl r0 /* clear the fraction part. */ 108 clrl r1 109 ret 110 111allfrac: 112 /* the fraction is ready in r0. */ 113 clrl (r6) /* zero the int part. */ 114 clrl 4(r6) 115 ret 116 117ret_zero: 118 clrl (r6) 119 clrl 4(r6) 120 clrl r0 121 clrl r1 122 ret 123