diff --git a/kernel/cellaigs.cc b/kernel/cellaigs.cc index 0f897cd58..00be50bab 100644 --- a/kernel/cellaigs.cc +++ b/kernel/cellaigs.cc @@ -501,6 +501,27 @@ Aig::Aig(Cell *cell) goto optimize; } + if (cell->type == ID($priority)) + { + int width = GetSize(cell->getPort(ID::Y)); + RTLIL::Const polarity = cell->getParam(ID::POLARITY); + vector A = mk.inport_vec(ID::A, width); + vector Y; + int any_previous_active; + if (width) { + any_previous_active = polarity[0] ? A[0] : mk.not_gate(A[0]); + Y.push_back(A[0]); + } + for (int i = 1; i < width; i++) { + int inactive_val = mk.bool_node(!polarity[i]); + Y.push_back(mk.mux_gate(A[i], inactive_val, any_previous_active)); + int is_active = mk.xnor_gate(inactive_val, A[i]); + any_previous_active = mk.or_gate(any_previous_active, is_active); + } + mk.outport_vec(Y, ID::Y); + goto optimize; + } + name.clear(); return; diff --git a/tests/aiger/gold/_priority_00000.aag b/tests/aiger/gold/_priority_00000.aag new file mode 100644 index 000000000..7a4cd3156 --- /dev/null +++ b/tests/aiger/gold/_priority_00000.aag @@ -0,0 +1,5 @@ +aag 1 1 0 1 0 +2 +2 +c +Generated by Yosys diff --git a/tests/aiger/gold/_reduce_and_00000.aag b/tests/aiger/gold/_reduce_and_00000.aag index 06db9a1dd..7528ef437 100644 --- a/tests/aiger/gold/_reduce_and_00000.aag +++ b/tests/aiger/gold/_reduce_and_00000.aag @@ -1,7 +1,12 @@ -aag 1 1 0 3 0 -2 +aag 5 3 0 4 2 2 +4 +6 +10 0 0 +0 +8 4 2 +10 8 6 c Generated by Yosys diff --git a/tests/aiger/gold/_reduce_bool_00000.aag b/tests/aiger/gold/_reduce_bool_00000.aag index 48a1410c8..a33077f69 100644 --- a/tests/aiger/gold/_reduce_bool_00000.aag +++ b/tests/aiger/gold/_reduce_bool_00000.aag @@ -1,13 +1,9 @@ -aag 7 4 0 3 3 +aag 5 3 0 1 2 2 4 6 -8 -15 -0 -0 -10 5 3 -12 10 7 -14 12 9 +11 +8 5 3 +10 8 7 c Generated by Yosys diff --git a/tests/aiger/gold/_reduce_or_00000.aag b/tests/aiger/gold/_reduce_or_00000.aag index d5e8085c2..5fb08a56c 100644 --- a/tests/aiger/gold/_reduce_or_00000.aag +++ b/tests/aiger/gold/_reduce_or_00000.aag @@ -1,7 +1,10 @@ -aag 3 2 0 1 1 +aag 1 1 0 6 0 2 -4 -7 -6 5 3 +2 +0 +0 +0 +0 +0 c Generated by Yosys diff --git a/tests/aiger/gold/_reduce_xnor_00000.aag b/tests/aiger/gold/_reduce_xnor_00000.aag index 6ad6ac39e..05bc1659c 100644 --- a/tests/aiger/gold/_reduce_xnor_00000.aag +++ b/tests/aiger/gold/_reduce_xnor_00000.aag @@ -1,30 +1,10 @@ -aag 25 6 0 2 19 +aag 5 2 0 2 3 2 4 -6 -8 -10 -12 -51 +11 0 -14 4 2 -16 5 3 -18 17 15 -20 18 6 -22 17 15 -24 23 7 -26 25 21 -28 26 8 -30 25 21 -32 31 9 -34 33 29 -36 34 10 -38 33 29 -40 39 11 -42 41 37 -44 42 12 -46 41 37 -48 47 13 -50 49 45 +6 4 2 +8 5 3 +10 9 7 c Generated by Yosys diff --git a/tests/aiger/gold/_reduce_xor_00000.aag b/tests/aiger/gold/_reduce_xor_00000.aag index ab4bc32ad..06db9a1dd 100644 --- a/tests/aiger/gold/_reduce_xor_00000.aag +++ b/tests/aiger/gold/_reduce_xor_00000.aag @@ -1,9 +1,7 @@ -aag 5 2 0 1 3 +aag 1 1 0 3 0 2 -4 -10 -6 4 2 -8 5 3 -10 9 7 +2 +0 +0 c Generated by Yosys diff --git a/tests/aiger/gold/_sub_00000.aag b/tests/aiger/gold/_sub_00000.aag index e9d976b32..f81a90b30 100644 --- a/tests/aiger/gold/_sub_00000.aag +++ b/tests/aiger/gold/_sub_00000.aag @@ -1,20 +1,35 @@ -aag 16 13 0 1 3 +aag 29 6 0 3 23 2 4 6 8 10 12 -14 -16 -18 -20 -22 -24 -26 -33 -28 17 2 -30 16 3 -32 31 29 +19 +38 +58 +14 7 2 +16 6 3 +18 17 15 +20 6 3 +22 20 15 +24 9 4 +26 8 5 +28 27 25 +30 28 23 +32 27 25 +34 20 15 +36 34 33 +38 37 31 +40 27 23 +42 41 25 +44 11 4 +46 10 5 +48 47 45 +50 48 43 +52 47 45 +54 41 25 +56 54 53 +58 57 51 c Generated by Yosys diff --git a/tests/aiger/gold/_xnor_00000.aag b/tests/aiger/gold/_xnor_00000.aag index 9dd097862..85cf802b0 100644 --- a/tests/aiger/gold/_xnor_00000.aag +++ b/tests/aiger/gold/_xnor_00000.aag @@ -1,12 +1,16 @@ -aag 10 4 0 4 6 +aag 10 4 0 8 6 2 4 6 8 15 21 -21 -21 +1 +1 +1 +1 +1 +1 10 6 2 12 7 3 14 13 11 diff --git a/tests/aiger/gold/_xor_00000.aag b/tests/aiger/gold/_xor_00000.aag index 453b8d0ee..883df0907 100644 --- a/tests/aiger/gold/_xor_00000.aag +++ b/tests/aiger/gold/_xor_00000.aag @@ -1,12 +1,51 @@ -aag 8 5 0 1 3 +aag 40 16 0 8 24 2 4 6 8 10 +12 +14 16 -12 8 2 -14 9 3 -16 15 13 +18 +20 +22 +24 +26 +28 +30 +32 +38 +44 +50 +56 +62 +68 +74 +80 +34 18 2 +36 19 3 +38 37 35 +40 20 4 +42 21 5 +44 43 41 +46 22 6 +48 23 7 +50 49 47 +52 24 8 +54 25 9 +56 55 53 +58 26 10 +60 27 11 +62 61 59 +64 28 12 +66 29 13 +68 67 65 +70 30 14 +72 31 15 +74 73 71 +76 32 16 +78 33 17 +80 79 77 c Generated by Yosys