mirror of https://github.com/YosysHQ/yosys.git
Optimize ceil_log2 function
This commit is contained in:
parent
752553d8e9
commit
bafbb9ee90
|
@ -151,14 +151,16 @@ void yosys_banner()
|
||||||
|
|
||||||
int ceil_log2(int x)
|
int ceil_log2(int x)
|
||||||
{
|
{
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
return x > 1 ? (8*sizeof(int)) - __builtin_clz(x-1) : 0;
|
||||||
|
#else
|
||||||
if (x <= 0)
|
if (x <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < 32; i++)
|
for (int i = 0; i < 32; i++)
|
||||||
if (((x-1) >> i) == 0)
|
if (((x-1) >> i) == 0)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
log_abort();
|
log_abort();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string stringf(const char *fmt, ...)
|
std::string stringf(const char *fmt, ...)
|
||||||
|
|
|
@ -244,7 +244,7 @@ extern bool memhasher_active;
|
||||||
inline void memhasher() { if (memhasher_active) memhasher_do(); }
|
inline void memhasher() { if (memhasher_active) memhasher_do(); }
|
||||||
|
|
||||||
void yosys_banner();
|
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 stringf(const char *fmt, ...) YS_ATTRIBUTE(format(printf, 1, 2));
|
||||||
std::string vstringf(const char *fmt, va_list ap);
|
std::string vstringf(const char *fmt, va_list ap);
|
||||||
int readsome(std::istream &f, char *s, int n);
|
int readsome(std::istream &f, char *s, int n);
|
||||||
|
|
Loading…
Reference in New Issue