Open falk-hueffner opened 3 years ago
Hi,
I've written an optimizer using z3 that generates the minimum number of instructions/cycles. Many codes can be improved, e.g.:
// code=0x2b, function=(C ? (B nand A) : (B nor A)), lowered=((C and not ((B and A))) or (not (C) and not ((B or A)))), set=intel template<> uint64_t ternary<0x2b>(const uint64_t A, const uint64_t B, const uint64_t C) { const uint64_t t0 = B & A; const uint64_t t1 = ~t0; const uint64_t t2 = C & t1; const uint64_t t3 = ~C; const uint64_t t4 = B | A; const uint64_t t5 = ~t4; const uint64_t t6 = t3 & t5; const uint64_t t7 = t2 | t6; return t7; }
can be
template<> uint64_t ternary<0x2b>(const uint64_t A, const uint64_t B, const uint64_t C) { const uint64_t t0 = B ^ A; const uint64_t t1 = ~C; const uint64_t t2 = A ^ C; const uint64_t t3 = t0 | t2; const uint64_t t4 = t3 ^ t1; return t4; }
I've attached the script.
ternary-logic.py.gz
I've updated the script a bit and put it here instead: https://github.com/falk-hueffner/ternary-logic-optimization
Hi,
I've written an optimizer using z3 that generates the minimum number of instructions/cycles. Many codes can be improved, e.g.:
can be
I've attached the script.
ternary-logic.py.gz