Blender V5.3
BLI_math_bits.hh
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.hh"
12#include "BLI_math_inline.hh"
13#include "BLI_sys_types.hh"
14
15namespace blender {
16
17/* Search the value from LSB to MSB for a set bit. Returns index of this bit. */
18
19MINLINE int bitscan_forward_i(int a);
20MINLINE unsigned int bitscan_forward_uint(unsigned int a);
21MINLINE unsigned int bitscan_forward_uint64(unsigned long long a);
22
23/* Similar to above, but also clears the bit. */
24
26MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a);
28
29/* Search the value from MSB to LSB for a set bit. Returns index of this bit. */
30
31MINLINE int bitscan_reverse_i(int a);
32MINLINE unsigned int bitscan_reverse_uint(unsigned int a);
33MINLINE unsigned int bitscan_reverse_uint64(unsigned long long a);
34
35/* Similar to above, but also clears the bit. */
36
38MINLINE unsigned int bitscan_reverse_clear_uint(unsigned int *a);
39
40/* NOTE: Those functions returns 2 to the power of index of highest order bit. */
41
42MINLINE unsigned int highest_order_bit_uint(unsigned int n);
43MINLINE unsigned short highest_order_bit_s(unsigned short n);
44
45#if COMPILER_GCC || COMPILER_CLANG
46# define count_bits_i(i) __builtin_popcount(i)
47# define count_bits_uint64(i) __builtin_popcountll(i)
48#elif COMPILER_MSVC
49# define count_bits_i(i) __popcnt(i)
50# define count_bits_uint64(i) __popcnt64(i)
51#else
52MINLINE int count_bits_i(unsigned int n);
54#endif
55
56MINLINE int float_as_int(float f);
57MINLINE unsigned int float_as_uint(float f);
58MINLINE float int_as_float(int i);
59MINLINE float uint_as_float(unsigned int i);
60MINLINE float xor_fl(float x, int y);
61
62} // namespace blender
63
64#if BLI_MATH_DO_INLINE
65# include "intern/math_bits_inline.cc" // IWYU pragma: export
66#endif
#define MINLINE
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91
MINLINE unsigned int bitscan_forward_uint(unsigned int a)
MINLINE int count_bits_i(unsigned int n)
MINLINE unsigned int highest_order_bit_uint(unsigned int n)
MINLINE unsigned int float_as_uint(float f)
MINLINE unsigned int bitscan_forward_clear_uint64(uint64_t *a)
MINLINE int bitscan_forward_i(int a)
MINLINE int bitscan_reverse_clear_i(int *a)
MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a)
MINLINE int count_bits_uint64(uint64_t a)
MINLINE unsigned int bitscan_reverse_uint(unsigned int a)
MINLINE float int_as_float(int i)
MINLINE unsigned int bitscan_forward_uint64(unsigned long long a)
MINLINE unsigned short highest_order_bit_s(unsigned short n)
MINLINE unsigned int bitscan_reverse_clear_uint(unsigned int *a)
MINLINE float xor_fl(float x, int y)
MINLINE float uint_as_float(unsigned int i)
MINLINE int bitscan_forward_clear_i(int *a)
MINLINE unsigned int bitscan_reverse_uint64(unsigned long long a)
MINLINE int bitscan_reverse_i(int a)
MINLINE int float_as_int(float f)