From f9ee5c552249f946596ee1bc18d76769c0656d00 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 8 May 2013 11:50:27 +0200 Subject: [PATCH] create private copy of isl/int.h We will shortly be introducing a new isl_val abstraction that is meant to replace isl_int as well as some abuses of isl_qpolynomial. To implement this new abstraction, we will need some additional isl_int_* functions. However, we do not want to publicly expose these isl_int_* functions since we do not want to encourage their use by external users. We therefore create a private copy of isl/int.h where we can add the additional functions. Once the transition is complete, the public version can be removed. Signed-off-by: Sven Verdoolaege --- Makefile.am | 1 + isl_gmp.c | 2 +- isl_int.h | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ isl_piplib.h | 2 +- 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 isl_int.h diff --git a/Makefile.am b/Makefile.am index 055cbc5..2477a73 100644 --- a/Makefile.am +++ b/Makefile.am @@ -83,6 +83,7 @@ libisl_la_SOURCES = \ isl_hmap_map_basic_set.h \ isl_ilp.c \ isl_input.c \ + isl_int.h \ isl_local_space_private.h \ isl_local_space.c \ isl_lp.c \ diff --git a/isl_gmp.c b/isl_gmp.c index 94119b6..d488fd2 100644 --- a/isl_gmp.c +++ b/isl_gmp.c @@ -7,7 +7,7 @@ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium */ -#include +#include uint32_t isl_gmp_hash(mpz_t v, uint32_t hash) { diff --git a/isl_int.h b/isl_int.h new file mode 100644 index 0000000..8669116 --- /dev/null +++ b/isl_int.h @@ -0,0 +1,113 @@ +/* + * Copyright 2008-2009 Katholieke Universiteit Leuven + * + * Use of this software is governed by the MIT license + * + * Written by Sven Verdoolaege, K.U.Leuven, Departement + * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium + */ + +#ifndef ISL_INT_H +#define ISL_INT_H + +#include +#include +#include + +#ifndef mp_get_memory_functions +void mp_get_memory_functions( + void *(**alloc_func_ptr) (size_t), + void *(**realloc_func_ptr) (void *, size_t, size_t), + void (**free_func_ptr) (void *, size_t)); +#endif + +/* isl_int is the basic integer type. It currently always corresponds + * to a gmp mpz_t, but in the future, different types such as long long + * or cln::cl_I will be supported. + */ +typedef mpz_t isl_int; + +#define isl_int_init(i) mpz_init(i) +#define isl_int_clear(i) mpz_clear(i) + +#define isl_int_set(r,i) mpz_set(r,i) +#define isl_int_set_gmp(r,i) mpz_set(r,i) +#define isl_int_set_si(r,i) mpz_set_si(r,i) +#define isl_int_set_ui(r,i) mpz_set_ui(r,i) +#define isl_int_get_gmp(i,g) mpz_set(g,i) +#define isl_int_get_si(r) mpz_get_si(r) +#define isl_int_get_ui(r) mpz_get_ui(r) +#define isl_int_get_d(r) mpz_get_d(r) +#define isl_int_get_str(r) mpz_get_str(0, 10, r) +typedef void (*isl_int_print_gmp_free_t)(void *, size_t); +#define isl_int_free_str(s) \ + do { \ + isl_int_print_gmp_free_t gmp_free; \ + mp_get_memory_functions(NULL, NULL, &gmp_free); \ + (*gmp_free)(s, strlen(s) + 1); \ + } while (0) +#define isl_int_abs(r,i) mpz_abs(r,i) +#define isl_int_neg(r,i) mpz_neg(r,i) +#define isl_int_swap(i,j) mpz_swap(i,j) +#define isl_int_swap_or_set(i,j) mpz_swap(i,j) +#define isl_int_add_ui(r,i,j) mpz_add_ui(r,i,j) +#define isl_int_sub_ui(r,i,j) mpz_sub_ui(r,i,j) + +#define isl_int_add(r,i,j) mpz_add(r,i,j) +#define isl_int_sub(r,i,j) mpz_sub(r,i,j) +#define isl_int_mul(r,i,j) mpz_mul(r,i,j) +#define isl_int_mul_2exp(r,i,j) mpz_mul_2exp(r,i,j) +#define isl_int_mul_ui(r,i,j) mpz_mul_ui(r,i,j) +#define isl_int_pow_ui(r,i,j) mpz_pow_ui(r,i,j) +#define isl_int_addmul(r,i,j) mpz_addmul(r,i,j) +#define isl_int_submul(r,i,j) mpz_submul(r,i,j) + +#define isl_int_gcd(r,i,j) mpz_gcd(r,i,j) +#define isl_int_gcdext(g,x,y,i,j) mpz_gcdext(g,x,y,i,j) +#define isl_int_lcm(r,i,j) mpz_lcm(r,i,j) +#define isl_int_divexact(r,i,j) mpz_divexact(r,i,j) +#define isl_int_divexact_ui(r,i,j) mpz_divexact_ui(r,i,j) +#define isl_int_tdiv_q(r,i,j) mpz_tdiv_q(r,i,j) +#define isl_int_cdiv_q(r,i,j) mpz_cdiv_q(r,i,j) +#define isl_int_fdiv_q(r,i,j) mpz_fdiv_q(r,i,j) +#define isl_int_fdiv_r(r,i,j) mpz_fdiv_r(r,i,j) +#define isl_int_fdiv_q_ui(r,i,j) mpz_fdiv_q_ui(r,i,j) + +#define isl_int_read(r,s) mpz_set_str(r,s,10) +#define isl_int_print(out,i,width) \ + do { \ + char *s; \ + s = mpz_get_str(0, 10, i); \ + fprintf(out, "%*s", width, s); \ + isl_int_free_str(s); \ + } while (0) + +#define isl_int_sgn(i) mpz_sgn(i) +#define isl_int_cmp(i,j) mpz_cmp(i,j) +#define isl_int_cmp_si(i,si) mpz_cmp_si(i,si) +#define isl_int_eq(i,j) (mpz_cmp(i,j) == 0) +#define isl_int_ne(i,j) (mpz_cmp(i,j) != 0) +#define isl_int_lt(i,j) (mpz_cmp(i,j) < 0) +#define isl_int_le(i,j) (mpz_cmp(i,j) <= 0) +#define isl_int_gt(i,j) (mpz_cmp(i,j) > 0) +#define isl_int_ge(i,j) (mpz_cmp(i,j) >= 0) +#define isl_int_abs_eq(i,j) (mpz_cmpabs(i,j) == 0) +#define isl_int_abs_ne(i,j) (mpz_cmpabs(i,j) != 0) +#define isl_int_abs_lt(i,j) (mpz_cmpabs(i,j) < 0) +#define isl_int_abs_gt(i,j) (mpz_cmpabs(i,j) > 0) +#define isl_int_abs_ge(i,j) (mpz_cmpabs(i,j) >= 0) + + +#define isl_int_is_zero(i) (isl_int_sgn(i) == 0) +#define isl_int_is_one(i) (isl_int_cmp_si(i,1) == 0) +#define isl_int_is_negone(i) (isl_int_cmp_si(i,-1) == 0) +#define isl_int_is_pos(i) (isl_int_sgn(i) > 0) +#define isl_int_is_neg(i) (isl_int_sgn(i) < 0) +#define isl_int_is_nonpos(i) (isl_int_sgn(i) <= 0) +#define isl_int_is_nonneg(i) (isl_int_sgn(i) >= 0) +#define isl_int_is_divisible_by(i,j) mpz_divisible_p(i,j) + +uint32_t isl_gmp_hash(mpz_t v, uint32_t hash); +#define isl_int_hash(v,h) isl_gmp_hash(v,h) + +#endif diff --git a/isl_piplib.h b/isl_piplib.h index b28fbcf..ef9b2d1 100644 --- a/isl_piplib.h +++ b/isl_piplib.h @@ -11,7 +11,7 @@ #define ISL_PIPLIB_H #include -#include +#include #include #ifndef ISL_PIPLIB #error "no piplib" -- 2.7.4