1 1.4 matt /* $NetBSD: floatunditf_ieee754.c,v 1.4 2012/08/05 04:28:58 matt Exp $ */ 2 1.1 matt 3 1.1 matt /*- 4 1.1 matt * Copyright (c) 1992, 1993 5 1.1 matt * The Regents of the University of California. All rights reserved. 6 1.1 matt * 7 1.1 matt * This software was developed by the Computer Systems Engineering group 8 1.1 matt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9 1.1 matt * contributed to Berkeley. 10 1.1 matt * 11 1.1 matt * Redistribution and use in source and binary forms, with or without 12 1.1 matt * modification, are permitted provided that the following conditions 13 1.1 matt * are met: 14 1.1 matt * 1. Redistributions of source code must retain the above copyright 15 1.1 matt * notice, this list of conditions and the following disclaimer. 16 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright 17 1.1 matt * notice, this list of conditions and the following disclaimer in the 18 1.1 matt * documentation and/or other materials provided with the distribution. 19 1.1 matt * 3. Neither the name of the University nor the names of its contributors 20 1.1 matt * may be used to endorse or promote products derived from this software 21 1.1 matt * without specific prior written permission. 22 1.1 matt * 23 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 1.1 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 1.1 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 1.1 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 1.1 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 1.1 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 1.1 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 1.1 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 1.1 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 1.1 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 1.1 matt * SUCH DAMAGE. 34 1.1 matt */ 35 1.1 matt 36 1.1 matt #include <sys/cdefs.h> 37 1.1 matt #if defined(LIBC_SCCS) && !defined(lint) 38 1.1 matt #if 0 39 1.1 matt static char sccsid[] = "@(#)floatunsdidf.c 8.1 (Berkeley) 6/4/93"; 40 1.1 matt #else 41 1.4 matt __RCSID("$NetBSD: floatunditf_ieee754.c,v 1.4 2012/08/05 04:28:58 matt Exp $"); 42 1.1 matt #endif 43 1.1 matt #endif /* LIBC_SCCS and not lint */ 44 1.1 matt 45 1.4 matt #ifdef SOFTFLOAT 46 1.4 matt #include "softfloat/softfloat-for-gcc.h" 47 1.4 matt #endif 48 1.4 matt 49 1.1 matt #include "quad.h" 50 1.1 matt #ifdef __vax__ 51 1.1 matt #error vax does not support a distinct long double 52 1.1 matt #endif 53 1.1 matt #include <machine/ieee.h> 54 1.1 matt 55 1.1 matt /* 56 1.1 matt * Convert (unsigned) quad to long double. 57 1.1 matt * This is exactly like floatdidf.c except that negatives never occur. 58 1.1 matt */ 59 1.1 matt long double 60 1.1 matt __floatunditf(u_quad_t x) 61 1.1 matt { 62 1.1 matt #if 0 63 1.1 matt long double ld; 64 1.1 matt union uu u; 65 1.1 matt 66 1.1 matt u.uq = x; 67 1.1 matt ld = (long double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); 68 1.1 matt ld += u.ul[L]; 69 1.1 matt return (ld); 70 1.1 matt #else 71 1.1 matt union ieee_ext_u extu; 72 1.2 matt quad_t tmp = x; /* must be signed */ 73 1.3 christos unsigned int width = 64; 74 1.3 christos unsigned int bit = 0; 75 1.2 matt quad_t mask = ~(quad_t)0; 76 1.1 matt 77 1.1 matt if (x == 0) 78 1.1 matt return 0.0L; 79 1.1 matt if (x == 1) 80 1.1 matt return 1.0L; 81 1.1 matt 82 1.1 matt while (mask != 0 && (tmp >= 0)) { 83 1.1 matt width >>= 1; 84 1.1 matt mask <<= width; 85 1.1 matt if ((tmp & mask) == 0) { 86 1.1 matt tmp <<= width; 87 1.1 matt bit += width; 88 1.1 matt } 89 1.1 matt } 90 1.1 matt 91 1.1 matt x <<= (bit + 1); 92 1.1 matt extu.extu_sign = 0; 93 1.1 matt extu.extu_exp = EXT_EXP_BIAS + (64 - (bit + 1)); 94 1.3 christos extu.extu_frach = (unsigned int)(x >> (64 - EXT_FRACHBITS)); 95 1.1 matt x <<= EXT_FRACHBITS; 96 1.1 matt #ifdef EXT_FRACHMBITS 97 1.3 christos extu.extu_frachm =(unsigned int)(x >> (64 - EXT_FRACHMBITS)); 98 1.1 matt x <<= EXT_FRACHMBITS; 99 1.1 matt #endif 100 1.1 matt #ifdef EXT_FRACLMBITS 101 1.3 christos extu.extu_fraclm =(unsigned int)(x >> (64 - EXT_FRACLMBITS)); 102 1.1 matt x <<= EXT_FRACLMBITS; 103 1.1 matt #endif 104 1.3 christos extu.extu_fracl =(unsigned int)(x >> (64 - EXT_FRACLBITS)); 105 1.1 matt 106 1.1 matt return extu.extu_ld; 107 1.1 matt #endif 108 1.1 matt } 109