From f38104fe37c5f95832b1e83d3e9863fb4373fdcf Mon Sep 17 00:00:00 2001 From: Lnc Date: Tue, 17 Jun 2014 12:03:53 +0200 Subject: [PATCH] Add osl_relation_set_same_precision function --- include/osl/int.h | 8 ++++++++ include/osl/relation.h | 2 ++ source/int.c | 19 +++++++++++++++++++ source/relation.c | 40 ++++++++++++++++++++++++++++++++++++++++ tests/Makefile.am | 23 +++++++++++++---------- 5 files changed, 82 insertions(+), 10 deletions(-) diff --git a/include/osl/int.h b/include/osl/int.h index ed01849..fa21219 100644 --- a/include/osl/int.h +++ b/include/osl/int.h @@ -163,6 +163,14 @@ int osl_int_mone(int, osl_const_int_t); int osl_int_divisible(int, osl_const_int_t, osl_const_int_t); +/*+*************************************************************************** + * Processing functions * + *****************************************************************************/ + + +void osl_int_set_precision(int const, int const, osl_int_p); + + # if defined(__cplusplus) } # endif diff --git a/include/osl/relation.h b/include/osl/relation.h index 909244f..10854fa 100644 --- a/include/osl/relation.h +++ b/include/osl/relation.h @@ -199,6 +199,8 @@ void osl_relation_get_attributes(osl_relation_p, int *, int *, int *, int *, int *); osl_relation_p osl_relation_extend_output(osl_relation_p, int); osl_interface_p osl_relation_interface(); +void osl_relation_set_precision(int const, osl_relation_p); +void osl_relation_set_same_precision(osl_relation_p, osl_relation_p); # if defined(__cplusplus) } diff --git a/source/int.c b/source/int.c index 18f9d85..52cb418 100644 --- a/source/int.c +++ b/source/int.c @@ -1162,3 +1162,22 @@ int osl_int_divisible(int precision, OSL_error("unknown precision"); } } + + +/*+*************************************************************************** + * Processing functions * + *****************************************************************************/ + + +/** + * osl_int_set_precision function: + * this function changes the precision of the osl_int + */ +void osl_int_set_precision(int const precision, int const new_precision, + osl_int_p i) { + if (i != NULL && precision != new_precision) { + int v = osl_int_get_si(precision, *i); // TODO Fix to avoid overflow + osl_int_clear(precision, i); + osl_int_init_set_si(new_precision, i, v); + } +} \ No newline at end of file diff --git a/source/relation.c b/source/relation.c index b318811..925def2 100644 --- a/source/relation.c +++ b/source/relation.c @@ -2981,3 +2981,43 @@ osl_interface_p osl_relation_interface() { return interface; } + + +/** + * osl_relation_set_precision function: + * this function gets the highest precision of the relations + * and set this precision to the other relation if necessary + */ +void osl_relation_set_precision(int const precision, osl_relation_p r) { + while (r != NULL) { + if (precision != r->precision) { + size_t i; + size_t j; + for (i = 0; i < (size_t)r->nb_rows; ++i) { + for (j = 0; j < (size_t)r->nb_columns; ++j) { + osl_int_set_precision(r->precision, precision, &r->m[i][j]); + } + } + r->precision = precision; + } + r = r->next; + } +} + + +/** + * osl_relation_set_same_precision function: + * this function changes the precision of the osl_relation + */ +void osl_relation_set_same_precision(osl_relation_p a, osl_relation_p b) { + if (a != NULL && b != NULL && a->precision != b->precision) { + if (a->precision == OSL_PRECISION_MP || b->precision == OSL_PRECISION_MP) { + osl_relation_set_precision(OSL_PRECISION_MP, a); + osl_relation_set_precision(OSL_PRECISION_MP, b); + } + else if (a->precision == OSL_PRECISION_DP || b->precision == OSL_PRECISION_DP) { + osl_relation_set_precision(OSL_PRECISION_DP, a); + osl_relation_set_precision(OSL_PRECISION_DP, b); + } + } +} \ No newline at end of file diff --git a/tests/Makefile.am b/tests/Makefile.am index 6a7dd8f..daf4fbe 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -75,17 +75,19 @@ MAINTAINERCLEANFILES = Makefile.in ############################################################################# -noinst_PROGRAMS = osl_test osl_int osl_pluto_unroll +noinst_PROGRAMS = osl_test osl_int osl_pluto_unroll osl_relation_set_precision -TESTS = osl_test osl_int osl_pluto_unroll +TESTS = osl_test osl_int osl_pluto_unroll osl_relation_set_precision -osl_test_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static -osl_int_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static -osl_pluto_unroll_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static +osl_test_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static +osl_int_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static +osl_pluto_unroll_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static +osl_relation_set_precision_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static -osl_test_LDADD = ../libosl.la -osl_int_LDADD = ../libosl.la -osl_pluto_unroll_LDADD = ../libosl.la +osl_test_LDADD = ../libosl.la +osl_int_LDADD = ../libosl.la +osl_pluto_unroll_LDADD = ../libosl.la +osl_relation_set_precision_LDADD = ../libosl.la osl_test_SOURCES = \ osl_test.c \ @@ -101,7 +103,8 @@ osl_test_SOURCES = \ test_clay.scop \ test_no_statement.scop \ test_scop_list.scop -osl_int_SOURCES = osl_int.c -osl_pluto_unroll_SOURCES = osl_pluto_unroll.c +osl_int_SOURCES = osl_int.c +osl_pluto_unroll_SOURCES = osl_pluto_unroll.c +osl_relation_set_precision_SOURCES = osl_relation_set_precision.c MAINTAINERCLEANFILE = ../autoconf/texinfo.tex -- 2.11.4.GIT