|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1988 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: * ! 19: * This code is derived from software contributed to Berkeley by ! 20: * Computer Consoles Inc. ! 21: */ ! 22: ! 23: #if defined(LIBC_SCCS) && !defined(lint) ! 24: .asciz "@(#)modf.s 1.5 (Berkeley) 6/1/90" ! 25: #endif /* LIBC_SCCS and not lint */ ! 26: ! 27: /* ! 28: * double modf (value, iptr) ! 29: * double value, *iptr; ! 30: * ! 31: * Modf returns the fractional part of "value", ! 32: * and stores the integer part indirectly through "iptr". ! 33: * ! 34: * This version uses floating point (look in ../fpe for ! 35: * a much slower integer version). ! 36: */ ! 37: ! 38: #include "DEFS.h" ! 39: ! 40: ENTRY(modf, 0) ! 41: ldd 4(fp) # value ! 42: cvdl r2 # integerize ! 43: bvs 1f # did integer part overflow? ! 44: cvld r2 # integer part ! 45: std r0 ! 46: std *12(fp) # *iptr = r2 ! 47: ldd 4(fp) ! 48: subd r0 # value-(int)value ! 49: std r0 # return fraction ! 50: ret ! 51: 1: ! 52: /* ! 53: * If the integer portion overflowed, mask out the fractional ! 54: * bits in the double word instead of cvdl-ing. ! 55: */ ! 56: ldd 4(fp) ! 57: std r0 # (r0,r1) = value ! 58: shrl $23,r0,r2 # extract sign,exponent of value ! 59: andl2 $255,r2 # exponent ! 60: subl2 $152,r2 # e-152 ! 61: /* ! 62: * If it overflowed then value>=2^31 and e>=160 ! 63: * so we mask only r1 (low bits of fraction), not r0 ! 64: */ ! 65: mnegl $1,r3 ! 66: shrl r2,r3,r3 # -1>>(e-152) is neg mask to clear fraction ! 67: mcoml r3,r3 # complement mask ! 68: andl2 r3,r1 # mask off truly fractional bits from fraction ! 69: ldd r0 # now (r0,r1) = integerized value ! 70: std *12(fp) # *iptr = integerized ! 71: ldd 4(fp) ! 72: subd r0 ! 73: std r0 # return fraction ! 74: ret
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.