History

Remove libc dependency from lib-arm64

Moving the u128_t struct may invoke calls to memcpy/memmove when compiled with tinycc, which would depend on libc. For example, some configure scripts get confused if they fail to build test programs involving long doubles. I'm not sure if this is the root cause, though.

Aleksi Hannula committed 9 months ago

Commit 8c61b911 parent aeae4b41 file · +52 −47Browse files

Unified · Split

lib/lib-arm64.c+52−47
@@ -18,7 +18,14 @@ typedef int int32_t; · 17 unmodified lines
18typedef unsigned uint32_t;18typedef unsigned uint32_t;
19typedef long long int64_t;19typedef long long int64_t;
20typedef unsigned long long uint64_t;20typedef unsigned long long uint64_t;
21void *memcpy(void*,void*,__SIZE_TYPE__);21static void *memcpy(void* d, void* s, __SIZE_TYPE__ c) {
22 char *d_, *s_;
23 d_ = d; s_ = s;
24 for (__SIZE_TYPE__ i = 0; i < c; ++i) {
25 d_[i] = s_[i];
26 }
27 return d;
28}
22#else29#else
23#include <stdint.h>30#include <stdint.h>
24#include <string.h>31#include <string.h>
@@ -103,74 +110,72 @@ static void f3_unpack(int *sgn, int32_t *exp, u128_t *mnt, long double f) · 78 unmodified lines
103 x.x1 |= (uint64_t)1 << 48;110 x.x1 |= (uint64_t)1 << 48;
104 else111 else
105 *exp = 1;112 *exp = 1;
106 *mnt = x;113 memcpy(mnt, &x, 16);
107}114}
108 115
109static u128_t f3_normalise(int32_t *exp, u128_t mnt)116static void f3_normalise(int32_t *exp, u128_t *mnt)
110{117{
111 int sh;118 int sh;
112 if (!(mnt.x0 | mnt.x1))119 if (!(mnt->x0 | mnt->x1))
113 return mnt;120 return;
114 if (!mnt.x1) {121 if (!mnt->x1) {
115 mnt.x1 = mnt.x0;122 mnt->x1 = mnt->x0;
116 mnt.x0 = 0;123 mnt->x0 = 0;
117 *exp -= 64;124 *exp -= 64;
118 }125 }
119 for (sh = 32; sh; sh >>= 1) {126 for (sh = 32; sh; sh >>= 1) {
120 if (!(mnt.x1 >> (64 - sh))) {127 if (!(mnt->x1 >> (64 - sh))) {
121 mnt.x1 = mnt.x1 << sh | mnt.x0 >> (64 - sh);128 mnt->x1 = mnt->x1 << sh | mnt->x0 >> (64 - sh);
122 mnt.x0 = mnt.x0 << sh;129 mnt->x0 = mnt->x0 << sh;
123 *exp -= sh;130 *exp -= sh;
124 }131 }
125 }132 }
126 return mnt;
127}133}
128 134
129static u128_t f3_sticky_shift(int32_t sh, u128_t x)135static void f3_sticky_shift(int32_t sh, u128_t *x)
130{136{
131 if (sh >= 128) {137 if (sh >= 128) {
132 x.x0 = !!(x.x0 | x.x1);138 x->x0 = !!(x->x0 | x->x1);
133 x.x1 = 0;139 x->x1 = 0;
134 return x;140 return;
135 }141 }
136 if (sh >= 64) {142 if (sh >= 64) {
137 x.x0 = x.x1 | !!x.x0;143 x->x0 = x->x1 | !!x->x0;
138 x.x1 = 0;144 x->x1 = 0;
139 sh -= 64;145 sh -= 64;
140 }146 }
141 if (sh > 0) {147 if (sh > 0) {
142 x.x0 = x.x0 >> sh | x.x1 << (64 - sh) | !!(x.x0 << (64 - sh));148 x->x0 = x->x0 >> sh | x->x1 << (64 - sh) | !!(x->x0 << (64 - sh));
143 x.x1 = x.x1 >> sh;149 x->x1 = x->x1 >> sh;
144 }150 }
145 return x;
146}151}
147 152
148static long double f3_round(int sgn, int32_t exp, u128_t x)153static long double f3_round(int sgn, int32_t exp, u128_t *x)
149{154{
150 long double f;155 long double f;
151 int error;156 int error;
152 157
153 if (exp > 0) {158 if (exp > 0) {
154 x = f3_sticky_shift(13, x);159 f3_sticky_shift(13, x);
155 }160 }
156 else {161 else {
157 x = f3_sticky_shift(14 - exp, x);162 f3_sticky_shift(14 - exp, x);
158 exp = 0;163 exp = 0;
159 }164 }
160 165
161 error = x.x0 & 3;166 error = x->x0 & 3;
162 x.x0 = x.x0 >> 2 | x.x1 << 62;167 x->x0 = x->x0 >> 2 | x->x1 << 62;
163 x.x1 = x.x1 >> 2;168 x->x1 = x->x1 >> 2;
164 169
165 if (error == 3 || ((error == 2) & (x.x0 & 1))) {170 if (error == 3 || ((error == 2) & (x->x0 & 1))) {
166 if (!++x.x0) {171 if (!++x->x0) {
167 ++x.x1;172 ++x->x1;
168 if (x.x1 == (uint64_t)1 << 48)173 if (x->x1 == (uint64_t)1 << 48)
169 exp = 1;174 exp = 1;
170 else if (x.x1 == (uint64_t)1 << 49) {175 else if (x->x1 == (uint64_t)1 << 49) {
171 ++exp;176 ++exp;
172 x.x0 = x.x0 >> 1 | x.x1 << 63;177 x->x0 = x->x0 >> 1 | x->x1 << 63;
173 x.x1 = x.x1 >> 1;178 x->x1 = x->x1 >> 1;
174 }179 }
175 }180 }
176 }181 }
@@ -178,8 +183,8 @@ static long double f3_round(int sgn, int32_t exp, u128_t x) · 1 unmodified line
178 if (exp >= 32767)183 if (exp >= 32767)
179 return f3_infinity(sgn);184 return f3_infinity(sgn);
180 185
181 x.x1 = x.x1 << 16 >> 16 | (uint64_t)exp << 48 | (uint64_t)sgn << 63;186 x->x1 = x->x1 << 16 >> 16 | (uint64_t)exp << 48 | (uint64_t)sgn << 63;
182 memcpy(&f, &x, 16);187 memcpy(&f, x, 16);
183 return f;188 return f;
184}189}
185 190
@@ -214,11 +219,11 @@ static long double f3_add(long double fa, long double fb, int neg) · 28 unmodified lines
214 b.x0 = b.x0 << 3;219 b.x0 = b.x0 << 3;
215 220
216 if (a_exp <= b_exp) {221 if (a_exp <= b_exp) {
217 a = f3_sticky_shift(b_exp - a_exp, a);222 f3_sticky_shift(b_exp - a_exp, &a);
218 a_exp = b_exp;223 a_exp = b_exp;
219 }224 }
220 else {225 else {
221 b = f3_sticky_shift(a_exp - b_exp, b);226 f3_sticky_shift(a_exp - b_exp, &b);
222 b_exp = a_exp;227 b_exp = a_exp;
223 }228 }
224 229
@@ -241,9 +246,9 @@ static long double f3_add(long double fa, long double fb, int neg) · 16 unmodified lines
241 if (!(x.x0 | x.x1))246 if (!(x.x0 | x.x1))
242 return f3_zero(0);247 return f3_zero(0);
243 248
244 x = f3_normalise(&x_exp, x);249 f3_normalise(&x_exp, &x);
245 250
246 return f3_round(x_sgn, x_exp + 12, x);251 return f3_round(x_sgn, x_exp + 12, &x);
247}252}
248 253
249long double __addtf3(long double a, long double b)254long double __addtf3(long double a, long double b)
@@ -278,8 +283,8 @@ long double __multf3(long double fa, long double fb) · 28 unmodified lines
278 if (!(a.x0 | a.x1) || !(b.x0 | b.x1))283 if (!(a.x0 | a.x1) || !(b.x0 | b.x1))
279 return f3_zero(a_sgn ^ b_sgn);284 return f3_zero(a_sgn ^ b_sgn);
280 285
281 a = f3_normalise(&a_exp, a);286 f3_normalise(&a_exp, &a);
282 b = f3_normalise(&b_exp, b);287 f3_normalise(&b_exp, &b);
283 288
284 x_sgn = a_sgn ^ b_sgn;289 x_sgn = a_sgn ^ b_sgn;
285 x_exp = a_exp + b_exp - 16352;290 x_exp = a_exp + b_exp - 16352;
@@ -318,7 +323,7 @@ long double __multf3(long double fa, long double fb) · 32 unmodified lines
318 x.x1 = y1;323 x.x1 = y1;
319 }324 }
320 325
321 return f3_round(x_sgn, x_exp, x);326 return f3_round(x_sgn, x_exp, &x);
322}327}
323 328
324long double __divtf3(long double fa, long double fb)329long double __divtf3(long double fa, long double fb)
@@ -343,8 +348,8 @@ long double __divtf3(long double fa, long double fb) · 18 unmodified lines
343 if (!(a.x0 | a.x1) || b_exp == 32767)348 if (!(a.x0 | a.x1) || b_exp == 32767)
344 return f3_zero(a_sgn ^ b_sgn);349 return f3_zero(a_sgn ^ b_sgn);
345 350
346 a = f3_normalise(&a_exp, a);351 f3_normalise(&a_exp, &a);
347 b = f3_normalise(&b_exp, b);352 f3_normalise(&b_exp, &b);
348 353
349 x_sgn = a_sgn ^ b_sgn;354 x_sgn = a_sgn ^ b_sgn;
350 x_exp = a_exp - b_exp + 16395;355 x_exp = a_exp - b_exp + 16395;
@@ -368,9 +373,9 @@ long double __divtf3(long double fa, long double fb) · 17 unmodified lines
368 }373 }
369 x.x0 |= !!(a.x0 | a.x1);374 x.x0 |= !!(a.x0 | a.x1);
370 375
371 x = f3_normalise(&x_exp, x);376 f3_normalise(&x_exp, &x);
372 377
373 return f3_round(x_sgn, x_exp, x);378 return f3_round(x_sgn, x_exp, &x);
374}379}
375 380
376long double __negtf2(long double f)381long double __negtf2(long double f)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t