Merge pull request #596 from litghost/make_clang_format
Run "make clangformat" to fix formatting in new Bits library.
This commit is contained in:
commit
5de1978632
@ -24,7 +24,8 @@
|
|||||||
|
|
||||||
namespace nextpnr {
|
namespace nextpnr {
|
||||||
|
|
||||||
int Bits::generic_popcount(unsigned int v) {
|
int Bits::generic_popcount(unsigned int v)
|
||||||
|
{
|
||||||
unsigned int c; // c accumulates the total bits set in v
|
unsigned int c; // c accumulates the total bits set in v
|
||||||
for (c = 0; v; c++) {
|
for (c = 0; v; c++) {
|
||||||
v &= v - 1; // clear the least significant bit set
|
v &= v - 1; // clear the least significant bit set
|
||||||
@ -33,13 +34,14 @@ int Bits::generic_popcount(unsigned int v) {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bits::generic_ctz(unsigned int x) {
|
int Bits::generic_ctz(unsigned int x)
|
||||||
if(x == 0) {
|
{
|
||||||
|
if (x == 0) {
|
||||||
throw std::runtime_error("Cannot call ctz with arg = 0");
|
throw std::runtime_error("Cannot call ctz with arg = 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
for(size_t i = 0; i < std::numeric_limits<unsigned int>::digits; ++i) {
|
for (size_t i = 0; i < std::numeric_limits<unsigned int>::digits; ++i) {
|
||||||
if((x & (1 << i)) != 0) {
|
if ((x & (1 << i)) != 0) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,4 +50,4 @@ int Bits::generic_ctz(unsigned int x) {
|
|||||||
throw std::runtime_error("Unreachable!");
|
throw std::runtime_error("Unreachable!");
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
}; // namespace nextpnr
|
||||||
|
@ -34,18 +34,20 @@
|
|||||||
|
|
||||||
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
|
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
#pragma intrinsic(_BitScanForward,_BitScanReverse,__popcnt)
|
#pragma intrinsic(_BitScanForward, _BitScanReverse, __popcnt)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Uses plain nextpnr namespace to avoid header inclusion nightmare that is
|
// Uses plain nextpnr namespace to avoid header inclusion nightmare that is
|
||||||
// "nextpnr.h".
|
// "nextpnr.h".
|
||||||
namespace nextpnr {
|
namespace nextpnr {
|
||||||
|
|
||||||
struct Bits {
|
struct Bits
|
||||||
|
{
|
||||||
static int generic_popcount(unsigned int x);
|
static int generic_popcount(unsigned int x);
|
||||||
static int generic_ctz(unsigned int x);
|
static int generic_ctz(unsigned int x);
|
||||||
|
|
||||||
static int popcount(unsigned int x) {
|
static int popcount(unsigned int x)
|
||||||
|
{
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
return __builtin_popcount(x);
|
return __builtin_popcount(x);
|
||||||
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
|
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
|
||||||
@ -55,7 +57,8 @@ struct Bits {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ctz(unsigned int x) {
|
static int ctz(unsigned int x)
|
||||||
|
{
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
return __builtin_ctz(x);
|
return __builtin_ctz(x);
|
||||||
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
|
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
|
||||||
@ -68,6 +71,6 @@ struct Bits {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
}; // namespace nextpnr
|
||||||
|
|
||||||
#endif /* BITS_H */
|
#endif /* BITS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user