Add inplace variants for rz_bv_(un)signed_cast() (#6164)
This commit is contained in:
parent
f007f5f309
commit
995f73b1ad
3 changed files with 47 additions and 0 deletions
|
|
@ -144,7 +144,9 @@ RZ_API ut32 rz_bv_hash(RZ_NULLABLE RzBitVector *x);
|
|||
RZ_API RZ_OWN RzBitVector *rz_bv_pred(RZ_NONNULL RzBitVector *bv);
|
||||
RZ_API RZ_OWN RzBitVector *rz_bv_succ(RZ_NONNULL RzBitVector *bv);
|
||||
RZ_API bool rz_bv_arshift(RZ_NONNULL RzBitVector *bv, ut32 dist);
|
||||
RZ_API bool rz_bv_signed_cast_inplace(RZ_INOUT RZ_NONNULL RzBitVector *bv, ut32 to_size);
|
||||
RZ_API RZ_OWN RzBitVector *rz_bv_signed_cast(RZ_NONNULL RzBitVector *bv, ut32 to_size);
|
||||
RZ_API bool rz_bv_unsigned_cast_inplace(RZ_INOUT RZ_NONNULL RzBitVector *bv, ut32 to_size);
|
||||
RZ_API RZ_OWN RzBitVector *rz_bv_unsigned_cast(RZ_NONNULL RzBitVector *bv, ut32 to_size);
|
||||
|
||||
RZ_API bool rz_bv_slt(RZ_NONNULL RzBitVector *x, RZ_NONNULL RzBitVector *y);
|
||||
|
|
|
|||
|
|
@ -2312,6 +2312,16 @@ RZ_API RzBitVector *rz_bv_cast(RZ_NONNULL RzBitVector *bv, ut32 to_size, bool fi
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* signed cast of bv, (signed_cast x n) = (cast x n (msb x))
|
||||
* \param bv The vector which is cast in place. Its length changes.
|
||||
* \param to_size cast bitvector length
|
||||
* \return True if casting succeeded, false in case of failure.
|
||||
*/
|
||||
RZ_API bool rz_bv_signed_cast_inplace(RZ_INOUT RZ_NONNULL RzBitVector *bv, ut32 to_size) {
|
||||
return rz_bv_cast_inplace(bv, to_size, rz_bv_msb(bv));
|
||||
}
|
||||
|
||||
/**
|
||||
* signed cast of bv, (signed_cast x n) = (cast x n (msb x))
|
||||
* \param bv
|
||||
|
|
@ -2322,6 +2332,16 @@ RZ_API RZ_OWN RzBitVector *rz_bv_signed_cast(RZ_NONNULL RzBitVector *bv, ut32 to
|
|||
return rz_bv_cast(bv, to_size, rz_bv_msb(bv));
|
||||
}
|
||||
|
||||
/**
|
||||
* unsigned cast of bv, (signed_cast x n) = (cast x n 0)
|
||||
* \param bv The vector which is cast in place. Its length changes.
|
||||
* \param to_size cast bitvector length
|
||||
* \return True if casting succeeded, false in case of failure.
|
||||
*/
|
||||
RZ_API bool rz_bv_unsigned_cast_inplace(RZ_INOUT RZ_NONNULL RzBitVector *bv, ut32 to_size) {
|
||||
return rz_bv_cast_inplace(bv, to_size, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* unsigned cast of bv, (unsigned_cast x n) = (cast x n 0)
|
||||
* \param bv
|
||||
|
|
|
|||
|
|
@ -1603,6 +1603,31 @@ bool test_rz_bv_cast_inplace(void) {
|
|||
|
||||
rz_bv_free(small);
|
||||
rz_bv_free(large);
|
||||
|
||||
small = rz_bv_new_from_ut64(20, 0xe1234);
|
||||
mu_assert_true(rz_bv_unsigned_cast_inplace(small, 24), "Cast failed");
|
||||
mu_assert_eq(small->len, 24, "new size");
|
||||
mu_assert_streq_free(rz_bv_as_hex_string(small, false), "0xe1234", "unsigned cast inplace result");
|
||||
rz_bv_free(small);
|
||||
|
||||
small = rz_bv_new_from_ut64(20, 0x31234);
|
||||
mu_assert_true(rz_bv_unsigned_cast_inplace(small, 24), "Cast failed");
|
||||
mu_assert_eq(small->len, 24, "new size");
|
||||
mu_assert_streq_free(rz_bv_as_hex_string(small, false), "0x31234", "unsigned cast inplace result");
|
||||
rz_bv_free(small);
|
||||
|
||||
small = rz_bv_new_from_ut64(20, 0xe1234);
|
||||
mu_assert_true(rz_bv_signed_cast_inplace(small, 24), "Cast failed");
|
||||
mu_assert_eq(small->len, 24, "new size");
|
||||
mu_assert_streq_free(rz_bv_as_hex_string(small, false), "0xfe1234", "signed cast inplace result");
|
||||
rz_bv_free(small);
|
||||
|
||||
small = rz_bv_new_from_ut64(20, 0x31234);
|
||||
mu_assert_true(rz_bv_signed_cast_inplace(small, 24), "Cast failed");
|
||||
mu_assert_eq(small->len, 24, "new size");
|
||||
mu_assert_streq_free(rz_bv_as_hex_string(small, false), "0x31234", "signed cast inplace result");
|
||||
rz_bv_free(small);
|
||||
|
||||
mu_end;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue