From 543e0256c19f397921a332e06b423215fd9aecb5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 15:51:05 +0800 Subject: build: don't define FUNC_ATTR_* as empty in headers (#26317) FUNC_ATTR_* should only be used in .c files with generated headers. Defining FUNC_ATTR_* as empty in headers causes misuses of them to be silently ignored. Instead don't define them by default, and only define them as empty after a .c file has included its generated header. --- src/nvim/math.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/math.c') diff --git a/src/nvim/math.c b/src/nvim/math.c index 96ff1bef10..79e0be691b 100644 --- a/src/nvim/math.c +++ b/src/nvim/math.c @@ -7,10 +7,11 @@ #include "nvim/math.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -# include "math.c.generated.h" // IWYU pragma: export +# include "math.c.generated.h" #endif int xfpclassify(double d) + FUNC_ATTR_CONST { uint64_t m; @@ -29,11 +30,13 @@ int xfpclassify(double d) } int xisinf(double d) + FUNC_ATTR_CONST { return FP_INFINITE == xfpclassify(d); } int xisnan(double d) + FUNC_ATTR_CONST { return FP_NAN == xfpclassify(d); } -- cgit From 3c2c022e5e299ecac4663c3813e2db5e2b099ffa Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Thu, 7 Dec 2023 01:34:29 +0600 Subject: refactor(options): remove option type macros Problem: We have `P_(BOOL|NUM|STRING)` macros to represent an option's type, which is redundant because `OptValType` can already do that. The current implementation of option type flags is also too limited to allow adding multitype options in the future. Solution: Remove `P_(BOOL|NUM|STRING)` and replace it with a new `type_flags` attribute in `vimoption_T`. Also do some groundwork for adding multitype options in the future. Side-effects: Attempting to set an invalid keycode option (e.g. `set t_foo=123`) no longer gives an error. --- src/nvim/math.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/nvim/math.c') 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 +} -- cgit