OpenScop  0.9.0
int.h
Go to the documentation of this file.
1 
2  /*+-----------------------------------------------------------------**
3  ** OpenScop Library **
4  **-----------------------------------------------------------------**
5  ** int.h **
6  **-----------------------------------------------------------------**
7  ** First version: 18/07/2011 **
8  **-----------------------------------------------------------------**
9 
10 
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  *****************************************************************************/
62 
63 
64 #ifndef OSL_INT_H
65 # define OSL_INT_H
66 
67 # ifdef OSL_GMP_IS_HERE
68 # include <gmp.h>
69 # endif
70 
71 # if defined(__cplusplus)
72 extern "C"
73  {
74 # endif
75 
79 union osl_int {
80  long int sp;
81  long long dp;
82 #ifdef OSL_GMP_IS_HERE
83  mpz_t* mp;
84 #else
85  void* mp;
86 #endif
87 };
88 typedef union osl_int osl_int_t;
89 typedef union osl_int * osl_int_p;
90 typedef union osl_int const osl_const_int_t;
91 typedef union osl_int * const osl_int_const_p;
92 typedef union osl_int const * osl_const_int_p;
93 typedef union osl_int const * const osl_const_int_const_p;
94 
95 
96 /*+***************************************************************************
97  * Basic Functions *
98  *****************************************************************************/
99 
100 
102 void osl_int_dump_precision(FILE *, int);
103 void osl_int_init(int, osl_int_const_p);
104 osl_int_p osl_int_malloc(int);
105 void osl_int_assign(int, osl_int_const_p, osl_const_int_t);
106 void osl_int_set_si(int, osl_int_const_p, int);
108 double osl_int_get_d(int, osl_const_int_t);
109 void osl_int_init_set(int, osl_int_const_p, osl_const_int_t);
110 void osl_int_init_set_si(int, osl_int_const_p, int);
111 void osl_int_swap(int, osl_int_const_p, osl_int_const_p);
112 void osl_int_clear(int, osl_int_const_p);
113 void osl_int_free(int, osl_int_const_p);
114 void osl_int_print(FILE *, int, osl_const_int_t);
115 void osl_int_sprint(char *, int, osl_const_int_t);
116 void osl_int_sprint_txt(char *, int, osl_const_int_t);
117 int osl_int_sscanf(char*, int, osl_int_const_p);
118 void osl_int_sread(char **, int, osl_int_const_p);
119 
120 
121 /*+***************************************************************************
122  * Arithmetic Operations *
123  *****************************************************************************/
124 
125 
126 void osl_int_increment(int, osl_int_const_p, osl_const_int_t);
127 void osl_int_decrement(int, osl_int_const_p, osl_const_int_t);
128 void osl_int_add(int, osl_int_const_p, osl_const_int_t, osl_const_int_t);
129 void osl_int_add_si(int, osl_int_const_p, osl_const_int_t, int);
130 void osl_int_sub(int, osl_int_const_p, osl_const_int_t, osl_const_int_t);
131 void osl_int_mul(int, osl_int_const_p, osl_const_int_t, osl_const_int_t);
132 void osl_int_mul_si(int, osl_int_const_p, osl_const_int_t, int);
133 void osl_int_div_exact(int const, osl_int_const_p,
135 void osl_int_floor_div_q(int const, osl_int_const_p,
137 void osl_int_floor_div_r(int const, osl_int_const_p,
139 void osl_int_floor_div_q_r(int const, osl_int_const_p, osl_int_const_p,
141 void osl_int_mod(int const, osl_int_const_p,
143 void osl_int_gcd(int const, osl_int_const_p,
145 void osl_int_oppose(int, osl_int_const_p, osl_const_int_t);
146 void osl_int_abs(int, osl_int_const_p, osl_const_int_t);
147 size_t osl_int_size_in_base_2(int const, osl_const_int_t);
148 size_t osl_int_size_in_base_10(int const, osl_const_int_t);
149 
150 
151 /*+***************************************************************************
152  * Conditional Operations *
153  *****************************************************************************/
154 
155 
158 int osl_int_pos(int, osl_const_int_t);
159 int osl_int_neg(int, osl_const_int_t);
160 int osl_int_zero(int, osl_const_int_t);
161 int osl_int_one(int, osl_const_int_t);
162 int osl_int_mone(int, osl_const_int_t);
164 
165 
166 /*+***************************************************************************
167  * Processing functions *
168  *****************************************************************************/
169 
170 
171 void osl_int_set_precision(int const, int const, osl_int_p);
172 
173 
174 # if defined(__cplusplus)
175  }
176 # endif
177 
178 #endif /* define OSL_INT_H */
void osl_int_print(FILE *, int, osl_const_int_t)
Definition: int.c:423
void osl_int_floor_div_r(int const, osl_int_const_p, osl_const_int_t, osl_const_int_t)
r = a - b * (a / b)
Definition: int.c:863
void osl_int_set_si(int, osl_int_const_p, int)
variable = i
Definition: int.c:208
union osl_int *const osl_int_const_p
Definition: int.h:91
void osl_int_decrement(int, osl_int_const_p, osl_const_int_t)
variable = value - 1
Definition: int.c:568
void osl_int_sprint_txt(char *, int, osl_const_int_t)
Definition: int.c:471
double osl_int_get_d(int, osl_const_int_t)
Get the value in a double.
Definition: int.c:277
long long dp
Definition: int.h:81
void osl_int_clear(int, osl_int_const_p)
variable = 0 // including cleaning for GMP
Definition: int.c:382
void osl_int_init(int, osl_int_const_p)
Initialize the osl int.
Definition: int.c:137
int osl_int_neg(int, osl_const_int_t)
value < 0
Definition: int.c:1174
void osl_int_add(int, osl_int_const_p, osl_const_int_t, osl_const_int_t)
variable = val1 + val2
Definition: int.c:581
union osl_int * osl_int_p
Definition: int.h:89
void osl_int_floor_div_q(int const, osl_int_const_p, osl_const_int_t, osl_const_int_t)
q = floor(a / b)
Definition: int.c:821
void * mp
Definition: int.h:85
int osl_int_mone(int, osl_const_int_t)
value == -1
Definition: int.c:1249
void osl_int_mul_si(int, osl_int_const_p, osl_const_int_t, int)
variable = val1 * i
Definition: int.c:752
union osl_int const osl_const_int_t
Definition: int.h:90
osl_int_p osl_int_malloc(int)
Initialize the osl int.
Definition: int.c:164
void osl_int_oppose(int, osl_int_const_p, osl_const_int_t)
variable = - value
Definition: int.c:981
union osl_int const * osl_const_int_p
Definition: int.h:92
void osl_int_gcd(int const, osl_int_const_p, osl_const_int_t, osl_const_int_t)
Compute the gcd (greatest common divisor) of a and b.
Definition: int.c:959
void osl_int_increment(int, osl_int_const_p, osl_const_int_t)
variable = value + 1
Definition: int.c:556
void osl_int_abs(int, osl_int_const_p, osl_const_int_t)
variable = | value |
Definition: int.c:1010
void osl_int_mod(int const, osl_int_const_p, osl_const_int_t, osl_const_int_t)
mod = a % b
Definition: int.c:925
void osl_int_floor_div_q_r(int const, osl_int_const_p, osl_int_const_p, osl_const_int_t, osl_const_int_t)
Compute (q, r) such that a = b * q + r.
Definition: int.c:894
void osl_int_assign(int, osl_int_const_p, osl_const_int_t)
variable = value
Definition: int.c:179
int osl_int_eq(int, osl_const_int_t, osl_const_int_t)
val1 == val2
Definition: int.c:1112
Definition: int.h:79
void osl_int_div_exact(int const, osl_int_const_p, osl_const_int_t, osl_const_int_t)
q = a / b
Definition: int.c:797
size_t osl_int_size_in_base_2(int const, osl_const_int_t)
Get the size in base 2.
Definition: int.c:1050
void osl_int_sread(char **, int, osl_int_const_p)
sread for osl int
Definition: int.c:539
int osl_int_pos(int, osl_const_int_t)
value > 0
Definition: int.c:1149
void osl_int_sprint(char *, int, osl_const_int_t)
Definition: int.c:439
int osl_int_sscanf(char *, int, osl_int_const_p)
sscanf for osl int
Definition: int.c:504
int osl_int_one(int, osl_const_int_t)
value == 1
Definition: int.c:1224
void osl_int_init_set(int, osl_int_const_p, osl_const_int_t)
variable = i // including initialization for GMP
Definition: int.c:302
int osl_int_ne(int, osl_const_int_t, osl_const_int_t)
val1 != val2
Definition: int.c:1138
void osl_int_mul(int, osl_int_const_p, osl_const_int_t, osl_const_int_t)
variable = val1 * val2
Definition: int.c:708
long int sp
Definition: int.h:80
void osl_int_dump_precision(FILE *, int)
Definition: int.c:113
void osl_int_sub(int, osl_int_const_p, osl_const_int_t, osl_const_int_t)
variable = val1 - val2
Definition: int.c:685
int osl_int_zero(int, osl_const_int_t)
value == 0
Definition: int.c:1199
int osl_int_get_si(int, osl_const_int_t)
Get the value in a int.
Definition: int.c:236
int osl_int_divisible(int, osl_const_int_t, osl_const_int_t)
(val1 % val2) == 0
Definition: int.c:1275
union osl_int const *const osl_const_int_const_p
Definition: int.h:93
void osl_int_set_precision(int const, int const, osl_int_p)
Change the precision of the osl_int.
Definition: int.c:1306
void osl_int_swap(int, osl_int_const_p, osl_int_const_p)
Swap the osl ints.
Definition: int.c:343
int osl_int_is_precision_supported(int)
Definition: int.c:90
mpz_t * mp
Definition: int.h:83
void osl_int_init_set_si(int, osl_int_const_p, int)
variable = i // including initialization for GMP
Definition: int.c:314
void osl_int_free(int, osl_int_const_p)
Free thr osl int.
Definition: int.c:410
size_t osl_int_size_in_base_10(int const, osl_const_int_t)
Get the size in base 10.
Definition: int.c:1084
void osl_int_add_si(int, osl_int_const_p, osl_const_int_t, int)
variable = val1 + i
Definition: int.c:631