Blender V5.0
BLI_math_bits.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include "BLI_build_config.h"
12#include "BLI_math_inline.h"
13
14/* Search the value from LSB to MSB for a set bit. Returns index of this bit. */
15
16MINLINE int bitscan_forward_i(int a);
17MINLINE unsigned int bitscan_forward_uint(unsigned int a);
18MINLINE unsigned int bitscan_forward_uint64(unsigned long long a);
19
20/* Similar to above, but also clears the bit. */
21
23MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a);
24
25/* Search the value from MSB to LSB for a set bit. Returns index of this bit. */
26
27MINLINE int bitscan_reverse_i(int a);
28MINLINE unsigned int bitscan_reverse_uint(unsigned int a);
29MINLINE unsigned int bitscan_reverse_uint64(unsigned long long a);
30
31/* Similar to above, but also clears the bit. */
32
34MINLINE unsigned int bitscan_reverse_clear_uint(unsigned int *a);
35
36/* NOTE: Those functions returns 2 to the power of index of highest order bit. */
37
38MINLINE unsigned int highest_order_bit_uint(unsigned int n);
39MINLINE unsigned short highest_order_bit_s(unsigned short n);
40
41#if COMPILER_GCC || COMPILER_CLANG
42# define count_bits_i(i) __builtin_popcount(i)
43# define count_bits_uint64(i) __builtin_popcountll(i)
44#elif COMPILER_MSVC
45# define count_bits_i(i) __popcnt(i)
46# define count_bits_uint64(i) __popcnt64(i)
47#else
48MINLINE int count_bits_i(unsigned int n);
50#endif
51
52MINLINE int float_as_int(float f);
53MINLINE unsigned int float_as_uint(float f);
54MINLINE float int_as_float(int i);
55MINLINE float uint_as_float(unsigned int i);
56MINLINE float xor_fl(float x, int y);
57
58#if BLI_MATH_DO_INLINE
59# include "intern/math_bits_inline.cc" // IWYU pragma: export
60#endif
MINLINE int float_as_int(float f)
MINLINE unsigned int bitscan_forward_uint(unsigned int a)
MINLINE int bitscan_forward_clear_i(int *a)
MINLINE float xor_fl(float x, int y)
MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a)
MINLINE float int_as_float(int i)
MINLINE unsigned int float_as_uint(float f)
MINLINE unsigned int bitscan_reverse_uint(unsigned int a)
MINLINE int bitscan_reverse_clear_i(int *a)
MINLINE unsigned short highest_order_bit_s(unsigned short n)
MINLINE float uint_as_float(unsigned int i)
MINLINE int count_bits_uint64(uint64_t a)
MINLINE int bitscan_forward_i(int a)
MINLINE int count_bits_i(unsigned int n)
MINLINE unsigned int bitscan_forward_uint64(unsigned long long a)
MINLINE unsigned int bitscan_reverse_clear_uint(unsigned int *a)
MINLINE unsigned int highest_order_bit_uint(unsigned int n)
MINLINE int bitscan_reverse_i(int a)
MINLINE unsigned int bitscan_reverse_uint64(unsigned long long a)
#define MINLINE
unsigned long long int uint64_t
i
Definition text_draw.cc:230