Blender V4.3
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
11#include "BLI_build_config.h"
12#include "BLI_math_inline.h"
13#include "BLI_utildefines.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/* Search the value from LSB to MSB for a set bit. Returns index of this bit. */
20
21MINLINE int bitscan_forward_i(int a);
22MINLINE unsigned int bitscan_forward_uint(unsigned int a);
23MINLINE unsigned int bitscan_forward_uint64(unsigned long long a);
24
25/* Similar to above, but also clears the bit. */
26
28MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a);
29
30/* Search the value from MSB to LSB for a set bit. Returns index of this bit. */
31
32MINLINE int bitscan_reverse_i(int a);
33MINLINE unsigned int bitscan_reverse_uint(unsigned int a);
34MINLINE unsigned int bitscan_reverse_uint64(unsigned long long a);
35
36/* Similar to above, but also clears the bit. */
37
39MINLINE unsigned int bitscan_reverse_clear_uint(unsigned int *a);
40
41/* NOTE: Those functions returns 2 to the power of index of highest order bit. */
42
43MINLINE unsigned int highest_order_bit_uint(unsigned int n);
44MINLINE unsigned short highest_order_bit_s(unsigned short n);
45
46#if COMPILER_GCC || COMPILER_CLANG
47# define count_bits_i(i) __builtin_popcount(i)
48# define count_bits_uint64(i) __builtin_popcountll(i)
49#elif COMPILER_MSVC
50# define count_bits_i(i) __popcnt(i)
51# define count_bits_uint64(i) __popcnt64(i)
52#else
53MINLINE int count_bits_i(unsigned int n);
55#endif
56
57MINLINE int float_as_int(float f);
58MINLINE unsigned int float_as_uint(float f);
59MINLINE float int_as_float(int i);
60MINLINE float uint_as_float(unsigned int i);
61MINLINE float xor_fl(float x, int y);
62
63#if BLI_MATH_DO_INLINE
65#endif
66
67#ifdef __cplusplus
68}
69#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 __int64 uint64_t
Definition stdint.h:90