on master help sign in
fix for bugs in the bits primitive operations

See previous commit message for the explanation of the bug. This commit gives the right fix for the bug, which is to take out the values that you will need from the arguments before using the allocator. The reason is that the allocator may trigger a GC collection which will move your arguments away. While you can use the resulting FWD pointer to get the data, FWD values should never be used outside of the garbage collector. The gmp operations should be looked at to make sure it is not doing this. In summary, any C code that uses the allocator should save any relevant values that its pointers are pointing to first.

commitbe386bdba2869ff905234986d32c832e95e26a83 authorEvanR <evanrinehart@gmail.com> dateTue 7 Oct 2014, 10:41 (12 years ago) parent6184856
2 files changed+216−93
rts/idris_bitstring.c+216−88 rts/idris_rts.h−5
rts/idris_bitstring.c+216−88
@@ -1,58 +1,66 @@
11#include "idris_rts.h"
22
33VAL idris_b8CopyForGC(VM *vm, VAL a) {
4+ uint8_t A = a->info.bits8;
45 VAL cl = allocate(vm, sizeof(Closure), 1);
56 SETTY(cl, BITS8);
6− cl->info.bits8 = GETBITS8(a);
7+ cl->info.bits8 = A;
78 return cl;
89}
910
1011VAL idris_b16CopyForGC(VM *vm, VAL a) {
12+ uint16_t A = a->info.bits16;
1113 VAL cl = allocate(vm, sizeof(Closure), 1);
1214 SETTY(cl, BITS16);
13− cl->info.bits16 = GETBITS16(a);
15+ cl->info.bits16 = A;
1416 return cl;
1517}
1618
1719VAL idris_b32CopyForGC(VM *vm, VAL a) {
20+ uint32_t A = a->info.bits32;
1821 VAL cl = allocate(vm, sizeof(Closure), 1);
1922 SETTY(cl, BITS32);
20− cl->info.bits32 = GETBITS32(a);
23+ cl->info.bits32 = A;
2124 return cl;
2225}
2326
2427VAL idris_b64CopyForGC(VM *vm, VAL a) {
28+ uint64_t A = a->info.bits64;
2529 VAL cl = allocate(vm, sizeof(Closure), 1);
2630 SETTY(cl, BITS64);
27− cl->info.bits64 = GETBITS64(a);
31+ cl->info.bits64 = A;
2832 return cl;
2933}
3034
3135VAL idris_b8(VM *vm, VAL a) {
36+ uint8_t A = GETINT(a);
3237 VAL cl = allocate(vm, sizeof(Closure), 0);
3338 SETTY(cl, BITS8);
34− cl->info.bits8 = (uint8_t) GETINT(a);
39+ cl->info.bits8 = (uint8_t) A;
3540 return cl;
3641}
3742
3843VAL idris_b16(VM *vm, VAL a) {
44+ uint16_t A = GETINT(a);
3945 VAL cl = allocate(vm, sizeof(Closure), 0);
4046 SETTY(cl, BITS16);
41− cl->info.bits16 = (uint16_t) GETINT(a);
47+ cl->info.bits16 = (uint16_t) A;
4248 return cl;
4349}
4450
4551VAL idris_b32(VM *vm, VAL a) {
52+ uint32_t A = GETINT(a);
4653 VAL cl = allocate(vm, sizeof(Closure), 0);
4754 SETTY(cl, BITS32);
48− cl->info.bits32 = (uint32_t) GETINT(a);
55+ cl->info.bits32 = (uint32_t) A;
4956 return cl;
5057}
5158
5259VAL idris_b64(VM *vm, VAL a) {
60+ uint64_t A = GETINT(a);
5361 VAL cl = allocate(vm, sizeof(Closure), 0);
5462 SETTY(cl, BITS64);
55− cl->info.bits64 = (uint64_t) GETINT(a);
63+ cl->info.bits64 = (uint64_t) A;
5664 return cl;
5765}
5866
@@ -89,51 +97,65 @@ VAL idris_b64const(VM *vm, uint64_t a) {
8997}
9098
9199VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
100+ uint8_t A = a->info.bits8;
101+ uint8_t B = b->info.bits8;
92102 VAL cl = allocate(vm, sizeof(Closure), 0);
93103 SETTY(cl, BITS8);
94− cl->info.bits8 = GETBITS8(a) + GETBITS8(b);
104+ cl->info.bits8 = A + B;
95105 return cl;
96106}
97107
98108VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
109+ uint8_t A = a->info.bits8;
110+ uint8_t B = b->info.bits8;
99111 VAL cl = allocate(vm, sizeof(Closure), 0);
100112 SETTY(cl, BITS8);
101− cl->info.bits8 = GETBITS8(a) - GETBITS8(b);
113+ cl->info.bits8 = A - B;
102114 return cl;
103115}
104116
105117VAL idris_b8Times(VM *vm, VAL a, VAL b) {
118+ uint8_t A = a->info.bits8;
119+ uint8_t B = b->info.bits8;
106120 VAL cl = allocate(vm, sizeof(Closure), 0);
107121 SETTY(cl, BITS8);
108− cl->info.bits8 = GETBITS8(a) * GETBITS8(b);
122+ cl->info.bits8 = A * B;
109123 return cl;
110124}
111125
112126VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
127+ uint8_t A = a->info.bits8;
128+ uint8_t B = b->info.bits8;
113129 VAL cl = allocate(vm, sizeof(Closure), 0);
114130 SETTY(cl, BITS8);
115− cl->info.bits8 = GETBITS8(a) / GETBITS8(b);
131+ cl->info.bits8 = A / B;
116132 return cl;
117133}
118134
119135VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
136+ uint8_t A = a->info.bits8;
137+ uint8_t B = b->info.bits8;
120138 VAL cl = allocate(vm, sizeof(Closure), 0);
121139 SETTY(cl, BITS8);
122− cl->info.bits8 = (uint8_t) (((int8_t) GETBITS8(a)) / ((int8_t) GETBITS8(b)));
140+ cl->info.bits8 = (uint8_t) (((int8_t) A) / ((int8_t) B));
123141 return cl;
124142}
125143
126144VAL idris_b8URem(VM *vm, VAL a, VAL b) {
145+ uint8_t A = a->info.bits8;
146+ uint8_t B = b->info.bits8;
127147 VAL cl = allocate(vm, sizeof(Closure), 0);
128148 SETTY(cl, BITS8);
129− cl->info.bits8 = GETBITS8(a) % GETBITS8(b);
149+ cl->info.bits8 = A % B;
130150 return cl;
131151}
132152
133153VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
154+ uint8_t A = a->info.bits8;
155+ uint8_t B = b->info.bits8;
134156 VAL cl = allocate(vm, sizeof(Closure), 0);
135157 SETTY(cl, BITS8);
136− cl->info.bits8 = (uint8_t) (((int8_t) GETBITS8(a)) % ((int8_t) GETBITS8(b)));
158+ cl->info.bits8 = (uint8_t) (((int8_t) A) % ((int8_t) B));
137159 return cl;
138160}
139161
@@ -158,102 +180,127 @@ VAL idris_b8Gte(VM *vm, VAL a, VAL b) {
158180}
159181
160182VAL idris_b8Compl(VM *vm, VAL a) {
183+ uint8_t A = a->info.bits8;
161184 VAL cl = allocate(vm, sizeof(Closure), 0);
162185 SETTY(cl, BITS8);
163− cl->info.bits8 = ~ GETBITS8(a);
186+ cl->info.bits8 = ~ A;
164187 return cl;
165188}
166189
167190VAL idris_b8And(VM *vm, VAL a, VAL b) {
191+ uint8_t A = a->info.bits8;
192+ uint8_t B = b->info.bits8;
168193 VAL cl = allocate(vm, sizeof(Closure), 0);
169194 SETTY(cl, BITS8);
170− cl->info.bits8 = GETBITS8(a) & GETBITS8(b);
195+ cl->info.bits8 = A & B;
171196 return cl;
172197}
173198
174199VAL idris_b8Or(VM *vm, VAL a, VAL b) {
200+ uint8_t A = a->info.bits8;
201+ uint8_t B = b->info.bits8;
175202 VAL cl = allocate(vm, sizeof(Closure), 0);
176203 SETTY(cl, BITS8);
177− cl->info.bits8 = GETBITS8(a) | GETBITS8(b);
204+ cl->info.bits8 = A | B;
178205 return cl;
179206}
180207
181208VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
209+ uint8_t A = a->info.bits8;
210+ uint8_t B = b->info.bits8;
182211 VAL cl = allocate(vm, sizeof(Closure), 0);
183212 SETTY(cl, BITS8);
184− cl->info.bits8 = GETBITS8(a) ^ GETBITS8(b);
213+ cl->info.bits8 = A ^ B;
185214 return cl;
186215}
187216
188217VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
218+ uint8_t A = a->info.bits8;
219+ uint8_t B = b->info.bits8;
189220 VAL cl = allocate(vm, sizeof(Closure), 0);
190221 SETTY(cl, BITS8);
191− cl->info.bits8 = GETBITS8(a) << GETBITS8(b);
222+ cl->info.bits8 = A << B;
192223 return cl;
193224}
194225
195226VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
227+ uint8_t A = a->info.bits8;
228+ uint8_t B = b->info.bits8;
196229 VAL cl = allocate(vm, sizeof(Closure), 0);
197230 SETTY(cl, BITS8);
198− cl->info.bits8 = GETBITS8(a) >> GETBITS8(b);
231+ cl->info.bits8 = A >> B;
199232 return cl;
200233}
201234
202235VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
236+ uint8_t A = a->info.bits8;
237+ uint8_t B = b->info.bits8;
203238 VAL cl = allocate(vm, sizeof(Closure), 0);
204239 SETTY(cl, BITS8);
205− cl->info.bits8 = (uint8_t) (((int8_t)GETBITS8(a)) >> ((int8_t)GETBITS8(b)));
240+ cl->info.bits8 = (uint8_t) (((int8_t) A) >> ((int8_t) B));
206241 return cl;
207242}
208243
209244VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
245+ uint16_t A = a->info.bits16;
246+ uint16_t B = b->info.bits16;
210247 VAL cl = allocate(vm, sizeof(Closure), 0);
211248 SETTY(cl, BITS16);
212− cl->info.bits16 = GETBITS16(a) + GETBITS16(b);
249+ cl->info.bits16 = A + B;
213250 return cl;
214251}
215252
216253VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
254+ uint16_t A = a->info.bits16;
255+ uint16_t B = b->info.bits16;
217256 VAL cl = allocate(vm, sizeof(Closure), 0);
218257 SETTY(cl, BITS16);
219− cl->info.bits16 = GETBITS16(a) - GETBITS16(b);
258+ cl->info.bits16 = A - B;
220259 return cl;
221260}
222261
223262VAL idris_b16Times(VM *vm, VAL a, VAL b) {
263+ uint16_t A = a->info.bits16;
264+ uint16_t B = b->info.bits16;
224265 VAL cl = allocate(vm, sizeof(Closure), 0);
225266 SETTY(cl, BITS16);
226− cl->info.bits16 = GETBITS16(a) * GETBITS16(b);
267+ cl->info.bits16 = A * B;
227268 return cl;
228269}
229270
230271VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
272+ uint16_t A = a->info.bits16;
273+ uint16_t B = b->info.bits16;
231274 VAL cl = allocate(vm, sizeof(Closure), 0);
232275 SETTY(cl, BITS16);
233− cl->info.bits16 = GETBITS16(a) / GETBITS16(b);
276+ cl->info.bits16 = A / B;
234277 return cl;
235278}
236279
237280VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
281+ uint16_t A = a->info.bits16;
282+ uint16_t B = b->info.bits16;
238283 VAL cl = allocate(vm, sizeof(Closure), 0);
239284 SETTY(cl, BITS16);
240− cl->info.bits16 =
241− (uint16_t) (((int16_t) GETBITS16(a)) / ((int16_t) GETBITS16(b)));
285+ cl->info.bits16 = (uint16_t) (((int16_t) A) / ((int16_t) B));
242286 return cl;
243287}
244288
245289VAL idris_b16URem(VM *vm, VAL a, VAL b) {
290+ uint16_t A = a->info.bits16;
291+ uint16_t B = b->info.bits16;
246292 VAL cl = allocate(vm, sizeof(Closure), 0);
247293 SETTY(cl, BITS16);
248− cl->info.bits16 = GETBITS16(a) % GETBITS16(b);
294+ cl->info.bits16 = A % B;
249295 return cl;
250296}
251297
252298VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
299+ uint16_t A = a->info.bits16;
300+ uint16_t B = b->info.bits16;
253301 VAL cl = allocate(vm, sizeof(Closure), 0);
254302 SETTY(cl, BITS16);
255− cl->info.bits16 =
256− (uint16_t) (((int16_t) GETBITS16(a)) % ((int16_t) GETBITS16(b)));
303+ cl->info.bits16 = (uint16_t) (((int16_t) A) % ((int16_t) B));
257304 return cl;
258305}
259306
@@ -278,102 +325,127 @@ VAL idris_b16Gte(VM *vm, VAL a, VAL b) {
278325}
279326
280327VAL idris_b16Compl(VM *vm, VAL a) {
328+ uint16_t A = a->info.bits16;
281329 VAL cl = allocate(vm, sizeof(Closure), 0);
282330 SETTY(cl, BITS16);
283− cl->info.bits16 = ~ GETBITS16(a);
331+ cl->info.bits16 = ~ A;
284332 return cl;
285333}
286334
287335VAL idris_b16And(VM *vm, VAL a, VAL b) {
336+ uint16_t A = a->info.bits16;
337+ uint16_t B = b->info.bits16;
288338 VAL cl = allocate(vm, sizeof(Closure), 0);
289339 SETTY(cl, BITS16);
290− cl->info.bits16 = GETBITS16(a) & GETBITS16(b);
340+ cl->info.bits16 = A & B;
291341 return cl;
292342}
293343
294344VAL idris_b16Or(VM *vm, VAL a, VAL b) {
345+ uint16_t A = a->info.bits16;
346+ uint16_t B = b->info.bits16;
295347 VAL cl = allocate(vm, sizeof(Closure), 0);
296348 SETTY(cl, BITS16);
297− cl->info.bits16 = GETBITS16(a) | GETBITS16(b);
349+ cl->info.bits16 = A | B;
298350 return cl;
299351}
300352
301353VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
354+ uint16_t A = a->info.bits16;
355+ uint16_t B = b->info.bits16;
302356 VAL cl = allocate(vm, sizeof(Closure), 0);
303357 SETTY(cl, BITS16);
304− cl->info.bits16 = GETBITS16(a) ^ GETBITS16(b);
358+ cl->info.bits16 = A ^ B;
305359 return cl;
306360}
307361
308362VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
363+ uint16_t A = a->info.bits16;
364+ uint16_t B = b->info.bits16;
309365 VAL cl = allocate(vm, sizeof(Closure), 0);
310366 SETTY(cl, BITS16);
311− cl->info.bits16 = GETBITS16(a) << GETBITS16(b);
367+ cl->info.bits16 = A << B;
312368 return cl;
313369}
314370
315371VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
372+ uint16_t A = a->info.bits16;
373+ uint16_t B = b->info.bits16;
316374 VAL cl = allocate(vm, sizeof(Closure), 0);
317375 SETTY(cl, BITS16);
318− cl->info.bits16 = GETBITS16(a) >> GETBITS16(b);
376+ cl->info.bits16 = A >> B;
319377 return cl;
320378}
321379
322380VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
381+ uint16_t A = a->info.bits16;
382+ uint16_t B = b->info.bits16;
323383 VAL cl = allocate(vm, sizeof(Closure), 0);
324384 SETTY(cl, BITS16);
325− cl->info.bits16 = (uint16_t) (((int16_t)GETBITS16(a)) >> ((int16_t)GETBITS16(b)));
385+ cl->info.bits16 = (uint16_t) (((int16_t) A) >> ((int16_t) B));
326386 return cl;
327387}
328388
329389VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
390+ uint32_t A = a->info.bits32;
391+ uint32_t B = b->info.bits32;
330392 VAL cl = allocate(vm, sizeof(Closure), 0);
331393 SETTY(cl, BITS32);
332− cl->info.bits32 = GETBITS32(a) + GETBITS32(b);
394+ cl->info.bits32 = A + B;
333395 return cl;
334396}
335397
336398VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
399+ uint32_t A = a->info.bits32;
400+ uint32_t B = b->info.bits32;
337401 VAL cl = allocate(vm, sizeof(Closure), 0);
338402 SETTY(cl, BITS32);
339− cl->info.bits32 = GETBITS32(a) - GETBITS32(b);
403+ cl->info.bits32 = A - B;
340404 return cl;
341405}
342406
343407VAL idris_b32Times(VM *vm, VAL a, VAL b) {
408+ uint32_t A = a->info.bits32;
409+ uint32_t B = b->info.bits32;
344410 VAL cl = allocate(vm, sizeof(Closure), 0);
345411 SETTY(cl, BITS32);
346− cl->info.bits32 = GETBITS32(a) * GETBITS32(b);
412+ cl->info.bits32 = A * B;
347413 return cl;
348414}
349415
350416VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
417+ uint32_t A = a->info.bits32;
418+ uint32_t B = b->info.bits32;
351419 VAL cl = allocate(vm, sizeof(Closure), 0);
352420 SETTY(cl, BITS32);
353− cl->info.bits32 = GETBITS32(a) / GETBITS32(b);
421+ cl->info.bits32 = A / B;
354422 return cl;
355423}
356424
357425VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
426+ uint32_t A = a->info.bits32;
427+ uint32_t B = b->info.bits32;
358428 VAL cl = allocate(vm, sizeof(Closure), 0);
359429 SETTY(cl, BITS32);
360− cl->info.bits32 =
361− (uint32_t) (((int32_t) GETBITS32(a)) / ((int32_t) GETBITS32(b)));
430+ cl->info.bits32 = (uint32_t) (((int32_t) A) / ((int32_t) B));
362431 return cl;
363432}
364433
365434VAL idris_b32URem(VM *vm, VAL a, VAL b) {
435+ uint32_t A = a->info.bits32;
436+ uint32_t B = b->info.bits32;
366437 VAL cl = allocate(vm, sizeof(Closure), 0);
367438 SETTY(cl, BITS32);
368− cl->info.bits32 = GETBITS32(a) % GETBITS32(b);
439+ cl->info.bits32 = A % B;
369440 return cl;
370441}
371442
372443VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
444+ uint32_t A = a->info.bits32;
445+ uint32_t B = b->info.bits32;
373446 VAL cl = allocate(vm, sizeof(Closure), 0);
374447 SETTY(cl, BITS32);
375− cl->info.bits32 =
376− (uint32_t) (((int32_t) GETBITS32(a)) % ((int32_t) GETBITS32(b)));
448+ cl->info.bits32 = (uint32_t) (((int32_t) A) % ((int32_t) B));
377449 return cl;
378450}
379451
@@ -398,102 +470,127 @@ VAL idris_b32Gte(VM *vm, VAL a, VAL b) {
398470}
399471
400472VAL idris_b32Compl(VM *vm, VAL a) {
473+ uint32_t A = a->info.bits32;
401474 VAL cl = allocate(vm, sizeof(Closure), 0);
402475 SETTY(cl, BITS32);
403− cl->info.bits32 = ~ GETBITS32(a);
476+ cl->info.bits32 = ~ A;
404477 return cl;
405478}
406479
407480VAL idris_b32And(VM *vm, VAL a, VAL b) {
481+ uint32_t A = a->info.bits32;
482+ uint32_t B = b->info.bits32;
408483 VAL cl = allocate(vm, sizeof(Closure), 0);
409484 SETTY(cl, BITS32);
410− cl->info.bits32 = GETBITS32(a) & GETBITS32(b);
485+ cl->info.bits32 = A & B;
411486 return cl;
412487}
413488
414489VAL idris_b32Or(VM *vm, VAL a, VAL b) {
490+ uint32_t A = a->info.bits32;
491+ uint32_t B = b->info.bits32;
415492 VAL cl = allocate(vm, sizeof(Closure), 0);
416493 SETTY(cl, BITS32);
417− cl->info.bits32 = GETBITS32(a) | GETBITS32(b);
494+ cl->info.bits32 = A | B;
418495 return cl;
419496}
420497
421498VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
499+ uint32_t A = a->info.bits32;
500+ uint32_t B = b->info.bits32;
422501 VAL cl = allocate(vm, sizeof(Closure), 0);
423502 SETTY(cl, BITS32);
424− cl->info.bits32 = GETBITS32(a) ^ GETBITS32(b);
503+ cl->info.bits32 = A ^ B;
425504 return cl;
426505}
427506
428507VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
508+ uint32_t A = a->info.bits32;
509+ uint32_t B = b->info.bits32;
429510 VAL cl = allocate(vm, sizeof(Closure), 0);
430511 SETTY(cl, BITS32);
431− cl->info.bits32 = GETBITS32(a) << GETBITS32(b);
512+ cl->info.bits32 = A << B;
432513 return cl;
433514}
434515
435516VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
517+ uint32_t A = a->info.bits32;
518+ uint32_t B = b->info.bits32;
436519 VAL cl = allocate(vm, sizeof(Closure), 0);
437520 SETTY(cl, BITS32);
438− cl->info.bits32 = GETBITS32(a) >> GETBITS32(b);
521+ cl->info.bits32 = A >> B;
439522 return cl;
440523}
441524
442525VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
526+ uint32_t A = a->info.bits32;
527+ uint32_t B = b->info.bits32;
443528 VAL cl = allocate(vm, sizeof(Closure), 0);
444529 SETTY(cl, BITS32);
445− cl->info.bits32 = (uint32_t) (((int32_t)GETBITS32(a)) >> ((int32_t)GETBITS32(b)));
530+ cl->info.bits32 = (uint32_t) (((int32_t)A) >> ((int32_t)B));
446531 return cl;
447532}
448533
449534VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
535+ uint64_t A = a->info.bits64;
536+ uint64_t B = b->info.bits64;
450537 VAL cl = allocate(vm, sizeof(Closure), 0);
451538 SETTY(cl, BITS64);
452− cl->info.bits64 = GETBITS64(a) + GETBITS64(b);
539+ cl->info.bits64 = A + B;
453540 return cl;
454541}
455542
456543VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
544+ uint64_t A = a->info.bits64;
545+ uint64_t B = b->info.bits64;
457546 VAL cl = allocate(vm, sizeof(Closure), 0);
458547 SETTY(cl, BITS64);
459− cl->info.bits64 = GETBITS64(a) - GETBITS64(b);
548+ cl->info.bits64 = A - B;
460549 return cl;
461550}
462551
463552VAL idris_b64Times(VM *vm, VAL a, VAL b) {
553+ uint64_t A = a->info.bits64;
554+ uint64_t B = b->info.bits64;
464555 VAL cl = allocate(vm, sizeof(Closure), 0);
465556 SETTY(cl, BITS64);
466− cl->info.bits64 = GETBITS64(a) * GETBITS64(b);
557+ cl->info.bits64 = A * B;
467558 return cl;
468559}
469560
470561VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
562+ uint64_t A = a->info.bits64;
563+ uint64_t B = b->info.bits64;
471564 VAL cl = allocate(vm, sizeof(Closure), 0);
472565 SETTY(cl, BITS64);
473− cl->info.bits64 = GETBITS64(a) / GETBITS64(b);
566+ cl->info.bits64 = A / B;
474567 return cl;
475568}
476569
477570VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
571+ uint64_t A = a->info.bits64;
572+ uint64_t B = b->info.bits64;
478573 VAL cl = allocate(vm, sizeof(Closure), 0);
479574 SETTY(cl, BITS64);
480− cl->info.bits64 =
481− (uint64_t) (((int64_t) GETBITS64(a)) / ((int64_t) GETBITS64(b)));
575+ cl->info.bits64 = (uint64_t) (((int64_t) A) / ((int64_t) B));
482576 return cl;
483577}
484578
485579VAL idris_b64URem(VM *vm, VAL a, VAL b) {
580+ uint64_t A = a->info.bits64;
581+ uint64_t B = b->info.bits64;
486582 VAL cl = allocate(vm, sizeof(Closure), 0);
487583 SETTY(cl, BITS64);
488− cl->info.bits64 = GETBITS64(a) % GETBITS64(b);
584+ cl->info.bits64 = A % B;
489585 return cl;
490586}
491587
492588VAL idris_b64SRem(VM *vm, VAL a, VAL b) {
589+ uint64_t A = a->info.bits64;
590+ uint64_t B = b->info.bits64;
493591 VAL cl = allocate(vm, sizeof(Closure), 0);
494592 SETTY(cl, BITS64);
495− cl->info.bits64 =
496− (uint64_t) (((int64_t) GETBITS64(a)) % ((int64_t) GETBITS64(b)));
593+ cl->info.bits64 = (uint64_t) (((int64_t) A) % ((int64_t) B));
497594 return cl;
498595}
499596
@@ -518,177 +615,208 @@ VAL idris_b64Gte(VM *vm, VAL a, VAL b) {
518615}
519616
520617VAL idris_b64Compl(VM *vm, VAL a) {
618+ uint64_t A = a->info.bits64;
521619 VAL cl = allocate(vm, sizeof(Closure), 0);
522620 SETTY(cl, BITS64);
523− cl->info.bits64 = ~ GETBITS64(a);
621+ cl->info.bits64 = ~ A;
524622 return cl;
525623}
526624
527625VAL idris_b64And(VM *vm, VAL a, VAL b) {
626+ uint64_t A = a->info.bits64;
627+ uint64_t B = b->info.bits64;
528628 VAL cl = allocate(vm, sizeof(Closure), 0);
529629 SETTY(cl, BITS64);
530− cl->info.bits64 = GETBITS64(a) & GETBITS64(b);
630+ cl->info.bits64 = A & B;
531631 return cl;
532632}
533633
534634VAL idris_b64Or(VM *vm, VAL a, VAL b) {
635+ uint64_t A = a->info.bits64;
636+ uint64_t B = b->info.bits64;
535637 VAL cl = allocate(vm, sizeof(Closure), 0);
536638 SETTY(cl, BITS64);
537− cl->info.bits64 = GETBITS64(a) | GETBITS64(b);
639+ cl->info.bits64 = A | B;
538640 return cl;
539641}
540642
541643VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
644+ uint64_t A = a->info.bits64;
645+ uint64_t B = b->info.bits64;
542646 VAL cl = allocate(vm, sizeof(Closure), 0);
543647 SETTY(cl, BITS64);
544− cl->info.bits64 = GETBITS64(a) ^ GETBITS64(b);
648+ cl->info.bits64 = A ^ B;
545649 return cl;
546650}
547651
548652VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
653+ uint64_t A = a->info.bits64;
654+ uint64_t B = b->info.bits64;
549655 VAL cl = allocate(vm, sizeof(Closure), 0);
550656 SETTY(cl, BITS64);
551− cl->info.bits64 = GETBITS64(a) << GETBITS64(b);
657+ cl->info.bits64 = A << B;
552658 return cl;
553659}
554660
555661VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
662+ uint64_t A = a->info.bits64;
663+ uint64_t B = b->info.bits64;
556664 VAL cl = allocate(vm, sizeof(Closure), 0);
557665 SETTY(cl, BITS64);
558− cl->info.bits64 = GETBITS64(a) >> GETBITS64(b);
666+ cl->info.bits64 = A >> B;
559667 return cl;
560668}
561669
562670VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
671+ uint64_t A = a->info.bits64;
672+ uint64_t B = b->info.bits64;
563673 VAL cl = allocate(vm, sizeof(Closure), 0);
564674 SETTY(cl, BITS64);
565− cl->info.bits64 = (uint64_t) (((int64_t)GETBITS64(a)) >> ((int64_t)GETBITS64(b)));
675+ cl->info.bits64 = (uint64_t) (((int64_t) A) >> ((int64_t) B));
566676 return cl;
567677}
568678
569679VAL idris_b8Z16(VM *vm, VAL a) {
680+ uint8_t A = a->info.bits8;
570681 VAL cl = allocate(vm, sizeof(Closure), 0);
571682 SETTY(cl, BITS16);
572− cl->info.bits16 = (uint16_t) GETBITS8(a);
683+ cl->info.bits16 = (uint16_t) A;
573684 return cl;
574685}
575686
576687VAL idris_b8Z32(VM *vm, VAL a) {
688+ uint8_t A = a->info.bits8;
577689 VAL cl = allocate(vm, sizeof(Closure), 0);
578690 SETTY(cl, BITS32);
579− cl->info.bits32 = (uint32_t) GETBITS8(a);
691+ cl->info.bits32 = (uint32_t) A;
580692 return cl;
581693}
582694
583695VAL idris_b8Z64(VM *vm, VAL a) {
696+ uint8_t A = a->info.bits8;
584697 VAL cl = allocate(vm, sizeof(Closure), 0);
585698 SETTY(cl, BITS64);
586− cl->info.bits64 = (uint64_t) GETBITS8(a);
699+ cl->info.bits64 = (uint64_t) A;
587700 return cl;
588701}
589702
590703VAL idris_b8S16(VM *vm, VAL a) {
704+ uint8_t A = a->info.bits8;
591705 VAL cl = allocate(vm, sizeof(Closure), 0);
592706 SETTY(cl, BITS16);
593− cl->info.bits16 = (uint16_t) (int16_t) (int8_t) GETBITS8(a);
707+ cl->info.bits16 = (uint16_t) (int16_t) (int8_t) A;
594708 return cl;
595709}
596710
597711VAL idris_b8S32(VM *vm, VAL a) {
712+ uint8_t A = a->info.bits8;
598713 VAL cl = allocate(vm, sizeof(Closure), 0);
599714 SETTY(cl, BITS32);
600− cl->info.bits32 = (uint32_t) (int32_t) (int8_t) GETBITS8(a);
715+ cl->info.bits32 = (uint32_t) (int32_t) (int8_t) A;
601716 return cl;
602717}
603718
604719VAL idris_b8S64(VM *vm, VAL a) {
720+ uint8_t A = a->info.bits8;
605721 VAL cl = allocate(vm, sizeof(Closure), 0);
606722 SETTY(cl, BITS64);
607− cl->info.bits64 = (uint64_t) (int64_t) (int8_t) GETBITS8(a);
723+ cl->info.bits64 = (uint64_t) (int64_t) (int8_t) A;
608724 return cl;
609725}
610726
611727VAL idris_b16Z32(VM *vm, VAL a) {
728+ uint16_t A = a->info.bits16;
612729 VAL cl = allocate(vm, sizeof(Closure), 0);
613730 SETTY(cl, BITS32);
614− cl->info.bits32 = (uint32_t) GETBITS16(a);
731+ cl->info.bits32 = (uint32_t) A;
615732 return cl;
616733}
617734
618735VAL idris_b16Z64(VM *vm, VAL a) {
736+ uint16_t A = a->info.bits16;
619737 VAL cl = allocate(vm, sizeof(Closure), 0);
620738 SETTY(cl, BITS64);
621− cl->info.bits64 = (uint64_t) GETBITS16(a);
739+ cl->info.bits64 = (uint64_t) A;
622740 return cl;
623741}
624742
625743VAL idris_b16S32(VM *vm, VAL a) {
744+ uint16_t A = a->info.bits16;
626745 VAL cl = allocate(vm, sizeof(Closure), 0);
627746 SETTY(cl, BITS32);
628− cl->info.bits32 = (uint32_t) (int32_t) (int16_t) GETBITS16(a);
747+ cl->info.bits32 = (uint32_t) (int32_t) (int16_t) A;
629748 return cl;
630749}
631750
632751VAL idris_b16S64(VM *vm, VAL a) {
752+ uint16_t A = a->info.bits16;
633753 VAL cl = allocate(vm, sizeof(Closure), 0);
634754 SETTY(cl, BITS64);
635− cl->info.bits64 = (uint64_t) (int64_t) (int16_t) GETBITS16(a);
755+ cl->info.bits64 = (uint64_t) (int64_t) (int16_t) A;
636756 return cl;
637757}
638758
639759VAL idris_b16T8(VM *vm, VAL a) {
760+ uint16_t A = a->info.bits16;
640761 VAL cl = allocate(vm, sizeof(Closure), 0);
641762 SETTY(cl, BITS8);
642− cl->info.bits8 = (uint8_t) GETBITS16(a);
763+ cl->info.bits8 = (uint8_t) A;
643764 return cl;
644765}
645766
646767VAL idris_b32Z64(VM *vm, VAL a) {
768+ uint32_t A = a->info.bits32;
647769 VAL cl = allocate(vm, sizeof(Closure), 0);
648770 SETTY(cl, BITS64);
649− cl->info.bits64 = (uint64_t) GETBITS32(a);
771+ cl->info.bits64 = (uint64_t) A;
650772 return cl;
651773}
652774
653775VAL idris_b32S64(VM *vm, VAL a) {
776+ uint32_t A = a->info.bits32;
654777 VAL cl = allocate(vm, sizeof(Closure), 0);
655778 SETTY(cl, BITS64);
656− cl->info.bits64 = (uint64_t) (int64_t) (int32_t) GETBITS32(a);
779+ cl->info.bits64 = (uint64_t) (int64_t) (int32_t) A;
657780 return cl;
658781}
659782
660783VAL idris_b32T8(VM *vm, VAL a) {
784+ uint32_t A = a->info.bits32;
661785 VAL cl = allocate(vm, sizeof(Closure), 0);
662786 SETTY(cl, BITS8);
663− cl->info.bits8 = (uint8_t) GETBITS32(a);
787+ cl->info.bits8 = (uint8_t) A;
664788 return cl;
665789}
666790
667791VAL idris_b32T16(VM *vm, VAL a) {
792+ uint32_t A = a->info.bits32;
668793 VAL cl = allocate(vm, sizeof(Closure), 0);
669794 SETTY(cl, BITS16);
670− cl->info.bits16 = (uint16_t) GETBITS32(a);
795+ cl->info.bits16 = (uint16_t) A;
671796 return cl;
672797}
673798
674799VAL idris_b64T8(VM *vm, VAL a) {
800+ uint64_t A = a->info.bits64;
675801 VAL cl = allocate(vm, sizeof(Closure), 0);
676802 SETTY(cl, BITS8);
677− cl->info.bits8 = (uint8_t) GETBITS64(a);
803+ cl->info.bits8 = (uint8_t) A;
678804 return cl;
679805}
680806
681807VAL idris_b64T16(VM *vm, VAL a) {
808+ uint64_t A = a->info.bits64;
682809 VAL cl = allocate(vm, sizeof(Closure), 0);
683810 SETTY(cl, BITS16);
684− cl->info.bits16 = (uint16_t) GETBITS64(a);
811+ cl->info.bits16 = (uint16_t) A;
685812 return cl;
686813}
687814
688815VAL idris_b64T32(VM *vm, VAL a) {
816+ uint64_t A = a->info.bits64;
689817 VAL cl = allocate(vm, sizeof(Closure), 0);
690818 SETTY(cl, BITS32);
691− cl->info.bits32 = (uint32_t) GETBITS64(a);
819+ cl->info.bits32 = (uint32_t) A;
692820 return cl;
693821}
694822
rts/idris_rts.h−5
@@ -129,11 +129,6 @@ typedef void(*func)(VM*, VAL*);
129129#define GETMPTR(x) (((VAL)(x))->info.mptr->data)
130130#define GETFLOAT(x) (((VAL)(x))->info.f)
131131
132−#define GETBITS64(x) ((x)->ty == FWD ? ((VAL)((x)->info.ptr))->info.bits64 : (x)->info.bits64)
133−#define GETBITS32(x) ((x)->ty == FWD ? ((VAL)((x)->info.ptr))->info.bits32 : (x)->info.bits32)
134−#define GETBITS16(x) ((x)->ty == FWD ? ((VAL)((x)->info.ptr))->info.bits16 : (x)->info.bits16)
135−#define GETBITS8(x) ((x)->ty == FWD ? ((VAL)((x)->info.ptr))->info.bits8 : (x)->info.bits8)
136−
137132#define TAG(x) (ISINT(x) || x == NULL ? (-1) : ( GETTY(x) == CON ? (x)->info.c.tag_arity >> 8 : (-1)) )
138133#define ARITY(x) (ISINT(x) || x == NULL ? (-1) : ( GETTY(x) == CON ? (x)->info.c.tag_arity & 0x000000ff : (-1)) )
139134