evalue.c: evalue_shift_variables: allow shifting of only parameters
[barvinok/uuh.git] / ev_size.c
blobfabc48f54e1993d193d9f6c0c7790343094aeedf
1 #include <assert.h>
2 #include <dlfcn.h>
3 #include <string.h>
4 #include <barvinok/evalue.h>
5 #include <barvinok/barvinok.h>
7 static long long value_bitsize(Value v);
8 static long long domain_bitsize(Polyhedron *D);
9 static long long enode_bitsize(enode *p);
10 static long long evalue_bitsize(evalue *e);
11 static long long Enumeration_bitsize(Enumeration *en);
13 long long value_bitsize(Value v)
15 int last = (v[0]._mp_size > 0 ? v[0]._mp_size : -v[0]._mp_size) - 1;
16 if (last == -1)
17 return 0;
19 return last * sizeof(v[0]._mp_d[0]) * 8 + ffs(v[0]._mp_d[last]) + 1;
22 long long domain_bitsize(Polyhedron *D)
24 int i, j;
25 long long s = ffs(D->Dimension) + ffs(D->NbConstraints);
27 for (i = 0; i < D->NbConstraints; ++i)
28 for (j = 0; j < D->Dimension+2; ++j)
29 s += value_bitsize(D->Constraint[i][j]);
31 return D->next ? s+domain_bitsize(D->next) : s;
34 long long enode_bitsize(enode *p)
36 //long long s = (sizeof(*p) - sizeof(p->arr[0])) * 8;
37 long long s = ffs(p->size);
38 int i;
40 if (p->type == partition)
41 for (i = 0; i < p->size/2; ++i) {
42 s += domain_bitsize(EVALUE_DOMAIN(p->arr[2*i]));
43 s += evalue_bitsize(&p->arr[2*i+1]);
45 else
46 for (i = 0; i < p->size; ++i) {
47 s += evalue_bitsize(&p->arr[i]);
49 return s;
52 long long evalue_bitsize(evalue *e)
54 //long long s = sizeof(*e) * 8;
55 long long s = 0;
56 s += value_bitsize(e->d);
57 if (value_notzero_p(e->d))
58 s += value_bitsize(e->x.n);
59 else
60 s += enode_bitsize(e->x.p);
61 return s;
64 long long Enumeration_bitsize(Enumeration *en)
66 long long s = 0;
68 for (; en; en = en->next) {
69 s += domain_bitsize(en->ValidityDomain);
70 s += evalue_bitsize(&en->EP);
72 return s;
75 evalue* barvinok_enumerate_ev(Polyhedron *P, Polyhedron* C, unsigned MaxRays)
77 static evalue *(*orig)(Polyhedron *, Polyhedron *c, unsigned) = NULL;
78 evalue *res;
79 int c;
81 if (!orig) {
82 void *handle = dlopen("libbarvinok.so", RTLD_LAZY);
83 assert(handle);
84 orig = dlsym(handle, "barvinok_enumerate_ev");
85 assert(orig);
86 dlclose(handle);
89 res = orig(P, C, MaxRays);
91 fprintf(stderr, "SIZE: %d %lld %lld\n", P->Dimension - P->NbEq,
92 domain_bitsize(P) + domain_bitsize(C), evalue_bitsize(res));
94 return res;
97 #undef Enumeration
99 Enumeration *Polyhedron_Enumerate(Polyhedron *P,Polyhedron *C,unsigned MAXRAYS,char **param_name)
101 static Enumeration *(*orig)(Polyhedron *, Polyhedron *c, unsigned, char **) = NULL;
102 Enumeration *res;
103 int c;
105 if (!orig) {
106 void *handle = dlopen("libpolylibgmp.so", RTLD_LAZY);
107 assert(handle);
108 orig = dlsym(handle, "Polyhedron_Enumerate");
109 assert(orig);
110 dlclose(handle);
113 res = orig(P, C, MAXRAYS, param_name);
115 fprintf(stderr, "SIZE: %d %lld %lld\n", P->Dimension - P->NbEq,
116 domain_bitsize(P) + domain_bitsize(C), Enumeration_bitsize(res));
118 return res;