diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2024-05-02 07:49:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 07:49:07 -0700 |
commit | e5c69df679159cd56fe34d6fc66a898bed9a87d0 (patch) | |
tree | c2b20f0b3581f8e861134c177489ff294be911ea /src/nvim/math.c | |
parent | 350d81856473b45100d6b0e5920b757df1b4ad27 (diff) | |
parent | 037ea6e786b5d05f4a8965e4c2ba6aa60ec7c01a (diff) | |
download | rneovim-e5c69df679159cd56fe34d6fc66a898bed9a87d0.tar.gz rneovim-e5c69df679159cd56fe34d6fc66a898bed9a87d0.tar.bz2 rneovim-e5c69df679159cd56fe34d6fc66a898bed9a87d0.zip |
Merge #28101 nvim__redraw
Diffstat (limited to 'src/nvim/math.c')
-rw-r--r-- | src/nvim/math.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/nvim/math.c b/src/nvim/math.c index 47a667416c..1ccf4d7806 100644 --- a/src/nvim/math.c +++ b/src/nvim/math.c @@ -77,6 +77,23 @@ int xctz(uint64_t x) #endif } +/// Count number of set bits in bit field. +int popcount(uint64_t x) +{ + // Use compiler builtin if possible. +#if defined(__clang__) || defined(__GNUC__) + return __builtin_popcountll(x); +#else + int count = 0; + for (; x != 0; x >>= 1) { + if (x & 1) { + count++; + } + } + return count; +#endif +} + /// For overflow detection, add a digit safely to an int value. int vim_append_digit_int(int *value, int digit) { |