You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
4.7 KiB

  1. /*
  2. * Copyright 2011-2016 Formal Methods and Tools, University of Twente
  3. * Copyright 2016-2017 Tom van Dijk, Johannes Kepler University Linz
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* Do not include this file directly. Instead, include sylvan_int.h */
  18. /**
  19. * Internals for MTBDDs
  20. */
  21. #ifndef SYLVAN_MTBDD_INT_H
  22. #define SYLVAN_MTBDD_INT_H
  23. /**
  24. * BDD/MTBDD node structure
  25. */
  26. typedef struct __attribute__((packed)) mtbddnode {
  27. uint64_t a, b;
  28. } * mtbddnode_t; // 16 bytes
  29. static inline mtbddnode_t
  30. MTBDD_GETNODE(MTBDD dd)
  31. {
  32. return (mtbddnode_t)llmsset_index_to_ptr(nodes, dd&0x000000ffffffffff);
  33. }
  34. /**
  35. * Complement handling macros
  36. */
  37. static inline int
  38. MTBDD_HASMARK(MTBDD dd)
  39. {
  40. return (dd & mtbdd_complement) ? 1 : 0;
  41. }
  42. static inline MTBDD
  43. MTBDD_TOGGLEMARK(MTBDD dd)
  44. {
  45. return dd ^ mtbdd_complement;
  46. }
  47. static inline MTBDD
  48. MTBDD_STRIPMARK(MTBDD dd)
  49. {
  50. return dd & (~mtbdd_complement);
  51. }
  52. static inline MTBDD
  53. MTBDD_TRANSFERMARK(MTBDD from, MTBDD to)
  54. {
  55. return (to ^ (from & mtbdd_complement));
  56. }
  57. /**
  58. * Are two MTBDDs equal modulo mark?
  59. */
  60. static inline int
  61. MTBDD_EQUALM(MTBDD a, MTBDD b)
  62. {
  63. return ((a^b)&(~mtbdd_complement)) ? 0 : 1;
  64. }
  65. // Leaf: a = L=1, M, type; b = value
  66. // Node: a = L=0, C, M, high; b = variable, low
  67. // Only complement edge on "high"
  68. static inline int __attribute__((unused))
  69. mtbddnode_isleaf(mtbddnode_t n)
  70. {
  71. return n->a & 0x4000000000000000 ? 1 : 0;
  72. }
  73. static inline uint32_t __attribute__((unused))
  74. mtbddnode_gettype(mtbddnode_t n)
  75. {
  76. return n->a & 0x00000000ffffffff;
  77. }
  78. static inline uint64_t __attribute__((unused))
  79. mtbddnode_getvalue(mtbddnode_t n)
  80. {
  81. return n->b;
  82. }
  83. static inline int __attribute__((unused))
  84. mtbddnode_getcomp(mtbddnode_t n)
  85. {
  86. return n->a & 0x8000000000000000 ? 1 : 0;
  87. }
  88. static inline uint64_t __attribute__((unused))
  89. mtbddnode_getlow(mtbddnode_t n)
  90. {
  91. return n->b & 0x000000ffffffffff; // 40 bits
  92. }
  93. static inline uint64_t __attribute__((unused))
  94. mtbddnode_gethigh(mtbddnode_t n)
  95. {
  96. return n->a & 0x800000ffffffffff; // 40 bits plus high bit of first
  97. }
  98. static inline uint32_t __attribute__((unused))
  99. mtbddnode_getvariable(mtbddnode_t n)
  100. {
  101. return (uint32_t)(n->b >> 40);
  102. }
  103. static inline int __attribute__((unused))
  104. mtbddnode_getmark(mtbddnode_t n)
  105. {
  106. return n->a & 0x2000000000000000 ? 1 : 0;
  107. }
  108. static inline void __attribute__((unused))
  109. mtbddnode_setmark(mtbddnode_t n, int mark)
  110. {
  111. if (mark) n->a |= 0x2000000000000000;
  112. else n->a &= 0xdfffffffffffffff;
  113. }
  114. static inline void __attribute__((unused))
  115. mtbddnode_makeleaf(mtbddnode_t n, uint32_t type, uint64_t value)
  116. {
  117. n->a = 0x4000000000000000 | (uint64_t)type;
  118. n->b = value;
  119. }
  120. static inline void __attribute__((unused))
  121. mtbddnode_makenode(mtbddnode_t n, uint32_t var, uint64_t low, uint64_t high)
  122. {
  123. n->a = high;
  124. n->b = ((uint64_t)var)<<40 | low;
  125. }
  126. static inline void __attribute__((unused))
  127. mtbddnode_makemapnode(mtbddnode_t n, uint32_t var, uint64_t low, uint64_t high)
  128. {
  129. n->a = high | 0x1000000000000000;
  130. n->b = ((uint64_t)var)<<40 | low;
  131. }
  132. static inline int __attribute__((unused))
  133. mtbddnode_ismapnode(mtbddnode_t n)
  134. {
  135. return n->a & 0x1000000000000000 ? 1 : 0;
  136. }
  137. static MTBDD __attribute__((unused))
  138. mtbddnode_followlow(MTBDD mtbdd, mtbddnode_t node)
  139. {
  140. return MTBDD_TRANSFERMARK(mtbdd, mtbddnode_getlow(node));
  141. }
  142. static MTBDD __attribute__((unused))
  143. mtbddnode_followhigh(MTBDD mtbdd, mtbddnode_t node)
  144. {
  145. return MTBDD_TRANSFERMARK(mtbdd, mtbddnode_gethigh(node));
  146. }
  147. /**
  148. * Compatibility
  149. */
  150. #define node_getlow mtbddnode_followlow
  151. #define node_gethigh mtbddnode_followhigh
  152. #define BDD_HASMARK MTBDD_HASMARK
  153. #define BDD_TOGGLEMARK MTBDD_TOGGLEMARK
  154. #define BDD_STRIPMARK MTBDD_STRIPMARK
  155. #define BDD_TRANSFERMARK MTBDD_TRANSFERMARK
  156. #define BDD_EQUALM MTBDD_EQUALM
  157. #define bddnode mtbddnode
  158. #define bddnode_t mtbddnode_t
  159. #define bddnode_getcomp mtbddnode_getcomp
  160. #define bddnode_getlow mtbddnode_getlow
  161. #define bddnode_gethigh mtbddnode_gethigh
  162. #define bddnode_getvariable mtbddnode_getvariable
  163. #define bddnode_getmark mtbddnode_getmark
  164. #define bddnode_setmark mtbddnode_setmark
  165. #define bddnode_makenode mtbddnode_makenode
  166. #define bddnode_makemapnode mtbddnode_makemapnode
  167. #define bddnode_ismapnode mtbddnode_ismapnode
  168. #define node_low node_getlow
  169. #define node_high node_gethigh
  170. #endif