Skip to content

Commit 46ab7c8

Browse files
committed
Warning on x86 gcc, removed redundant macro
1 parent 8d986bb commit 46ab7c8

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

rts/idris_gmp.c

+27-33
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@ VAL MKBIGI(int val) {
2222
return MKINT((i_int)val);
2323
}
2424

25-
static mpz_t * big(BigInt * v) {
26-
return (mpz_t*)(v->big);
27-
}
28-
29-
#define BIG(x) big((BigInt*)(x))
30-
3125
static BigInt * allocBig(VM * vm) {
3226
idris_requireAlloc(vm, IDRIS_MAXGMP);
3327
BigInt * cl = iallocate(vm, sizeof(*cl) + sizeof(mpz_t), 0);
3428
idris_doneAlloc(vm);
3529
SETTY(cl, CT_BIGINT);
36-
mpz_init(*big(cl));
30+
mpz_init(*getmpz(cl));
3731
return cl;
3832
}
3933

@@ -43,39 +37,39 @@ VAL MKBIGC(VM* vm, char* val) {
4337
}
4438
else {
4539
BigInt * cl = allocBig(vm);
46-
mpz_set_str(*big(cl), val, 10);
40+
mpz_set_str(*getmpz(cl), val, 10);
4741
return (VAL)cl;
4842
}
4943
}
5044

5145
VAL MKBIGM(VM* vm, void* ibig) {
5246
BigInt * cl = allocBig(vm);
53-
mpz_set(*big(cl), *((mpz_t*)ibig));
47+
mpz_set(*getmpz(cl), *((mpz_t*)ibig));
5448
return (VAL)cl;
5549
}
5650

5751
VAL MKBIGMc(VM* vm, void* ibig) {
5852
BigInt * cl = allocBig(vm);
59-
mpz_init_set(*big(cl), *((mpz_t*)ibig));
53+
mpz_init_set(*getmpz(cl), *((mpz_t*)ibig));
6054
return (VAL)cl;
6155
}
6256

6357
VAL MKBIGUI(VM* vm, unsigned long val) {
6458
BigInt * cl = allocBig(vm);
65-
mpz_init_set_ui(*big(cl), val);
59+
mpz_init_set_ui(*getmpz(cl), val);
6660
return (VAL)cl;
6761
}
6862

6963
VAL MKBIGSI(VM* vm, signed long val) {
7064
BigInt * cl = allocBig(vm);
71-
mpz_init_set_si(*big(cl), val);
65+
mpz_init_set_si(*getmpz(cl), val);
7266
return (VAL)cl;
7367
}
7468

7569
static BigInt * getbig(VM * vm, VAL x) {
7670
if (ISINT(x)) {
7771
BigInt * cl = allocBig(vm);
78-
mpz_set_si(*big(cl), GETINT(x));
72+
mpz_set_si(*getmpz(cl), GETINT(x));
7973
return cl;
8074
} else {
8175
switch(GETTY(x)) {
@@ -91,62 +85,62 @@ static BigInt * getbig(VM * vm, VAL x) {
9185

9286
VAL bigAdd(VM* vm, VAL x, VAL y) {
9387
BigInt * cl = allocBig(vm);
94-
mpz_add(*big(cl), *big(getbig(vm,x)), *big(getbig(vm,y)));
88+
mpz_add(*getmpz(cl), *getmpz(getbig(vm,x)), *getmpz(getbig(vm,y)));
9589
return (VAL)cl;
9690
}
9791

9892
VAL bigSub(VM* vm, VAL x, VAL y) {
9993
BigInt * cl = allocBig(vm);
100-
mpz_sub(*big(cl), *big(getbig(vm,x)), *big(getbig(vm,y)));
94+
mpz_sub(*getmpz(cl), *getmpz(getbig(vm,x)), *getmpz(getbig(vm,y)));
10195
return (VAL)cl;
10296
}
10397

10498
VAL bigMul(VM* vm, VAL x, VAL y) {
10599
BigInt * cl = allocBig(vm);
106-
mpz_mul(*big(cl), *big(getbig(vm,x)), *big(getbig(vm,y)));
100+
mpz_mul(*getmpz(cl), *getmpz(getbig(vm,x)), *getmpz(getbig(vm,y)));
107101
return (VAL)cl;
108102
}
109103

110104
VAL bigDiv(VM* vm, VAL x, VAL y) {
111105
BigInt * cl = allocBig(vm);
112-
mpz_tdiv_q(*big(cl), *big(getbig(vm,x)), *big(getbig(vm,y)));
106+
mpz_tdiv_q(*getmpz(cl), *getmpz(getbig(vm,x)), *getmpz(getbig(vm,y)));
113107
return (VAL)cl;
114108
}
115109

116110
VAL bigMod(VM* vm, VAL x, VAL y) {
117111
BigInt * cl = allocBig(vm);
118-
mpz_tdiv_r(*big(cl), *big(getbig(vm,x)), *big(getbig(vm,y)));
112+
mpz_tdiv_r(*getmpz(cl), *getmpz(getbig(vm,x)), *getmpz(getbig(vm,y)));
119113
return (VAL)cl;
120114
}
121115

122116
VAL bigAnd(VM* vm, VAL x, VAL y) {
123117
BigInt * cl = allocBig(vm);
124-
mpz_and(*big(cl), *big(getbig(vm,x)), *big(getbig(vm,y)));
118+
mpz_and(*getmpz(cl), *getmpz(getbig(vm,x)), *getmpz(getbig(vm,y)));
125119
return (VAL)cl;
126120
}
127121

128122
VAL bigOr(VM* vm, VAL x, VAL y) {
129123
BigInt * cl = allocBig(vm);
130-
mpz_ior(*big(cl), *big(getbig(vm,x)), *big(getbig(vm,y)));
124+
mpz_ior(*getmpz(cl), *getmpz(getbig(vm,x)), *getmpz(getbig(vm,y)));
131125
return (VAL)cl;
132126
}
133127

134128
VAL bigShiftLeft(VM* vm, VAL x, VAL y) {
135129
BigInt * cl = allocBig(vm);
136-
mpz_mul_2exp(*big(cl), *big(getbig(vm,x)), GETINT(y));
130+
mpz_mul_2exp(*getmpz(cl), *getmpz(getbig(vm,x)), GETINT(y));
137131
return (VAL)cl;
138132
}
139133

140134

141135
VAL bigLShiftRight(VM* vm, VAL x, VAL y) {
142136
BigInt * cl = allocBig(vm);
143-
mpz_fdiv_q_2exp(*big(cl), *big(getbig(vm,x)), GETINT(y));
137+
mpz_fdiv_q_2exp(*getmpz(cl), *getmpz(getbig(vm,x)), GETINT(y));
144138
return (VAL)cl;
145139
}
146140

147141
VAL bigAShiftRight(VM* vm, VAL x, VAL y) {
148142
BigInt * cl = allocBig(vm);
149-
mpz_fdiv_q_2exp(*big(cl), *big(getbig(vm,x)), GETINT(y));
143+
mpz_fdiv_q_2exp(*getmpz(cl), *getmpz(getbig(vm,x)), GETINT(y));
150144
return (VAL)cl;
151145
}
152146

@@ -266,29 +260,29 @@ VAL idris_bigMod(VM* vm, VAL x, VAL y) {
266260
int bigEqConst(VAL x, int c) {
267261
if (ISINT(x)) { return (GETINT(x) == c); }
268262
else {
269-
int rv = mpz_cmp_si(*BIG(x), c);
263+
int rv = mpz_cmp_si(GETMPZ(x), c);
270264
return (rv == 0);
271265
}
272266
}
273267

274268
VAL bigEq(VM* vm, VAL x, VAL y) {
275-
return MKINT((i_int)(mpz_cmp(*BIG(x), *BIG(y)) == 0));
269+
return MKINT((i_int)(mpz_cmp(GETMPZ(x), GETMPZ(y)) == 0));
276270
}
277271

278272
VAL bigLt(VM* vm, VAL x, VAL y) {
279-
return MKINT((i_int)(mpz_cmp(*BIG(x), *BIG(y)) < 0));
273+
return MKINT((i_int)(mpz_cmp(GETMPZ(x), GETMPZ(y)) < 0));
280274
}
281275

282276
VAL bigGt(VM* vm, VAL x, VAL y) {
283-
return MKINT((i_int)(mpz_cmp(*BIG(x), *BIG(y)) > 0));
277+
return MKINT((i_int)(mpz_cmp(GETMPZ(x), GETMPZ(y)) > 0));
284278
}
285279

286280
VAL bigLe(VM* vm, VAL x, VAL y) {
287-
return MKINT((i_int)(mpz_cmp(*BIG(x), *BIG(y)) <= 0));
281+
return MKINT((i_int)(mpz_cmp(GETMPZ(x), GETMPZ(y)) <= 0));
288282
}
289283

290284
VAL bigGe(VM* vm, VAL x, VAL y) {
291-
return MKINT((i_int)(mpz_cmp(*BIG(x), *BIG(y)) >= 0));
285+
return MKINT((i_int)(mpz_cmp(GETMPZ(x), GETMPZ(y)) >= 0));
292286
}
293287

294288
VAL idris_bigEq(VM* vm, VAL x, VAL y) {
@@ -340,22 +334,22 @@ VAL idris_castBigInt(VM* vm, VAL i) {
340334
if (ISINT(i)) {
341335
return i;
342336
} else {
343-
return MKINT((i_int)(mpz_get_ui(*BIG(i))));
337+
return MKINT((i_int)(mpz_get_ui(GETMPZ(i))));
344338
}
345339
}
346340

347341
VAL idris_castBigFloat(VM* vm, VAL i) {
348342
if (ISINT(i)) {
349343
return MKFLOAT(vm, GETINT(i));
350344
} else {
351-
return MKFLOAT(vm, mpz_get_d(*BIG(i)));
345+
return MKFLOAT(vm, mpz_get_d(GETMPZ(i)));
352346
}
353347
}
354348

355349
VAL idris_castFloatBig(VM* vm, VAL f) {
356350
double val = GETFLOAT(f);
357351
BigInt * cl = allocBig(vm);
358-
mpz_init_set_d(*big(cl), val);
352+
mpz_init_set_d(*getmpz(cl), val);
359353
return (VAL)cl;
360354
}
361355

@@ -364,7 +358,7 @@ VAL idris_castStrBig(VM* vm, VAL i) {
364358
}
365359

366360
VAL idris_castBigStr(VM* vm, VAL i) {
367-
char* str = mpz_get_str(NULL, 10, *big(getbig(vm, i)));
361+
char* str = mpz_get_str(NULL, 10, *getmpz(getbig(vm, i)));
368362
return MKSTR(vm, str);
369363
}
370364

rts/idris_gmp.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ VAL idris_bigLShiftRight(VM* vm, VAL x, VAL y);
4848

4949
uint64_t idris_truncBigB64(const mpz_t bi);
5050

51-
#define GETMPZ(x) *((mpz_t*)(((BigInt*)(x))->big))
51+
static inline mpz_t * getmpz(BigInt * v) {
52+
return (mpz_t*)(v->big);
53+
}
54+
55+
#define GETMPZ(x) *getmpz((BigInt*)x)
5256

5357
#endif

0 commit comments

Comments
 (0)