logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git
commit: dd36b398d1d8497ebe47766a1a11286d135ce102
parent 5f61b01da9f50968b18af900f9f9b3f024b314a1
Author: Michael Forney <mforney@mforney.org>
Date:   Fri,  7 Jun 2019 14:44:11 -0700

libxkbcommon: Avoid __builtin_popcount

Diffstat:

Mpkg/libxkbcommon/config.h1-
Apkg/libxkbcommon/patch/0001-Use-bitwise-test-for-power-of-2-instead-of-popcount.patch88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpkg/libxkbcommon/ver2+-
3 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/pkg/libxkbcommon/config.h b/pkg/libxkbcommon/config.h @@ -8,6 +8,5 @@ #define HAVE_MMAP 1 #define HAVE_POSIX_FALLOCATE 1 #define HAVE___BUILTIN_EXPECT 1 -#define HAVE___BUILTIN_POPCOUNT 1 #define XLOCALEDIR "/share/xlocale" #define _GNU_SOURCE 1 diff --git a/pkg/libxkbcommon/patch/0001-Use-bitwise-test-for-power-of-2-instead-of-popcount.patch b/pkg/libxkbcommon/patch/0001-Use-bitwise-test-for-power-of-2-instead-of-popcount.patch @@ -0,0 +1,88 @@ +From a0c5a34683049641590bdda2ae11149e5265fd91 Mon Sep 17 00:00:00 2001 +From: Michael Forney <mforney@mforney.org> +Date: Tue, 4 Jun 2019 14:01:02 -0700 +Subject: [PATCH] Use bitwise test for power-of-2 instead of popcount + +We don't need to determine the total number of bits set to determine if +at most one is set. + +Additionally, on x86_64 without any -march=* flag, __builtin_popcount +will get compiled to a function call to the compiler runtime (on gcc), +or a long sequence of bit operations (on clang). + +Signed-off-by: Michael Forney <mforney@mforney.org> +--- + configure.ac | 1 - + meson.build | 3 --- + src/state.c | 3 ++- + src/utils.h | 14 -------------- + 4 files changed, 2 insertions(+), 19 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 957da59..cd958b0 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -77,7 +77,6 @@ AS_IF([test "x$ac_cv_func_secure_getenv" = xno -a \ + ]) + + AX_GCC_BUILTIN(__builtin_expect) +-AX_GCC_BUILTIN(__builtin_popcount) + + # Some tests use Linux-specific headers + AC_CHECK_HEADER([linux/input.h]) +diff --git a/meson.build b/meson.build +index 6f0b596..61ba681 100644 +--- a/meson.build ++++ b/meson.build +@@ -76,9 +76,6 @@ endif + if cc.links('int main(){if(__builtin_expect(1<0,0)){}}', name: '__builtin_expect') + configh_data.set('HAVE___BUILTIN_EXPECT', 1) + endif +-if cc.links('int main(){__builtin_popcount(1);}', name: '__builtin_popcount') +- configh_data.set('HAVE___BUILTIN_POPCOUNT', 1) +-endif + if cc.has_header_symbol('unistd.h', 'eaccess', prefix: '#define _GNU_SOURCE') + configh_data.set('HAVE_EACCESS', 1) + endif +diff --git a/src/state.c b/src/state.c +index 16a4caa..dc1c651 100644 +--- a/src/state.c ++++ b/src/state.c +@@ -1373,7 +1373,8 @@ key_get_consumed(struct xkb_state *state, const struct xkb_key *key, + if (XkbLevelsSameSyms(level, no_mods_level)) + continue; + +- if (entry == matching_entry || my_popcount(entry->mods.mask) == 1) ++ if (entry == matching_entry || ++ (entry->mods.mask & (entry->mods.mask - 1)) == 0) + consumed |= entry->mods.mask & ~entry->preserve.mask; + } + break; +diff --git a/src/utils.h b/src/utils.h +index cb98e8e..060f071 100644 +--- a/src/utils.h ++++ b/src/utils.h +@@ -186,20 +186,6 @@ msb_pos(uint32_t mask) + return pos; + } + +-// Avoid conflict with other popcount()s. +-static inline int +-my_popcount(uint32_t x) +-{ +- int count; +-#if defined(HAVE___BUILTIN_POPCOUNT) +- count = __builtin_popcount(x); +-#else +- for (count = 0; x; count++) +- x &= x - 1; +-#endif +- return count; +-} +- + bool + map_file(FILE *file, char **string_out, size_t *size_out); + +-- +2.20.1 + diff --git a/pkg/libxkbcommon/ver b/pkg/libxkbcommon/ver @@ -1 +1 @@ -0.8.4 r0 +0.8.4 r1