From patchwork Tue Nov 14 17:00:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 79849 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C89FB3857C58 for ; Tue, 14 Nov 2023 17:00:55 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8CBA63858032 for ; Tue, 14 Nov 2023 17:00:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8CBA63858032 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8CBA63858032 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699981238; cv=none; b=tXGPRcERZngBg54CLuNr06HuGj7UErCacQfBt4EuS/QiidfQ1Xj4zaRNreQDXclIJMH+ubMxjhOYkWRYIogSZyZVNuTRWYYbm3wxXY0AWl0TgFPg5ecHW1V+V1BEAHduxI+WEbqEkE3PKFTbgggYD5RP9RwqHeF213JP8HHOE8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699981238; c=relaxed/simple; bh=WUU+aM4KRk+WruDZF+ZmFRsfKNu5jLszUAjXC/lysBw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=tF/NvD4DcYAhxwfaO64uuFYCihoWaYrcjMKzKqALLHAYqyxTiYXwYE2sYsfL1CCYB2btTYyMFCrb/wEcQPpsJQTrhdAQ6rCO+B3h42YBgPVMkQyhX2qJRABHc/8sUiEg6doiW1NWJKHmzl6guacdNYy/hczeazkM4Xufjy+cczs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699981232; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type; bh=uXuCOQ75PReZhD0apj0ww3DKn8KPs8HsYIbec/nG+ac=; b=hOHryHuiIXJXxOhAWoLa6Bq/kg9iGTxpdSp3vVOpJCbPplNDt4Gbh51Rj7f1ww0GNXJ8Mm We2SY/Y2ldQl7aUu+uo5dkD79yPL6k8tT97/Uq+nOoSJ/li0Zrc5DIHhdmUrstnOZTA9w6 cc2WNNlX+jhbds6b7nmly6o5EKwwieM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-280-t4uKE7fhPSulS-F4H5RVrg-1; Tue, 14 Nov 2023 12:00:30 -0500 X-MC-Unique: t4uKE7fhPSulS-F4H5RVrg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 434E8811E7B; Tue, 14 Nov 2023 17:00:30 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A511A40C6EB9; Tue, 14 Nov 2023 17:00:29 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AEH0Q5g1909841 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 14 Nov 2023 18:00:27 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AEH0P0a1909840; Tue, 14 Nov 2023 18:00:25 +0100 Date: Tue, 14 Nov 2023 18:00:25 +0100 From: Jakub Jelinek To: "Joseph S. Myers" , libc-alpha@sourceware.org Subject: [RFC] stdbit.h implementation Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Hi! In order to double-check the __builtin_{clz,ctz,popcount}g builtins I've added today to GCC, I've tried to implement the C23 stdbit.h header (but just the header, not anything further) plus a test (though, in GCC style where it aborts on error and returns 0 otherwise) for it. Tested with gcc 13, clang 14 and gcc trunk from today. I assume stdc_bit_ceil* should return 1 on zero input because that is the smallest integral power of 2 greater or equal than 0. What isn't done: 1) uint_leastN_t, or int_leastN_t types should be defined when including the header, but the header just defines size_t and uintN_t, intN_t - either some guard around stdint.h definitions of the *least*_t types needs to be added, or move those into a separate helper header 2) when not using GCC 14+, the header will only support unsigned _BitInt with sizeof 1, 2, 4, 8 (and handle them as if it was unsigned char/short/int/long long), and it will not support unsigned __int128, nor say unsigned __int20 etc.; if needed, guess unsigned __int128 support could be added, say with #ifdef __SIZEOF_INT128__ #endif part which would define __extern_always_inline functions with some non-standard prefix not exported from glibc which would handle the 2x sizeof (long long) cases by hand and conditionally using some macro add them to the macros with _Generic 3) the 70 new non-type-generic functions need to be defined somewhere just in case somebody takes their address; dunno if you want 70 new (albeit mostly very small) functions added into libc.so, or if they should go into libc_nonshared.a given that it is unlikely people will actually need them (except when using non-GCC/clang/icc compilers or GCC older than 3.4 which added the __builtin_{clz,ctz,popcount}{,l,ll} builtins); in any case, I think glibc assumes to be compiled with non-prehistoric GCC, so e.g. the definitions of the __extern_always_inline functions could be very well also used for the out of line functions Jakub diff --git a/stdlib/stdbit.h b/stdlib/stdbit.h new file mode 100644 index 0000000000..1baf27953a --- /dev/null +++ b/stdlib/stdbit.h @@ -0,0 +1,1002 @@ +/* Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* + * ISO C23: 7.18 Bit and byte utilities + */ + +#ifndef _STDBIT_H +#define _STDBIT_H 1 + +#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION +#include + +__BEGIN_DECLS + +#define __need_size_t +#include +#include +#include + +#define __STDC_VERSION_STDBIT_H__ 202311L + +#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \ + && defined(__ORDER_BIG_ENDIAN__) +# define __STDC_ENDIAN_LITTLE__ __ORDER_LITTLE_ENDIAN__ +# define __STDC_ENDIAN_BIG__ __ORDER_BIG_ENDIAN__ +# define __STDC_ENDIAN_NATIVE__ __BYTE_ORDER__ +#endif + +unsigned int stdc_leading_zeros_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_leading_zeros_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_leading_zeros_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_leading_zeros_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_leading_zeros_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_leading_ones_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_leading_ones_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_leading_ones_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_leading_ones_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_leading_ones_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_trailing_zeros_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_trailing_zeros_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_trailing_zeros_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_trailing_zeros_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_trailing_zeros_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_trailing_ones_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_trailing_ones_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_trailing_ones_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_trailing_ones_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_trailing_ones_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_first_leading_zero_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_first_leading_zero_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_first_leading_zero_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_first_leading_zero_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_first_leading_zero_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_first_leading_one_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_first_leading_one_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_first_leading_one_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_first_leading_one_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_first_leading_one_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_first_trailing_zero_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_first_trailing_zero_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_first_trailing_zero_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_first_trailing_zero_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_first_trailing_zero_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_first_trailing_one_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_first_trailing_one_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_first_trailing_one_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_first_trailing_one_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_first_trailing_one_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_count_zeros_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_count_zeros_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_count_zeros_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_count_zeros_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_count_zeros_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_count_ones_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_count_ones_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_count_ones_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_count_ones_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_count_ones_ull (unsigned long long __value) + __THROW __attribute_const__; + +_Bool stdc_has_single_bit_uc (unsigned char __value) + __THROW __attribute_const__; +_Bool stdc_has_single_bit_us (unsigned short __value) + __THROW __attribute_const__; +_Bool stdc_has_single_bit_ui (unsigned int __value) + __THROW __attribute_const__; +_Bool stdc_has_single_bit_ul (unsigned long __value) + __THROW __attribute_const__; +_Bool stdc_has_single_bit_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned int stdc_bit_width_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned int stdc_bit_width_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_bit_width_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned int stdc_bit_width_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned int stdc_bit_width_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned char stdc_bit_floor_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned short stdc_bit_floor_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_bit_floor_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned long stdc_bit_floor_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned long long stdc_bit_floor_ull (unsigned long long __value) + __THROW __attribute_const__; + +unsigned char stdc_bit_ceil_uc (unsigned char __value) + __THROW __attribute_const__; +unsigned short stdc_bit_ceil_us (unsigned short __value) + __THROW __attribute_const__; +unsigned int stdc_bit_ceil_ui (unsigned int __value) + __THROW __attribute_const__; +unsigned long stdc_bit_ceil_ul (unsigned long __value) + __THROW __attribute_const__; +unsigned long long stdc_bit_ceil_ull (unsigned long long __value) + __THROW __attribute_const__; + +#if __GNUC_PREREQ (3, 4) && defined(__extern_always_inline) +__extern_always_inline unsigned int +__NTH (stdc_leading_zeros_uc (unsigned char __value)) +{ + return (__value == 0 ? __builtin_popcount ((unsigned char) ~0U) + : __builtin_clz (__value) - __builtin_popcount (~(unsigned char) ~0U)); +} + +__extern_always_inline unsigned int +__NTH (stdc_leading_zeros_us (unsigned short __value)) +{ + return (__value == 0 ? __builtin_popcount ((unsigned short) ~0U) + : __builtin_clz (__value) - __builtin_popcount (~(unsigned short) ~0U)); +} + +__extern_always_inline unsigned int +__NTH (stdc_leading_zeros_ui (unsigned int __value)) +{ + return __value == 0 ? __builtin_popcount (~0U) : __builtin_clz (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_leading_zeros_ul (unsigned long __value)) +{ + return __value == 0 ? __builtin_popcountl (~0UL) : __builtin_clzl (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_leading_zeros_ull (unsigned long long __value)) +{ + return (__value == 0 ? __builtin_popcountll (~0ULL) + : __builtin_clzll (__value)); +} + +__extern_always_inline unsigned int +__NTH (stdc_leading_ones_uc (unsigned char __value)) +{ + return stdc_leading_zeros_uc ((unsigned char) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_leading_ones_us (unsigned short __value)) +{ + return stdc_leading_zeros_us ((unsigned short) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_leading_ones_ui (unsigned int __value)) +{ + return stdc_leading_zeros_ui ((unsigned int) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_leading_ones_ul (unsigned long __value)) +{ + return stdc_leading_zeros_ul ((unsigned long) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_leading_ones_ull (unsigned long long __value)) +{ + return stdc_leading_zeros_ull ((unsigned long long) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_zeros_uc (unsigned char __value)) +{ + return (__value == 0 ? __builtin_popcount ((unsigned char) ~0U) + : __builtin_ctz (__value)); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_zeros_us (unsigned short __value)) +{ + return (__value == 0 ? __builtin_popcount ((unsigned short) ~0U) + : __builtin_ctz (__value)); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_zeros_ui (unsigned int __value)) +{ + return __value == 0 ? __builtin_popcount (~0U) : __builtin_ctz (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_zeros_ul (unsigned long __value)) +{ + return __value == 0 ? __builtin_popcountl (~0UL) : __builtin_ctzl (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_zeros_ull (unsigned long long __value)) +{ + return (__value == 0 ? __builtin_popcountll (~0ULL) + : __builtin_ctzll (__value)); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_ones_uc (unsigned char __value)) +{ + return stdc_trailing_zeros_uc ((unsigned char) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_ones_us (unsigned short __value)) +{ + return stdc_trailing_zeros_us ((unsigned short) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_ones_ui (unsigned int __value)) +{ + return stdc_trailing_zeros_ui ((unsigned int) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_ones_ul (unsigned long __value)) +{ + return stdc_trailing_zeros_ul ((unsigned long) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_trailing_ones_ull (unsigned long long __value)) +{ + return stdc_trailing_zeros_ull ((unsigned long long) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_one_uc (unsigned char __value)) +{ + return __value == 0 ? 0 : stdc_leading_zeros_uc (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_one_us (unsigned short __value)) +{ + return __value == 0 ? 0 : stdc_leading_zeros_us (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_one_ui (unsigned int __value)) +{ + return __value == 0 ? 0 : stdc_leading_zeros_ui (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_one_ul (unsigned long __value)) +{ + return __value == 0 ? 0 : stdc_leading_zeros_ul (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_one_ull (unsigned long long __value)) +{ + return __value == 0 ? 0 : stdc_leading_zeros_ull (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_zero_uc (unsigned char __value)) +{ + return (__value == (unsigned char) ~0 ? 0 + : stdc_leading_ones_uc (__value) + 1); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_zero_us (unsigned short __value)) +{ + return (__value == (unsigned short) ~0 ? 0 + : stdc_leading_ones_us (__value) + 1); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_zero_ui (unsigned int __value)) +{ + return __value == ~0U ? 0 : stdc_leading_ones_ui (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_zero_ul (unsigned long __value)) +{ + return __value == ~0UL ? 0 : stdc_leading_ones_ul (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_leading_zero_ull (unsigned long long __value)) +{ + return __value == ~0ULL ? 0 : stdc_leading_ones_ull (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_one_uc (unsigned char __value)) +{ + return __builtin_ffs (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_one_us (unsigned short __value)) +{ + return __builtin_ffs (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_one_ui (unsigned int __value)) +{ + return __builtin_ffs (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_one_ul (unsigned long __value)) +{ + return __builtin_ffsl (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_one_ull (unsigned long long __value)) +{ + return __builtin_ffsll (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_zero_uc (unsigned char __value)) +{ + return (__value == (unsigned char) ~0 ? 0 + : stdc_trailing_ones_uc (__value) + 1); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_zero_us (unsigned short __value)) +{ + return (__value == (unsigned short) ~0 ? 0 + : stdc_trailing_ones_us (__value) + 1); +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_zero_ui (unsigned int __value)) +{ + return __value == ~0U ? 0 : stdc_trailing_ones_ui (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_zero_ul (unsigned long __value)) +{ + return __value == ~0UL ? 0 : stdc_trailing_ones_ul (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_first_trailing_zero_ull (unsigned long long __value)) +{ + return __value == ~0ULL ? 0 : stdc_trailing_ones_ull (__value) + 1; +} + +__extern_always_inline unsigned int +__NTH (stdc_count_ones_uc (unsigned char __value)) +{ + return __builtin_popcount (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_count_ones_us (unsigned short __value)) +{ + return __builtin_popcount (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_count_ones_ui (unsigned int __value)) +{ + return __builtin_popcount (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_count_ones_ul (unsigned long __value)) +{ + return __builtin_popcountl (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_count_ones_ull (unsigned long long __value)) +{ + return __builtin_popcountll (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_count_zeros_uc (unsigned char __value)) +{ + return stdc_count_ones_uc ((unsigned char) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_count_zeros_us (unsigned short __value)) +{ + return stdc_count_ones_us ((unsigned short) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_count_zeros_ui (unsigned int __value)) +{ + return stdc_count_ones_ui ((unsigned int) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_count_zeros_ul (unsigned long __value)) +{ + return stdc_count_ones_ul ((unsigned long) ~__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_count_zeros_ull (unsigned long long __value)) +{ + return stdc_count_ones_ull ((unsigned long long) ~__value); +} + +__extern_always_inline _Bool +__NTH (stdc_has_single_bit_uc (unsigned char __value)) +{ + return __value && (__value & (__value - 1)) == 0; +} + +__extern_always_inline _Bool +__NTH (stdc_has_single_bit_us (unsigned short __value)) +{ + return __value && (__value & (__value - 1)) == 0; +} + +__extern_always_inline _Bool +__NTH (stdc_has_single_bit_ui (unsigned int __value)) +{ + return __value && (__value & (__value - 1)) == 0; +} + +__extern_always_inline _Bool +__NTH (stdc_has_single_bit_ul (unsigned long __value)) +{ + return __value && (__value & (__value - 1)) == 0; +} + +__extern_always_inline _Bool +__NTH (stdc_has_single_bit_ull (unsigned long long __value)) +{ + return __value && (__value & (__value - 1)) == 0; +} + +__extern_always_inline unsigned int +__NTH (stdc_bit_width_uc (unsigned char __value)) +{ + return (__builtin_popcount ((unsigned char) ~0U) + - stdc_leading_zeros_uc (__value)); +} + +__extern_always_inline unsigned int +__NTH (stdc_bit_width_us (unsigned short __value)) +{ + return (__builtin_popcount ((unsigned short) ~0U) + - stdc_leading_zeros_us (__value)); +} + +__extern_always_inline unsigned int +__NTH (stdc_bit_width_ui (unsigned int __value)) +{ + return __builtin_popcount (~0U) - stdc_leading_zeros_ui (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_bit_width_ul (unsigned long __value)) +{ + return __builtin_popcountl (~0UL) - stdc_leading_zeros_ul (__value); +} + +__extern_always_inline unsigned int +__NTH (stdc_bit_width_ull (unsigned long long __value)) +{ + return __builtin_popcountll (~0ULL) - stdc_leading_zeros_ull (__value); +} + +__extern_always_inline unsigned char +__NTH (stdc_bit_floor_uc (unsigned char __value)) +{ + return (__value == 0 ? 0U + : 1U << (__builtin_popcount (~0U) - 1 - __builtin_clz (__value))); +} + +__extern_always_inline unsigned short +__NTH (stdc_bit_floor_us (unsigned short __value)) +{ + return (__value == 0 ? 0U + : 1U << (__builtin_popcount (~0U) - 1 - __builtin_clz (__value))); +} + +__extern_always_inline unsigned int +__NTH (stdc_bit_floor_ui (unsigned int __value)) +{ + return (__value == 0 ? 0U + : 1U << (__builtin_popcount (~0U) - 1 - __builtin_clz (__value))); +} + +__extern_always_inline unsigned long +__NTH (stdc_bit_floor_ul (unsigned long __value)) +{ + return (__value == 0 ? 0UL + : 1UL << (__builtin_popcountl (~0UL) + - 1 - __builtin_clzl (__value))); +} + +__extern_always_inline unsigned long long +__NTH (stdc_bit_floor_ull (unsigned long long __value)) +{ + return (__value == 0 ? 0ULL + : 1ULL << (__builtin_popcountll (~0ULL) + - 1 - __builtin_clzll (__value))); +} + +__extern_always_inline unsigned char +__NTH (stdc_bit_ceil_uc (unsigned char __value)) +{ + return (__value <= 1 ? 1U + : 1U << (__builtin_popcount (~0U) - __builtin_clz (__value - 1))); +} + +__extern_always_inline unsigned short +__NTH (stdc_bit_ceil_us (unsigned short __value)) +{ + return (__value <= 1 ? 1U + : 1U << (__builtin_popcount (~0U) - __builtin_clz (__value - 1))); +} + +__extern_always_inline unsigned int +__NTH (stdc_bit_ceil_ui (unsigned int __value)) +{ + return (__value <= 1 ? 1U + : 1U << (__builtin_popcount (~0U) - __builtin_clz (__value - 1))); +} + +__extern_always_inline unsigned long +__NTH (stdc_bit_ceil_ul (unsigned long __value)) +{ + return (__value <= 1 ? 1UL + : 1UL << (__builtin_popcountl (~0UL) + - __builtin_clzl (__value - 1))); +} + +__extern_always_inline unsigned long long +__NTH (stdc_bit_ceil_ull (unsigned long long __value)) +{ + return (__value <= 1 ? 1ULL + : 1ULL << (__builtin_popcountll (~0ULL) + - __builtin_clzll (__value - 1))); +} +#endif + +#if __glibc_has_builtin (__builtin_clzg) \ + && __glibc_has_builtin (__builtin_ctzg) \ + && __glibc_has_builtin (__builtin_popcountg) +# define __glibc_type_width(value) \ + __builtin_popcountg ((__typeof (value)) ~(__typeof (value)) 0) +# define stdc_leading_zeros(value) \ + ((unsigned int) __builtin_clzg (value, __glibc_type_width (value))) +# define stdc_leading_ones(value) \ + ((unsigned int) __builtin_clzg ((__typeof (value)) ~(value), \ + __glibc_type_width (value))) +# define stdc_trailing_zeros(value) \ + ((unsigned int) __builtin_ctzg (value, __glibc_type_width (value))) +# define stdc_trailing_ones(value) \ + ((unsigned int) __builtin_ctzg ((__typeof (value)) ~(value), \ + __glibc_type_width (value))) +# define stdc_first_leading_zero(value) \ + ((unsigned int) __builtin_clzg ((__typeof (value)) ~(value), -1) + 1) +# define stdc_first_leading_one(value) \ + ((unsigned int) __builtin_clzg (value, -1) + 1) +# define stdc_first_trailing_zero(value) \ + ((unsigned int) __builtin_ctzg ((__typeof (value)) ~(value), -1) + 1) +# define stdc_first_trailing_one(value) \ + ((unsigned int) __builtin_ctzg (value, -1) + 1) +# define stdc_count_zeros(value) \ + ((unsigned int) __builtin_popcountg ((__typeof (value)) ~(value))) +# define stdc_count_ones(value) \ + ((unsigned int) __builtin_popcountg (value)) +# define stdc_bit_width(value) \ + ((unsigned int) (__glibc_type_width (value) \ + - __builtin_clzg (value, __glibc_type_width (value)))) +# define stdc_has_single_bit(value) \ + ({ __typeof (value) __stdc_has_single_bit_val = (value); \ + (_Bool) (__stdc_has_single_bit_val \ + && (__stdc_has_single_bit_val \ + & (__stdc_has_single_bit_val - 1)) == 0); }) +# define stdc_bit_floor(value) \ + ({ __typeof (value) __stdc_bit_floor_val = (value); \ + __stdc_bit_floor_val == 0 ? (__typeof (__stdc_bit_floor_val)) 0 \ + : (__typeof (__stdc_bit_floor_val)) 1 \ + << (__glibc_type_width (__stdc_bit_floor_val) - 1 \ + - __builtin_clzg (__stdc_bit_floor_val)); }) +# define stdc_bit_ceil(value) \ + ({ __typeof (value) __stdc_bit_ceil_val = (value); \ + __stdc_bit_ceil_val <= 1 ? (__typeof (__stdc_bit_ceil_val)) 1 \ + : (__typeof (__stdc_bit_ceil_val)) 1 \ + << (__glibc_type_width (__stdc_bit_ceil_val) \ + - __builtin_clzg ((__typeof (__stdc_bit_ceil_val)) \ + (__stdc_bit_ceil_val - 1))); }) +#else +# define stdc_leading_zeros(value) \ + _Generic ((value), \ + unsigned char: stdc_leading_zeros_uc ((unsigned char) value), \ + unsigned short: stdc_leading_zeros_us ((unsigned short) (value)),\ + unsigned int: stdc_leading_zeros_ui ((unsigned int) (value)), \ + unsigned long: stdc_leading_zeros_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_leading_zeros_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_leading_zeros_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_leading_zeros_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_leading_zeros_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_leading_zeros_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_leading_zeros_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_leading_ones(value) \ + _Generic ((value), \ + unsigned char: stdc_leading_ones_uc ((unsigned char) (value)), \ + unsigned short: stdc_leading_ones_us ((unsigned short) (value)), \ + unsigned int: stdc_leading_ones_ui ((unsigned int) (value)), \ + unsigned long: stdc_leading_ones_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_leading_ones_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_leading_ones_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_leading_ones_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_leading_ones_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_leading_ones_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_leading_ones_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_trailing_zeros(value) \ + _Generic ((value), \ + unsigned char: stdc_trailing_zeros_uc ((unsigned char) (value)), \ + unsigned short: \ + stdc_trailing_zeros_us ((unsigned short) (value)), \ + unsigned int: stdc_trailing_zeros_ui ((unsigned int) (value)), \ + unsigned long: stdc_trailing_zeros_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_trailing_zeros_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_trailing_zeros_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_trailing_zeros_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_trailing_zeros_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_trailing_zeros_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_trailing_zeros_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_trailing_ones(value) \ + _Generic ((value), \ + unsigned char: stdc_trailing_ones_uc ((unsigned char) (value)), \ + unsigned short: stdc_trailing_ones_us ((unsigned short) (value)),\ + unsigned int: stdc_trailing_ones_ui ((unsigned int) (value)), \ + unsigned long: stdc_trailing_ones_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_trailing_ones_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_trailing_ones_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_trailing_ones_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_trailing_ones_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_trailing_ones_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_trailing_ones_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_first_leading_zero(value) \ + _Generic ((value), \ + unsigned char: \ + stdc_first_leading_zero_uc ((unsigned char) (value)), \ + unsigned short: \ + stdc_first_leading_zero_us ((unsigned short) (value)), \ + unsigned int: \ + stdc_first_leading_zero_ui ((unsigned int) (value)), \ + unsigned long: \ + stdc_first_leading_zero_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_first_leading_zero_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_first_leading_zero_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_first_leading_zero_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_first_leading_zero_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_first_leading_zero_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_first_leading_zero_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_first_leading_one(value) \ + _Generic ((value), \ + unsigned char: \ + stdc_first_leading_one_uc ((unsigned char) (value)), \ + unsigned short: \ + stdc_first_leading_one_us ((unsigned short) (value)), \ + unsigned int: stdc_first_leading_one_ui ((unsigned int) (value)),\ + unsigned long: \ + stdc_first_leading_one_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_first_leading_one_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_first_leading_one_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_first_leading_one_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_first_leading_one_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_first_leading_one_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_first_leading_one_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_first_trailing_zero(value) \ + _Generic ((value), \ + unsigned char: \ + stdc_first_trailing_zero_uc ((unsigned char) (value)), \ + unsigned short: \ + stdc_first_trailing_zero_us ((unsigned short) (value)), \ + unsigned int: \ + stdc_first_trailing_zero_ui ((unsigned int) (value)), \ + unsigned long: \ + stdc_first_trailing_zero_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_first_trailing_zero_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_first_trailing_zero_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_first_trailing_zero_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_first_trailing_zero_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_first_trailing_zero_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_first_trailing_zero_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_first_trailing_one(value) \ + _Generic ((value), \ + unsigned char: \ + stdc_first_trailing_one_uc ((unsigned char) (value)), \ + unsigned short: \ + stdc_first_trailing_one_us ((unsigned short) (value)), \ + unsigned int: \ + stdc_first_trailing_one_ui ((unsigned int) (value)), \ + unsigned long: \ + stdc_first_trailing_one_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_first_trailing_one_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_first_trailing_one_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_first_trailing_one_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_first_trailing_one_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_first_trailing_one_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_first_trailing_one_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_count_zeros(value) \ + _Generic ((value), \ + unsigned char: stdc_count_zeros_uc ((unsigned char) (value)), \ + unsigned short: stdc_count_zeros_us ((unsigned short) (value)), \ + unsigned int: stdc_count_zeros_ui ((unsigned int) (value)), \ + unsigned long: stdc_count_zeros_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_count_zeros_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_count_zeros_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_count_zeros_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_count_zeros_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_count_zeros_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_count_zeros_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_count_ones(value) \ + _Generic ((value), \ + unsigned char: stdc_count_ones_uc ((unsigned char) (value)), \ + unsigned short: stdc_count_ones_us ((unsigned short) (value)), \ + unsigned int: stdc_count_ones_ui ((unsigned int) (value)), \ + unsigned long: stdc_count_ones_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_count_ones_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_count_ones_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_count_ones_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_count_ones_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_count_ones_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_count_ones_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_has_single_bit(value) \ + _Generic ((value), \ + unsigned char: stdc_has_single_bit_uc ((unsigned char) (value)), \ + unsigned short: \ + stdc_has_single_bit_us ((unsigned short) (value)), \ + unsigned int: stdc_has_single_bit_ui ((unsigned int) (value)), \ + unsigned long: stdc_has_single_bit_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_has_single_bit_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_has_single_bit_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_has_single_bit_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_has_single_bit_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_has_single_bit_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_has_single_bit_ull ((unsigned long long) (value)) \ + : (_Bool) 0) +# define stdc_bit_width(value) \ + _Generic ((value), \ + unsigned char: stdc_bit_width_uc ((unsigned char) (value)), \ + unsigned short: stdc_bit_width_us ((unsigned short) (value)), \ + unsigned int: stdc_bit_width_ui ((unsigned int) (value)), \ + unsigned long: stdc_bit_width_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_bit_width_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? stdc_bit_width_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? stdc_bit_width_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? stdc_bit_width_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? stdc_bit_width_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? stdc_bit_width_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_bit_floor(value) \ + _Generic ((value), \ + unsigned char: stdc_bit_floor_uc ((unsigned char) (value)), \ + unsigned short: stdc_bit_floor_us ((unsigned short) (value)), \ + unsigned int: stdc_bit_floor_ui ((unsigned int) (value)), \ + unsigned long: stdc_bit_floor_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_bit_floor_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? (__typeof (value)) \ + stdc_bit_floor_uc ((unsigned char) (value)) \ + : sizeof (value) == sizeof (unsigned short) \ + ? (__typeof (value)) \ + stdc_bit_floor_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? (__typeof (value)) stdc_bit_floor_ui ((unsigned int) (value))\ + : sizeof (value) == sizeof (unsigned long) \ + ? (__typeof (value)) \ + stdc_bit_floor_ul ((unsigned long) (value)) \ + : sizeof (value) == sizeof (unsigned long long) \ + ? (__typeof (value)) \ + stdc_bit_floor_ull ((unsigned long long) (value)) \ + : 0U) +# define stdc_bit_ceil(value) \ + _Generic ((value), \ + unsigned char: stdc_bit_ceil_uc ((unsigned char) (value)), \ + unsigned short: stdc_bit_ceil_us ((unsigned short) (value)), \ + unsigned int: stdc_bit_ceil_ui ((unsigned int) (value)), \ + unsigned long: stdc_bit_ceil_ul ((unsigned long) (value)), \ + unsigned long long: \ + stdc_bit_ceil_ull ((unsigned long long) (value)), \ + default: \ + sizeof (value) == sizeof (unsigned char) \ + ? (__typeof (value)) stdc_bit_ceil_uc ((unsigned char) (value))\ + : sizeof (value) == sizeof (unsigned short) \ + ? (__typeof (value)) \ + stdc_bit_ceil_us ((unsigned short) (value)) \ + : sizeof (value) == sizeof (unsigned int) \ + ? (__typeof (value)) stdc_bit_ceil_ui ((unsigned int) (value)) \ + : sizeof (value) == sizeof (unsigned long) \ + ? (__typeof (value)) stdc_bit_ceil_ul ((unsigned long) (value))\ + : sizeof (value) == sizeof (unsigned long long) \ + ? (__typeof (value)) \ + stdc_bit_ceil_ull ((unsigned long long) (value)) \ + : 0U) +#endif + +__END_DECLS + +#endif /* stdbit.h */ diff --git a/stdlib/tst-stdbit.c b/stdlib/tst-stdbit.c new file mode 100644 index 0000000000..95930d1b09 --- /dev/null +++ b/stdlib/tst-stdbit.c @@ -0,0 +1,488 @@ +/* Test stdbit.h header. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +int +main () +{ + if (stdc_leading_zeros_uc (0) != UCHAR_WIDTH + || stdc_leading_zeros ((unsigned char) 0) != UCHAR_WIDTH + || stdc_leading_zeros_us (0) != USHRT_WIDTH + || stdc_leading_zeros ((unsigned short) 0) != USHRT_WIDTH + || stdc_leading_zeros_ui (0) != UINT_WIDTH + || stdc_leading_zeros (0U) != UINT_WIDTH + || stdc_leading_zeros_ul (0) != ULONG_WIDTH + || stdc_leading_zeros (0UL) != ULONG_WIDTH + || stdc_leading_zeros_ull (0) != ULLONG_WIDTH + || stdc_leading_zeros (0ULL) != ULLONG_WIDTH) + abort (); + if (stdc_leading_zeros_uc ((unsigned char) ~0U) != 0 + || stdc_leading_zeros ((unsigned char) ~0U) != 0 + || stdc_leading_zeros_us ((unsigned short) ~0U) != 0 + || stdc_leading_zeros ((unsigned short) ~0U) != 0 + || stdc_leading_zeros_ui (~0U) != 0 + || stdc_leading_zeros (~0U) != 0 + || stdc_leading_zeros_ul (~0UL) != 0 + || stdc_leading_zeros (~0UL) != 0 + || stdc_leading_zeros_ull (~0ULL) != 0 + || stdc_leading_zeros (~0ULL) != 0) + abort (); + if (stdc_leading_zeros_uc (1) != UCHAR_WIDTH - 1 + || stdc_leading_zeros ((unsigned char) 3) != UCHAR_WIDTH - 2 + || stdc_leading_zeros_us (5) != USHRT_WIDTH - 3 + || stdc_leading_zeros ((unsigned short) 9) != USHRT_WIDTH - 4 + || stdc_leading_zeros_ui (16) != UINT_WIDTH - 5 + || stdc_leading_zeros (34U) != UINT_WIDTH - 6 + || stdc_leading_zeros_ul (65) != ULONG_WIDTH - 7 + || stdc_leading_zeros (130UL) != ULONG_WIDTH - 8 + || stdc_leading_zeros_ull (275) != ULLONG_WIDTH - 9 + || stdc_leading_zeros (512ULL) != ULLONG_WIDTH - 10) + abort (); + if (stdc_leading_ones_uc (0) != 0 + || stdc_leading_ones ((unsigned char) 0) != 0 + || stdc_leading_ones_us (0) != 0 + || stdc_leading_ones ((unsigned short) 0) != 0 + || stdc_leading_ones_ui (0) != 0 + || stdc_leading_ones (0U) != 0 + || stdc_leading_ones_ul (0) != 0 + || stdc_leading_ones (0UL) != 0 + || stdc_leading_ones_ull (0) != 0 + || stdc_leading_ones (0ULL) != 0) + abort (); + if (stdc_leading_ones_uc ((unsigned char) ~0U) != UCHAR_WIDTH + || stdc_leading_ones ((unsigned char) ~0U) != UCHAR_WIDTH + || stdc_leading_ones_us ((unsigned short) ~0U) != USHRT_WIDTH + || stdc_leading_ones ((unsigned short) ~0U) != USHRT_WIDTH + || stdc_leading_ones_ui (~0U) != UINT_WIDTH + || stdc_leading_ones (~0U) != UINT_WIDTH + || stdc_leading_ones_ul (~0UL) != ULONG_WIDTH + || stdc_leading_ones (~0UL) != ULONG_WIDTH + || stdc_leading_ones_ull (~0ULL) != ULLONG_WIDTH + || stdc_leading_ones (~0ULL) != ULLONG_WIDTH) + abort (); + if (stdc_leading_ones_uc (~1) != UCHAR_WIDTH - 1 + || stdc_leading_ones ((unsigned char) ~3) != UCHAR_WIDTH - 2 + || stdc_leading_ones_us (~5) != USHRT_WIDTH - 3 + || stdc_leading_ones ((unsigned short) ~9) != USHRT_WIDTH - 4 + || stdc_leading_ones_ui (~16) != UINT_WIDTH - 5 + || stdc_leading_ones (~34U) != UINT_WIDTH - 6 + || stdc_leading_ones_ul (~65UL) != ULONG_WIDTH - 7 + || stdc_leading_ones (~130UL) != ULONG_WIDTH - 8 + || stdc_leading_ones_ull (~275ULL) != ULLONG_WIDTH - 9 + || stdc_leading_ones (~512ULL) != ULLONG_WIDTH - 10) + abort (); + if (stdc_trailing_zeros_uc (0) != UCHAR_WIDTH + || stdc_trailing_zeros ((unsigned char) 0) != UCHAR_WIDTH + || stdc_trailing_zeros_us (0) != USHRT_WIDTH + || stdc_trailing_zeros ((unsigned short) 0) != USHRT_WIDTH + || stdc_trailing_zeros_ui (0) != UINT_WIDTH + || stdc_trailing_zeros (0U) != UINT_WIDTH + || stdc_trailing_zeros_ul (0) != ULONG_WIDTH + || stdc_trailing_zeros (0UL) != ULONG_WIDTH + || stdc_trailing_zeros_ull (0) != ULLONG_WIDTH + || stdc_trailing_zeros (0ULL) != ULLONG_WIDTH) + abort (); + if (stdc_trailing_zeros_uc ((unsigned char) ~0U) != 0 + || stdc_trailing_zeros ((unsigned char) ~0U) != 0 + || stdc_trailing_zeros_us ((unsigned short) ~0U) != 0 + || stdc_trailing_zeros ((unsigned short) ~0U) != 0 + || stdc_trailing_zeros_ui (~0U) != 0 + || stdc_trailing_zeros (~0U) != 0 + || stdc_trailing_zeros_ul (~0UL) != 0 + || stdc_trailing_zeros (~0UL) != 0 + || stdc_trailing_zeros_ull (~0ULL) != 0 + || stdc_trailing_zeros (~0ULL) != 0) + abort (); + if (stdc_trailing_zeros_uc (1) != 0 + || stdc_trailing_zeros ((unsigned char) 2) != 1 + || stdc_trailing_zeros_us (4) != 2 + || stdc_trailing_zeros ((unsigned short) 24) != 3 + || stdc_trailing_zeros_ui (16) != 4 + || stdc_trailing_zeros (32U) != 5 + || stdc_trailing_zeros_ul (192) != 6 + || stdc_trailing_zeros (128UL) != 7 + || stdc_trailing_zeros_ull (256) != 8 + || stdc_trailing_zeros (512ULL) != 9) + abort (); + if (stdc_trailing_ones_uc (0) != 0 + || stdc_trailing_ones ((unsigned char) 0) != 0 + || stdc_trailing_ones_us (0) != 0 + || stdc_trailing_ones ((unsigned short) 0) != 0 + || stdc_trailing_ones_ui (0) != 0 + || stdc_trailing_ones (0U) != 0 + || stdc_trailing_ones_ul (0) != 0 + || stdc_trailing_ones (0UL) != 0 + || stdc_trailing_ones_ull (0) != 0 + || stdc_trailing_ones (0ULL) != 0) + abort (); + if (stdc_trailing_ones_uc ((unsigned char) ~0U) != UCHAR_WIDTH + || stdc_trailing_ones ((unsigned char) ~0U) != UCHAR_WIDTH + || stdc_trailing_ones_us ((unsigned short) ~0U) != USHRT_WIDTH + || stdc_trailing_ones ((unsigned short) ~0U) != USHRT_WIDTH + || stdc_trailing_ones_ui (~0U) != UINT_WIDTH + || stdc_trailing_ones (~0U) != UINT_WIDTH + || stdc_trailing_ones_ul (~0UL) != ULONG_WIDTH + || stdc_trailing_ones (~0UL) != ULONG_WIDTH + || stdc_trailing_ones_ull (~0ULL) != ULLONG_WIDTH + || stdc_trailing_ones (~0ULL) != ULLONG_WIDTH) + abort (); + if (stdc_trailing_ones_uc (7) != 3 + || stdc_trailing_ones ((unsigned char) 5) != 1 + || stdc_trailing_ones_us (6) != 0 + || stdc_trailing_ones ((unsigned short) 15) != 4 + || stdc_trailing_ones_ui (31 | 128) != 5 + || stdc_trailing_ones (127U) != 7 + || stdc_trailing_ones_ul (255UL & ~32UL) != 5 + || stdc_trailing_ones (511UL) != 9 + || stdc_trailing_ones_ull (255ULL) != 8 + || stdc_trailing_ones (~0ULL >> 2) != ULLONG_WIDTH - 2) + abort (); + if (stdc_first_leading_zero_uc (0) != 1 + || stdc_first_leading_zero ((unsigned char) 0) != 1 + || stdc_first_leading_zero_us (0) != 1 + || stdc_first_leading_zero ((unsigned short) 0) != 1 + || stdc_first_leading_zero_ui (0) != 1 + || stdc_first_leading_zero (0U) != 1 + || stdc_first_leading_zero_ul (0) != 1 + || stdc_first_leading_zero (0UL) != 1 + || stdc_first_leading_zero_ull (0) != 1 + || stdc_first_leading_zero (0ULL) != 1) + abort (); + if (stdc_first_leading_zero_uc ((unsigned char) ~0U) != 0 + || stdc_first_leading_zero ((unsigned char) ~0U) != 0 + || stdc_first_leading_zero_us ((unsigned short) ~0U) != 0 + || stdc_first_leading_zero ((unsigned short) ~0U) != 0 + || stdc_first_leading_zero_ui (~0U) != 0 + || stdc_first_leading_zero (~0U) != 0 + || stdc_first_leading_zero_ul (~0UL) != 0 + || stdc_first_leading_zero (~0UL) != 0 + || stdc_first_leading_zero_ull (~0ULL) != 0 + || stdc_first_leading_zero (~0ULL) != 0) + abort (); + if (stdc_first_leading_zero_uc ((unsigned char) ~1U) != UCHAR_WIDTH + || stdc_first_leading_zero ((unsigned char) ~3U) != UCHAR_WIDTH - 1 + || stdc_first_leading_zero_us ((unsigned short) ~7U) != USHRT_WIDTH - 2 + || stdc_first_leading_zero ((unsigned short) ~15U) != USHRT_WIDTH - 3 + || stdc_first_leading_zero_ui (~31U) != UINT_WIDTH - 4 + || stdc_first_leading_zero (~63U) != UINT_WIDTH - 5 + || stdc_first_leading_zero_ul (~127UL) != ULONG_WIDTH - 6 + || stdc_first_leading_zero (~255UL) != ULONG_WIDTH - 7 + || stdc_first_leading_zero_ull (~511ULL) != ULLONG_WIDTH - 8 + || stdc_first_leading_zero (~1023ULL) != ULLONG_WIDTH - 9) + abort (); + if (stdc_first_leading_one_uc (0) != 0 + || stdc_first_leading_one ((unsigned char) 0) != 0 + || stdc_first_leading_one_us (0) != 0 + || stdc_first_leading_one ((unsigned short) 0) != 0 + || stdc_first_leading_one_ui (0) != 0 + || stdc_first_leading_one (0U) != 0 + || stdc_first_leading_one_ul (0) != 0 + || stdc_first_leading_one (0UL) != 0 + || stdc_first_leading_one_ull (0) != 0 + || stdc_first_leading_one (0ULL) != 0) + abort (); + if (stdc_first_leading_one_uc ((unsigned char) ~0U) != 1 + || stdc_first_leading_one ((unsigned char) ~0U) != 1 + || stdc_first_leading_one_us ((unsigned short) ~0U) != 1 + || stdc_first_leading_one ((unsigned short) ~0U) != 1 + || stdc_first_leading_one_ui (~0U) != 1 + || stdc_first_leading_one (~0U) != 1 + || stdc_first_leading_one_ul (~0UL) != 1 + || stdc_first_leading_one (~0UL) != 1 + || stdc_first_leading_one_ull (~0ULL) != 1 + || stdc_first_leading_one (~0ULL) != 1) + abort (); + if (stdc_first_leading_one_uc (1) != UCHAR_WIDTH + || stdc_first_leading_one ((unsigned char) 3) != UCHAR_WIDTH - 1 + || stdc_first_leading_one_us (5) != USHRT_WIDTH - 2 + || stdc_first_leading_one ((unsigned short) 9) != USHRT_WIDTH - 3 + || stdc_first_leading_one_ui (16) != UINT_WIDTH - 4 + || stdc_first_leading_one (34U) != UINT_WIDTH - 5 + || stdc_first_leading_one_ul (65UL) != ULONG_WIDTH - 6 + || stdc_first_leading_one (130UL) != ULONG_WIDTH - 7 + || stdc_first_leading_one_ull (275ULL) != ULLONG_WIDTH - 8 + || stdc_first_leading_one (512ULL) != ULLONG_WIDTH - 9) + abort (); + if (stdc_first_trailing_zero_uc (0) != 1 + || stdc_first_trailing_zero ((unsigned char) 0) != 1 + || stdc_first_trailing_zero_us (0) != 1 + || stdc_first_trailing_zero ((unsigned short) 0) != 1 + || stdc_first_trailing_zero_ui (0) != 1 + || stdc_first_trailing_zero (0U) != 1 + || stdc_first_trailing_zero_ul (0) != 1 + || stdc_first_trailing_zero (0UL) != 1 + || stdc_first_trailing_zero_ull (0) != 1 + || stdc_first_trailing_zero (0ULL) != 1) + abort (); + if (stdc_first_trailing_zero_uc ((unsigned char) ~0U) != 0 + || stdc_first_trailing_zero ((unsigned char) ~0U) != 0 + || stdc_first_trailing_zero_us ((unsigned short) ~0U) != 0 + || stdc_first_trailing_zero ((unsigned short) ~0U) != 0 + || stdc_first_trailing_zero_ui (~0U) != 0 + || stdc_first_trailing_zero (~0U) != 0 + || stdc_first_trailing_zero_ul (~0UL) != 0 + || stdc_first_trailing_zero (~0UL) != 0 + || stdc_first_trailing_zero_ull (~0ULL) != 0 + || stdc_first_trailing_zero (~0ULL) != 0) + abort (); + if (stdc_first_trailing_zero_uc (1) != 2 + || stdc_first_trailing_zero ((unsigned char) 2) != 1 + || stdc_first_trailing_zero_us (7) != 4 + || stdc_first_trailing_zero ((unsigned short) 15) != 5 + || stdc_first_trailing_zero_ui (31) != 6 + || stdc_first_trailing_zero (63U) != 7 + || stdc_first_trailing_zero_ul (127U | 512U) != 8 + || stdc_first_trailing_zero (128UL) != 1 + || stdc_first_trailing_zero_ull (255) != 9 + || stdc_first_trailing_zero (511ULL) != 10) + abort (); + if (stdc_first_trailing_one_uc (0) != 0 + || stdc_first_trailing_one ((unsigned char) 0) != 0 + || stdc_first_trailing_one_us (0) != 0 + || stdc_first_trailing_one ((unsigned short) 0) != 0 + || stdc_first_trailing_one_ui (0) != 0 + || stdc_first_trailing_one (0U) != 0 + || stdc_first_trailing_one_ul (0) != 0 + || stdc_first_trailing_one (0UL) != 0 + || stdc_first_trailing_one_ull (0) != 0 + || stdc_first_trailing_one (0ULL) != 0) + abort (); + if (stdc_first_trailing_one_uc ((unsigned char) ~0U) != 1 + || stdc_first_trailing_one ((unsigned char) ~0U) != 1 + || stdc_first_trailing_one_us ((unsigned short) ~0U) != 1 + || stdc_first_trailing_one ((unsigned short) ~0U) != 1 + || stdc_first_trailing_one_ui (~0U) != 1 + || stdc_first_trailing_one (~0U) != 1 + || stdc_first_trailing_one_ul (~0UL) != 1 + || stdc_first_trailing_one (~0UL) != 1 + || stdc_first_trailing_one_ull (~0ULL) != 1 + || stdc_first_trailing_one (~0ULL) != 1) + abort (); + if (stdc_first_trailing_one_uc (7) != 1 + || stdc_first_trailing_one ((unsigned char) 4) != 3 + || stdc_first_trailing_one_us (6) != 2 + || stdc_first_trailing_one ((unsigned short) 96) != 6 + || stdc_first_trailing_one_ui (128) != 8 + || stdc_first_trailing_one (127U) != 1 + || stdc_first_trailing_one_ul (255UL & ~31UL) != 6 + || stdc_first_trailing_one (511UL) != 1 + || stdc_first_trailing_one_ull (255ULL << 3) != 4 + || stdc_first_trailing_one (~0ULL << 12) != 13) + abort (); + if (stdc_count_zeros_uc (0) != UCHAR_WIDTH + || stdc_count_zeros ((unsigned char) 0) != UCHAR_WIDTH + || stdc_count_zeros_us (0) != USHRT_WIDTH + || stdc_count_zeros ((unsigned short) 0) != USHRT_WIDTH + || stdc_count_zeros_ui (0) != UINT_WIDTH + || stdc_count_zeros (0U) != UINT_WIDTH + || stdc_count_zeros_ul (0) != ULONG_WIDTH + || stdc_count_zeros (0UL) != ULONG_WIDTH + || stdc_count_zeros_ull (0) != ULLONG_WIDTH + || stdc_count_zeros (0ULL) != ULLONG_WIDTH) + abort (); + if (stdc_count_zeros_uc ((unsigned char) ~0U) != 0 + || stdc_count_zeros ((unsigned char) ~0U) != 0 + || stdc_count_zeros_us ((unsigned short) ~0U) != 0 + || stdc_count_zeros ((unsigned short) ~0U) != 0 + || stdc_count_zeros_ui (~0U) != 0 + || stdc_count_zeros (~0U) != 0 + || stdc_count_zeros_ul (~0UL) != 0 + || stdc_count_zeros (~0UL) != 0 + || stdc_count_zeros_ull (~0ULL) != 0 + || stdc_count_zeros (~0ULL) != 0) + abort (); + if (stdc_count_zeros_uc ((unsigned char) ~1U) != 1 + || stdc_count_zeros ((unsigned char) 1U) != UCHAR_WIDTH - 1 + || stdc_count_zeros_us ((unsigned short) 5U) != USHRT_WIDTH - 2 + || stdc_count_zeros ((unsigned short) 42) != USHRT_WIDTH - 3 + || stdc_count_zeros_ui (~42U) != 3 + || stdc_count_zeros (291U) != UINT_WIDTH - 4 + || stdc_count_zeros_ul (~291UL) != 4 + || stdc_count_zeros (~1315UL) != 5 + || stdc_count_zeros_ull (1315ULL) != ULLONG_WIDTH - 5 + || stdc_count_zeros (3363ULL) != ULLONG_WIDTH - 6) + abort (); + if (stdc_count_ones_uc (0) != 0 + || stdc_count_ones ((unsigned char) 0) != 0 + || stdc_count_ones_us (0) != 0 + || stdc_count_ones ((unsigned short) 0) != 0 + || stdc_count_ones_ui (0) != 0 + || stdc_count_ones (0U) != 0 + || stdc_count_ones_ul (0) != 0 + || stdc_count_ones (0UL) != 0 + || stdc_count_ones_ull (0) != 0 + || stdc_count_ones (0ULL) != 0) + abort (); + if (stdc_count_ones_uc ((unsigned char) ~0U) != UCHAR_WIDTH + || stdc_count_ones ((unsigned char) ~0U) != UCHAR_WIDTH + || stdc_count_ones_us ((unsigned short) ~0U) != USHRT_WIDTH + || stdc_count_ones ((unsigned short) ~0U) != USHRT_WIDTH + || stdc_count_ones_ui (~0U) != UINT_WIDTH + || stdc_count_ones (~0U) != UINT_WIDTH + || stdc_count_ones_ul (~0UL) != ULONG_WIDTH + || stdc_count_ones (~0UL) != ULONG_WIDTH + || stdc_count_ones_ull (~0ULL) != ULLONG_WIDTH + || stdc_count_ones (~0ULL) != ULLONG_WIDTH) + abort (); + if (stdc_count_ones_uc ((unsigned char) 1U) != 1 + || stdc_count_ones ((unsigned char) ~1U) != UCHAR_WIDTH - 1 + || stdc_count_ones_us ((unsigned short) ~5U) != USHRT_WIDTH - 2 + || stdc_count_ones ((unsigned short) ~42) != USHRT_WIDTH - 3 + || stdc_count_ones_ui (42U) != 3 + || stdc_count_ones (~291U) != UINT_WIDTH - 4 + || stdc_count_ones_ul (291UL) != 4 + || stdc_count_ones (1315UL) != 5 + || stdc_count_ones_ull (~1315ULL) != ULLONG_WIDTH - 5 + || stdc_count_ones (~3363ULL) != ULLONG_WIDTH - 6) + abort (); + if (stdc_has_single_bit_uc (0) + || stdc_has_single_bit ((unsigned char) 0) + || stdc_has_single_bit_us (0) + || stdc_has_single_bit ((unsigned short) 0) + || stdc_has_single_bit_ui (0) + || stdc_has_single_bit (0U) + || stdc_has_single_bit_ul (0) + || stdc_has_single_bit (0UL) + || stdc_has_single_bit_ull (0) + || stdc_has_single_bit (0ULL)) + abort (); + if (!stdc_has_single_bit_uc (1) + || !stdc_has_single_bit ((unsigned char) 2) + || !stdc_has_single_bit_us (4) + || !stdc_has_single_bit ((unsigned short) 8) + || !stdc_has_single_bit_ui (16) + || !stdc_has_single_bit (32U) + || !stdc_has_single_bit_ul (64) + || !stdc_has_single_bit (128UL) + || !stdc_has_single_bit_ull (256) + || !stdc_has_single_bit (512ULL)) + abort (); + if (stdc_has_single_bit_uc (3) + || stdc_has_single_bit ((unsigned char) 7) + || stdc_has_single_bit_us (31) + || stdc_has_single_bit ((unsigned short) 96) + || stdc_has_single_bit_ui (129) + || stdc_has_single_bit (513U) + || stdc_has_single_bit_ul (511) + || stdc_has_single_bit (1022UL) + || stdc_has_single_bit_ull (6) + || stdc_has_single_bit (12ULL)) + abort (); + if (stdc_bit_width_uc (0) != 0 + || stdc_bit_width ((unsigned char) 0) != 0 + || stdc_bit_width_us (0) != 0 + || stdc_bit_width ((unsigned short) 0) != 0 + || stdc_bit_width_ui (0) != 0 + || stdc_bit_width (0U) != 0 + || stdc_bit_width_ul (0) != 0 + || stdc_bit_width (0UL) != 0 + || stdc_bit_width_ull (0) != 0 + || stdc_bit_width (0ULL) != 0) + abort (); + if (stdc_bit_width_uc ((unsigned char) ~0U) != UCHAR_WIDTH + || stdc_bit_width ((unsigned char) ~0U) != UCHAR_WIDTH + || stdc_bit_width_us ((unsigned short) ~0U) != USHRT_WIDTH + || stdc_bit_width ((unsigned short) ~0U) != USHRT_WIDTH + || stdc_bit_width_ui (~0U) != UINT_WIDTH + || stdc_bit_width (~0U) != UINT_WIDTH + || stdc_bit_width_ul (~0UL) != ULONG_WIDTH + || stdc_bit_width (~0UL) != ULONG_WIDTH + || stdc_bit_width_ull (~0ULL) != ULLONG_WIDTH + || stdc_bit_width (~0ULL) != ULLONG_WIDTH) + abort (); + if (stdc_bit_width_uc ((unsigned char) ~0U >> 1) != UCHAR_WIDTH - 1 + || stdc_bit_width ((unsigned char) 6) != 3 + || stdc_bit_width_us ((unsigned short) 12U) != 4 + || stdc_bit_width ((unsigned short) ((unsigned short) ~0U >> 5)) != USHRT_WIDTH - 5 + || stdc_bit_width_ui (137U) != 8 + || stdc_bit_width (269U) != 9 + || stdc_bit_width_ul (39UL) != 6 + || stdc_bit_width (~0UL >> 2) != ULONG_WIDTH - 2 + || stdc_bit_width_ull (1023) != 10 + || stdc_bit_width (1024ULL) != 11) + abort (); + if (stdc_bit_floor_uc (0) != 0 + || stdc_bit_floor ((unsigned char) 0) != 0 + || stdc_bit_floor_us (0) != 0 + || stdc_bit_floor ((unsigned short) 0) != 0 + || stdc_bit_floor_ui (0) != 0U + || stdc_bit_floor (0U) != 0U + || stdc_bit_floor_ul (0) != 0UL + || stdc_bit_floor (0UL) != 0UL + || stdc_bit_floor_ull (0) != 0ULL + || stdc_bit_floor (0ULL) != 0ULL) + abort (); + if (stdc_bit_floor_uc ((unsigned char) ~0U) != (1U << (UCHAR_WIDTH - 1)) + || stdc_bit_floor ((unsigned char) ~0U) != (1U << (UCHAR_WIDTH - 1)) + || stdc_bit_floor_us ((unsigned short) ~0U) != (1U << (USHRT_WIDTH - 1)) + || stdc_bit_floor ((unsigned short) ~0U) != (1U << (USHRT_WIDTH - 1)) + || stdc_bit_floor_ui (~0U) != (1U << (UINT_WIDTH - 1)) + || stdc_bit_floor (~0U) != (1U << (UINT_WIDTH - 1)) + || stdc_bit_floor_ul (~0UL) != (1UL << (ULONG_WIDTH - 1)) + || stdc_bit_floor (~0UL) != (1UL << (ULONG_WIDTH - 1)) + || stdc_bit_floor_ull (~0ULL) != (1ULL << (ULLONG_WIDTH - 1)) + || stdc_bit_floor (~0ULL) != (1ULL << (ULLONG_WIDTH - 1))) + abort (); + if (stdc_bit_floor_uc ((unsigned char) 4) != 4 + || stdc_bit_floor ((unsigned char) 7) != 4 + || stdc_bit_floor_us ((unsigned short) 8U) != 8 + || stdc_bit_floor ((unsigned short) 31U) != 16 + || stdc_bit_floor_ui (137U) != 128U + || stdc_bit_floor (269U) != 256U + || stdc_bit_floor_ul (511UL) != 256UL + || stdc_bit_floor (512UL) != 512UL + || stdc_bit_floor_ull (513) != 512ULL + || stdc_bit_floor (1024ULL) != 1024ULL) + abort (); + if (stdc_bit_ceil_uc (0) != 1 + || stdc_bit_ceil ((unsigned char) 0) != 1 + || stdc_bit_ceil_us (0) != 1 + || stdc_bit_ceil ((unsigned short) 0) != 1 + || stdc_bit_ceil_ui (0) != 1U + || stdc_bit_ceil (0U) != 1U + || stdc_bit_ceil_ul (0) != 1UL + || stdc_bit_ceil (0UL) != 1UL + || stdc_bit_ceil_ull (0) != 1ULL + || stdc_bit_ceil (0ULL) != 1ULL) + abort (); + if (stdc_bit_ceil_uc ((unsigned char) ~0U >> 1) != (1U << (UCHAR_WIDTH - 1)) + || stdc_bit_ceil ((unsigned char) ((unsigned char) ~0U >> 1)) != (1U << (UCHAR_WIDTH - 1)) + || stdc_bit_ceil_us ((unsigned short) ~0U >> 1) != (1U << (USHRT_WIDTH - 1)) + || stdc_bit_ceil ((unsigned short) ((unsigned short) ~0U >> 1)) != (1U << (USHRT_WIDTH - 1)) + || stdc_bit_ceil_ui (~0U >> 1) != (1U << (UINT_WIDTH - 1)) + || stdc_bit_ceil (1U << (UINT_WIDTH - 1)) != (1U << (UINT_WIDTH - 1)) + || stdc_bit_ceil_ul (~0UL >> 1) != (1UL << (ULONG_WIDTH - 1)) + || stdc_bit_ceil (~0UL >> 1) != (1UL << (ULONG_WIDTH - 1)) + || stdc_bit_ceil_ull (1ULL << (ULLONG_WIDTH - 1)) != (1ULL << (ULLONG_WIDTH - 1)) + || stdc_bit_ceil (~0ULL >> 1) != (1ULL << (ULLONG_WIDTH - 1))) + abort (); + if (stdc_bit_ceil_uc ((unsigned char) 1) != 1 + || stdc_bit_ceil ((unsigned char) 2) != 2 + || stdc_bit_ceil_us ((unsigned short) 3U) != 4 + || stdc_bit_ceil ((unsigned short) 4U) != 4 + || stdc_bit_ceil_ui (5U) != 8U + || stdc_bit_ceil (269U) != 512U + || stdc_bit_ceil_ul (511UL) != 512UL + || stdc_bit_ceil (512UL) != 512UL + || stdc_bit_ceil_ull (513) != 1024ULL + || stdc_bit_ceil (1025ULL) != 2048ULL) + abort (); +}