2 * Copyright 2019 Cerebras Systems
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA
10 #include <isl_multi_macro.h>
12 /* Add "v" to the constant terms of all the base expressions of "multi".
14 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),add_constant_val
)(
15 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_val
*v
)
21 zero
= isl_val_is_zero(v
);
22 n
= FN(MULTI(BASE
),size
)(multi
);
23 if (zero
< 0 || n
< 0)
30 multi
= FN(MULTI(BASE
),cow
)(multi
);
34 for (i
= 0; i
< n
; ++i
) {
35 multi
->u
.p
[i
] = FN(EL
,add_constant_val
)(multi
->u
.p
[i
],
44 FN(MULTI(BASE
),free
)(multi
);
49 /* Add the elements of "mv" to the constant terms of
50 * the corresponding base expressions of "multi".
52 __isl_give
MULTI(BASE
) *FN(MULTI(BASE
),add_constant_multi_val
)(
53 __isl_take
MULTI(BASE
) *multi
, __isl_take isl_multi_val
*mv
)
55 isl_space
*multi_space
, *mv_space
;
60 zero
= isl_multi_val_is_zero(mv
);
61 n
= FN(MULTI(BASE
),size
)(multi
);
62 multi_space
= FN(MULTI(BASE
),peek_space
)(multi
);
63 mv_space
= isl_multi_val_peek_space(mv
);
64 equal
= isl_space_tuple_is_equal(multi_space
, isl_dim_out
,
65 mv_space
, isl_dim_out
);
66 if (zero
< 0 || n
< 0 || equal
< 0)
69 isl_die(isl_multi_val_get_ctx(mv
), isl_error_invalid
,
70 "spaces don't match", goto error
);
72 isl_multi_val_free(mv
);
76 multi
= FN(MULTI(BASE
),cow
)(multi
);
80 for (i
= 0; i
< n
; ++i
) {
81 isl_val
*v
= isl_multi_val_get_at(mv
, i
);
82 multi
->u
.p
[i
] = FN(EL
,add_constant_val
)(multi
->u
.p
[i
], v
);
87 isl_multi_val_free(mv
);
90 FN(MULTI(BASE
),free
)(multi
);
91 isl_multi_val_free(mv
);