X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=kernel%2Fyosys.cc;h=377572fc2984243a2ede59d2e35af34a7fa27b8d;hb=d26646051c4ae9740decd5d76eec6a3afd63844a;hp=20d972150a978239ae96731ef5622b47929a488a;hpb=314ff1e4ca00ef8024bbb0d2f031efd78b01f9a1;p=yosys.git 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, ...)