mirror of
https://github.com/opnsense/src.git
synced 2026-07-15 04:01:09 -04:00
This new header complies with ISO/IEC 9899:2024 (C23). Contrary to glibc, we do not provide inline definitions in <stdbit.h> as we expect our system compiler to soon recognise these as builtins anyway. Relnotes: yes MFC after: 1 month Reviewed by: adrian Approved by: markj (mentor) Differential Revision: https://reviews.freebsd.org/D53657 (cherry picked from commit 6296500a85c8474e3ff3fe2f8e4a9d56dd0acd64)
53 lines
772 B
C
53 lines
772 B
C
/*
|
|
* Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <limits.h>
|
|
#include <stdbit.h>
|
|
|
|
unsigned int
|
|
stdc_bit_width_uc(unsigned char x)
|
|
{
|
|
if (x == 0)
|
|
return (0);
|
|
|
|
return (UINT_WIDTH - __builtin_clz(x));
|
|
}
|
|
|
|
unsigned int
|
|
stdc_bit_width_us(unsigned short x)
|
|
{
|
|
if (x == 0)
|
|
return (0);
|
|
|
|
return (UINT_WIDTH - __builtin_clz(x));
|
|
}
|
|
|
|
unsigned int
|
|
stdc_bit_width_ui(unsigned int x)
|
|
{
|
|
if (x == 0)
|
|
return (0);
|
|
|
|
return (UINT_WIDTH - __builtin_clz(x));
|
|
}
|
|
|
|
unsigned int
|
|
stdc_bit_width_ul(unsigned long x)
|
|
{
|
|
if (x == 0)
|
|
return (0);
|
|
|
|
return (ULONG_WIDTH - __builtin_clzl(x));
|
|
}
|
|
|
|
unsigned int
|
|
stdc_bit_width_ull(unsigned long long x)
|
|
{
|
|
if (x == 0)
|
|
return (0);
|
|
|
|
return (ULLONG_WIDTH - __builtin_clzll(x));
|
|
}
|