1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 23 */ 24 /* 25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 #ifndef _LIBM_MACROS_H 30 #define _LIBM_MACROS_H 31 32 #include <sys/isa_defs.h> 33 34 #if defined(__sparc) 35 36 #define HIWORD 0 37 #define LOWORD 1 38 #define HIXWORD 0 /* index of int containing exponent */ 39 #define XSGNMSK 0x80000000 /* exponent bit mask within the int */ 40 #define XBIASED_EXP(x) ((((int *)&x)[HIXWORD] & ~0x80000000) >> 16) 41 #define ISZEROL(x) (((((int *)&x)[0] & ~XSGNMSK) | ((int *)&x)[1] | \ 42 ((int *)&x)[2] | ((int *)&x)[3]) == 0) 43 44 #include <stdint.h> 45 46 typedef union 47 { 48 double value; 49 struct 50 { 51 uint32_t msw; 52 uint32_t lsw; 53 } parts; 54 } ieee_double_shape_type; 55 56 #elif defined(__x86) 57 58 #define HIWORD 1 59 #define LOWORD 0 60 #define HIXWORD 2 61 #define XSGNMSK 0x8000 62 #define XBIASED_EXP(x) (((int *)&x)[HIXWORD] & 0x7fff) 63 #define ISZEROL(x) (x == 0.0L) 64 65 #include <stdint.h> 66 67 typedef union 68 { 69 double value; 70 struct 71 { 72 uint32_t lsw; 73 uint32_t msw; 74 } parts; 75 } ieee_double_shape_type; 76 77 #define HANDLE_UNSUPPORTED 78 79 /* 80 * "convert" the high-order 32 bits of a SPARC quad precision 81 * value ("I") to the sign, exponent, and high-order bits of an 82 * x86 extended double precision value ("E"); the low-order bits 83 * in the 12-byte quantity are left intact 84 */ 85 #define ITOX(I, E) \ 86 E[2] = 0xffff & ((I) >> 16); \ 87 E[1] = (((I) & 0x7fff0000) == 0)? \ 88 (E[1] & 0x7fff) | (0x7fff8000 & ((I) << 15)) :\ 89 0x80000000 | (E[1] & 0x7fff) | (0x7fff8000 & ((I) << 15)) 90 91 /* 92 * "convert" the sign, exponent, and high-order bits of an x86 93 * extended double precision value ("E") to the high-order 32 bits 94 * of a SPARC quad precision value ("I") 95 */ 96 #define XTOI(E, I) \ 97 I = ((E[2]<<16) | (0xffff & (E[1]>>15))) 98 99 #else 100 #error Unknown architecture 101 #endif 102 103 #define EXTRACT_WORDS(ix0,ix1,d) \ 104 { \ 105 ieee_double_shape_type ew_u; \ 106 ew_u.value = (d); \ 107 (ix0) = ew_u.parts.msw; \ 108 (ix1) = ew_u.parts.lsw; \ 109 } 110 111 #define GET_HIGH_WORD(i,d) \ 112 { \ 113 ieee_double_shape_type gh_u; \ 114 gh_u.value = (d); \ 115 (i) = gh_u.parts.msw; \ 116 } 117 118 #define SET_HIGH_WORD(d,v) \ 119 { \ 120 ieee_double_shape_type sh_u; \ 121 sh_u.value = (d); \ 122 sh_u.parts.msw = (v); \ 123 (d) = sh_u.value; \ 124 } 125 126 #define INSERT_WORDS(d,ix0,ix1) \ 127 { \ 128 ieee_double_shape_type iw_u; \ 129 iw_u.parts.msw = (ix0); \ 130 iw_u.parts.lsw = (ix1); \ 131 (d) = iw_u.value; \ 132 } 133 134 #endif /* _LIBM_MACROS_H */ 135