blob: c579969dcfef38dc95e782693c865326c3455dd4 [file] [log] [blame]
Elliott Hughes02c78a32014-04-11 17:02:20 -07001/* $OpenBSD: ieee.h,v 1.4 2011/11/08 17:06:51 deraadt Exp $ */
Serban Constantinescue2104882013-09-26 11:37:10 +01002/* $NetBSD: ieee.h,v 1.2 2001/02/21 17:43:50 bjh21 Exp $ */
3
4/*
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This software was developed by the Computer Systems Engineering group
9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10 * contributed to Berkeley.
11 *
12 * All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by the University of
15 * California, Lawrence Berkeley Laboratory.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. All advertising materials mentioning features or use of this software
26 * must display the following acknowledgement:
27 * This product includes software developed by the University of
28 * California, Berkeley and its contributors.
29 * 4. Neither the name of the University nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
37 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * SUCH DAMAGE.
44 *
45 * @(#)ieee.h 8.1 (Berkeley) 6/11/93
46 */
47
Elliott Hughescb65cc32014-04-16 16:31:17 -070048#ifndef _MACHINE_IEEE_H_
49#define _MACHINE_IEEE_H_
Serban Constantinescue2104882013-09-26 11:37:10 +010050
Elliott Hughescb65cc32014-04-16 16:31:17 -070051#include <sys/types.h>
Serban Constantinescue2104882013-09-26 11:37:10 +010052
Elliott Hughescb65cc32014-04-16 16:31:17 -070053__BEGIN_DECLS
Elliott Hughes4bd97ce2014-04-10 17:48:14 -070054
Elliott Hughescb65cc32014-04-16 16:31:17 -070055#define SNG_EXPBITS 8
56#define SNG_FRACBITS 23
Elliott Hughes4bd97ce2014-04-10 17:48:14 -070057
Elliott Hughescb65cc32014-04-16 16:31:17 -070058#define SNG_EXP_INFNAN 255
59#define SNG_EXP_BIAS 127
Elliott Hughes4bd97ce2014-04-10 17:48:14 -070060
Serban Constantinescue2104882013-09-26 11:37:10 +010061struct ieee_single {
Elliott Hughescb65cc32014-04-16 16:31:17 -070062 unsigned sng_frac:23;
63 unsigned sng_exp:8;
64 unsigned sng_sign:1;
Serban Constantinescue2104882013-09-26 11:37:10 +010065};
66
Elliott Hughescb65cc32014-04-16 16:31:17 -070067#define DBL_EXPBITS 11
68#define DBL_FRACHBITS 20
69#define DBL_FRACLBITS 32
70#define DBL_FRACBITS 52
71
72#define DBL_EXP_INFNAN 2047
73#define DBL_EXP_BIAS 1023
74
Serban Constantinescue2104882013-09-26 11:37:10 +010075struct ieee_double {
Elliott Hughescb65cc32014-04-16 16:31:17 -070076 unsigned dbl_fracl;
77 unsigned dbl_frach:20;
78 unsigned dbl_exp:11;
79 unsigned dbl_sign:1;
Serban Constantinescue2104882013-09-26 11:37:10 +010080};
Serban Constantinescue2104882013-09-26 11:37:10 +010081
Elliott Hughescb65cc32014-04-16 16:31:17 -070082#if __LP64__
83
84/* 64-bit Android uses ld128 long doubles. */
85
86#define EXT_EXPBITS 15
87#define EXT_FRACHBITS 16
88#define EXT_FRACHMBITS 32
89#define EXT_FRACLMBITS 32
90#define EXT_FRACLBITS 32
91#define EXT_FRACBITS 112
92
93#define EXT_EXP_INFNAN 32767
94#define EXT_EXP_BIAS 16383
95
96#define EXT_IMPLICIT_NBIT
97
98#define EXT_TO_ARRAY32(p, a) do { \
99 (a)[0] = (uint32_t)(p)->ext_fracl; \
100 (a)[1] = (uint32_t)(p)->ext_fraclm; \
101 (a)[2] = (uint32_t)(p)->ext_frachm; \
102 (a)[3] = (uint32_t)(p)->ext_frach; \
103} while(0)
104
Elliott Hughes4bd97ce2014-04-10 17:48:14 -0700105struct ieee_ext {
Elliott Hughescb65cc32014-04-16 16:31:17 -0700106 unsigned ext_fracl;
107 unsigned ext_fraclm;
108 unsigned ext_frachm;
109 unsigned ext_frach:16;
110 unsigned ext_exp:15;
111 unsigned ext_sign:1;
Elliott Hughes4bd97ce2014-04-10 17:48:14 -0700112};
113
Elliott Hughescb65cc32014-04-16 16:31:17 -0700114#endif
Serban Constantinescue2104882013-09-26 11:37:10 +0100115
Elliott Hughescb65cc32014-04-16 16:31:17 -0700116__END_DECLS
117
118#endif /* _MACHINE_IEEE_H_ */