1/* 2 * Copyright (c) 1986 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 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the University of California, Berkeley. The name of the 14 * University may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 */ 20 21#if defined(SYSLIBC_SCCS) && !defined(lint) 22 .asciz "@(#)cvtld.s 1.2 (Berkeley) 02/17/89" 23#endif /* SYSLIBC_SCCS and not lint */ 24 25#include <tahoemath/fp.h> 26#include "DEFS.h" 27 28XENTRY(cvtld, R2|R3|R4|R5) 29 # 30 #Some initializations: 31 # 32 clrl r4 # r4 - negative flag. 33 clrl r2 # r2 - exponent. 34 movl 4(fp),r0 # fetch operand. 35 movl r0,r5 # need another copy. 36 jeql retzero # return zero. 37 jgtr positive 38 mnegl r0,r0 39 jvs retmin # return minimum integer. 40 incl r4 # remember it was negative. 41 movl r0,r5 # remember the negated value. 42 # 43 #Compute exponent: 44 # 45positive: 46 ffs r0,r1 47 incl r1 48 addl2 r1,r2 49 shrl r1,r0,r0 50 jneq positive # look for more set bits. 51 # 52 #we have the exponent in r2. 53 # 54 movl r5,r0 # r0,r1 will hold the resulting f.p. number. 55 clrl r1 56 # 57 #Shift the fraction part to its proper place: 58 # 59 subl3 r2,$HID_POS,r3 60 jlss shiftr # if less then zero we have to shift right. 61 shll r3,r0,r0 # else we shift left. 62 jmp shifted 63shiftr: 64 mnegl r3,r3 65 shrq r3,r0,r0 66shifted: 67 andl2 $CLEARHID,r0 # clear the hidden bit. 68 shal $EXPSHIFT,r2,r2 # shift the exponent to its proper place. 69 orl2 $EXPSIGN,r2 # set the exponent sign bit(to bias it). 70 orl2 r2,r0 # combine exponent & fraction. 71 bbc $0,r4,sign_ok # do we have to set the sign bit? 72 orl2 $SIGNBIT,r0 # yes... 73sign_ok: 74 ret 75 76retzero: 77 clrl r0 78 clrl r1 79 ret 80 81retmin: 82 movl $0xd0000000,r0 83 clrl r1 84 ret 85 86 87 88