3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-23 17:15:33 +00:00

Added "int ceil_log2(int)" function

This commit is contained in:
Clifford Wolf 2016-02-13 16:52:16 +01:00
parent a75f94ec4a
commit 0d7fd2585e
5 changed files with 58 additions and 10 deletions

View file

@ -124,6 +124,31 @@ void yosys_banner()
log("\n");
}
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;
}
std::string stringf(const char *fmt, ...)
{
std::string string;

View file

@ -222,6 +222,7 @@ extern bool memhasher_active;
inline void memhasher() { if (memhasher_active) memhasher_do(); }
void yosys_banner();
int ceil_log2(int x);
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);