1 | #include "mdd.h" |
---|
2 | |
---|
3 | /* |
---|
4 | * MDD Package |
---|
5 | * |
---|
6 | * $Id: mdd_func2.c,v 1.11 2002/08/25 05:30:12 fabio Exp $ |
---|
7 | * |
---|
8 | * Author: Timothy Kam |
---|
9 | * |
---|
10 | * Copyright 1992 by the Regents of the University of California. |
---|
11 | * |
---|
12 | * All rights reserved. Permission to use, copy, modify and distribute |
---|
13 | * this software is hereby granted, provided that the above copyright |
---|
14 | * notice and this permission notice appear in all copies. This software |
---|
15 | * is made available as is, with no warranties. |
---|
16 | */ |
---|
17 | |
---|
18 | mdd_t * |
---|
19 | mdd_func2( |
---|
20 | mdd_manager *mgr, |
---|
21 | int mvar1, |
---|
22 | int mvar2, |
---|
23 | boolean (*func2)(int, int)) |
---|
24 | { |
---|
25 | mvar_type x, y; |
---|
26 | array_t *child_list_x, *child_list_y; |
---|
27 | int i, j; |
---|
28 | mdd_t *tx, *ty; |
---|
29 | array_t *mvar_list = mdd_ret_mvar_list(mgr); |
---|
30 | mdd_t *one, *zero; |
---|
31 | |
---|
32 | one = mdd_one(mgr); |
---|
33 | zero = mdd_zero(mgr); |
---|
34 | |
---|
35 | x = array_fetch(mvar_type, mvar_list, mvar1); |
---|
36 | y = array_fetch(mvar_type, mvar_list, mvar2); |
---|
37 | |
---|
38 | if (x.status == MDD_BUNDLED) { |
---|
39 | (void) fprintf(stderr, |
---|
40 | "\nWarning: mdd_func2, bundled variable %s is used\n", x.name); |
---|
41 | fail(""); |
---|
42 | } |
---|
43 | |
---|
44 | if (y.status == MDD_BUNDLED) { |
---|
45 | (void) fprintf(stderr, |
---|
46 | "\nWarning: mdd_func2 bundled variable %s is used\n", y.name); |
---|
47 | fail(""); |
---|
48 | } |
---|
49 | |
---|
50 | child_list_x = array_alloc(mdd_t *, 0); |
---|
51 | for (i=0; i<x.values; i++) { |
---|
52 | child_list_y = array_alloc(mdd_t *, 0); |
---|
53 | for (j=0; j<y.values; j++) { |
---|
54 | if (func2(i,j)) |
---|
55 | array_insert_last(mdd_t *, child_list_y, one); |
---|
56 | else |
---|
57 | array_insert_last(mdd_t *, child_list_y, zero); |
---|
58 | } |
---|
59 | ty = mdd_case(mgr, mvar2, child_list_y); |
---|
60 | array_insert_last(mdd_t *, child_list_x, ty); |
---|
61 | array_free(child_list_y); |
---|
62 | } |
---|
63 | tx = mdd_case(mgr, mvar1, child_list_x); |
---|
64 | array_free(child_list_x); |
---|
65 | mdd_free(one); |
---|
66 | mdd_free(zero); |
---|
67 | return tx; |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | /***** internal functions *****/ |
---|
72 | |
---|
73 | boolean |
---|
74 | eq2(int x, int y) |
---|
75 | { |
---|
76 | return (x == y); |
---|
77 | } |
---|
78 | |
---|
79 | boolean |
---|
80 | geq2(int x, int y) |
---|
81 | { |
---|
82 | return (x >= y); |
---|
83 | } |
---|
84 | |
---|
85 | boolean |
---|
86 | gt2(int x, int y) |
---|
87 | { |
---|
88 | return (x > y); |
---|
89 | } |
---|
90 | |
---|
91 | boolean |
---|
92 | leq2(int x, int y) |
---|
93 | { |
---|
94 | return (x <= y); |
---|
95 | } |
---|
96 | |
---|
97 | boolean |
---|
98 | lt2(int x, int y) |
---|
99 | { |
---|
100 | return (x < y); |
---|
101 | } |
---|
102 | |
---|
103 | boolean |
---|
104 | neq2(int x, int y) |
---|
105 | { |
---|
106 | return (x != y); |
---|
107 | } |
---|
108 | |
---|
109 | boolean |
---|
110 | unary_minus2(int x, int y) |
---|
111 | { |
---|
112 | return (x+y == 0); |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | /*---------------------------------------------------------------------------*/ |
---|
117 | /* Static function prototypes */ |
---|
118 | /*---------------------------------------------------------------------------*/ |
---|
119 | |
---|