Polly
20.0.0git
llvm-project
polly
lib
External
isl
isl_test_imath.c
Go to the documentation of this file.
1
/*
2
* Copyright 2015 INRIA Paris-Rocquencourt
3
*
4
* Use of this software is governed by the MIT license
5
*
6
* Written by Michael Kruse, INRIA Paris-Rocquencourt,
7
* Domaine de Voluceau, Rocquenqourt, B.P. 105,
8
* 78153 Le Chesnay Cedex France
9
*/
10
11
#include <limits.h>
12
#include <assert.h>
13
#include <
isl_imath.h
>
14
15
/* This constant is not defined in limits.h, but IMath uses it */
16
#define ULONG_MIN 0ul
17
18
/* Test the IMath internals assumed by the imath implementation of isl_int.
19
*
20
* In particular, we test the ranges of IMath-defined types.
21
*
22
* Also, isl uses the existence and function of imath's struct
23
* fields. The digits are stored with less significant digits at lower array
24
* indices. Where they are stored (on the heap or in the field 'single') does
25
* not matter.
26
*/
27
int
test_imath_internals
()
28
{
29
mpz_t
val
;
30
mp_result
retval;
31
32
assert
(
sizeof
(
mp_small
) ==
sizeof
(
long
));
33
assert
(
MP_SMALL_MIN
== LONG_MIN);
34
assert
(
MP_SMALL_MAX
== LONG_MAX);
35
36
assert
(
sizeof
(
mp_usmall
) ==
sizeof
(
unsigned
long
));
37
assert
(
MP_USMALL_MAX
== ULONG_MAX);
38
39
retval =
mp_int_init_value
(&
val
, 0);
40
assert
(retval ==
MP_OK
);
41
assert
(
val
.alloc >=
val
.used);
42
assert
(
val
.used == 1);
43
assert
(
val
.sign ==
MP_ZPOS
);
44
assert
(
val
.digits[0] == 0);
45
46
retval =
mp_int_set_value
(&
val
, -1);
47
assert
(retval ==
MP_OK
);
48
assert
(
val
.alloc >=
val
.used);
49
assert
(
val
.used == 1);
50
assert
(
val
.sign ==
MP_NEG
);
51
assert
(
val
.digits[0] == 1);
52
53
retval =
mp_int_set_value
(&
val
, 1);
54
assert
(retval ==
MP_OK
);
55
assert
(
val
.alloc >=
val
.used);
56
assert
(
val
.used == 1);
57
assert
(
val
.sign ==
MP_ZPOS
);
58
assert
(
val
.digits[0] == 1);
59
60
retval =
mp_int_mul_pow2
(&
val
,
sizeof
(
mp_digit
) * CHAR_BIT, &
val
);
61
assert
(retval ==
MP_OK
);
62
assert
(
val
.alloc >=
val
.used);
63
assert
(
val
.used == 2);
64
assert
(
val
.sign ==
MP_ZPOS
);
65
assert
(
val
.digits[0] == 0);
66
assert
(
val
.digits[1] == 1);
67
68
mp_int_clear
(&
val
);
69
return
0;
70
}
71
72
int
main
()
73
{
74
if
(
test_imath_internals
() < 0)
75
return
-1;
76
77
return
0;
78
}
val
__isl_export __isl_give ISL_HMAP __isl_take ISL_KEY __isl_take ISL_VAL * val
Definition:
hmap.h:32
MP_USMALL_MAX
#define MP_USMALL_MAX
Definition:
imath/imath.h:85
mp_digit
uint32_t mp_digit
Definition:
imath/imath.h:52
mp_small
long mp_small
Definition:
imath/imath.h:41
MP_SMALL_MAX
#define MP_SMALL_MAX
Definition:
imath/imath.h:84
mp_result
int mp_result
Definition:
imath/imath.h:40
MP_SMALL_MIN
#define MP_SMALL_MIN
Definition:
imath/imath.h:83
mp_usmall
unsigned long mp_usmall
Definition:
imath/imath.h:42
isl_imath.h
assert
#define assert(exp)
Definition:
isl_test_cpp-checked.cc:43
test_imath_internals
int test_imath_internals()
Definition:
isl_test_imath.c:27
main
int main()
Definition:
isl_test_imath.c:72
mpz_t
Definition:
imath/imath.h:58
mp_int_clear
#define mp_int_clear
Definition:
wrap.h:72
mp_int_set_value
#define mp_int_set_value
Definition:
wrap.h:114
MP_ZPOS
#define MP_ZPOS
Definition:
wrap.h:14
MP_NEG
#define MP_NEG
Definition:
wrap.h:8
mp_int_mul_pow2
#define mp_int_mul_pow2
Definition:
wrap.h:104
mp_int_init_value
#define mp_int_init_value
Definition:
wrap.h:98
MP_OK
#define MP_OK
Definition:
wrap.h:9
Generated on Wed Nov 13 2024 03:17:29 for Polly by
1.9.6