ieee.h revision 1.10 1 1.10 matt /* $NetBSD: ieee.h,v 1.10 2014/01/31 11:53:37 matt Exp $ */
2 1.6 matt
3 1.6 matt /*
4 1.6 matt * Copyright (c) 1992, 1993
5 1.6 matt * The Regents of the University of California. All rights reserved.
6 1.6 matt *
7 1.6 matt * This software was developed by the Computer Systems Engineering group
8 1.6 matt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.6 matt * contributed to Berkeley.
10 1.6 matt *
11 1.6 matt * All advertising materials mentioning features or use of this software
12 1.6 matt * must display the following acknowledgement:
13 1.6 matt * This product includes software developed by the University of
14 1.6 matt * California, Lawrence Berkeley Laboratory.
15 1.6 matt *
16 1.6 matt * Redistribution and use in source and binary forms, with or without
17 1.6 matt * modification, are permitted provided that the following conditions
18 1.6 matt * are met:
19 1.6 matt * 1. Redistributions of source code must retain the above copyright
20 1.6 matt * notice, this list of conditions and the following disclaimer.
21 1.6 matt * 2. Redistributions in binary form must reproduce the above copyright
22 1.6 matt * notice, this list of conditions and the following disclaimer in the
23 1.6 matt * documentation and/or other materials provided with the distribution.
24 1.6 matt * 3. Neither the name of the University nor the names of its contributors
25 1.6 matt * may be used to endorse or promote products derived from this software
26 1.6 matt * without specific prior written permission.
27 1.6 matt *
28 1.6 matt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.6 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.6 matt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.6 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.6 matt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.6 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.6 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.6 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.6 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.6 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.6 matt * SUCH DAMAGE.
39 1.6 matt *
40 1.6 matt * @(#)ieee.h 8.1 (Berkeley) 6/11/93
41 1.6 matt */
42 1.6 matt
43 1.6 matt /*
44 1.6 matt * ieee.h defines the machine-dependent layout of the machine's IEEE
45 1.6 matt * floating point. It does *not* define (yet?) any of the rounding
46 1.6 matt * mode bits, exceptions, and so forth.
47 1.6 matt */
48 1.6 matt
49 1.6 matt #ifndef _MIPS_IEEE_H
50 1.6 matt #define _MIPS_IEEE_H
51 1.1 mycroft
52 1.3 kleink #include <sys/ieee754.h>
53 1.4 kleink
54 1.4 kleink /*
55 1.10 matt * The MIPS architecture defines the following IEEE 754 compliant
56 1.6 matt * 128-bit extended-precision format, which is supported only by the
57 1.6 matt * v9 toolchain.
58 1.4 kleink */
59 1.4 kleink
60 1.6 matt #if defined(__mips_n32) || defined(__mips_n64)
61 1.6 matt
62 1.6 matt #define EXT_EXPBITS 15
63 1.10 matt #define EXT_FRACHBITS 48
64 1.10 matt #define EXT_FRACLBITS 64
65 1.10 matt #define EXT_FRACBITS (EXT_FRACLBITS + EXT_FRACHBITS)
66 1.10 matt
67 1.10 matt #define EXT_TO_ARRAY32(u, a) do { \
68 1.10 matt (a)[0] = (uint32_t)((u).extu_ext.ext_fracl >> 0); \
69 1.10 matt (a)[1] = (uint32_t)((u).extu_ext.ext_fracl >> 32); \
70 1.10 matt (a)[2] = (uint32_t)((u).extu_ext.ext_frach >> 0); \
71 1.10 matt (a)[3] = (uint32_t)((u).extu_ext.ext_frach >> 32); \
72 1.6 matt } while(/*CONSTCOND*/0)
73 1.6 matt
74 1.6 matt struct ieee_ext {
75 1.6 matt #if _BYTE_ORDER == _BIG_ENDIAN
76 1.10 matt uint64_t ext_sign:1;
77 1.10 matt uint64_t ext_exp:EXT_EXPBITS;
78 1.10 matt uint64_t ext_frach:EXT_FRACHBITS;
79 1.10 matt uint64_t ext_fracl;
80 1.6 matt #else
81 1.10 matt uint64_t ext_fracl;
82 1.10 matt uint64_t ext_frach:EXT_FRACHBITS;
83 1.10 matt uint64_t ext_exp:EXT_EXPBITS;
84 1.10 matt uint64_t ext_sign:1;
85 1.6 matt #endif
86 1.6 matt };
87 1.6 matt
88 1.6 matt /*
89 1.6 matt * Floats whose exponent is in [1..INFNAN) (of whatever type) are
90 1.6 matt * `normal'. Floats whose exponent is INFNAN are either Inf or NaN.
91 1.6 matt * Floats whose exponent is zero are either zero (iff all fraction
92 1.6 matt * bits are zero) or subnormal values.
93 1.6 matt *
94 1.6 matt * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its
95 1.6 matt * high fraction; if the bit is set, it is a `quiet NaN'.
96 1.6 matt */
97 1.6 matt #define EXT_EXP_INFNAN 0x7fff
98 1.6 matt #define EXT_EXP_INF 0x7fff
99 1.6 matt #define EXT_EXP_NAN 0x7fff
100 1.6 matt
101 1.4 kleink #if 0
102 1.4 kleink #define SNG_QUIETNAN (1 << 22)
103 1.4 kleink #define DBL_QUIETNAN (1 << 19)
104 1.6 matt #define EXT_QUIETNAN (1 << 15)
105 1.4 kleink #endif
106 1.6 matt
107 1.6 matt /*
108 1.6 matt * Exponent biases.
109 1.6 matt */
110 1.6 matt #define EXT_EXP_BIAS 16383
111 1.6 matt
112 1.6 matt /*
113 1.6 matt * Convenience data structures.
114 1.6 matt */
115 1.6 matt union ieee_ext_u {
116 1.6 matt long double extu_ld;
117 1.6 matt struct ieee_ext extu_ext;
118 1.6 matt };
119 1.6 matt
120 1.6 matt #define extu_exp extu_ext.ext_exp
121 1.6 matt #define extu_sign extu_ext.ext_sign
122 1.6 matt #define extu_fracl extu_ext.ext_fracl
123 1.6 matt #define extu_frach extu_ext.ext_frach
124 1.6 matt
125 1.9 matt #define LDBL_IMPLICIT_NBIT 1 /* our NBIT is implicit */
126 1.6 matt
127 1.6 matt #endif /* __mips_n32 || __mips_n64 */
128 1.6 matt
129 1.6 matt #endif /* _MIPS_IEEE_H */
130