refactor: share comparison-predicate selection across int libfuncs#1627
refactor: share comparison-predicate selection across int libfuncs#1627TomerStarkware wants to merge 1 commit into
Conversation
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 6 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on TomerStarkware).
src/libfuncs.rs line 558 at r1 (raw file):
/// biased to start at zero regardless of `L`'s sign — is stored as a /// non-negative integer and uses the unsigned variant. fn compare_predicate(
mix is strange - either return CmpiPredicate without getting it as input - or just let the function return a boolean asking if the value is stored as signed or as unsigned.
481a3e5 to
22033f3
Compare
Benchmarking resultsBenchmark for program
|
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
8.614 ± 0.067 | 8.555 | 8.782 | 5.69 ± 0.07 |
cairo-native (embedded AOT) |
1.513 ± 0.014 | 1.498 | 1.538 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.543 ± 0.039 | 1.503 | 1.639 | 1.02 ± 0.03 |
Benchmark for program dict_snapshot
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
431.7 ± 2.9 | 427.8 | 439.1 | 1.00 |
cairo-native (embedded AOT) |
1335.8 ± 12.4 | 1320.1 | 1362.7 | 3.09 ± 0.04 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1364.3 ± 32.2 | 1344.0 | 1452.2 | 3.16 ± 0.08 |
Benchmark for program factorial_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
3.929 ± 0.063 | 3.860 | 4.054 | 2.23 ± 0.05 |
cairo-native (embedded AOT) |
1.775 ± 0.020 | 1.749 | 1.808 | 1.01 ± 0.02 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.763 ± 0.029 | 1.733 | 1.823 | 1.00 |
Benchmark for program fib_2M
Open benchmarks
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
3.836 ± 0.085 | 3.781 | 4.070 | 2.84 ± 0.07 |
cairo-native (embedded AOT) |
1.353 ± 0.015 | 1.337 | 1.389 | 1.00 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1.390 ± 0.024 | 1.346 | 1.426 | 1.03 ± 0.02 |
Benchmark for program linear_search
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
473.0 ± 6.6 | 465.1 | 485.3 | 1.00 |
cairo-native (embedded AOT) |
1370.4 ± 18.2 | 1348.7 | 1396.4 | 2.90 ± 0.06 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1401.9 ± 23.2 | 1376.1 | 1432.7 | 2.96 ± 0.06 |
Benchmark for program logistic_map
Open benchmarks
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
Cairo-vm (Rust, Cairo 1) |
414.4 ± 4.7 | 404.6 | 419.8 | 1.00 |
cairo-native (embedded AOT) |
1532.5 ± 29.1 | 1499.4 | 1598.5 | 3.70 ± 0.08 |
cairo-native (embedded JIT using LLVM's ORC Engine) |
1650.7 ± 18.1 | 1629.7 | 1687.3 | 3.98 ± 0.06 |
Benchmark results Main vs HEAD.Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
Base
Head
|
22033f3 to
da05c0c
Compare
|
✅ Code is now correctly formatted. |
aef451b to
2db1a69
Compare
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware made 1 comment.
Reviewable status: 3 of 6 files reviewed, 1 unresolved discussion (waiting on orizi).
src/libfuncs.rs line 558 at r1 (raw file):
Previously, orizi wrote…
mix is strange - either return
CmpiPredicatewithout getting it as input - or just let the function return a boolean asking if the value is stored as signed or as unsigned.
Done.
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 4 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).
`int_range_try_new`, `int_range_pop_front`, and `bounded_int_constrain` each picked between signed/unsigned cmpi predicates with near-identical inline logic. Lift it into a `compare_predicate` helper on `src/libfuncs.rs` that takes the operand's `CoreTypeConcrete`, the registry, and the (signed, unsigned) predicate pair, and routes to whichever variant matches the stored representation: `i8..i128` is two's complement, while `u*` and `BoundedInt<L, U>` are stored as non-negative integers (the latter biased to start at zero regardless of `L`'s sign). Adds a VM-equivalence test (`int_range_try_new_bounded_int_negative_lower_vm_equivalence`) over `BoundedInt<-10, 10>` covering 7 input pairs around the 5-bit MSB threshold. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2db1a69 to
ac4fb91
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: 5 of 6 files reviewed, 1 unresolved discussion (waiting on TomerStarkware).
src/libfuncs/int_range.rs line 113 at r4 (raw file):
let x = entry.extract_value(context, location, range, inner_ty, 0)?; let k1 = entry.const_int_from_type(context, location, 1, inner_ty)?; let x_p_1 = entry.addi(x, k1, location)?;
delay addition and use Sle,Ule.
Summary
compare_predicatehelper insrc/libfuncs.rsthat picksthe signed or unsigned
cmpivariant from the operand's storedrepresentation (
i8..i128→ signed;u*andBoundedInt<L, U>→unsigned, since bounded ints are biased to start at zero).
int_range_try_new,int_range_pop_front, andbounded_int_constrainthrough the new helper, removing threenear-identical inline ladders.
BoundedInt<-10, 10>for
int_range_try_new, checking 7 input pairs against cairo-vm.This change is