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
1818 typedef unsigned uint32_t;
1919 typedef long long int64_t;
2020 typedef unsigned long long uint64_t;
21−void *memcpy(void*,void*,__SIZE_TYPE__);
21+static 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+}
2229 #else
2330 #include <stdint.h>
2431 #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
103110 x.x1 |= (uint64_t)1 << 48;
104111 else
105112 *exp = 1;
106− *mnt = x;
113+ memcpy(mnt, &x, 16);
107114 }
108115
109−static u128_t f3_normalise(int32_t *exp, u128_t mnt)
116+static void f3_normalise(int32_t *exp, u128_t *mnt)
110117 {
111118 int sh;
112− if (!(mnt.x0 | mnt.x1))
113− return mnt;
114− if (!mnt.x1) {
115− mnt.x1 = mnt.x0;
116− mnt.x0 = 0;
119+ if (!(mnt->x0 | mnt->x1))
120+ return;
121+ if (!mnt->x1) {
122+ mnt->x1 = mnt->x0;
123+ mnt->x0 = 0;
117124 *exp -= 64;
118125 }
119126 for (sh = 32; sh; sh >>= 1) {
120− if (!(mnt.x1 >> (64 - sh))) {
121− mnt.x1 = mnt.x1 << sh | mnt.x0 >> (64 - sh);
122− mnt.x0 = mnt.x0 << sh;
127+ if (!(mnt->x1 >> (64 - sh))) {
128+ mnt->x1 = mnt->x1 << sh | mnt->x0 >> (64 - sh);
129+ mnt->x0 = mnt->x0 << sh;
123130 *exp -= sh;
124131 }
125132 }
126− return mnt;
127133 }
128134
129−static u128_t f3_sticky_shift(int32_t sh, u128_t x)
135+static void f3_sticky_shift(int32_t sh, u128_t *x)
130136 {
131137 if (sh >= 128) {
132− x.x0 = !!(x.x0 | x.x1);
133− x.x1 = 0;
134− return x;
138+ x->x0 = !!(x->x0 | x->x1);
139+ x->x1 = 0;
140+ return;
135141 }
136142 if (sh >= 64) {
137− x.x0 = x.x1 | !!x.x0;
138− x.x1 = 0;
143+ x->x0 = x->x1 | !!x->x0;
144+ x->x1 = 0;
139145 sh -= 64;
140146 }
141147 if (sh > 0) {
142− x.x0 = x.x0 >> sh | x.x1 << (64 - sh) | !!(x.x0 << (64 - sh));
143− x.x1 = x.x1 >> sh;
148+ x->x0 = x->x0 >> sh | x->x1 << (64 - sh) | !!(x->x0 << (64 - sh));
149+ x->x1 = x->x1 >> sh;
144150 }
145− return x;
146151 }
147152
148−static long double f3_round(int sgn, int32_t exp, u128_t x)
153+static long double f3_round(int sgn, int32_t exp, u128_t *x)
149154 {
150155 long double f;
151156 int error;
152157
153158 if (exp > 0) {
154− x = f3_sticky_shift(13, x);
159+ f3_sticky_shift(13, x);
155160 }
156161 else {
157− x = f3_sticky_shift(14 - exp, x);
162+ f3_sticky_shift(14 - exp, x);
158163 exp = 0;
159164 }
160165
161− error = x.x0 & 3;
162− x.x0 = x.x0 >> 2 | x.x1 << 62;
163− x.x1 = x.x1 >> 2;
166+ error = x->x0 & 3;
167+ x->x0 = x->x0 >> 2 | x->x1 << 62;
168+ x->x1 = x->x1 >> 2;
164169
165− if (error == 3 || ((error == 2) & (x.x0 & 1))) {
166− if (!++x.x0) {
167− ++x.x1;
168− if (x.x1 == (uint64_t)1 << 48)
170+ if (error == 3 || ((error == 2) & (x->x0 & 1))) {
171+ if (!++x->x0) {
172+ ++x->x1;
173+ if (x->x1 == (uint64_t)1 << 48)
169174 exp = 1;
170− else if (x.x1 == (uint64_t)1 << 49) {
175+ else if (x->x1 == (uint64_t)1 << 49) {
171176 ++exp;
172− x.x0 = x.x0 >> 1 | x.x1 << 63;
173− x.x1 = x.x1 >> 1;
177+ x->x0 = x->x0 >> 1 | x->x1 << 63;
178+ x->x1 = x->x1 >> 1;
174179 }
175180 }
176181 }
@@ -178,8 +183,8 @@ static long double f3_round(int sgn, int32_t exp, u128_t x) · 1 unmodified line
178183 if (exp >= 32767)
179184 return f3_infinity(sgn);
180185
181− x.x1 = x.x1 << 16 >> 16 | (uint64_t)exp << 48 | (uint64_t)sgn << 63;
182− memcpy(&f, &x, 16);
186+ x->x1 = x->x1 << 16 >> 16 | (uint64_t)exp << 48 | (uint64_t)sgn << 63;
187+ memcpy(&f, x, 16);
183188 return f;
184189 }
185190
@@ -214,11 +219,11 @@ static long double f3_add(long double fa, long double fb, int neg) · 28 unmodified lines
214219 b.x0 = b.x0 << 3;
215220
216221 if (a_exp <= b_exp) {
217− a = f3_sticky_shift(b_exp - a_exp, a);
222+ f3_sticky_shift(b_exp - a_exp, &a);
218223 a_exp = b_exp;
219224 }
220225 else {
221− b = f3_sticky_shift(a_exp - b_exp, b);
226+ f3_sticky_shift(a_exp - b_exp, &b);
222227 b_exp = a_exp;
223228 }
224229
@@ -241,9 +246,9 @@ static long double f3_add(long double fa, long double fb, int neg) · 16 unmodified lines
241246 if (!(x.x0 | x.x1))
242247 return f3_zero(0);
243248
244− x = f3_normalise(&x_exp, x);
249+ f3_normalise(&x_exp, &x);
245250
246− return f3_round(x_sgn, x_exp + 12, x);
251+ return f3_round(x_sgn, x_exp + 12, &x);
247252 }
248253
249254 long double __addtf3(long double a, long double b)
@@ -278,8 +283,8 @@ long double __multf3(long double fa, long double fb) · 28 unmodified lines
278283 if (!(a.x0 | a.x1) || !(b.x0 | b.x1))
279284 return f3_zero(a_sgn ^ b_sgn);
280285
281− a = f3_normalise(&a_exp, a);
282− b = f3_normalise(&b_exp, b);
286+ f3_normalise(&a_exp, &a);
287+ f3_normalise(&b_exp, &b);
283288
284289 x_sgn = a_sgn ^ b_sgn;
285290 x_exp = a_exp + b_exp - 16352;
@@ -318,7 +323,7 @@ long double __multf3(long double fa, long double fb) · 32 unmodified lines
318323 x.x1 = y1;
319324 }
320325
321− return f3_round(x_sgn, x_exp, x);
326+ return f3_round(x_sgn, x_exp, &x);
322327 }
323328
324329 long double __divtf3(long double fa, long double fb)
@@ -343,8 +348,8 @@ long double __divtf3(long double fa, long double fb) · 18 unmodified lines
343348 if (!(a.x0 | a.x1) || b_exp == 32767)
344349 return f3_zero(a_sgn ^ b_sgn);
345350
346− a = f3_normalise(&a_exp, a);
347− b = f3_normalise(&b_exp, b);
351+ f3_normalise(&a_exp, &a);
352+ f3_normalise(&b_exp, &b);
348353
349354 x_sgn = a_sgn ^ b_sgn;
350355 x_exp = a_exp - b_exp + 16395;
@@ -368,9 +373,9 @@ long double __divtf3(long double fa, long double fb) · 17 unmodified lines
368373 }
369374 x.x0 |= !!(a.x0 | a.x1);
370375
371− x = f3_normalise(&x_exp, x);
376+ f3_normalise(&x_exp, &x);
372377
373− return f3_round(x_sgn, x_exp, x);
378+ return f3_round(x_sgn, x_exp, &x);
374379 }
375380
376381 long 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