Skip to content

refactor(cast): merge upcast and downcast implementation of felt252 c… - #1652

Merged
TomerStarkware merged 1 commit into
mainfrom
tomer/merge-upcast-and-downcast-implementation
Aug 5, 2026
Merged

refactor(cast): merge upcast and downcast implementation of felt252 c…#1652
TomerStarkware merged 1 commit into
mainfrom
tomer/merge-upcast-and-downcast-implementation

Conversation

@TomerStarkware

@TomerStarkware TomerStarkware commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

…anonicalization

Check downcast bounds against info.to_range instead of the destination type's range, and convert signed two's complement values to the canonical felt representation (negative = P - absolute) when downcasting to felt252, via a signed_to_felt252_repr helper shared with build_upcast.


This change is Reviewable

@TomerStarkware
TomerStarkware requested a review from orizi August 4, 2026 14:08
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

✅ Code is now correctly formatted.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 10.876 ± 0.042 10.783 10.957 5.65 ± 0.07
cairo-native (embedded AOT) 1.928 ± 0.023 1.902 1.958 1.00 ± 0.02
cairo-native (embedded JIT using LLVM's ORC Engine) 1.925 ± 0.023 1.883 1.962 1.00

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 561.3 ± 7.9 550.0 574.8 1.00
cairo-native (embedded AOT) 1703.7 ± 37.4 1654.4 1763.7 3.04 ± 0.08
cairo-native (embedded JIT using LLVM's ORC Engine) 1700.9 ± 18.9 1671.6 1725.2 3.03 ± 0.05

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.654 ± 0.017 4.634 4.686 2.69 ± 0.02
cairo-native (embedded AOT) 1.729 ± 0.021 1.703 1.767 1.00 ± 0.01
cairo-native (embedded JIT using LLVM's ORC Engine) 1.728 ± 0.011 1.714 1.745 1.00

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.817 ± 0.029 4.794 4.894 2.76 ± 0.07
cairo-native (embedded AOT) 1.745 ± 0.046 1.673 1.830 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 1.772 ± 0.021 1.734 1.799 1.02 ± 0.03

Benchmark for program linear_search

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 599.9 ± 5.0 591.3 606.4 1.00
cairo-native (embedded AOT) 1756.4 ± 26.5 1711.6 1795.1 2.93 ± 0.05
cairo-native (embedded JIT using LLVM's ORC Engine) 1794.5 ± 31.5 1763.3 1876.2 2.99 ± 0.06

Benchmark for program logistic_map

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 509.6 ± 19.0 492.6 559.5 1.00
cairo-native (embedded AOT) 1685.3 ± 39.4 1620.6 1732.5 3.31 ± 0.15
cairo-native (embedded JIT using LLVM's ORC Engine) 1716.2 ± 36.2 1679.0 1781.2 3.37 ± 0.14

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 1.845 ± 0.034 1.798 1.886 1.00
base dict_insert.cairo (AOT) 1.858 ± 0.022 1.828 1.893 1.01 ± 0.02

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 1.915 ± 0.061 1.829 1.981 1.00
head dict_insert.cairo (AOT) 1.937 ± 0.017 1.908 1.954 1.01 ± 0.03

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 1.652 ± 0.013 1.631 1.670 1.01 ± 0.01
base dict_snapshot.cairo (AOT) 1.630 ± 0.020 1.606 1.662 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 1.727 ± 0.013 1.701 1.754 1.02 ± 0.01
head dict_snapshot.cairo (AOT) 1.694 ± 0.007 1.687 1.704 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 1.683 ± 0.017 1.659 1.710 1.01 ± 0.01
base factorial_2M.cairo (AOT) 1.658 ± 0.008 1.650 1.672 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 1.783 ± 0.025 1.739 1.805 1.00
head factorial_2M.cairo (AOT) 1.797 ± 0.027 1.755 1.842 1.01 ± 0.02

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 1.628 ± 0.011 1.611 1.641 1.00
base fib_2M.cairo (AOT) 1.649 ± 0.022 1.620 1.700 1.01 ± 0.02

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 1.734 ± 0.033 1.687 1.788 1.00 ± 0.02
head fib_2M.cairo (AOT) 1.728 ± 0.025 1.690 1.778 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 1.721 ± 0.041 1.674 1.780 1.07 ± 0.03
base linear_search.cairo (AOT) 1.615 ± 0.010 1.599 1.629 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 1.745 ± 0.025 1.714 1.785 1.00 ± 0.02
head linear_search.cairo (AOT) 1.740 ± 0.016 1.722 1.768 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 1.661 ± 0.045 1.612 1.735 1.04 ± 0.03
base logistic_map.cairo (AOT) 1.598 ± 0.017 1.571 1.633 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 1.728 ± 0.014 1.697 1.740 1.01 ± 0.02
head logistic_map.cairo (AOT) 1.712 ± 0.028 1.685 1.775 1.00

…anonicalization

Check downcast bounds against info.to_range instead of the destination
type's range, and convert signed two's complement values to the canonical
felt representation (negative = P - absolute) when downcasting to felt252,
via a signed_to_felt252_repr helper shared with build_upcast.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@TomerStarkware
TomerStarkware force-pushed the tomer/merge-upcast-and-downcast-implementation branch from a9f2e88 to d796b82 Compare August 5, 2026 08:22

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@orizi reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

@TomerStarkware
TomerStarkware added this pull request to the merge queue Aug 5, 2026
Merged via the queue into main with commit 0aaf5bf Aug 5, 2026
15 checks passed
@TomerStarkware
TomerStarkware deleted the tomer/merge-upcast-and-downcast-implementation branch August 5, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants