Add openscop_int_p associated free
[openscop.git] / source / int.c
blob6536cad7cb6746d355c7ebf19f3754211df66d01
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_malloc(int precision) {
163 void * value;
165 switch (precision) {
166 case OPENSCOP_PRECISION_SP:
167 value = malloc(sizeof(long int));
168 break;
170 case OPENSCOP_PRECISION_DP:
171 value = malloc(sizeof(long long int));
172 *(long long int *)value = 0;
173 break;
175 #ifdef OPENSCOP_GMP_IS_HERE
176 case OPENSCOP_PRECISION_MP:
177 value = malloc(sizeof(mpz_t));
178 break;
179 #endif
181 default:
182 OPENSCOP_error("unknown precision");
185 openscop_int_init(precision, value, 0);
186 return value;
190 void openscop_int_assign(int precision,
191 void * val1_base, int val1_offset,
192 void * val2_base, int val2_offset) {
193 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
194 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
196 switch (precision) {
197 case OPENSCOP_PRECISION_SP:
198 *(long int *)val1 = *(long int *)val2;
199 break;
201 case OPENSCOP_PRECISION_DP:
202 *(long long int *)val1 = *(long long int *)val2;
203 break;
205 #ifdef OPENSCOP_GMP_IS_HERE
206 case OPENSCOP_PRECISION_MP:
207 mpz_set(*(mpz_t *)val1, *(mpz_t *)val2);
208 break;
209 #endif
211 default:
212 OPENSCOP_error("unknown precision");
217 void openscop_int_set_si(int precision, void * value_base, int value_offset,
218 int i) {
219 void * value = openscop_int_address(precision, value_base, value_offset);
221 switch (precision) {
222 case OPENSCOP_PRECISION_SP:
223 *(long int *)value = (long int)i;
224 break;
226 case OPENSCOP_PRECISION_DP:
227 *(long long int *)value = (long long int)i;
228 break;
230 #ifdef OPENSCOP_GMP_IS_HERE
231 case OPENSCOP_PRECISION_MP:
232 mpz_set_si(*(mpz_t *)value, i);
233 break;
234 #endif
236 default:
237 OPENSCOP_error("unknown precision");
242 int openscop_int_get_si(int precision, void * value_base, int value_offset) {
243 void * value = openscop_int_address(precision, value_base, value_offset);
245 switch (precision) {
246 case OPENSCOP_PRECISION_SP:
247 return *(int *)value;
249 case OPENSCOP_PRECISION_DP:
250 return *(int *)value;
252 #ifdef OPENSCOP_GMP_IS_HERE
253 case OPENSCOP_PRECISION_MP:
254 return mpz_get_si(*(mpz_t *)value);
255 #endif
257 default:
258 OPENSCOP_error("unknown precision");
263 void openscop_int_init_set_si(int precision,
264 void * value_base, int value_offset, int i) {
265 void * value = openscop_int_address(precision, value_base, value_offset);
267 switch (precision) {
268 case OPENSCOP_PRECISION_SP:
269 *(long int *)value = (long int)i;
270 break;
272 case OPENSCOP_PRECISION_DP:
273 *(long long int *)value = (long long int)i;
274 break;
276 #ifdef OPENSCOP_GMP_IS_HERE
277 case OPENSCOP_PRECISION_MP:
278 mpz_init_set_si(*(mpz_t *)value, i);
279 break;
280 #endif
282 default:
283 OPENSCOP_error("unknown precision");
288 void openscop_int_clear(int precision, void * value_base, int value_offset) {
289 void * value = openscop_int_address(precision, value_base, value_offset);
291 switch (precision) {
292 case OPENSCOP_PRECISION_SP:
293 *(long int *)value = 0;
294 break;
296 case OPENSCOP_PRECISION_DP:
297 *(long long int *)value = 0;
298 break;
300 #ifdef OPENSCOP_GMP_IS_HERE
301 case OPENSCOP_PRECISION_MP:
302 mpz_clear(*(mpz_t *)value);
303 break;
304 #endif
306 default:
307 OPENSCOP_error("unknown precision");
312 void openscop_int_free(int precision, void * value_base, int value_offset) {
313 void * value = openscop_int_address(precision, value_base, value_offset);
315 openscop_int_clear(precision, value_base, value_offset);
316 free(value);
321 * openscop_int_print function:
322 * this function displays an integer value into a file (file, possibly stdout).
323 * \param file The file 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_print(FILE * file, 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 fprintf(file, OPENSCOP_FMT_SP, *(long int *)value);
334 break;
336 case OPENSCOP_PRECISION_DP:
337 fprintf(file, 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 fprintf(file, OPENSCOP_FMT_MP, str);
345 free(str);
346 break;
348 #endif
350 default:
351 OPENSCOP_error("unknown precision");
357 * openscop_int_sprint function:
358 * this function prints an integer value into a string.
359 * \param string The string where the integer has to be printed.
360 * \param precision The precision of the integer.
361 * \param value Address of the integer value.
363 void openscop_int_sprint(char * string, int precision,
364 void * value_base, int value_offset) {
365 void * value = openscop_int_address(precision, value_base, value_offset);
367 switch (precision) {
368 case OPENSCOP_PRECISION_SP:
369 sprintf(string, OPENSCOP_FMT_SP, *(long int *)value);
370 break;
372 case OPENSCOP_PRECISION_DP:
373 sprintf(string, OPENSCOP_FMT_DP, *(long long int *)value);
374 break;
376 #ifdef OPENSCOP_GMP_IS_HERE
377 case OPENSCOP_PRECISION_MP: {
378 char * str;
379 str = mpz_get_str(0, 10, *(mpz_t *)value); //TODO: 10 -> #define
380 sprintf(string, OPENSCOP_FMT_MP, str);
381 free(str);
382 break;
384 #endif
386 default:
387 OPENSCOP_error("unknown precision");
392 void openscop_int_sread(char * string, int precision,
393 void * value_base, int value_offset) {
394 void * value = openscop_int_address(precision, value_base, value_offset);
395 int nb_read;
397 switch (precision) {
398 case OPENSCOP_PRECISION_SP:
399 nb_read = sscanf(string, OPENSCOP_FMT_TXT_SP, (long int *)value);
400 if (nb_read == 0)
401 OPENSCOP_error("failed to read an integer");
402 break;
404 case OPENSCOP_PRECISION_DP:
405 nb_read = sscanf(string, OPENSCOP_FMT_TXT_DP, (long long int *)value);
406 if (nb_read == 0)
407 OPENSCOP_error("failed to read an integer");
408 break;
410 #ifdef OPENSCOP_GMP_IS_HERE
411 case OPENSCOP_PRECISION_MP: {
412 long long int tmp;
413 nb_read = sscanf(string, OPENSCOP_FMT_TXT_DP, &tmp);
414 if (nb_read == 0)
415 OPENSCOP_error("failed to read an integer");
416 mpz_set_si(*(mpz_t *)value, tmp);
417 break;
419 #endif
421 default:
422 OPENSCOP_error("unknown precision");
427 /*+***************************************************************************
428 * Arithmetic Operations *
429 *****************************************************************************/
432 void openscop_int_increment(int precision,
433 void * result_base, int result_offset,
434 void * value_base, int value_offset) {
435 void * result = openscop_int_address(precision, result_base, result_offset);
436 void * value = openscop_int_address(precision, value_base, value_offset);
438 switch (precision) {
439 case OPENSCOP_PRECISION_SP:
440 *(long int *)result = *(long int *)value + (long int)1;
441 break;
443 case OPENSCOP_PRECISION_DP:
444 *(long long int *)result = *(long long int *)value + (long long int)1;
445 break;
447 #ifdef OPENSCOP_GMP_IS_HERE
448 case OPENSCOP_PRECISION_MP:
449 mpz_add_ui(*(mpz_t *)result, *(mpz_t *)value, 1);
450 break;
451 #endif
453 default:
454 OPENSCOP_error("unknown precision");
459 void openscop_int_add(int precision,
460 void * result_base, int result_offset,
461 void * val1_base, int val1_offset,
462 void * val2_base, int val2_offset) {
463 void * result = openscop_int_address(precision, result_base, result_offset);
464 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
465 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
467 switch (precision) {
468 case OPENSCOP_PRECISION_SP:
469 *(long int *)result = *(long int *)val1 + *(long int *)val2;
470 break;
472 case OPENSCOP_PRECISION_DP:
473 *(long long int *)result = *(long long int *)val1 +
474 *(long long int *)val2;
475 break;
477 #ifdef OPENSCOP_GMP_IS_HERE
478 case OPENSCOP_PRECISION_MP:
479 mpz_add(*(mpz_t *)result, *(mpz_t *)val1, *(mpz_t *)val2);
480 break;
481 #endif
483 default:
484 OPENSCOP_error("unknown precision");
489 void openscop_int_add_ui(int precision,
490 void * result_base, int result_offset,
491 void * value_base, int value_offset, int i) {
492 void * result = openscop_int_address(precision, result_base, result_offset);
493 void * value = openscop_int_address(precision, value_base, value_offset);
495 switch (precision) {
496 case OPENSCOP_PRECISION_SP:
497 *(long int *)result = *(long int *)value + (long int)i;
498 break;
500 case OPENSCOP_PRECISION_DP:
501 *(long long int *)result = *(long long int *)value + (long long int)i;
502 break;
504 #ifdef OPENSCOP_GMP_IS_HERE
505 case OPENSCOP_PRECISION_MP:
506 mpz_add_ui(*(mpz_t *)result, *(mpz_t *)value, (long int)i);
507 break;
508 #endif
510 default:
511 OPENSCOP_error("unknown precision");
516 void openscop_int_mul(int precision,
517 void * result_base, int result_offset,
518 void * val1_base, int val1_offset,
519 void * val2_base, int val2_offset) {
520 void * result = openscop_int_address(precision, result_base, result_offset);
521 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
522 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
524 switch (precision) {
525 case OPENSCOP_PRECISION_SP:
526 *(long int *)result = *(long int *)val1 * *(long int *)val2;
527 break;
529 case OPENSCOP_PRECISION_DP:
530 *(long long int *)result = *(long long int *)val1 *
531 *(long long int *)val2;
532 break;
534 #ifdef OPENSCOP_GMP_IS_HERE
535 case OPENSCOP_PRECISION_MP:
536 mpz_mul(*(mpz_t *)result, *(mpz_t *)val1, *(mpz_t *)val2);
537 break;
538 #endif
540 default:
541 OPENSCOP_error("unknown precision");
546 void openscop_int_mul_si(int precision,
547 void * result_base, int result_offset,
548 void * value_base, int value_offset, int i) {
549 void * result = openscop_int_address(precision, result_base, result_offset);
550 void * value = openscop_int_address(precision, value_base, value_offset);
552 switch (precision) {
553 case OPENSCOP_PRECISION_SP:
554 *(long int *)result = *(long int *)value * (long int)i;
555 break;
557 case OPENSCOP_PRECISION_DP:
558 *(long long int *)result = *(long long int *)value * (long long int)i;
559 break;
561 #ifdef OPENSCOP_GMP_IS_HERE
562 case OPENSCOP_PRECISION_MP:
563 mpz_mul_si(*(mpz_t *)result, *(mpz_t *)value, i);
564 break;
565 #endif
567 default:
568 OPENSCOP_error("unknown precision");
573 void openscop_int_sub(int precision,
574 void * result_base, int result_offset,
575 void * val1_base, int val1_offset,
576 void * val2_base, int val2_offset) {
577 void * result = openscop_int_address(precision, result_base, result_offset);
578 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
579 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
581 switch (precision) {
582 case OPENSCOP_PRECISION_SP:
583 *(long int *)result = *(long int *)val1 - *(long int *)val2;
584 break;
586 case OPENSCOP_PRECISION_DP:
587 *(long long int *)result = *(long long int *)val1 -
588 *(long long int *)val2;
589 break;
591 #ifdef OPENSCOP_GMP_IS_HERE
592 case OPENSCOP_PRECISION_MP:
593 mpz_sub(*(mpz_t *)result, *(mpz_t *)val1, *(mpz_t *)val2);
594 break;
595 #endif
597 default:
598 OPENSCOP_error("unknown precision");
603 void openscop_int_oppose(int precision,
604 void * result_base, int result_offset,
605 void * value_base, int value_offset) {
606 void * result = openscop_int_address(precision, result_base, result_offset);
607 void * value = openscop_int_address(precision, value_base, value_offset);
609 switch (precision) {
610 case OPENSCOP_PRECISION_SP:
611 *(long int *)result = -*(long int *)value;
612 break;
614 case OPENSCOP_PRECISION_DP:
615 *(long long int *)result = -*(long long int *)value;
616 break;
618 #ifdef OPENSCOP_GMP_IS_HERE
619 case OPENSCOP_PRECISION_MP:
620 mpz_neg(*(mpz_t *)result, *(mpz_t *)value);
621 break;
622 #endif
624 default:
625 OPENSCOP_error("unknown precision");
630 /*+***************************************************************************
631 * Conditional Operations *
632 *****************************************************************************/
635 int openscop_int_eq(int precision,
636 void * val1_base, int val1_offset,
637 void * val2_base, int val2_offset) {
638 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
639 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
641 switch (precision) {
642 case OPENSCOP_PRECISION_SP:
643 return (*(long int *)val1 == *(long int *)val2);
645 case OPENSCOP_PRECISION_DP:
646 return (*(long long int *)val1 == *(long long int *)val2);
648 #ifdef OPENSCOP_GMP_IS_HERE
649 case OPENSCOP_PRECISION_MP:
650 return (mpz_cmp(*(mpz_t *)val1, *(mpz_t *)val2) == 0);
651 #endif
653 default:
654 OPENSCOP_error("unknown precision");
659 int openscop_int_ne(int precision,
660 void * val1_base, int val1_offset,
661 void * val2_base, int val2_offset) {
662 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
663 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
665 switch (precision) {
666 case OPENSCOP_PRECISION_SP:
667 return (*(long int *)val1 != *(long int *)val2);
669 case OPENSCOP_PRECISION_DP:
670 return (*(long long int *)val1 != *(long long int *)val2);
672 #ifdef OPENSCOP_GMP_IS_HERE
673 case OPENSCOP_PRECISION_MP:
674 return (mpz_cmp(*(mpz_t *)val1, *(mpz_t *)val2) != 0);
675 #endif
677 default:
678 OPENSCOP_error("unknown precision");
683 int openscop_int_pos(int precision, void * value_base, int value_offset) {
684 void * value = openscop_int_address(precision, value_base, value_offset);
686 switch (precision) {
687 case OPENSCOP_PRECISION_SP:
688 return (*(long int *)value > 0);
690 case OPENSCOP_PRECISION_DP:
691 return (*(long long int *)value > 0);
693 #ifdef OPENSCOP_GMP_IS_HERE
694 case OPENSCOP_PRECISION_MP:
695 return (mpz_sgn(*(mpz_t *)value) > 0);
696 #endif
698 default:
699 OPENSCOP_error("unknown precision");
704 int openscop_int_neg(int precision, void * value_base, int value_offset) {
705 void * value = openscop_int_address(precision, value_base, value_offset);
707 switch (precision) {
708 case OPENSCOP_PRECISION_SP:
709 return (*(long int *)value < 0);
711 case OPENSCOP_PRECISION_DP:
712 return (*(long long int *)value < 0);
714 #ifdef OPENSCOP_GMP_IS_HERE
715 case OPENSCOP_PRECISION_MP:
716 return (mpz_sgn(*(mpz_t *)value) < 0);
717 #endif
719 default:
720 OPENSCOP_error("unknown precision");
725 int openscop_int_zero(int precision, void * value_base, int value_offset) {
726 void * value = openscop_int_address(precision, value_base, value_offset);
728 switch (precision) {
729 case OPENSCOP_PRECISION_SP:
730 return (*(long int *)value == 0);
732 case OPENSCOP_PRECISION_DP:
733 return (*(long long int *)value == 0);
735 #ifdef OPENSCOP_GMP_IS_HERE
736 case OPENSCOP_PRECISION_MP:
737 return (mpz_sgn(*(mpz_t *)value) == 0);
738 #endif
740 default:
741 OPENSCOP_error("unknown precision");
746 int openscop_int_notzero(int precision, void * value_base, int value_offset) {
747 void * value = openscop_int_address(precision, value_base, value_offset);
749 switch (precision) {
750 case OPENSCOP_PRECISION_SP:
751 return (*(long int *)value != 0);
753 case OPENSCOP_PRECISION_DP:
754 return (*(long long int *)value != 0);
756 #ifdef OPENSCOP_GMP_IS_HERE
757 case OPENSCOP_PRECISION_MP:
758 return (mpz_sgn(*(mpz_t *)value) != 0);
759 #endif
761 default:
762 OPENSCOP_error("unknown precision");
767 int openscop_int_one(int precision, void * value_base, int value_offset) {
768 void * value = openscop_int_address(precision, value_base, value_offset);
770 switch (precision) {
771 case OPENSCOP_PRECISION_SP:
772 return (*(long int *)value == (long int)1);
774 case OPENSCOP_PRECISION_DP:
775 return (*(long long int *)value == (long long int)1);
777 #ifdef OPENSCOP_GMP_IS_HERE
778 case OPENSCOP_PRECISION_MP:
779 return (mpz_cmp_si(*(mpz_t *)value, 1) == 0);
780 #endif
782 default:
783 OPENSCOP_error("unknown precision");
788 int openscop_int_mone(int precision, void * value_base, int value_offset) {
789 void * value = openscop_int_address(precision, value_base, value_offset);
791 switch (precision) {
792 case OPENSCOP_PRECISION_SP:
793 return (*(long int *)value == (long int)-1);
795 case OPENSCOP_PRECISION_DP:
796 return (*(long long int *)value == (long long int)-1);
798 #ifdef OPENSCOP_GMP_IS_HERE
799 case OPENSCOP_PRECISION_MP:
800 return (mpz_cmp_si(*(mpz_t *)value, -1) == 0);
801 #endif
803 default:
804 OPENSCOP_error("unknown precision");
809 int openscop_int_divisible(int precision,
810 void * val1_base, int val1_offset,
811 void * val2_base, int val2_offset) {
812 void * val1 = openscop_int_address(precision, val1_base, val1_offset);
813 void * val2 = openscop_int_address(precision, val2_base, val2_offset);
815 switch (precision) {
816 case OPENSCOP_PRECISION_SP:
817 return ((*(long int *)val1 % *(long int *)val2) == 0);
819 case OPENSCOP_PRECISION_DP:
820 return ((*(long long int *)val1 % *(long long int *)val2) == 0);
822 #ifdef OPENSCOP_GMP_IS_HERE
823 case OPENSCOP_PRECISION_MP:
824 return mpz_divisible_p(*(mpz_t *)val1, *(mpz_t *)val2);
825 #endif
827 default:
828 OPENSCOP_error("unknown precision");