Debian Codegraph @

common/softfloat.h

raw symbols SCIP
1 /* $Id: softfloat.h,v 1.23 2019/08/25 14:33:30 ragge Exp $ */
2
3 /*
4 * Copyright (c) 2015 Anders Magnusson. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include <stdint.h>
28
29 /*
30 * Definitions for softfloat routines.
31 *
32 * Floating point numbers will always be stored as the largest supported
33 * float type (long double). This in turn will be stuffed bitwise into
34 * an array of uint32_t for addressing.
35 */
36 #ifndef CROSS_COMPILING
37 #define DEBUGFP /* compare everything with native fp */
38 #endif
39
40 typedef struct softfloat {
41 union {
42 uint32_t fp[(SZLDOUBLE+31)/32];
43 #ifdef DEBUGFP
44 long double debugfp;
45 #endif
46 };
47 } SF;
48 typedef SF *SFP;
49
50 #define C(x,y) C2(x,y)
51 #define C2(x,y) x##y
52
53 struct FPI;
54 extern struct FPI *fpis[3]; /* FLOAT, DOUBLE, LDOUBLE, respectively */
55 extern struct FPI fpi_ffloat;
56 extern struct FPI fpi_dfloat;
57 extern struct FPI fpi_binary32;
58 extern struct FPI fpi_binary64;
59 extern struct FPI fpi_binaryx80;
60
61 /* MP package */
62 #define MAXMINT (256/16) /* nbits per uint16 */
63 typedef struct mint {
64 unsigned int len:15, sign:1; /* sign 1 if minus */
65 uint16_t allo; /* size in uint16_t */
66 uint16_t *val;
67 uint16_t vals[MAXMINT];
68 } MINT;
69 #define MINTDECL(x) x.len = x.sign = 0, x.allo = MAXMINT, x.val = x.vals
70
71 /*
72 * These defines are used in cpp.
73 */
74 #ifdef USE_IEEEFP_32
75 #define IEEEFP_32_RADIX 2
76 #define IEEEFP_32_DIG 6
77 #define IEEEFP_32_EPSILON 0x1.0p-23F
78 #define IEEEFP_32_MAX_10_EXP +38
79 #define IEEEFP_32_MAX_EXP +128
80 #define IEEEFP_32_MAX 0x1.fffffep+127F
81 #define IEEEFP_32_MIN_10_EXP -37
82 #define IEEEFP_32_MIN_EXP -125
83 #define IEEEFP_32_MIN 0x1.0p-126F
84 #define IEEEFP_32_MANT_DIG 24
85 #define IEEEFP_32_HAS_SUBNORM 1
86 #define IEEEFP_32_TRUE_MIN 0x1.0p-149F
87 #endif
88 #ifdef USE_IEEEFP_64
89 #define IEEEFP_64_DIG 15
90 #define IEEEFP_64_EPSILON 0x1.0p-52
91 #define IEEEFP_64_MAX_10_EXP 308
92 #define IEEEFP_64_MAX_EXP 1024
93 #define IEEEFP_64_MAX 0x1.fffffffffffffp+1023
94 #define IEEEFP_64_MIN_10_EXP (-307)
95 #define IEEEFP_64_MIN_EXP (-1021)
96 #define IEEEFP_64_MIN 0x1.0p-1022
97 #define IEEEFP_64_MANT_DIG 53
98 #define IEEEFP_64_HAS_SUBNORM 1
99 #define IEEEFP_64_TRUE_MIN 0x1.0p-1074
100 #endif
101 #ifdef USE_IEEEFP_X80
102 #define IEEEFP_X80_DIG 18
103 #define IEEEFP_X80_EPSILON 1.08420217248550443401e-19L
104 #define IEEEFP_X80_MAX_10_EXP 4932
105 #define IEEEFP_X80_MAX_EXP 16384
106 #define IEEEFP_X80_MAX 1.18973149535723176502e+4932L
107 #define IEEEFP_X80_MIN_10_EXP (-4931)
108 #define IEEEFP_X80_MIN_EXP (-16381)
109 #define IEEEFP_X80_MIN 3.36210314311209350626e-4932L
110 #define IEEEFP_X80_MANT_DIG 64
111 #define IEEEFP_X80_HAS_SUBNORM 1
112 #define IEEEFP_X80_TRUE_MIN 0x1.0p-16445L
113 #endif
114 #ifdef IEEEFP_128
115 #endif
116
117 #ifdef FDFLOAT
118 #define FFLOAT_DIG 6
119 #define FFLOAT_EPSILON 1.19209290E-7F
120 #define FFLOAT_MAX_10_EXP 38
121 #define FFLOAT_MAX_EXP (+127)
122 #define FFLOAT_MAX 1.70141173E+38F
123 #define FFLOAT_MIN_10_EXP (-38)
124 #define FFLOAT_MIN_EXP (-127)
125 #define FFLOAT_MIN 2.93873588E-39F
126 #define FFLOAT_MANT_DIG 24
127
128 #define DFLOAT_DIG 16
129 #define DFLOAT_EPSILON 2.77555756156289135E-17
130 #define DFLOAT_MAX_10_EXP 38
131 #define DFLOAT_MAX_EXP (+127)
132 #define DFLOAT_MAX 1.701411834604692294E+38
133 #define DFLOAT_MIN_10_EXP (-38)
134 #define DFLOAT_MIN_EXP (-127)
135 #define DFLOAT_MIN 2.938735877055718770E-39
136 #define DFLOAT_MANT_DIG 56
137 #endif
138
139 #define TARGET_FLT_RADIX C(FLT_FP,_RADIX)
140
141 #ifndef CC_DRIVER
142 void strtosf(SFP, char *, TWORD);
143 void soft_neg(SF *);
144 void soft_int2fp(SFP, CONSZ p, TWORD f, TWORD v);
145 CONSZ soft_fp2int(SF *p, TWORD v);
146 void soft_fp2fp(SFP p, TWORD v);
147 void soft_plus(SFP, SFP, TWORD);
148 void soft_minus(SFP, SFP, TWORD);
149 void soft_mul(SFP, SFP, TWORD);
150 void soft_div(SFP, SFP, TWORD);
151 int soft_cmp(SF*, SF*, int);
152 int soft_isz(SF*);
153 void soft_huge_val(SFP);
154 void soft_nan(SFP, char *);
155 uint32_t *soft_toush(SFP, TWORD, int *);
156 #ifdef DEBUGFP
157 void fpwarn(const char *s, long double soft, long double hard);
158 #endif
159 #endif