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