Commit graph

6 commits

Author SHA1 Message Date
Anton Kochkov
689bafb7a4
Rewrite the RzNum parser and calculator on tree-sitter (#4326)
Replace the hand-written parser in calc.c with a tree-sitter grammar
(subprojects/rizin-math-parser) and a typed evaluator. The old parser
could only ever produce a ut64 and folded anything it failed to read to
0, which left callers unable to tell a failed expression from one that
evaluated to zero.

Expressions now evaluate to an RzNumValue, a tagged union over ut64,
double, RzBitVector, arbitrary-precision integer and arbitrary-precision
decimal, carrying an RzNumError rather than signalling failure as 0.
Literals keep the width they were written with (5u8, 0xffu128, any width
from 1 to 65536), results that outgrow 64 bits promote to a big number on
their own, and a parse error, division by zero or unresolved identifier
reaches the caller.

rz_num_math() is deprecated. rz_num_math_ut64() keeps its exact behaviour
for callers that want a ut64, and rz_num_math_value() exposes the typed
result. rz_core_math() adds the RzCore-backed form used by the % command,
with rz_core_math_ut64() deprecated alongside it. rz-ax routes through the
typed API, so it prints values at full precision, reports errors on stderr
and exits non-zero. rz_il_lift_num() converts an expression to an
RzILOpPure, so a numeric argument can be lifted instead of pre-evaluated.

Legacy input still works: trailing base suffixes (101b, 35o, 212t), the
trailing-'h' hex form and the k/m/g scale suffixes are all accepted and
warn once, pointing at the 0b/0o/0t prefixes. doc/math.md documents the
language and doc/math-il-lift.md the lift; the grammar, the evaluator,
rz-ax and the % command are covered by unit and db tests.
2026-07-24 02:57:27 +08:00
Anton Angelov
c186f1ec83
Enhance performance of rz_bv_copy_nbits (#5541)
* Add benchmark for rz_bv_copy_nbits
* Improve performance for large to large and small to small bitvector copy
* Fix bug with nbit=64 and simplify code
* Add test for same bitvector copy
* Move bit copy logic to separate function in rz_bits.h + improve comments
* Support same vector copy for unaligned case
* Expect non-null RzTable in bench utils and add comments
* Test against reference implementation instead of hardcoded values
2025-11-23 21:52:23 +08:00
Rot127
8197025e2f
Update contact information of Rot127. (#5522) 2025-11-10 17:15:15 +00:00
Rot127
fdc9ecbacc
Add several memory helpers (required for speed up of string search). (#5372)
* Add function to memcpy memory with offset.

* Add count trailing zeros function.

* Add function to determine pointer alignment.

* Add helper to swap sequences of 2 bytes.

* Add helper to swap sequences of 4 bytes.

* Print pointer in warning

* Fix tests

* Use uintptr_t type to prevent undefined behavior.

* Remove alignment requirement and rely on malloc promises.

* Add in place byte swap functions.

* Move the endianness swapping into util/rz_endian

* Use GNU builtin __builtin_ctzll/clzll.

Also fixes the include guards of __builtin_clzll
and handles the undefined case of x == 0 of it.

* Add doxygen
2025-09-17 00:07:44 +08:00
Rot127
8cae918f01 Add a helper function to spread value bits according to mask. 2025-08-20 22:31:02 +08:00
Rot127
e8db163d65
librz/util: add bit counting and address alignment calculation helper. (#4886)
* Add bit counting function.
* Add address padding calculating function.
* Add doxygen to rz_bits_count_X()
* Rename rz_bits_count -> rz_bits_count_ones
2025-02-10 00:42:54 +08:00