X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_seq.c;h=42e6b63a78f2dcb911913d9a509ec248f812fcc9;hb=de51a9bc4da5dd3f1f9f57c2362da6f9752c44e0;hp=bbffae5e785a27ffb8a8b564f445dfdc94056acf;hpb=177d99db8865eca40bf8baf52da173f287b8d3c5;p=platform%2Fupstream%2Fisl.git diff --git a/isl_seq.c b/isl_seq.c index bbffae5..42e6b63 100644 --- a/isl_seq.c +++ b/isl_seq.c @@ -1,4 +1,14 @@ -#include "isl_seq.h" +/* + * 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 + */ + +#include +#include void isl_seq_clr(isl_int *p, unsigned len) { @@ -7,6 +17,20 @@ void isl_seq_clr(isl_int *p, unsigned len) isl_int_set_si(p[i], 0); } +void isl_seq_set_si(isl_int *p, int v, unsigned len) +{ + int i; + for (i = 0; i < len; ++i) + isl_int_set_si(p[i], v); +} + +void isl_seq_set(isl_int *p, isl_int v, unsigned len) +{ + int i; + for (i = 0; i < len; ++i) + isl_int_set(p[i], v); +} + void isl_seq_neg(isl_int *dst, isl_int *src, unsigned len) { int i; @@ -21,6 +45,20 @@ void isl_seq_cpy(isl_int *dst, isl_int *src, unsigned len) isl_int_set(dst[i], src[i]); } +void isl_seq_submul(isl_int *dst, isl_int f, isl_int *src, unsigned len) +{ + int i; + for (i = 0; i < len; ++i) + isl_int_submul(dst[i], f, src[i]); +} + +void isl_seq_addmul(isl_int *dst, isl_int f, isl_int *src, unsigned len) +{ + int i; + for (i = 0; i < len; ++i) + isl_int_addmul(dst[i], f, src[i]); +} + void isl_seq_swp_or_cpy(isl_int *dst, isl_int *src, unsigned len) { int i; @@ -42,6 +80,27 @@ void isl_seq_scale_down(isl_int *dst, isl_int *src, isl_int m, unsigned len) isl_int_divexact(dst[i], src[i], m); } +void isl_seq_cdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len) +{ + int i; + for (i = 0; i < len; ++i) + isl_int_cdiv_q(dst[i], src[i], m); +} + +void isl_seq_fdiv_q(isl_int *dst, isl_int *src, isl_int m, unsigned len) +{ + int i; + for (i = 0; i < len; ++i) + isl_int_fdiv_q(dst[i], src[i], m); +} + +void isl_seq_fdiv_r(isl_int *dst, isl_int *src, isl_int m, unsigned len) +{ + int i; + for (i = 0; i < len; ++i) + isl_int_fdiv_r(dst[i], src[i], m); +} + void isl_seq_combine(isl_int *dst, isl_int m1, isl_int *src1, isl_int m2, isl_int *src2, unsigned len) { @@ -97,6 +156,16 @@ int isl_seq_eq(isl_int *p1, isl_int *p2, unsigned len) return 1; } +int isl_seq_cmp(isl_int *p1, isl_int *p2, unsigned len) +{ + int i; + int cmp; + for (i = 0; i < len; ++i) + if ((cmp = isl_int_cmp(p1[i], p2[i])) != 0) + return cmp; + return 0; +} + int isl_seq_is_neg(isl_int *p1, isl_int *p2, unsigned len) { int i; @@ -122,6 +191,27 @@ int isl_seq_first_non_zero(isl_int *p, unsigned len) return -1; } +int isl_seq_last_non_zero(isl_int *p, unsigned len) +{ + int i; + + for (i = len - 1; i >= 0; --i) + if (!isl_int_is_zero(p[i])) + return i; + return -1; +} + +void isl_seq_abs_max(isl_int *p, unsigned len, isl_int *max) +{ + int i; + + isl_int_set_si(*max, 0); + + for (i = 0; i < len; ++i) + if (isl_int_abs_gt(p[i], *max)) + isl_int_abs(*max, p[i]); +} + int isl_seq_abs_min_non_zero(isl_int *p, unsigned len) { int i, min = isl_seq_first_non_zero(p, len); @@ -154,6 +244,29 @@ void isl_seq_gcd(isl_int *p, unsigned len, isl_int *gcd) } } +void isl_seq_normalize(struct isl_ctx *ctx, isl_int *p, unsigned len) +{ + if (len == 0) + return; + isl_seq_gcd(p, len, &ctx->normalize_gcd); + if (!isl_int_is_zero(ctx->normalize_gcd) && + !isl_int_is_one(ctx->normalize_gcd)) + isl_seq_scale_down(p, p, ctx->normalize_gcd, len); +} + +void isl_seq_lcm(isl_int *p, unsigned len, isl_int *lcm) +{ + int i; + + if (len == 0) { + isl_int_set_si(*lcm, 1); + return; + } + isl_int_set(*lcm, p[0]); + for (i = 1; i < len; ++i) + isl_int_lcm(*lcm, *lcm, p[i]); +} + void isl_seq_inner_product(isl_int *p1, isl_int *p2, unsigned len, isl_int *prod) { @@ -167,11 +280,9 @@ void isl_seq_inner_product(isl_int *p1, isl_int *p2, unsigned len, isl_int_addmul(*prod, p1[i], p2[i]); } -u_int32_t isl_seq_hash(isl_int *p, unsigned len, unsigned bits) +uint32_t isl_seq_hash(isl_int *p, unsigned len, uint32_t hash) { int i; - u_int32_t hash = 2166136261u; - for (i = 0; i < len; ++i) { if (isl_int_is_zero(p[i])) continue; @@ -179,9 +290,32 @@ u_int32_t isl_seq_hash(isl_int *p, unsigned len, unsigned bits) hash ^= (i & 0xFF); hash = isl_int_hash(p[i], hash); } - if (bits == 32) - return hash; - if (bits >= 16) - return (hash >> bits) ^ (hash & (((u_int32_t)1 << bits) - 1)); - return ((hash >> bits) ^ hash) & (((u_int32_t)1 << bits) - 1); + return hash; +} + +uint32_t isl_seq_get_hash(isl_int *p, unsigned len) +{ + uint32_t hash = isl_hash_init(); + + return isl_seq_hash(p, len, hash); +} + +uint32_t isl_seq_get_hash_bits(isl_int *p, unsigned len, unsigned bits) +{ + uint32_t hash; + + hash = isl_seq_get_hash(p, len); + return isl_hash_bits(hash, bits); +} + +void isl_seq_dump(isl_int *p, unsigned len) +{ + int i; + + for (i = 0; i < len; ++i) { + if (i) + fprintf(stderr, " "); + isl_int_print(stderr, p[i], 0); + } + fprintf(stderr, "\n"); }