diff options
author | Clifford Wolf <clifford@clifford.at> | 2019-05-07 19:46:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-07 19:46:27 +0200 |
commit | 0ee1759f00610b45f444a1248bf597b4c549ffa9 (patch) | |
tree | f7c7fd3fa8f03c002999ce8c63262dc10ffbe101 | |
parent | 09467bb9a3ca01bb7bbfc6c9013ed7385e42fd96 (diff) | |
parent | bafbb9ee905f042056d723ecde4a62d58b6d8f4c (diff) | |
download | yosys-0ee1759f00610b45f444a1248bf597b4c549ffa9.tar.gz yosys-0ee1759f00610b45f444a1248bf597b4c549ffa9.tar.bz2 yosys-0ee1759f00610b45f444a1248bf597b4c549ffa9.zip |
Merge pull request #996 from mdaiter/ceil_log2_opts
Optimize ceil_log2 function
-rw-r--r-- | kernel/yosys.cc | 6 | ||||
-rw-r--r-- | kernel/yosys.h | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 20d972150..377572fc2 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -151,14 +151,16 @@ void yosys_banner() int ceil_log2(int x) { +#if defined(__GNUC__) + return x > 1 ? (8*sizeof(int)) - __builtin_clz(x-1) : 0; +#else if (x <= 0) return 0; - for (int i = 0; i < 32; i++) if (((x-1) >> i) == 0) return i; - log_abort(); +#endif } std::string stringf(const char *fmt, ...) diff --git a/kernel/yosys.h b/kernel/yosys.h index 82eb069ab..c7b671724 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -244,7 +244,7 @@ extern bool memhasher_active; inline void memhasher() { if (memhasher_active) memhasher_do(); } void yosys_banner(); -int ceil_log2(int x); +int ceil_log2(int x) YS_ATTRIBUTE(const); std::string stringf(const char *fmt, ...) YS_ATTRIBUTE(format(printf, 1, 2)); std::string vstringf(const char *fmt, va_list ap); int readsome(std::istream &f, char *s, int n); |