Hybrid precision (32, 64, GMP)
[openscop.git] / source / int.c
blobd8f11fe8a259971498f099cbfc2afb8e4e1cdf94
2 /*+-----------------------------------------------------------------**
3 ** OpenScop Library **
4 **-----------------------------------------------------------------**
5 ** int.c **
6 **-----------------------------------------------------------------**
7 ** First version: 18/07/2011 **
8 **-----------------------------------------------------------------**
11 *****************************************************************************
12 * OpenScop: Structures and formats for polyhedral tools to talk together *
13 *****************************************************************************
14 * ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, *
15 * / / / // // // // / / / // // / / // / /|,_, *
16 * / / / // // // // / / / // // / / // / / / /\ *
17 * |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ *
18 * | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ *
19 * | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ *
20 * | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ *
21 * | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ *
22 * | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ *
23 * | I | | | | e | | | | | | | | | | | | | \ \ \ *
24 * | T | | | | | | | | | | | | | | | | | \ \ \ *
25 * | E | | | | | | | | | | | | | | | | | \ \ \ *
26 * | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ *
27 * | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / *
28 * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
29 * *
30 * Copyright (C) 2008 University Paris-Sud 11 and INRIA *
31 * *
32 * (3-clause BSD license) *
33 * Redistribution and use in source and binary forms, with or without *
34 * modification, are permitted provided that the following conditions *
35 * are met: *
36 * *
37 * 1. Redistributions of source code must retain the above copyright notice, *
38 * this list of conditions and the following disclaimer. *
39 * 2. Redistributions in binary form must reproduce the above copyright *
40 * notice, this list of conditions and the following disclaimer in the *
41 * documentation and/or other materials provided with the distribution. *
42 * 3. The name of the author may not be used to endorse or promote products *
43 * derived from this software without specific prior written permission. *
44 * *
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR *
46 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. *
48 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, *
49 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT *
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
51 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
52 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
53 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF *
54 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
55 * *
56 * OpenScop Library, a library to manipulate OpenScop formats and data *
57 * structures. Written by: *
58 * Cedric Bastoul <Cedric.Bastoul@u-psud.fr> and *
59 * Louis-Noel Pouchet <Louis-Noel.pouchet@inria.fr> *
60 * *
61 *****************************************************************************/
63 # include <stdlib.h>
64 # include <stdio.h>
65 # include <openscop/int.h>
68 /*+***************************************************************************
69 * Basic Functions *
70 *****************************************************************************/
73 /**
74 * openscop_int_dump_precision function:
75 * this function prints in a human readable fashion the precision
76 * corresponding to the "precision" parameter.
77 * \param[in] file The file where to print the precision.
78 * \param[in] precision The precision to print.
80 void openscop_int_dump_precision(FILE * file, int precision) {
82 switch (precision) {
83 case OPENSCOP_PRECISION_SP:
84 fprintf(file, "32 bits");
85 break;
86 case OPENSCOP_PRECISION_DP:
87 fprintf(file, "64 bits");
88 break;
89 #ifdef OPENSCOP_GMP_IS_HERE
90 case OPENSCOP_PRECISION_MP:
91 fprintf(file, "GMP");
92 break;
93 #endif
94 default:
95 fprintf(file, "unknown precision %d", precision);
100 int openscop_int_sizeof(int precision) {
101 switch (precision) {
102 case OPENSCOP_PRECISION_SP:
103 return sizeof(long int);
105 case OPENSCOP_PRECISION_DP:
106 return sizeof(long long int);
108 #ifdef OPENSCOP_GMP_IS_HERE
109 case OPENSCOP_PRECISION_MP:
110 return sizeof(mpz_t);
111 #endif
113 default:
114 OPENSCOP_error("unknown precision");
119 void * openscop_int_address(int precision, void * base, int offset) {
120 switch (precision) {
121 case OPENSCOP_PRECISION_SP:
122 return (long int *)base + offset;
124 case OPENSCOP_PRECISION_DP:
125 return (long long int *)base + offset;
127 #ifdef OPENSCOP_GMP_IS_HERE
128 case OPENSCOP_PRECISION_MP:
129 return (mpz_t *)base + offset;
130 #endif
132 default:
133 OPENSCOP_error("unknown precision");
138 void openscop_int_init(int precision, void * value_base, int value_offset) {
139 void * value = openscop_int_address(precision, value_base, value_offset);
141 switch (precision) {
142 case OPENSCOP_PRECISION_SP:
143 *(long int *)value = 0;
144 break;
146 case OPENSCOP_PRECISION_DP:
147 *(long long int *)value = 0;
148 break;
150 #ifdef OPENSCOP_GMP_IS_HERE
151 case OPENSCOP_PRECISION_MP:
152 mpz_init(*(mpz_t *)value);
153 break;
154 #endif
156 default:
157 OPENSCOP_error("unknown precision");
162 void openscop_int_assign(int precision,
163 void * val1_base, int val1_offset,
164 void * val2_base, int val2_offset) {
165 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
166 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
168 switch (precision) {
169 case OPENSCOP_PRECISION_SP:
170 *(long int *)val1 = *(long int *)val2;
171 break;
173 case OPENSCOP_PRECISION_DP:
174 *(long long int *)val1 = *(long long int *)val2;
175 break;
177 #ifdef OPENSCOP_GMP_IS_HERE
178 case OPENSCOP_PRECISION_MP:
179 mpz_set(*(mpz_t *)val1, *(mpz_t *)val2);
180 break;
181 #endif
183 default:
184 OPENSCOP_error("unknown precision");
189 void openscop_int_set_si(int precision, void * value_base, int value_offset,
190 int i) {
191 void * value = openscop_int_address(precision, value_base, value_offset);
193 switch (precision) {
194 case OPENSCOP_PRECISION_SP:
195 *(long int *)value = (long int)i;
196 break;
198 case OPENSCOP_PRECISION_DP:
199 *(long long int *)value = (long long int)i;
200 break;
202 #ifdef OPENSCOP_GMP_IS_HERE
203 case OPENSCOP_PRECISION_MP:
204 mpz_set_si(*(mpz_t *)value, i);
205 break;
206 #endif
208 default:
209 OPENSCOP_error("unknown precision");
214 int openscop_int_get_si(int precision, void * value_base, int value_offset) {
215 void * value = openscop_int_address(precision, value_base, value_offset);
217 switch (precision) {
218 case OPENSCOP_PRECISION_SP:
219 return *(int *)value;
221 case OPENSCOP_PRECISION_DP:
222 return *(int *)value;
224 #ifdef OPENSCOP_GMP_IS_HERE
225 case OPENSCOP_PRECISION_MP:
226 return mpz_get_si(*(mpz_t *)value);
227 #endif
229 default:
230 OPENSCOP_error("unknown precision");
235 void openscop_int_init_set_si(int precision,
236 void * value_base, int value_offset, int i) {
237 void * value = openscop_int_address(precision, value_base, value_offset);
239 switch (precision) {
240 case OPENSCOP_PRECISION_SP:
241 *(long int *)value = (long int)i;
242 break;
244 case OPENSCOP_PRECISION_DP:
245 *(long long int *)value = (long long int)i;
246 break;
248 #ifdef OPENSCOP_GMP_IS_HERE
249 case OPENSCOP_PRECISION_MP:
250 mpz_init_set_si(*(mpz_t *)value, i);
251 break;
252 #endif
254 default:
255 OPENSCOP_error("unknown precision");
260 void openscop_int_clear(int precision, void * value_base, int value_offset) {
261 void * value = openscop_int_address(precision, value_base, value_offset);
263 switch (precision) {
264 case OPENSCOP_PRECISION_SP:
265 *(long int *)value = 0;
266 break;
268 case OPENSCOP_PRECISION_DP:
269 *(long long int *)value = 0;
270 break;
272 #ifdef OPENSCOP_GMP_IS_HERE
273 case OPENSCOP_PRECISION_MP:
274 mpz_clear(*(mpz_t *)value);
275 break;
276 #endif
278 default:
279 OPENSCOP_error("unknown precision");
285 * openscop_int_print function:
286 * this function displays an integer value into a file (file, possibly stdout).
287 * \param file The file where the integer has to be printed.
288 * \param precision The precision of the integer.
289 * \param value Address of the integer value.
291 void openscop_int_print(FILE * file, int precision,
292 void * value_base, int value_offset) {
293 void * value = openscop_int_address(precision, value_base, value_offset);
295 switch (precision) {
296 case OPENSCOP_PRECISION_SP:
297 fprintf(file, OPENSCOP_FMT_SP, *(long int *)value);
298 break;
300 case OPENSCOP_PRECISION_DP:
301 fprintf(file, OPENSCOP_FMT_DP, *(long long int *)value);
302 break;
304 #ifdef OPENSCOP_GMP_IS_HERE
305 case OPENSCOP_PRECISION_MP: {
306 char * str;
307 str = mpz_get_str(0, 10, *(mpz_t *)value); //TODO: 10 -> #define
308 fprintf(file, OPENSCOP_FMT_MP, str);
309 free(str);
310 break;
312 #endif
314 default:
315 OPENSCOP_error("unknown precision");
321 * openscop_int_sprint function:
322 * this function prints an integer value into a string.
323 * \param string The string where the integer has to be printed.
324 * \param precision The precision of the integer.
325 * \param value Address of the integer value.
327 void openscop_int_sprint(char * string, int precision,
328 void * value_base, int value_offset) {
329 void * value = openscop_int_address(precision, value_base, value_offset);
331 switch (precision) {
332 case OPENSCOP_PRECISION_SP:
333 sprintf(string, OPENSCOP_FMT_SP, *(long int *)value);
334 break;
336 case OPENSCOP_PRECISION_DP:
337 sprintf(string, OPENSCOP_FMT_DP, *(long long int *)value);
338 break;
340 #ifdef OPENSCOP_GMP_IS_HERE
341 case OPENSCOP_PRECISION_MP: {
342 char * str;
343 str = mpz_get_str(0, 10, *(mpz_t *)value); //TODO: 10 -> #define
344 sprintf(string, OPENSCOP_FMT_MP, str);
345 free(str);
346 break;
348 #endif
350 default:
351 OPENSCOP_error("unknown precision");
356 void openscop_int_sread(char * string, int precision,
357 void * value_base, int value_offset) {
358 void * value = openscop_int_address(precision, value_base, value_offset);
359 int nb_read;
361 switch (precision) {
362 case OPENSCOP_PRECISION_SP:
363 nb_read = sscanf(string, OPENSCOP_FMT_TXT_SP, (long int *)value);
364 if (nb_read == 0)
365 OPENSCOP_error("failed to read an integer");
366 break;
368 case OPENSCOP_PRECISION_DP:
369 nb_read = sscanf(string, OPENSCOP_FMT_TXT_DP, (long long int *)value);
370 if (nb_read == 0)
371 OPENSCOP_error("failed to read an integer");
372 break;
374 #ifdef OPENSCOP_GMP_IS_HERE
375 case OPENSCOP_PRECISION_MP: {
376 long long int tmp;
377 nb_read = sscanf(string, OPENSCOP_FMT_TXT_DP, &tmp);
378 if (nb_read == 0)
379 OPENSCOP_error("failed to read an integer");
380 mpz_set_si(*(mpz_t *)value, tmp);
381 break;
383 #endif
385 default:
386 OPENSCOP_error("unknown precision");
391 /*+***************************************************************************
392 * Arithmetic Operations *
393 *****************************************************************************/
396 void openscop_int_increment(int precision,
397 void * result_base, int result_offset,
398 void * value_base, int value_offset) {
399 void * result = openscop_int_address(precision, result_base, result_offset);
400 void * value = openscop_int_address(precision, value_base, value_offset);
402 switch (precision) {
403 case OPENSCOP_PRECISION_SP:
404 *(long int *)result = *(long int *)value + (long int)1;
405 break;
407 case OPENSCOP_PRECISION_DP:
408 *(long long int *)result = *(long long int *)value + (long long int)1;
409 break;
411 #ifdef OPENSCOP_GMP_IS_HERE
412 case OPENSCOP_PRECISION_MP:
413 mpz_add_ui(*(mpz_t *)result, *(mpz_t *)value, 1);
414 break;
415 #endif
417 default:
418 OPENSCOP_error("unknown precision");
423 void openscop_int_add(int precision,
424 void * result_base, int result_offset,
425 void * val1_base, int val1_offset,
426 void * val2_base, int val2_offset) {
427 void * result = openscop_int_address(precision, result_base, result_offset);
428 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
429 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
431 switch (precision) {
432 case OPENSCOP_PRECISION_SP:
433 *(long int *)result = *(long int *)val1 + *(long int *)val2;
434 break;
436 case OPENSCOP_PRECISION_DP:
437 *(long long int *)result = *(long long int *)val1 +
438 *(long long int *)val2;
439 break;
441 #ifdef OPENSCOP_GMP_IS_HERE
442 case OPENSCOP_PRECISION_MP:
443 mpz_add(*(mpz_t *)result, *(mpz_t *)val1, *(mpz_t *)val2);
444 break;
445 #endif
447 default:
448 OPENSCOP_error("unknown precision");
453 void openscop_int_add_ui(int precision,
454 void * result_base, int result_offset,
455 void * value_base, int value_offset, int i) {
456 void * result = openscop_int_address(precision, result_base, result_offset);
457 void * value = openscop_int_address(precision, value_base, value_offset);
459 switch (precision) {
460 case OPENSCOP_PRECISION_SP:
461 *(long int *)result = *(long int *)value + (long int)i;
462 break;
464 case OPENSCOP_PRECISION_DP:
465 *(long long int *)result = *(long long int *)value + (long long int)i;
466 break;
468 #ifdef OPENSCOP_GMP_IS_HERE
469 case OPENSCOP_PRECISION_MP:
470 mpz_add_ui(*(mpz_t *)result, *(mpz_t *)value, (long int)i);
471 break;
472 #endif
474 default:
475 OPENSCOP_error("unknown precision");
480 void openscop_int_mul(int precision,
481 void * result_base, int result_offset,
482 void * val1_base, int val1_offset,
483 void * val2_base, int val2_offset) {
484 void * result = openscop_int_address(precision, result_base, result_offset);
485 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
486 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
488 switch (precision) {
489 case OPENSCOP_PRECISION_SP:
490 *(long int *)result = *(long int *)val1 * *(long int *)val2;
491 break;
493 case OPENSCOP_PRECISION_DP:
494 *(long long int *)result = *(long long int *)val1 *
495 *(long long int *)val2;
496 break;
498 #ifdef OPENSCOP_GMP_IS_HERE
499 case OPENSCOP_PRECISION_MP:
500 mpz_mul(*(mpz_t *)result, *(mpz_t *)val1, *(mpz_t *)val2);
501 break;
502 #endif
504 default:
505 OPENSCOP_error("unknown precision");
510 void openscop_int_mul_si(int precision,
511 void * result_base, int result_offset,
512 void * value_base, int value_offset, int i) {
513 void * result = openscop_int_address(precision, result_base, result_offset);
514 void * value = openscop_int_address(precision, value_base, value_offset);
516 switch (precision) {
517 case OPENSCOP_PRECISION_SP:
518 *(long int *)result = *(long int *)value * (long int)i;
519 break;
521 case OPENSCOP_PRECISION_DP:
522 *(long long int *)result = *(long long int *)value * (long long int)i;
523 break;
525 #ifdef OPENSCOP_GMP_IS_HERE
526 case OPENSCOP_PRECISION_MP:
527 mpz_mul_si(*(mpz_t *)result, *(mpz_t *)value, i);
528 break;
529 #endif
531 default:
532 OPENSCOP_error("unknown precision");
537 void openscop_int_sub(int precision,
538 void * result_base, int result_offset,
539 void * val1_base, int val1_offset,
540 void * val2_base, int val2_offset) {
541 void * result = openscop_int_address(precision, result_base, result_offset);
542 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
543 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
545 switch (precision) {
546 case OPENSCOP_PRECISION_SP:
547 *(long int *)result = *(long int *)val1 - *(long int *)val2;
548 break;
550 case OPENSCOP_PRECISION_DP:
551 *(long long int *)result = *(long long int *)val1 -
552 *(long long int *)val2;
553 break;
555 #ifdef OPENSCOP_GMP_IS_HERE
556 case OPENSCOP_PRECISION_MP:
557 mpz_sub(*(mpz_t *)result, *(mpz_t *)val1, *(mpz_t *)val2);
558 break;
559 #endif
561 default:
562 OPENSCOP_error("unknown precision");
567 void openscop_int_oppose(int precision,
568 void * result_base, int result_offset,
569 void * value_base, int value_offset) {
570 void * result = openscop_int_address(precision, result_base, result_offset);
571 void * value = openscop_int_address(precision, value_base, value_offset);
573 switch (precision) {
574 case OPENSCOP_PRECISION_SP:
575 *(long int *)result = -*(long int *)value;
576 break;
578 case OPENSCOP_PRECISION_DP:
579 *(long long int *)result = -*(long long int *)value;
580 break;
582 #ifdef OPENSCOP_GMP_IS_HERE
583 case OPENSCOP_PRECISION_MP:
584 mpz_neg(*(mpz_t *)result, *(mpz_t *)value);
585 break;
586 #endif
588 default:
589 OPENSCOP_error("unknown precision");
594 /*+***************************************************************************
595 * Conditional Operations *
596 *****************************************************************************/
599 int openscop_int_eq(int precision,
600 void * val1_base, int val1_offset,
601 void * val2_base, int val2_offset) {
602 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
603 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
605 switch (precision) {
606 case OPENSCOP_PRECISION_SP:
607 return (*(long int *)val1 == *(long int *)val2);
609 case OPENSCOP_PRECISION_DP:
610 return (*(long long int *)val1 == *(long long int *)val2);
612 #ifdef OPENSCOP_GMP_IS_HERE
613 case OPENSCOP_PRECISION_MP:
614 return (mpz_cmp(*(mpz_t *)val1, *(mpz_t *)val2) == 0);
615 #endif
617 default:
618 OPENSCOP_error("unknown precision");
623 int openscop_int_ne(int precision,
624 void * val1_base, int val1_offset,
625 void * val2_base, int val2_offset) {
626 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
627 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
629 switch (precision) {
630 case OPENSCOP_PRECISION_SP:
631 return (*(long int *)val1 != *(long int *)val2);
633 case OPENSCOP_PRECISION_DP:
634 return (*(long long int *)val1 != *(long long int *)val2);
636 #ifdef OPENSCOP_GMP_IS_HERE
637 case OPENSCOP_PRECISION_MP:
638 return (mpz_cmp(*(mpz_t *)val1, *(mpz_t *)val2) != 0);
639 #endif
641 default:
642 OPENSCOP_error("unknown precision");
647 int openscop_int_pos(int precision, void * value_base, int value_offset) {
648 void * value = openscop_int_address(precision, value_base, value_offset);
650 switch (precision) {
651 case OPENSCOP_PRECISION_SP:
652 return (*(long int *)value > 0);
654 case OPENSCOP_PRECISION_DP:
655 return (*(long long int *)value > 0);
657 #ifdef OPENSCOP_GMP_IS_HERE
658 case OPENSCOP_PRECISION_MP:
659 return (mpz_sgn(*(mpz_t *)value) > 0);
660 #endif
662 default:
663 OPENSCOP_error("unknown precision");
668 int openscop_int_neg(int precision, void * value_base, int value_offset) {
669 void * value = openscop_int_address(precision, value_base, value_offset);
671 switch (precision) {
672 case OPENSCOP_PRECISION_SP:
673 return (*(long int *)value < 0);
675 case OPENSCOP_PRECISION_DP:
676 return (*(long long int *)value < 0);
678 #ifdef OPENSCOP_GMP_IS_HERE
679 case OPENSCOP_PRECISION_MP:
680 return (mpz_sgn(*(mpz_t *)value) < 0);
681 #endif
683 default:
684 OPENSCOP_error("unknown precision");
689 int openscop_int_zero(int precision, void * value_base, int value_offset) {
690 void * value = openscop_int_address(precision, value_base, value_offset);
692 switch (precision) {
693 case OPENSCOP_PRECISION_SP:
694 return (*(long int *)value == 0);
696 case OPENSCOP_PRECISION_DP:
697 return (*(long long int *)value == 0);
699 #ifdef OPENSCOP_GMP_IS_HERE
700 case OPENSCOP_PRECISION_MP:
701 return (mpz_sgn(*(mpz_t *)value) == 0);
702 #endif
704 default:
705 OPENSCOP_error("unknown precision");
710 int openscop_int_notzero(int precision, void * value_base, int value_offset) {
711 void * value = openscop_int_address(precision, value_base, value_offset);
713 switch (precision) {
714 case OPENSCOP_PRECISION_SP:
715 return (*(long int *)value != 0);
717 case OPENSCOP_PRECISION_DP:
718 return (*(long long int *)value != 0);
720 #ifdef OPENSCOP_GMP_IS_HERE
721 case OPENSCOP_PRECISION_MP:
722 return (mpz_sgn(*(mpz_t *)value) != 0);
723 #endif
725 default:
726 OPENSCOP_error("unknown precision");
731 int openscop_int_one(int precision, void * value_base, int value_offset) {
732 void * value = openscop_int_address(precision, value_base, value_offset);
734 switch (precision) {
735 case OPENSCOP_PRECISION_SP:
736 return (*(long int *)value == (long int)1);
738 case OPENSCOP_PRECISION_DP:
739 return (*(long long int *)value == (long long int)1);
741 #ifdef OPENSCOP_GMP_IS_HERE
742 case OPENSCOP_PRECISION_MP:
743 return (mpz_cmp_si(*(mpz_t *)value, 1) == 0);
744 #endif
746 default:
747 OPENSCOP_error("unknown precision");
752 int openscop_int_mone(int precision, void * value_base, int value_offset) {
753 void * value = openscop_int_address(precision, value_base, value_offset);
755 switch (precision) {
756 case OPENSCOP_PRECISION_SP:
757 return (*(long int *)value == (long int)-1);
759 case OPENSCOP_PRECISION_DP:
760 return (*(long long int *)value == (long long int)-1);
762 #ifdef OPENSCOP_GMP_IS_HERE
763 case OPENSCOP_PRECISION_MP:
764 return (mpz_cmp_si(*(mpz_t *)value, -1) == 0);
765 #endif
767 default:
768 OPENSCOP_error("unknown precision");
773 int openscop_int_divisible(int precision,
774 void * val1_base, int val1_offset,
775 void * val2_base, int val2_offset) {
776 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
777 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
779 switch (precision) {
780 case OPENSCOP_PRECISION_SP:
781 return ((*(long int *)val1 % *(long int *)val2) == 0);
783 case OPENSCOP_PRECISION_DP:
784 return ((*(long long int *)val1 % *(long long int *)val2) == 0);
786 #ifdef OPENSCOP_GMP_IS_HERE
787 case OPENSCOP_PRECISION_MP:
788 return mpz_divisible_p(*(mpz_t *)val1, *(mpz_t *)val2);
789 #endif
791 default:
792 OPENSCOP_error("unknown precision");