106
int osl_int_sizeof(int precision) {
108
case OSL_PRECISION_SP:
109
return sizeof(long int);
111
case OSL_PRECISION_DP:
112
return sizeof(long long int);
114
#ifdef OSL_GMP_IS_HERE
115
case OSL_PRECISION_MP:
116
return sizeof(mpz_t);
120
OSL_error("unknown precision");
125
void * osl_int_address(int precision, void * base, int offset) {
127
case OSL_PRECISION_SP:
128
return (long int *)base + offset;
130
case OSL_PRECISION_DP:
131
return (long long int *)base + offset;
133
#ifdef OSL_GMP_IS_HERE
134
case OSL_PRECISION_MP:
135
return (mpz_t *)base + offset;
139
OSL_error("unknown precision");
144
void osl_int_init(int precision, void * value_base, int value_offset) {
145
void * value = osl_int_address(precision, value_base, value_offset);
148
case OSL_PRECISION_SP:
149
*(long int *)value = 0;
152
case OSL_PRECISION_DP:
153
*(long long int *)value = 0;
156
#ifdef OSL_GMP_IS_HERE
157
case OSL_PRECISION_MP:
158
mpz_init(*(mpz_t *)value);
163
OSL_error("unknown precision");
168
void * osl_int_malloc(int precision) {
172
case OSL_PRECISION_SP:
173
value = malloc(sizeof(long int));
176
case OSL_PRECISION_DP:
177
value = malloc(sizeof(long long int));
178
*(long long int *)value = 0;
181
#ifdef OSL_GMP_IS_HERE
182
case OSL_PRECISION_MP:
183
value = malloc(sizeof(mpz_t));
188
OSL_error("unknown precision");
191
osl_int_init(precision, value, 0);
197
* val1_base[val1_offset] = val2_base[val2_offset];
199
void osl_int_assign(int precision,
200
void * val1_base, int val1_offset,
201
void * val2_base, int val2_offset) {
202
void * val1 = osl_int_address(precision, val1_base, val1_offset);
203
void * val2 = osl_int_address(precision, val2_base, val2_offset);
206
case OSL_PRECISION_SP:
207
*(long int *)val1 = *(long int *)val2;
210
case OSL_PRECISION_DP:
211
*(long long int *)val1 = *(long long int *)val2;
214
#ifdef OSL_GMP_IS_HERE
215
case OSL_PRECISION_MP:
216
mpz_set(*(mpz_t *)val1, *(mpz_t *)val2);
221
OSL_error("unknown precision");
227
* value_base[value_offset] = i;
229
void osl_int_set_si(int precision, void * value_base, int value_offset,
231
void * value = osl_int_address(precision, value_base, value_offset);
234
case OSL_PRECISION_SP:
235
*(long int *)value = (long int)i;
238
case OSL_PRECISION_DP:
239
*(long long int *)value = (long long int)i;
242
#ifdef OSL_GMP_IS_HERE
243
case OSL_PRECISION_MP:
244
mpz_set_si(*(mpz_t *)value, i);
249
OSL_error("unknown precision");
255
* return value_base[value_offset];
257
int osl_int_get_si(int precision, void * value_base, int value_offset) {
258
void * value = osl_int_address(precision, value_base, value_offset);
261
case OSL_PRECISION_SP:
262
return *(int *)value;
264
case OSL_PRECISION_DP:
265
return *(int *)value;
267
#ifdef OSL_GMP_IS_HERE
268
case OSL_PRECISION_MP:
269
return mpz_get_si(*(mpz_t *)value);
273
OSL_error("unknown precision");
279
* value_base[value_offset] = i; // including initialization for GMP
281
void osl_int_init_set_si(int precision,
282
void * value_base, int value_offset, int i) {
283
void * value = osl_int_address(precision, value_base, value_offset);
286
case OSL_PRECISION_SP:
287
*(long int *)value = (long int)i;
290
case OSL_PRECISION_DP:
291
*(long long int *)value = (long long int)i;
294
#ifdef OSL_GMP_IS_HERE
295
case OSL_PRECISION_MP:
296
mpz_init_set_si(*(mpz_t *)value, i);
301
OSL_error("unknown precision");
307
* value_base[value_offset] = 0; // Including cleaning for GMP
309
void osl_int_clear(int precision, void * value_base, int value_offset) {
310
void * value = osl_int_address(precision, value_base, value_offset);
313
case OSL_PRECISION_SP:
314
*(long int *)value = 0;
317
case OSL_PRECISION_DP:
318
*(long long int *)value = 0;
321
#ifdef OSL_GMP_IS_HERE
322
case OSL_PRECISION_MP:
323
mpz_clear(*(mpz_t *)value);
328
OSL_error("unknown precision");
333
void osl_int_free(int precision, void * value_base, int value_offset) {
334
void * value = osl_int_address(precision, value_base, value_offset);
336
osl_int_clear(precision, value_base, value_offset);
130
void osl_int_init(int precision, osl_int_p variable) {
132
case OSL_PRECISION_SP:
136
case OSL_PRECISION_DP:
140
#ifdef OSL_GMP_IS_HERE
141
case OSL_PRECISION_MP:
142
OSL_malloc(variable->mp, void*, sizeof(mpz_t));
143
mpz_init(*((mpz_t*)variable->mp));
148
OSL_error("unknown precision");
153
osl_int_p osl_int_malloc(int precision) {
156
OSL_malloc(variable, osl_int_p, sizeof(osl_int_t));
157
osl_int_init(precision, variable);
165
void osl_int_assign(int precision, osl_int_p variable, osl_int_t value) {
167
case OSL_PRECISION_SP:
168
variable->sp = value.sp;
171
case OSL_PRECISION_DP:
172
variable->dp = value.dp;
175
#ifdef OSL_GMP_IS_HERE
176
case OSL_PRECISION_MP:
177
mpz_set(*((mpz_t*)variable->mp), *((mpz_t*)value.mp));
182
OSL_error("unknown precision");
190
void osl_int_set_si(int precision, osl_int_p variable, int i) {
192
case OSL_PRECISION_SP:
193
variable->sp = (long int)i;
196
case OSL_PRECISION_DP:
197
variable->dp = (long long int)i;
200
#ifdef OSL_GMP_IS_HERE
201
case OSL_PRECISION_MP:
202
mpz_set_si(*((mpz_t*)variable->mp), i);
207
OSL_error("unknown precision");
215
int osl_int_get_si(int precision, osl_int_t value) {
217
case OSL_PRECISION_SP:
220
case OSL_PRECISION_DP:
221
return (int)value.dp;
223
#ifdef OSL_GMP_IS_HERE
224
case OSL_PRECISION_MP:
225
return mpz_get_si(*((mpz_t*)value.mp));
229
OSL_error("unknown precision");
235
* variable = i; // including initialization for GMP
237
void osl_int_init_set_si(int precision, osl_int_p variable, int i) {
239
case OSL_PRECISION_SP:
240
variable->sp = (long int)i;
243
case OSL_PRECISION_DP:
244
variable->dp = (long long int)i;
247
#ifdef OSL_GMP_IS_HERE
248
case OSL_PRECISION_MP:
249
OSL_malloc(variable->mp, void*, sizeof(mpz_t));
250
mpz_init_set_si(*((mpz_t*)variable->mp), i);
255
OSL_error("unknown precision");
263
void osl_int_swap(int precision, osl_int_p var1, osl_int_p var2) {
265
case OSL_PRECISION_SP: {
266
long int temp = var1->sp;
272
case OSL_PRECISION_DP: {
273
long long int temp = var1->dp;
279
#ifdef OSL_GMP_IS_HERE
280
case OSL_PRECISION_MP: {
283
mpz_set(temp, *((mpz_t*)var1->mp));
284
mpz_set(*((mpz_t*)var1->mp), *((mpz_t*)var2->mp));
285
mpz_set(*((mpz_t*)var2->mp), temp);
292
OSL_error("unknown precision");
298
* variable = 0; // Including cleaning for GMP
300
void osl_int_clear(int precision, osl_int_p variable) {
302
case OSL_PRECISION_SP:
306
case OSL_PRECISION_DP:
310
#ifdef OSL_GMP_IS_HERE
311
case OSL_PRECISION_MP:
312
mpz_clear(*((mpz_t*)variable->mp));
318
OSL_error("unknown precision");
323
void osl_int_free(int precision, osl_int_p variable) {
324
osl_int_clear(precision, variable);
342
330
* osl_int_print function:
343
331
* this function displays an integer value into a file (file, possibly stdout).
344
* \param file The file where the integer has to be printed.
345
* \param precision The precision of the integer.
346
* \param value_base Address of the base integer value.
347
* \param value_offset Offset in number of values from the base integer value.
332
* \param file The file where the integer has to be printed.
333
* \param precision The precision of the integer.
334
* \param value The integer element to print.
349
void osl_int_print(FILE * file, int precision,
350
void * value_base, int value_offset) {
336
void osl_int_print(FILE * file, int precision, osl_int_t value) {
351
337
char string[OSL_MAX_STRING];
353
osl_int_sprint(string, precision, value_base, value_offset);
339
osl_int_sprint(string, precision, value);
354
340
fprintf(file, "%s", string);
359
345
* osl_int_sprint function:
360
346
* this function prints an integer value into a string, it uses the
361
347
* OpenScop Library formats OSL_FMT_* to format the printing.
362
* \param string The string where the integer has to be printed.
363
* \param precision The precision of the integer.
364
* \param value_base Address of the base integer value.
365
* \param value_offset Offset in number of values from the base integer value.
348
* \param string The string where the integer has to be printed.
349
* \param precision The precision of the integer.
350
* \param value The integer element to print.
367
void osl_int_sprint(char * string, int precision,
368
void * value_base, int value_offset) {
369
void * value = osl_int_address(precision, value_base, value_offset);
352
void osl_int_sprint(char * string, int precision, osl_int_t value) {
371
353
switch (precision) {
372
354
case OSL_PRECISION_SP:
373
sprintf(string, OSL_FMT_SP, *(long int *)value);
355
sprintf(string, OSL_FMT_SP, value.sp);
376
358
case OSL_PRECISION_DP:
377
sprintf(string, OSL_FMT_DP, *(long long int *)value);
359
sprintf(string, OSL_FMT_DP, value.dp);
380
362
#ifdef OSL_GMP_IS_HERE
381
363
case OSL_PRECISION_MP: {
383
str = mpz_get_str(0, 10, *(mpz_t *)value); //TODO: 10 -> #define
365
str = mpz_get_str(0, 10, *((mpz_t*)value.mp)); //TODO: 10 -> #define
384
366
sprintf(string, OSL_FMT_MP, str);
669
* result_base[result_offset] = val1_base[val1_offset]-val2_base[val2_offset];
614
* variable <- val1 - val2;
671
616
void osl_int_sub(int precision,
672
void * result_base, int result_offset,
673
void * val1_base, int val1_offset,
674
void * val2_base, int val2_offset) {
675
void * result = osl_int_address(precision, result_base, result_offset);
676
void * val1 = osl_int_address(precision, val1_base, val1_offset);
677
void * val2 = osl_int_address(precision, val2_base, val2_offset);
680
case OSL_PRECISION_SP:
681
*(long int *)result = *(long int *)val1 - *(long int *)val2;
684
case OSL_PRECISION_DP:
685
*(long long int *)result = *(long long int *)val1 -
686
*(long long int *)val2;
689
#ifdef OSL_GMP_IS_HERE
690
case OSL_PRECISION_MP:
691
mpz_sub(*(mpz_t *)result, *(mpz_t *)val1, *(mpz_t *)val2);
696
OSL_error("unknown precision");
702
* result_base[result_offset] = -value_base[value_offset];
704
void osl_int_oppose(int precision,
705
void * result_base, int result_offset,
706
void * value_base, int value_offset) {
707
void * result = osl_int_address(precision, result_base, result_offset);
708
void * value = osl_int_address(precision, value_base, value_offset);
711
case OSL_PRECISION_SP:
712
*(long int *)result = -*(long int *)value;
715
case OSL_PRECISION_DP:
716
*(long long int *)result = -*(long long int *)value;
719
#ifdef OSL_GMP_IS_HERE
720
case OSL_PRECISION_MP:
721
mpz_neg(*(mpz_t *)result, *(mpz_t *)value);
617
osl_int_p variable, osl_int_t val1, osl_int_t val2) {
619
case OSL_PRECISION_SP:
620
variable->sp = val1.sp - val2.sp;
623
case OSL_PRECISION_DP:
624
variable->dp = val1.dp - val2.dp;
627
#ifdef OSL_GMP_IS_HERE
628
case OSL_PRECISION_MP:
629
mpz_sub(*((mpz_t*)variable->mp), *((mpz_t*)val1.mp), *((mpz_t*)val2.mp));
634
OSL_error("unknown precision");
640
* variable <- -value;
642
void osl_int_oppose(int precision, osl_int_p variable, osl_int_t value) {
644
case OSL_PRECISION_SP:
645
variable->sp = -value.sp;
648
case OSL_PRECISION_DP:
649
variable->dp = -value.dp;
652
#ifdef OSL_GMP_IS_HERE
653
case OSL_PRECISION_MP:
654
mpz_neg(*((mpz_t*)variable->mp), *((mpz_t*)value.mp));
659
OSL_error("unknown precision");
665
* variable <- | value |;
667
void osl_int_abs(int precision, osl_int_p variable, osl_int_t value) {
669
case OSL_PRECISION_SP:
670
variable->sp = (value.sp > 0) ? value.sp : -value.sp;
673
case OSL_PRECISION_DP:
674
variable->dp = (value.dp > 0) ? value.dp : -value.dp;
677
#ifdef OSL_GMP_IS_HERE
678
case OSL_PRECISION_MP:
679
mpz_abs(*((mpz_t*)variable->mp), *((mpz_t*)value.mp));
737
* (val1_base[val1_offset] == val2_base[val2_offset])
739
int osl_int_eq(int precision,
740
void * val1_base, int val1_offset,
741
void * val2_base, int val2_offset) {
742
void * val1 = osl_int_address(precision, val1_base, val1_offset);
743
void * val2 = osl_int_address(precision, val2_base, val2_offset);
746
case OSL_PRECISION_SP:
747
return (*(long int *)val1 == *(long int *)val2);
749
case OSL_PRECISION_DP:
750
return (*(long long int *)val1 == *(long long int *)val2);
752
#ifdef OSL_GMP_IS_HERE
753
case OSL_PRECISION_MP:
754
return (mpz_cmp(*(mpz_t *)val1, *(mpz_t *)val2) == 0);
758
OSL_error("unknown precision");
764
* (val1_base[val1_offset] != val2_base[val2_offset])
766
int osl_int_ne(int precision,
767
void * val1_base, int val1_offset,
768
void * val2_base, int val2_offset) {
769
return !osl_int_eq(precision,
770
val1_base, val1_offset,
771
val2_base, val2_offset);
776
* (value_base[value_offset] > 0)
778
int osl_int_pos(int precision, void * value_base, int value_offset) {
779
void * value = osl_int_address(precision, value_base, value_offset);
782
case OSL_PRECISION_SP:
783
return (*(long int *)value > 0);
785
case OSL_PRECISION_DP:
786
return (*(long long int *)value > 0);
788
#ifdef OSL_GMP_IS_HERE
789
case OSL_PRECISION_MP:
790
return (mpz_sgn(*(mpz_t *)value) > 0);
794
OSL_error("unknown precision");
800
* (value_base[value_offset] < 0)
802
int osl_int_neg(int precision, void * value_base, int value_offset) {
803
void * value = osl_int_address(precision, value_base, value_offset);
806
case OSL_PRECISION_SP:
807
return (*(long int *)value < 0);
809
case OSL_PRECISION_DP:
810
return (*(long long int *)value < 0);
812
#ifdef OSL_GMP_IS_HERE
813
case OSL_PRECISION_MP:
814
return (mpz_sgn(*(mpz_t *)value) < 0);
818
OSL_error("unknown precision");
824
* (value_base[value_offset] == 0)
826
int osl_int_zero(int precision, void * value_base, int value_offset) {
827
void * value = osl_int_address(precision, value_base, value_offset);
830
case OSL_PRECISION_SP:
831
return (*(long int *)value == 0);
833
case OSL_PRECISION_DP:
834
return (*(long long int *)value == 0);
836
#ifdef OSL_GMP_IS_HERE
837
case OSL_PRECISION_MP:
838
return (mpz_sgn(*(mpz_t *)value) == 0);
842
OSL_error("unknown precision");
848
* (value_base[value_offset] == 1)
850
int osl_int_one(int precision, void * value_base, int value_offset) {
851
void * value = osl_int_address(precision, value_base, value_offset);
854
case OSL_PRECISION_SP:
855
return (*(long int *)value == (long int)1);
857
case OSL_PRECISION_DP:
858
return (*(long long int *)value == (long long int)1);
860
#ifdef OSL_GMP_IS_HERE
861
case OSL_PRECISION_MP:
862
return (mpz_cmp_si(*(mpz_t *)value, 1) == 0);
866
OSL_error("unknown precision");
872
* (value_base[value_offset] == -1)
874
int osl_int_mone(int precision, void * value_base, int value_offset) {
875
void * value = osl_int_address(precision, value_base, value_offset);
878
case OSL_PRECISION_SP:
879
return (*(long int *)value == (long int)-1);
881
case OSL_PRECISION_DP:
882
return (*(long long int *)value == (long long int)-1);
884
#ifdef OSL_GMP_IS_HERE
885
case OSL_PRECISION_MP:
886
return (mpz_cmp_si(*(mpz_t *)value, -1) == 0);
890
OSL_error("unknown precision");
896
* ((val1_base[val1_offset] % val2_base[val2_offset]) == 0)
898
int osl_int_divisible(int precision,
899
void * val1_base, int val1_offset,
900
void * val2_base, int val2_offset) {
901
void * val1 = osl_int_address(precision, val1_base, val1_offset);
902
void * val2 = osl_int_address(precision, val2_base, val2_offset);
905
case OSL_PRECISION_SP:
906
return ((*(long int *)val1 % *(long int *)val2) == 0);
908
case OSL_PRECISION_DP:
909
return ((*(long long int *)val1 % *(long long int *)val2) == 0);
911
#ifdef OSL_GMP_IS_HERE
912
case OSL_PRECISION_MP:
913
return mpz_divisible_p(*(mpz_t *)val1, *(mpz_t *)val2);
697
int osl_int_eq(int precision, osl_int_t val1, osl_int_t val2) {
699
case OSL_PRECISION_SP:
700
return (val1.sp == val2.sp);
702
case OSL_PRECISION_DP:
703
return (val1.dp == val2.dp);
705
#ifdef OSL_GMP_IS_HERE
706
case OSL_PRECISION_MP:
707
return (mpz_cmp(*((mpz_t*)val1.mp), *((mpz_t*)val2.mp)) == 0);
711
OSL_error("unknown precision");
719
int osl_int_ne(int precision, osl_int_t val1, osl_int_t val2) {
720
return !osl_int_eq(precision, val1, val2);
727
int osl_int_pos(int precision, osl_int_t value) {
729
case OSL_PRECISION_SP:
730
return (value.sp > 0);
732
case OSL_PRECISION_DP:
733
return (value.dp > 0);
735
#ifdef OSL_GMP_IS_HERE
736
case OSL_PRECISION_MP:
737
return (mpz_sgn(*((mpz_t*)value.mp)) > 0);
741
OSL_error("unknown precision");
749
int osl_int_neg(int precision, osl_int_t value) {
751
case OSL_PRECISION_SP:
752
return (value.sp < 0);
754
case OSL_PRECISION_DP:
755
return (value.dp < 0);
757
#ifdef OSL_GMP_IS_HERE
758
case OSL_PRECISION_MP:
759
return (mpz_sgn(*((mpz_t*)value.mp)) < 0);
763
OSL_error("unknown precision");
771
int osl_int_zero(int precision, osl_int_t value) {
773
case OSL_PRECISION_SP:
774
return (value.sp == 0);
776
case OSL_PRECISION_DP:
777
return (value.dp == 0);
779
#ifdef OSL_GMP_IS_HERE
780
case OSL_PRECISION_MP:
781
return (mpz_sgn(*((mpz_t*)value.mp)) == 0);
785
OSL_error("unknown precision");
793
int osl_int_one(int precision, osl_int_t value) {
795
case OSL_PRECISION_SP:
796
return (value.sp == (long int)1);
798
case OSL_PRECISION_DP:
799
return (value.dp == (long long int)1);
801
#ifdef OSL_GMP_IS_HERE
802
case OSL_PRECISION_MP:
803
return (mpz_cmp_si(*((mpz_t*)value.mp), 1) == 0);
807
OSL_error("unknown precision");
815
int osl_int_mone(int precision, osl_int_t value) {
817
case OSL_PRECISION_SP:
818
return (value.sp == (long int)-1);
820
case OSL_PRECISION_DP:
821
return (value.dp == (long long int)-1);
823
#ifdef OSL_GMP_IS_HERE
824
case OSL_PRECISION_MP:
825
return (mpz_cmp_si(*((mpz_t*)value.mp), -1) == 0);
829
OSL_error("unknown precision");
835
* ((val1 % val2) == 0)
837
int osl_int_divisible(int precision, osl_int_t val1, osl_int_t val2) {
839
case OSL_PRECISION_SP:
840
return ((val1.sp % val2.sp) == 0);
842
case OSL_PRECISION_DP:
843
return ((val1.dp % val2.dp) == 0);
845
#ifdef OSL_GMP_IS_HERE
846
case OSL_PRECISION_MP:
847
return mpz_divisible_p(*((mpz_t*)val1.mp), *((mpz_t*)val2.mp));