| 1041 | } |
| 1042 | |
| 1043 | static expr log2_rec(const expr &e, unsigned idx, unsigned bw) { |
| 1044 | if (idx == 0) |
| 1045 | return expr::mkUInt(0, bw); |
| 1046 | |
| 1047 | return expr::mkIf(e.extract(idx, idx) == 1, |
| 1048 | expr::mkUInt(idx, bw), |
| 1049 | log2_rec(e, idx - 1, bw)); |
| 1050 | } |
| 1051 | |
| 1052 | expr expr::isPowerOf2() const { |
| 1053 | return *this != 0 && (*this & (*this - mkUInt(1, *this))) == 0; |