X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=include%2Fwimlib%2Fbitops.h;h=e5c4872e40b4035cd987ad70bcc8e0026be73fbf;hb=HEAD;hp=1fc30f6c69a1b9a03e0987e215ffe5abe5900340;hpb=4a20aae0dd8469a352517a0b107416ffa99ccc55;p=wimlib diff --git a/include/wimlib/bitops.h b/include/wimlib/bitops.h index 1fc30f6c..e5c4872e 100644 --- a/include/wimlib/bitops.h +++ b/include/wimlib/bitops.h @@ -1,21 +1,28 @@ /* * bitops.h - inline functions for bit manipulation * - * The following copying information applies to this specific source code file: + * Copyright 2022 Eric Biggers * - * Written in 2014-2016 by Eric Biggers + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: * - * To the extent possible under law, the author(s) have dedicated all copyright - * and related and neighboring rights to this software to the public domain - * worldwide via the Creative Commons Zero 1.0 Universal Public Domain - * Dedication (the "CC0"). + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. * - * This software is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the CC0 for more details. - * - * You should have received a copy of the CC0 along with this software; if not - * see . + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ #ifndef _WIMLIB_BITOPS_H @@ -33,27 +40,13 @@ static forceinline unsigned bsr32(u32 v) { -#ifdef compiler_bsr32 - return compiler_bsr32(v); -#else - unsigned bit = 0; - while ((v >>= 1) != 0) - bit++; - return bit; -#endif + return 31 - __builtin_clz(v); } static forceinline unsigned bsr64(u64 v) { -#ifdef compiler_bsr64 - return compiler_bsr64(v); -#else - unsigned bit = 0; - while ((v >>= 1) != 0) - bit++; - return bit; -#endif + return 63 - __builtin_clzll(v); } static forceinline unsigned @@ -75,27 +68,13 @@ bsrw(machine_word_t v) static forceinline unsigned bsf32(u32 v) { -#ifdef compiler_bsf32 - return compiler_bsf32(v); -#else - unsigned bit; - for (bit = 0; !(v & 1); bit++, v >>= 1) - ; - return bit; -#endif + return __builtin_ctz(v); } static forceinline unsigned bsf64(u64 v) { -#ifdef compiler_bsf64 - return compiler_bsf64(v); -#else - unsigned bit; - for (bit = 0; !(v & 1); bit++, v >>= 1) - ; - return bit; -#endif + return __builtin_ctzll(v); } static forceinline unsigned