Date: Tue, 3 Dec 2019 17:43:57 +0000 (UTC) From: Ryan Libby <rlibby@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355344 - head/sys/sys Message-ID: <201912031743.xB3HhvUD025393@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rlibby Date: Tue Dec 3 17:43:57 2019 New Revision: 355344 URL: https://svnweb.freebsd.org/changeset/base/355344 Log: bitset: avoid pessimized code when bitset size is not constant We have a couple optimizations for when the bitset is known to be just one word. But with dynamically sized bitsets, it was actually more work to determine the size than just to do the necessary computation. Now, only use the optimization when the size is known to be constant. Reviewed by: markj Discussed with: jeff Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D22639 Modified: head/sys/sys/bitset.h Modified: head/sys/sys/bitset.h ============================================================================== --- head/sys/sys/bitset.h Tue Dec 3 17:43:52 2019 (r355343) +++ head/sys/sys/bitset.h Tue Dec 3 17:43:57 2019 (r355344) @@ -34,12 +34,19 @@ #ifndef _SYS_BITSET_H_ #define _SYS_BITSET_H_ +/* + * Whether expr is both constant and true. Result is itself constant. + * Used to enable optimizations for sets with a known small size. + */ +#define __constexpr_cond(expr) (__builtin_constant_p((expr)) && (expr)) + #define __bitset_mask(_s, n) \ - (1L << ((__bitset_words((_s)) == 1) ? \ + (1L << (__constexpr_cond(__bitset_words((_s)) == 1) ? \ (__size_t)(n) : ((n) % _BITSET_BITS))) #define __bitset_word(_s, n) \ - ((__bitset_words((_s)) == 1) ? 0 : ((n) / _BITSET_BITS)) + (__constexpr_cond(__bitset_words((_s)) == 1) ? \ + 0 : ((n) / _BITSET_BITS)) #define BIT_CLR(_s, n, p) \ ((p)->__bits[__bitset_word(_s, n)] &= ~__bitset_mask((_s), (n)))
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201912031743.xB3HhvUD025393>