1 /* Software floating-point emulation.
2 Definitions for Brain Floating Point format (bfloat16).
3 Copyright (C) 1997-2022 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 In addition to the permissions in the GNU Lesser General Public
12 License, the Free Software Foundation gives you unlimited
13 permission to link the compiled version of this file into
14 combinations with other programs, and to distribute those
15 combinations without any restriction coming from the use of this
16 file. (The Lesser General Public License restrictions do apply in
17 other respects; for example, they cover modification of the file,
18 and distribution when not linked into a combine executable.)
20 The GNU C Library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Lesser General Public License for more details.
25 You should have received a copy of the GNU Lesser General Public
26 License along with the GNU C Library; if not, see
27 <https://www.gnu.org/licenses/>. */
29 #ifndef SOFT_FP_BRAIN_H
30 #define SOFT_FP_BRAIN_H 1
32 #if _FP_W_TYPE_SIZE < 32
33 # error "Here's a nickel kid. Go buy yourself a real computer."
36 #define _FP_FRACTBITS_B (_FP_W_TYPE_SIZE)
38 #define _FP_FRACTBITS_DW_B (_FP_W_TYPE_SIZE)
40 #define _FP_FRACBITS_B 8
41 #define _FP_FRACXBITS_B (_FP_FRACTBITS_B - _FP_FRACBITS_B)
42 #define _FP_WFRACBITS_B (_FP_WORKBITS + _FP_FRACBITS_B)
43 #define _FP_WFRACXBITS_B (_FP_FRACTBITS_B - _FP_WFRACBITS_B)
44 #define _FP_EXPBITS_B 8
45 #define _FP_EXPBIAS_B 127
46 #define _FP_EXPMAX_B 255
48 #define _FP_QNANBIT_B ((_FP_W_TYPE) 1 << (_FP_FRACBITS_B-2))
49 #define _FP_QNANBIT_SH_B ((_FP_W_TYPE) 1 << (_FP_FRACBITS_B-2+_FP_WORKBITS))
50 #define _FP_IMPLBIT_B ((_FP_W_TYPE) 1 << (_FP_FRACBITS_B-1))
51 #define _FP_IMPLBIT_SH_B ((_FP_W_TYPE) 1 << (_FP_FRACBITS_B-1+_FP_WORKBITS))
52 #define _FP_OVERFLOW_B ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_B))
54 #define _FP_WFRACBITS_DW_B (2 * _FP_WFRACBITS_B)
55 #define _FP_WFRACXBITS_DW_B (_FP_FRACTBITS_DW_B - _FP_WFRACBITS_DW_B)
56 #define _FP_HIGHBIT_DW_B \
57 ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_B - 1) % _FP_W_TYPE_SIZE)
59 /* The implementation of _FP_MUL_MEAT_B and _FP_DIV_MEAT_B should be
60 chosen by the target machine. */
62 typedef float BFtype
__attribute__ ((mode (BF
)));
67 struct _FP_STRUCT_LAYOUT
69 #if __BYTE_ORDER == __BIG_ENDIAN
71 unsigned exp
: _FP_EXPBITS_B
;
72 unsigned frac
: _FP_FRACBITS_B
- (_FP_IMPLBIT_B
!= 0);
74 unsigned frac
: _FP_FRACBITS_B
- (_FP_IMPLBIT_B
!= 0);
75 unsigned exp
: _FP_EXPBITS_B
;
81 #define FP_DECL_B(X) _FP_DECL (1, X)
82 #define FP_UNPACK_RAW_B(X, val) _FP_UNPACK_RAW_1 (B, X, (val))
83 #define FP_UNPACK_RAW_BP(X, val) _FP_UNPACK_RAW_1_P (B, X, (val))
84 #define FP_PACK_RAW_B(val, X) _FP_PACK_RAW_1 (B, (val), X)
85 #define FP_PACK_RAW_BP(val, X) \
88 if (!FP_INHIBIT_RESULTS) \
89 _FP_PACK_RAW_1_P (B, (val), X); \
93 #define FP_UNPACK_B(X, val) \
96 _FP_UNPACK_RAW_1 (B, X, (val)); \
97 _FP_UNPACK_CANONICAL (B, 1, X); \
101 #define FP_UNPACK_BP(X, val) \
104 _FP_UNPACK_RAW_1_P (B, X, (val)); \
105 _FP_UNPACK_CANONICAL (B, 1, X); \
109 #define FP_UNPACK_SEMIRAW_B(X, val) \
112 _FP_UNPACK_RAW_1 (B, X, (val)); \
113 _FP_UNPACK_SEMIRAW (B, 1, X); \
117 #define FP_UNPACK_SEMIRAW_BP(X, val) \
120 _FP_UNPACK_RAW_1_P (B, X, (val)); \
121 _FP_UNPACK_SEMIRAW (B, 1, X); \
125 #define FP_PACK_B(val, X) \
128 _FP_PACK_CANONICAL (B, 1, X); \
129 _FP_PACK_RAW_1 (B, (val), X); \
133 #define FP_PACK_BP(val, X) \
136 _FP_PACK_CANONICAL (B, 1, X); \
137 if (!FP_INHIBIT_RESULTS) \
138 _FP_PACK_RAW_1_P (B, (val), X); \
142 #define FP_PACK_SEMIRAW_B(val, X) \
145 _FP_PACK_SEMIRAW (B, 1, X); \
146 _FP_PACK_RAW_1 (B, (val), X); \
150 #define FP_PACK_SEMIRAW_BP(val, X) \
153 _FP_PACK_SEMIRAW (B, 1, X); \
154 if (!FP_INHIBIT_RESULTS) \
155 _FP_PACK_RAW_1_P (B, (val), X); \
159 #define FP_TO_INT_B(r, X, rsz, rsg) _FP_TO_INT (B, 1, (r), X, (rsz), (rsg))
160 #define FP_TO_INT_ROUND_B(r, X, rsz, rsg) \
161 _FP_TO_INT_ROUND (B, 1, (r), X, (rsz), (rsg))
162 #define FP_FROM_INT_B(X, r, rs, rt) _FP_FROM_INT (B, 1, X, (r), (rs), rt)
164 /* BFmode arithmetic is not implemented. */
166 #define _FP_FRAC_HIGH_B(X) _FP_FRAC_HIGH_1 (X)
167 #define _FP_FRAC_HIGH_RAW_B(X) _FP_FRAC_HIGH_1 (X)
168 #define _FP_FRAC_HIGH_DW_B(X) _FP_FRAC_HIGH_1 (X)
170 #define FP_CMP_EQ_B(r, X, Y, ex) _FP_CMP_EQ (B, 1, (r), X, Y, (ex))
172 #endif /* !SOFT_FP_BRAIN_H */