diff options
| author | bfredl <bjorn.linse@gmail.com> | 2023-12-16 11:39:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-16 11:39:30 +0100 |
| commit | 7e7da962de404e3a0952bcc0adc6fbe53eda3cfb (patch) | |
| tree | 53bb22a303e70b589e6495b42ebae90c128ffe56 /src/nvim/math.c | |
| parent | 7cae94e91e495c6ffbd32c8e9ba7d3c572610409 (diff) | |
| parent | 3c2c022e5e299ecac4663c3813e2db5e2b099ffa (diff) | |
| download | rneovim-7e7da962de404e3a0952bcc0adc6fbe53eda3cfb.tar.gz rneovim-7e7da962de404e3a0952bcc0adc6fbe53eda3cfb.tar.bz2 rneovim-7e7da962de404e3a0952bcc0adc6fbe53eda3cfb.zip | |
Merge pull request #26512 from famiu/refactor/options/type_flags
refactor(options): remove option type macros
Diffstat (limited to 'src/nvim/math.c')
| -rw-r--r-- | src/nvim/math.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/nvim/math.c b/src/nvim/math.c index 79e0be691b..9a0825823c 100644 --- a/src/nvim/math.c +++ b/src/nvim/math.c @@ -40,3 +40,29 @@ int xisnan(double d) { return FP_NAN == xfpclassify(d); } + +/// Count trailing zeroes at the end of bit field. +int xctz(uint64_t x) +{ + // If x == 0, that means all bits are zeroes. + if (x == 0) { + return 8 * sizeof(x); + } + + // Use compiler builtin if possible. +#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 4)) + return __builtin_ctzll(x); +#else + int count = 0; + // Set x's trailing zeroes to ones and zero the rest. + x = (x ^ (x - 1)) >> 1; + + // Increment count until there are just zero bits remaining. + while (x) { + count++; + x >>= 1; + } + + return count; +#endif +} |