diff options
author | Clifford Wolf <clifford@clifford.at> | 2016-02-15 23:06:18 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2016-02-15 23:06:18 +0100 |
commit | 45af4a4acf6d3bc1f83b65f1cd103c0226f30b8b (patch) | |
tree | 16e2f1fc5aa9975761f84cdf9b416a0ea94ac3c1 /kernel | |
parent | 7a9257e7b5e4ea039e4bcc7183cee81b363b8166 (diff) | |
download | yosys-45af4a4acf6d3bc1f83b65f1cd103c0226f30b8b.tar.gz yosys-45af4a4acf6d3bc1f83b65f1cd103c0226f30b8b.tar.bz2 yosys-45af4a4acf6d3bc1f83b65f1cd103c0226f30b8b.zip |
Use easyer-to-read unoptimized ceil_log2()
see here for details on the optimized version:
http://svn.clifford.at/handicraft/2016/esbmc/ceilog2.c
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/yosys.cc | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 8590242dc..eba1aef11 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -129,24 +129,11 @@ int ceil_log2(int x) if (x <= 0) return 0; - int y = (x & (x - 1)); - y = (y | -y) >> 31; - - x |= (x >> 1); - x |= (x >> 2); - x |= (x >> 4); - x |= (x >> 8); - x |= (x >> 16); - - x >>= 1; - x -= ((x >> 1) & 0x55555555); - x = (((x >> 2) & 0x33333333) + (x & 0x33333333)); - x = (((x >> 4) + x) & 0x0f0f0f0f); - x += (x >> 8); - x += (x >> 16); - x = x & 0x0000003f; - - return x - y; + for (int i = 0; i < 32; i++) + if (((x-1) >> i) == 0) + return i; + + log_abort(); } std::string stringf(const char *fmt, ...) |