8 #define NELEM(N, ELEMPER) ((N + (ELEMPER)-1) / (ELEMPER))
9 #define BV_ELEM_SIZE 8U
13 #define reverse_byte(x) ((((x)*0x0802LU & 0x22110LU) | ((x)*0x8020LU & 0x88440LU)) * 0x10101LU >> 16)
23 for (
v >>= 1;
v;
v >>= 1) {
48 bv->bits.large_a =
tmp;
49 bv->_elem_len = real_elem_cnt;
61 free(bv->bits.large_a);
106 for (
ut32 i = bv->len - 1, j = 0;
i > 0; --
i, j++) {
126 char format[32] = { 0 };
134 const char *
hex =
"0123456789abcdef";
135 size_t str_len = (bv->_elem_len << 1) + 3;
144 for (
ut32 i = 0;
i < bv->_elem_len;
i++) {
145 ut8 b8 = bv->bits.large_a[bv->_elem_len -
i - 1];
152 if (
pad || low ||
i == bv->_elem_len - 1) {
189 if (
dst->len !=
src->len) {
191 }
else if (
dst->len <= 64) {
192 dst->bits.small_u =
src->bits.small_u;
193 return sizeof(
dst->bits.small_u);
198 return dst->_elem_len;
214 (
dst->len - dst_start_pos));
217 if (max_nbit < nbit) {
222 for (
ut32 i = 0;
i < nbit; ++
i) {
239 ut32 new_len = bv->len + delta_len;
245 for (
ut32 i = 0;
i < bv->len; ++
i) {
261 ut32 new_len = bv->len + delta_len;
284 ut32 new_len = bv->len - delta_len;
306 ut32 new_len = bv->len - delta_len;
313 for (
pos = 0,
i = delta_len;
pos < new_len; ++
i, ++
pos) {
345 bv->bits.small_u |= (1ull <<
pos);
347 bv->bits.small_u &= ~(1ull <<
pos);
371 bv->bits.small_u =
b ?
UT64_MAX >> (64 - bv->len) : 0;
377 memset(bv->bits.large_a, 0xff, bv->_elem_len);
383 memset(bv->bits.large_a, 0, bv->_elem_len);
399 bool new_bit = !cur_bit;
413 bv->bits.small_u = ~(bv->bits.small_u);
417 for (
ut32 i = 0;
i < bv->_elem_len; ++
i) {
418 bv->bits.large_a[
i] = ~(bv->bits.large_a[
i]);
432 return (bv->bits.small_u >>
pos) & 1;
477 if (
size >= bv->len) {
489 if (copied_size == 0) {
516 if (
size >= bv->len) {
528 if (copied_size == 0) {
548 if (
x->len != y->len) {
555 }
else if (
x->len <= 64) {
575 if (
x->len != y->len) {
582 }
else if (
x->len <= 64) {
602 if (
x->len != y->len) {
609 }
else if (
x->len <= 64) {
631 }
else if (ret->
len <= 64) {
641 for (
ut32 i = 0;
i < bv->_elem_len; ++
i) {
660 for (
i = 0;
i < bv->len; ++
i) {
668 for (;
i < bv->len; ++
i) {
686 if (
x->len != y->len) {
691 bool a =
false,
b =
false, _carry =
false;
698 _carry = ((
a &
b) | (
a & _carry)) | (
b & _carry);
738 bool cur_bit =
false;
740 if (
x->len != y->len) {
754 for (
ut32 i = 0;
i < y->len; ++
i) {
778 if (
x->len != y->len) {
791 return x_bit ? 1 : -1;
824 if (compare_result < 0) {
829 if (compare_result == 0) {
900 if ((!mx) && (!my)) {
959 if ((!mx) && (!my)) {
1025 return x->bits.small_u == 0;
1030 for (
ut32 i = 0;
i <
x->_elem_len; ++
i) {
1031 if (
x->bits.large_a[
i] != 0) {
1069 if (x_msb == y_msb) {
1089 if (
x->len != y->len) {
1094 for (
ut32 i = 0;
i <
x->len; ++
i) {
1152 return (bv->len + 7) >> 3;
1166 RZ_LOG_ERROR(
"RzIL: failed to allocate RzBitVector\n");
1184 RZ_LOG_ERROR(
"RzIL: failed to allocate RzBitVector\n");
1225 if (bv->len <= 64) {
1226 bv->bits.small_u =
value;
1227 bv->bits.small_u &= (
UT64_MAX >> (64 - bv->len));
1231 for (
ut32 i = 0;
i < bv->len; ++
i) {
1245 if (bv->len <= 64) {
1247 bv->bits.small_u &= (
UT64_MAX >> (64 - bv->len));
1251 for (
ut32 i = 0;
i < bv->len; ++
i) {
1268 if (!bit_offset &&
size <= 64) {
1277 for (
ut32 i = 0;
i < bv->len;
i++) {
1281 ut32 sh = (bit_offset +
i) & 7;
1300 for (
ut32 i = 0;
i < bv->len;
i++) {
1304 ut32 sh = ((bit_offset +
i) & 7);
1307 bit = (b8 >> sh) & 1;
1323 if (
i + 1 ==
bytes && bv->len % 8) {
1324 buf[
i] &= (0xff << (bv->len % 8)) & 0xff;
1325 buf[
i] |= bv->bits.large_a[
i];
1327 buf[
i] = bv->bits.large_a[
i];
1334 if (
i + 1 ==
bytes && bv->len % 8) {
1335 buf[
i] &= (0xff << (bv->len % 8)) & 0xff;
1355 buf[
end -
i] = bv->bits.large_a[
i];
1378 ut32 size = (
x->len > 64) ?
x->_elem_len :
sizeof(
x->bits.small_u);
1379 ut8 *
bits = (
x->len > 64) ?
x->bits.large_a : (
ut8 *)&
x->bits.small_u;
1403 for (
ut32 i = 0;
i <
x->len &&
i < 8; ++
i) {
1422 for (
ut32 i = 0;
i <
x->len &&
i < 16; ++
i) {
1441 for (
ut32 i = 0;
i <
x->len &&
i < 32; ++
i) {
1457 return x->bits.small_u;
1460 for (
ut32 i = 0;
i <
x->len &&
i < 64; ++
i) {
static RZ_NULLABLE RzILOpBitVector * shift(RzILOpBitVector *val, RZ_NULLABLE RzILOpBool **carry_out, arm_shifter type, RZ_OWN RzILOpBitVector *dist)
RZ_API RZ_OWN RzBitVector * rz_bv_add(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y, RZ_NULLABLE bool *carry)
RZ_API RZ_OWN RzBitVector * rz_bv_dup(const RZ_NONNULL RzBitVector *bv)
RZ_API bool rz_bv_lsb(RZ_NONNULL RzBitVector *bv)
RZ_API RZ_OWN RzBitVector * rz_bv_append(RZ_NONNULL RzBitVector *high, RZ_NONNULL RzBitVector *low)
RZ_API ut32 rz_bv_ctz(RZ_NONNULL RzBitVector *bv)
RZ_API ut32 rz_bv_copy(RZ_NONNULL const RzBitVector *src, RZ_NONNULL RzBitVector *dst)
#define NELEM(N, ELEMPER)
RZ_API RZ_OWN RzBitVector * rz_bv_prepend_zero(RZ_NONNULL RzBitVector *bv, ut32 delta_len)
RZ_API RZ_OWN RzBitVector * rz_bv_or(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API bool rz_bv_set_from_ut64(RZ_NONNULL RzBitVector *bv, ut64 value)
RZ_API void rz_bv_free(RZ_NULLABLE RzBitVector *bv)
RZ_API bool rz_bv_ule(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API bool rz_bv_lshift_fill(RZ_NONNULL RzBitVector *bv, ut32 size, bool fill_bit)
RZ_API bool rz_bv_cmp(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API void rz_bv_set_from_bytes_le(RZ_NONNULL RzBitVector *bv, RZ_IN RZ_NONNULL const ut8 *buf, ut32 bit_offset, ut32 size)
RZ_API void rz_bv_fini(RZ_NONNULL RzBitVector *bv)
Clear a RzBitVector structure.
RZ_API void rz_bv_set_to_bytes_le(RZ_NONNULL const RzBitVector *bv, RZ_OUT RZ_NONNULL ut8 *buf)
Set the buffer contents from the given bitvector's bits in little endian format.
RZ_API bool rz_bv_sle(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API ut64 rz_bv_to_ut64(RZ_NONNULL const RzBitVector *x)
RZ_API ut32 rz_bv_len(RZ_NONNULL const RzBitVector *bv)
RZ_API bool rz_bv_toggle(RZ_NONNULL RzBitVector *bv, ut32 pos)
RZ_API bool rz_bv_is_zero_vector(RZ_NONNULL const RzBitVector *x)
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_st64(ut32 length, st64 value)
RZ_API RZ_OWN RzBitVector * rz_bv_mod(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API bool rz_bv_set_all(RZ_NONNULL RzBitVector *bv, bool b)
RZ_API bool rz_bv_lshift(RZ_NONNULL RzBitVector *bv, ut32 size)
RZ_API ut32 rz_bv_to_ut32(RZ_NONNULL const RzBitVector *x)
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_ut64(ut32 length, ut64 value)
RZ_API ut8 rz_bv_to_ut8(RZ_NONNULL const RzBitVector *x)
RZ_API RZ_OWN char * rz_bv_as_string(RZ_NONNULL RzBitVector *bv)
RZ_API void rz_bv_set_from_bytes_be(RZ_NONNULL RzBitVector *bv, RZ_IN RZ_NONNULL const ut8 *buf, ut32 bit_offset, ut32 size)
Set the bitvector's contents from the given bits. The bitvector's size is unchanged....
RZ_API bool rz_bv_toggle_all(RZ_NONNULL RzBitVector *bv)
RZ_API RZ_OWN RzBitVector * rz_bv_cut_tail(RZ_NONNULL RzBitVector *bv, ut32 delta_len)
RZ_API ut32 rz_bv_hash(RZ_NULLABLE RzBitVector *x)
RZ_API ut32 rz_bv_len_bytes(RZ_NONNULL const RzBitVector *bv)
RZ_API RZ_OWN RzBitVector * rz_bv_complement_2(RZ_NONNULL RzBitVector *bv)
RZ_API bool rz_bv_rshift(RZ_NONNULL RzBitVector *bv, ut32 size)
ut8 reverse_lt_8bits(ut8 x, ut8 w)
RZ_API RZ_OWN RzBitVector * rz_bv_xor(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API RZ_OWN RzBitVector * rz_bv_mul(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API bool rz_bv_msb(RZ_NONNULL RzBitVector *bv)
RZ_API RZ_OWN RzBitVector * rz_bv_and(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API bool rz_bv_get(RZ_NONNULL const RzBitVector *bv, ut32 pos)
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_bytes_be(RZ_IN RZ_NONNULL const ut8 *buf, ut32 bit_offset, ut32 size)
RZ_API RZ_OWN RzBitVector * rz_bv_new(ut32 length)
RZ_API ut16 rz_bv_to_ut16(RZ_NONNULL const RzBitVector *x)
RZ_API ut32 rz_bv_clz(RZ_NONNULL RzBitVector *bv)
RZ_API bool rz_bv_set(RZ_NONNULL RzBitVector *bv, ut32 pos, bool b)
RZ_API RZ_OWN RzBitVector * rz_bv_new_from_bytes_le(RZ_IN RZ_NONNULL const ut8 *buf, ut32 bit_offset, ut32 size)
RZ_API RZ_OWN RzBitVector * rz_bv_sub(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y, RZ_NULLABLE bool *borrow)
RZ_API RZ_OWN RzBitVector * rz_bv_complement_1(RZ_NONNULL RzBitVector *bv)
RZ_API bool rz_bv_rshift_fill(RZ_NONNULL RzBitVector *bv, ut32 size, bool fill_bit)
RZ_API RZ_OWN RzBitVector * rz_bv_sdiv(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API void rz_bv_set_to_bytes_be(RZ_NONNULL const RzBitVector *bv, RZ_OUT RZ_NONNULL ut8 *buf)
Set the buffer contents from the given bitvector's bits in big endian format.
int bv_unsigned_cmp(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API RZ_OWN RzBitVector * rz_bv_smod(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API RZ_OWN RzBitVector * rz_bv_append_zero(RZ_NONNULL RzBitVector *bv, ut32 delta_len)
RZ_API bool rz_bv_init(RZ_NONNULL RzBitVector *bv, ut32 length)
Initialize a RzBitVector structure.
RZ_API bool rz_bv_set_from_st64(RZ_NONNULL RzBitVector *bv, st64 value)
RZ_API ut32 rz_bv_copy_nbits(RZ_NONNULL const RzBitVector *src, ut32 src_start_pos, RZ_NONNULL RzBitVector *dst, ut32 dst_start_pos, ut32 nbit)
RZ_API RZ_OWN RzBitVector * rz_bv_cut_head(RZ_NONNULL RzBitVector *bv, ut32 delta_len)
RZ_API bool rz_bv_eq(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API RZ_OWN RzBitVector * rz_bv_div(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y)
RZ_API RZ_OWN char * rz_bv_as_hex_string(RZ_NONNULL RzBitVector *bv, bool pad)
int bits(struct state *s, int need)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
static const char hex[16]
static void pad(RzStrBuf *sb, ut32 count)
#define rz_warn_if_reached()
#define rz_return_if_fail(expr)
#define rz_return_val_if_fail(expr, val)
#define rz_return_val_if_reached(val)
#define rz_bv_new_zero(l)
#define RZ_LOG_ERROR(fmtstr,...)
static ut64 rz_num_bitmask(ut8 width)
Get the 64-bit value that has exactly its width lowest bits set to 1. e.g. rz_num_bitmask(2) == 0b11 ...
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
union bitvector_t::@303 bits
ut32 len
number of bits – virtual / logical
ut8 * large_a
little endian array of bytes for bitvectors > 64 bits whose size is defined in _elem_len
ut64 small_u
value of the bitvector when the size is <= 64 bits
ut32 _elem_len
length of ut8 array (bits.large_a) – real / physical
ut64(WINAPI *w32_GetEnabledXStateFeatures)()