1#ifdef LIBC_SCCS 2 .asciz "@(#)cvtlf.s 1.1 (Berkeley/CCI) 07/02/86" 3#endif LIBC_SCCS 4 5#include <tahoemath/fp.h> 6#include "DEFS.h" 7 8XENTRY(cvtlf, R2|R3|R4|R5) 9 # 10 #Some initializations: 11 # 12 clrl r1 13 clrl r4 # r4 - negative flag. 14 clrl r2 # r2 - exponent. 15 movl 4(fp),r0 # fetch operand. 16 movl r0,r5 # need another copy. 17 jeql retzero # return zero. 18 jgtr positive 19 mnegl r0,r0 20 jvs retmin # return minimum integer. 21 incl r4 # remember it was negative. 22 movl r0,r5 # remember the negated value. 23 # 24 #Compute exponent: 25 # 26positive: 27 ffs r0,r1 28 incl r1 29 addl2 r1,r2 30 shrl r1,r0,r0 31 jneq positive # look for more set bits. 32 # 33 #we have the exponent in r2. 34 # 35 movl r5,r0 # r0 will hold the resulting f.p. number. 36 # 37 #Shift the fraction part to its proper place: 38 # 39 subl3 r2,$HID_POS,r3 40 jlss shiftr # if less then zero we have to shift right. 41 shll r3,r0,r0 # else we shift left. 42 jmp shifted 43shiftr: 44 mnegl r3,r3 45 shrl r3,r0,r0 46shifted: 47 andl2 $CLEARHID,r0 # clear the hidden bit. 48 shal $EXPSHIFT,r2,r2 # shift the exponent to its proper place. 49 orl2 $EXPSIGN,r2 # set the exponent sign bit(to bias it). 50 orl2 r2,r0 # combine exponent & fraction. 51 bbc $0,r4,sign_ok # do we have to set the sign bit? 52 orl2 $SIGNBIT,r0 # yes... 53sign_ok: 54 ret 55 56retzero: 57 clrl r0 58 ret 59 60retmin: 61 movl $0xd0000000,r0 62 ret 63 64 65 66