Polly 19.0.0git
isl_multi_arith_templ.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2012-2013 Ecole Normale Superieure
4 *
5 * Use of this software is governed by the MIT license
6 *
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
9 */
10
11#include <isl/space.h>
12#include <isl_val_private.h>
13
14#include <isl_multi_macro.h>
15
16/* Add "multi2" to "multi1" and return the result.
17 */
19 __isl_take MULTI(BASE) *multi2)
20{
21 return FN(MULTI(BASE),bin_op)(multi1, multi2, &FN(EL,add));
22}
23
24/* Subtract "multi2" from "multi1" and return the result.
25 */
27 __isl_take MULTI(BASE) *multi2)
28{
29 return FN(MULTI(BASE),bin_op)(multi1, multi2, &FN(EL,sub));
30}
31
32/* Depending on "fn", multiply or divide the elements of "multi" by "v" and
33 * return the result.
34 */
35static __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val_fn)(
38{
39 if (!multi || !v)
40 goto error;
41
42 if (isl_val_is_one(v)) {
43 isl_val_free(v);
44 return multi;
45 }
46
47 if (!isl_val_is_rat(v))
49 "expecting rational factor", goto error);
50
51 return FN(MULTI(BASE),fn_val)(multi, fn, v);
52error:
53 isl_val_free(v);
54 return FN(MULTI(BASE),free)(multi);
55}
56
57/* Multiply the elements of "multi" by "v" and return the result.
58 */
61{
62 return FN(MULTI(BASE),scale_val_fn)(multi, v, &FN(EL,scale_val));
63}
64
65/* Divide the elements of "multi" by "v" and return the result.
66 */
67__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_val)(
69{
70 if (!v)
71 goto error;
72 if (isl_val_is_zero(v))
74 "cannot scale down by zero", goto error);
75 return FN(MULTI(BASE),scale_val_fn)(multi, v, &FN(EL,scale_down_val));
76error:
77 isl_val_free(v);
78 return FN(MULTI(BASE),free)(multi);
79}
80
81/* Multiply the elements of "multi" by the corresponding element of "mv"
82 * and return the result.
83 */
84__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_multi_val)(
86{
87 return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,scale_val), mv);
88}
89
90/* Divide the elements of "multi" by the corresponding element of "mv"
91 * and return the result.
92 */
93__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_multi_val)(
95{
96 return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,scale_down_val), mv);
97}
98
99/* Compute the residues of the elements of "multi" modulo
100 * the corresponding element of "mv" and return the result.
101 */
102__isl_give MULTI(BASE) *FN(MULTI(BASE),mod_multi_val)(
104{
105 return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,mod_val), mv);
106}
107
108/* Return the opposite of "multi".
109 */
111{
112 return FN(MULTI(BASE),un_op)(multi, &FN(EL,neg));
113}
#define FN(TYPE, NAME)
#define __isl_take
Definition: ctx.h:22
#define __isl_give
Definition: ctx.h:19
#define isl_die(ctx, errno, msg, code)
Definition: ctx.h:137
@ isl_error_invalid
Definition: ctx.h:80
#define BASE
Definition: flow_cmp.c:49
isl_stat isl_stat(* fn)(__isl_take ISL_KEY *key, __isl_take ISL_VAL *val, void *user)
Definition: hmap.h:37
void GMPZAPI() neg(mp_int rop, mp_int op)
void GMPZAPI() sub(mp_int rop, mp_int op1, mp_int op2)
void GMPZAPI() add(mp_int rop, mp_int op1, mp_int op2)
#define EL
static __isl_give isl_qpolynomial * scale_val(__isl_take isl_qpolynomial *qp, void *user)
Definition: isl_fold.c:2106
#define MULTI(BASE)
static std::vector< Signature > bin_op
static std::vector< Signature > un_op
isl_ctx * isl_val_get_ctx(__isl_keep isl_val *val)
Definition: isl_val.c:355
__isl_null isl_val * isl_val_free(__isl_take isl_val *v)
Definition: isl_val.c:263
__isl_export isl_bool isl_val_is_zero(__isl_keep isl_val *v)
Definition: isl_val.c:1191
__isl_export isl_bool isl_val_is_one(__isl_keep isl_val *v)
Definition: isl_val.c:1201
__isl_export isl_bool isl_val_is_rat(__isl_keep isl_val *v)
Definition: isl_val.c:1151
struct isl_multi_val isl_multi_val
Definition: val_type.h:16