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.

128 lines
2.9 KiB

  1. /*
  2. * Copyright 2011-2015 Formal Methods and Tools, University of Twente
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * Internals for MTBDDs
  18. */
  19. #ifndef SYLVAN_MTBDD_INT_H
  20. #define SYLVAN_MTBDD_INT_H
  21. /**
  22. * MTBDD node structure
  23. */
  24. typedef struct __attribute__((packed)) mtbddnode {
  25. uint64_t a, b;
  26. } * mtbddnode_t; // 16 bytes
  27. #define GETNODE(mtbdd) ((mtbddnode_t)llmsset_index_to_ptr(nodes, mtbdd&0x000000ffffffffff))
  28. /**
  29. * Complement handling macros
  30. */
  31. #define MTBDD_HASMARK(s) (s&mtbdd_complement?1:0)
  32. #define MTBDD_TOGGLEMARK(s) (s^mtbdd_complement)
  33. #define MTBDD_STRIPMARK(s) (s&~mtbdd_complement)
  34. #define MTBDD_TRANSFERMARK(from, to) (to ^ (from & mtbdd_complement))
  35. // Equal under mark
  36. #define MTBDD_EQUALM(a, b) ((((a)^(b))&(~mtbdd_complement))==0)
  37. // Leaf: a = L=1, M, type; b = value
  38. // Node: a = L=0, C, M, high; b = variable, low
  39. // Only complement edge on "high"
  40. static inline int
  41. mtbddnode_isleaf(mtbddnode_t n)
  42. {
  43. return n->a & 0x4000000000000000 ? 1 : 0;
  44. }
  45. static inline uint32_t
  46. mtbddnode_gettype(mtbddnode_t n)
  47. {
  48. return n->a & 0x00000000ffffffff;
  49. }
  50. static inline uint64_t
  51. mtbddnode_getvalue(mtbddnode_t n)
  52. {
  53. return n->b;
  54. }
  55. static inline int
  56. mtbddnode_getcomp(mtbddnode_t n)
  57. {
  58. return n->a & 0x8000000000000000 ? 1 : 0;
  59. }
  60. static inline uint64_t
  61. mtbddnode_getlow(mtbddnode_t n)
  62. {
  63. return n->b & 0x000000ffffffffff; // 40 bits
  64. }
  65. static inline uint64_t
  66. mtbddnode_gethigh(mtbddnode_t n)
  67. {
  68. return n->a & 0x800000ffffffffff; // 40 bits plus high bit of first
  69. }
  70. static inline uint32_t
  71. mtbddnode_getvariable(mtbddnode_t n)
  72. {
  73. return (uint32_t)(n->b >> 40);
  74. }
  75. static inline int
  76. mtbddnode_getmark(mtbddnode_t n)
  77. {
  78. return n->a & 0x2000000000000000 ? 1 : 0;
  79. }
  80. static inline void
  81. mtbddnode_setmark(mtbddnode_t n, int mark)
  82. {
  83. if (mark) n->a |= 0x2000000000000000;
  84. else n->a &= 0xdfffffffffffffff;
  85. }
  86. static inline void
  87. mtbddnode_makeleaf(mtbddnode_t n, uint32_t type, uint64_t value)
  88. {
  89. n->a = 0x4000000000000000 | (uint64_t)type;
  90. n->b = value;
  91. }
  92. static inline void
  93. mtbddnode_makenode(mtbddnode_t n, uint32_t var, uint64_t low, uint64_t high)
  94. {
  95. n->a = high;
  96. n->b = ((uint64_t)var)<<40 | low;
  97. }
  98. static MTBDD
  99. node_getlow(MTBDD mtbdd, mtbddnode_t node)
  100. {
  101. return MTBDD_TRANSFERMARK(mtbdd, mtbddnode_getlow(node));
  102. }
  103. static MTBDD
  104. node_gethigh(MTBDD mtbdd, mtbddnode_t node)
  105. {
  106. return MTBDD_TRANSFERMARK(mtbdd, mtbddnode_gethigh(node));
  107. }
  108. #endif