2
# tag: cpp, werror, cpp20
4
from libcpp cimport bool
5
from libc.stdint cimport uint8_t, int8_t
6
from libcpp.bit cimport (bit_cast, has_single_bit, bit_ceil, bit_floor,
7
bit_width, rotr, rotl, countl_zero, countl_one, countr_zero,
12
Test bit_cast with a signed 8bit wide integer type.
18
cdef result = bit_cast[uint8_t, int8_t](x)
21
def test_has_single_bit():
23
Test has_single_bit with a unsigned 8bit wide integer type.
24
>>> test_has_single_bit()
28
cdef bint res = has_single_bit[uint8_t](x)
33
Test bit_ceil with a unsigned 8bit wide integer type.
38
cdef uint8_t res = bit_ceil[uint8_t](x)
43
Test bit_floor with a unsigned 8bit wide integer type.
48
cdef uint8_t res = bit_floor[uint8_t](x)
53
Test bit_width with a unsigned 8bit wide integer type.
58
cdef int res = bit_width[uint8_t](x)
63
Test rotl with a unsigned 8bit wide integer type.
69
cdef uint8_t res = rotl[uint8_t](x, s)
74
Test rotr with a unsigned 8bit wide integer type.
80
cdef uint8_t res = rotr[uint8_t](x, s)
83
def test_countl_zero():
85
Test countl_zero with a unsigned 8bit wide integer type.
86
>>> test_countl_zero()
90
cdef int res = countl_zero[uint8_t](x)
93
def test_countr_zero():
95
Test countr_zero with a unsigned 8bit wide integer type.
96
>>> test_countr_zero()
100
cdef int res = countr_zero[uint8_t](x)
103
def test_countl_one():
105
Test countl_one with a unsigned 8bit wide integer type.
106
>>> test_countl_one()
110
cdef int res = countl_one[uint8_t](x)
113
def test_countr_one():
115
Test countr_one with a unsigned 8bit wide integer type.
116
>>> test_countr_one()
120
cdef int res = countr_one[uint8_t](x)
125
Test popcount with a unsigned 8bit wide integer type.
130
cdef int res = popcount[uint8_t](x)