Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(p/uint256): uint256 #1778

Merged
merged 25 commits into from
Mar 29, 2024
Merged

feat(p/uint256): uint256 #1778

merged 25 commits into from
Mar 29, 2024

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Mar 15, 2024

original code from: https://github.com/holiman/uint256
gnoswap implementation: https://github.com/gnoswap-labs/gnoswap/tree/main/packages/big/uint256

ref: #1698 (comment)

here's the metrics for reference:

// gno test -v=true -print-runtime-metrics=true ./
=== RUN   TestAdd
--- PASS: TestAdd (0.00s)
---       runtime: cycle=25.9k imports=3 allocs=756.0k(0.15%)
=== RUN   TestSub
--- PASS: TestSub (0.00s)
---       runtime: cycle=54.7k imports=3 allocs=1.5M(0.30%)
=== RUN   TestMul
--- PASS: TestMul (0.00s)
---       runtime: cycle=76.5k imports=3 allocs=2.1M(0.42%)
=== RUN   TestDiv
--- PASS: TestDiv (0.00s)
---       runtime: cycle=87.6k imports=3 allocs=2.5M(0.50%)
=== RUN   TestMod
--- PASS: TestMod (0.00s)
---       runtime: cycle=100.8k imports=3 allocs=3.0M(0.59%)
=== RUN   TestDivMod
--- PASS: TestDivMod (0.00s)
---       runtime: cycle=128.8k imports=3 allocs=4.0M(0.80%)
=== RUN   TestNeg
--- PASS: TestNeg (0.00s)
---       runtime: cycle=203.1k imports=3 allocs=5.5M(1.10%)
=== RUN   TestExp
--- PASS: TestExp (0.00s)
---       runtime: cycle=356.9k imports=3 allocs=8.7M(1.73%)
=== RUN   TestOr
=== RUN   TestOr/all_zeros
--- PASS: TestOr/all_zeros (0.00s)
=== RUN   TestOr/all_ones
--- PASS: TestOr/all_ones (0.00s)
=== RUN   TestOr/mixed
--- PASS: TestOr/mixed (0.00s)
=== RUN   TestOr/one_operand_all_ones
--- PASS: TestOr/one_operand_all_ones (0.00s)
--- PASS: TestOr (0.00s)
---       runtime: cycle=364.2k imports=3 allocs=9.0M(1.80%)
=== RUN   TestAnd
=== RUN   TestAnd/all_zeros
--- PASS: TestAnd/all_zeros (0.00s)
=== RUN   TestAnd/all_ones
--- PASS: TestAnd/all_ones (0.00s)
=== RUN   TestAnd/mixed
--- PASS: TestAnd/mixed (0.00s)
=== RUN   TestAnd/mixed_2
--- PASS: TestAnd/mixed_2 (0.00s)
=== RUN   TestAnd/mixed_3
--- PASS: TestAnd/mixed_3 (0.00s)
=== RUN   TestAnd/one_operand_zero
--- PASS: TestAnd/one_operand_zero (0.00s)
=== RUN   TestAnd/one_operand_all_ones
--- PASS: TestAnd/one_operand_all_ones (0.00s)
--- PASS: TestAnd (0.00s)
---       runtime: cycle=376.6k imports=3 allocs=9.6M(1.92%)
=== RUN   TestNot
=== RUN   TestNot/all_zeros
--- PASS: TestNot/all_zeros (0.00s)
=== RUN   TestNot/all_ones
--- PASS: TestNot/all_ones (0.00s)
=== RUN   TestNot/mixed
--- PASS: TestNot/mixed (0.00s)
--- PASS: TestNot (0.00s)
---       runtime: cycle=381.2k imports=3 allocs=9.8M(1.97%)
=== RUN   TestAndNot
=== RUN   TestAndNot/all_zeros
--- PASS: TestAndNot/all_zeros (0.00s)
=== RUN   TestAndNot/all_ones
--- PASS: TestAndNot/all_ones (0.00s)
=== RUN   TestAndNot/mixed
--- PASS: TestAndNot/mixed (0.00s)
=== RUN   TestAndNot/mixed_2
--- PASS: TestAndNot/mixed_2 (0.00s)
=== RUN   TestAndNot/mixed_3
--- PASS: TestAndNot/mixed_3 (0.00s)
=== RUN   TestAndNot/one_operand_zero
--- PASS: TestAndNot/one_operand_zero (0.00s)
=== RUN   TestAndNot/one_operand_all_ones
--- PASS: TestAndNot/one_operand_all_ones (0.00s)
--- PASS: TestAndNot (0.00s)
---       runtime: cycle=393.6k imports=3 allocs=10.4M(2.08%)
=== RUN   TestXor
=== RUN   TestXor/all_zeros
--- PASS: TestXor/all_zeros (0.00s)
=== RUN   TestXor/all_ones
--- PASS: TestXor/all_ones (0.00s)
=== RUN   TestXor/mixed
--- PASS: TestXor/mixed (0.00s)
=== RUN   TestXor/mixed_2
--- PASS: TestXor/mixed_2 (0.00s)
=== RUN   TestXor/mixed_3
--- PASS: TestXor/mixed_3 (0.00s)
=== RUN   TestXor/one_operand_zero
--- PASS: TestXor/one_operand_zero (0.00s)
=== RUN   TestXor/one_operand_all_ones
--- PASS: TestXor/one_operand_all_ones (0.00s)
--- PASS: TestXor (0.00s)
---       runtime: cycle=406.0k imports=3 allocs=11.0M(2.20%)
=== RUN   TestLsh
--- PASS: TestLsh (0.00s)
---       runtime: cycle=531.2k imports=3 allocs=13.8M(2.77%)
=== RUN   TestRsh
--- PASS: TestRsh (0.00s)
---       runtime: cycle=636.1k imports=3 allocs=16.3M(3.25%)
=== RUN   TestCmp
--- PASS: TestCmp (0.00s)
---       runtime: cycle=647.6k imports=3 allocs=16.7M(3.34%)
=== RUN   TestIsZero
--- PASS: TestIsZero (0.00s)
---       runtime: cycle=650.3k imports=3 allocs=16.8M(3.36%)
=== RUN   TestLtUint64
--- PASS: TestLtUint64 (0.00s)
---       runtime: cycle=656.1k imports=3 allocs=17.0M(3.40%)
=== RUN   TestSGT
--- PASS: TestSGT (0.00s)
---       runtime: cycle=666.1k imports=3 allocs=17.2M(3.44%)
=== RUN   TestEq
--- PASS: TestEq (0.00s)
---       runtime: cycle=714.3k imports=3 allocs=18.2M(3.64%)
=== RUN   TestIsUint64
--- PASS: TestIsUint64 (0.00s)
---       runtime: cycle=719.5k imports=3 allocs=18.3M(3.67%)
=== RUN   TestDec
=== RUN   TestDec/zero
--- PASS: TestDec/zero (0.00s)
=== RUN   TestDec/less_than_20_digits
--- PASS: TestDec/less_than_20_digits (0.00s)
=== RUN   TestDec/max_possible_value
--- PASS: TestDec/max_possible_value (0.00s)
--- PASS: TestDec (0.00s)
---       runtime: cycle=735.2k imports=3 allocs=18.9M(3.78%)
ok      ./ 	0.61s

cc: @r3v4s @dongwon8247 @mconcat

@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Mar 15, 2024
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 44.82%. Comparing base (281815a) to head (347258a).
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1778      +/-   ##
==========================================
- Coverage   47.51%   44.82%   -2.70%     
==========================================
  Files         388      459      +71     
  Lines       61331    67677    +6346     
==========================================
+ Hits        29144    30337    +1193     
- Misses      29747    34798    +5051     
- Partials     2440     2542     +102     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@notJoon notJoon changed the title WIP: uint256 feat(p/uint256): uin256 Mar 27, 2024
@r3v4s r3v4s mentioned this pull request Mar 27, 2024
5 tasks
@notJoon notJoon marked this pull request as ready for review March 27, 2024 09:51
@notJoon notJoon requested review from a team as code owners March 27, 2024 09:51
@notJoon notJoon changed the title feat(p/uint256): uin256 feat(p/uint256): uint256 Mar 27, 2024
Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

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

Looks great 💯

Thank you for the addition 🙏

examples/gno.land/p/demo/uint256/uint256_test.gno Outdated Show resolved Hide resolved
@zivkovicmilos zivkovicmilos merged commit eb36ec9 into gnolang:master Mar 29, 2024
188 checks passed
@notJoon notJoon deleted the u256 branch March 29, 2024 03:53
zivkovicmilos pushed a commit that referenced this pull request Mar 29, 2024
This pr implements `int256` package to handle huge numbers in gno.
To support this, it uses `uint256` package in its own struct
> there is pr to bring holiman's uint256 into gno-vm #1778 

origin(go) implementation: https://github.com/mempooler/int256
gnoswap(gno) implementation:
[https://github.com/gnoswap-labs/gnoswap/package/big/int256](https://github.com/gnoswap-labs/gnoswap/tree/51439a5b097e6c523cb8a77b1a792b7f7aacb863/packages/big/int256
)

### gno test metrics
```bash
gno test -v=true -print-runtime-metrics=true ./examples/gno.land/p/demo/int256

=== RUN   TestAbs
--- PASS: TestAbs (0.00s)
---       runtime: cycle=30.5k imports=3 allocs=797.6k(0.16%)
=== RUN   TestAbsGt
--- PASS: TestAbsGt (0.00s)
---       runtime: cycle=108.7k imports=3 allocs=2.5M(0.50%)
=== RUN   TestAdd
--- PASS: TestAdd (0.00s)
---       runtime: cycle=155.2k imports=3 allocs=4.0M(0.79%)
=== RUN   TestSub
--- PASS: TestSub (0.00s)
---       runtime: cycle=259.1k imports=3 allocs=6.3M(1.26%)
=== RUN   TestMul
--- PASS: TestMul (0.00s)
---       runtime: cycle=278.4k imports=3 allocs=7.0M(1.39%)
=== RUN   TestDiv
--- PASS: TestDiv (0.00s)
---       runtime: cycle=307.6k imports=3 allocs=8.1M(1.62%)
=== RUN   TestRem
--- PASS: TestRem (0.00s)
---       runtime: cycle=342.8k imports=3 allocs=9.5M(1.90%)
=== RUN   TestEq
--- PASS: TestEq (0.00s)
---       runtime: cycle=422.1k imports=3 allocs=11.3M(2.25%)
=== RUN   TestCmp
--- PASS: TestCmp (0.00s)
---       runtime: cycle=466.7k imports=3 allocs=12.4M(2.47%)
=== RUN   TestIsZero
--- PASS: TestIsZero (0.00s)
---       runtime: cycle=471.3k imports=3 allocs=12.6M(2.51%)
=== RUN   TestIsNeg
--- PASS: TestIsNeg (0.00s)
---       runtime: cycle=476.6k imports=3 allocs=12.8M(2.56%)
=== RUN   TestLt
--- PASS: TestLt (0.00s)
---       runtime: cycle=522.7k imports=3 allocs=14.0M(2.79%)
=== RUN   TestClone
--- PASS: TestClone (0.00s)
---       runtime: cycle=565.1k imports=3 allocs=14.9M(2.98%)
=== RUN   TestSetInt64
--- PASS: TestSetInt64 (0.00s)
---       runtime: cycle=567.2k imports=3 allocs=15.0M(3.01%)
=== RUN   TestSetUint64
--- PASS: TestSetUint64 (0.00s)
---       runtime: cycle=568.3k imports=3 allocs=15.1M(3.02%)
=== RUN   TestUint64
--- PASS: TestUint64 (0.00s)
---       runtime: cycle=605.7k imports=3 allocs=16.0M(3.21%)
=== RUN   TestInt64
--- PASS: TestInt64 (0.00s)
---       runtime: cycle=624.5k imports=3 allocs=16.5M(3.31%)
=== RUN   TestNeg
--- PASS: TestNeg (0.00s)
---       runtime: cycle=636.2k imports=3 allocs=16.9M(3.38%)
=== RUN   TestSign
--- PASS: TestSign (0.00s)
---       runtime: cycle=639.4k imports=3 allocs=17.1M(3.41%)
ok      ./examples/gno.land/p/demo/int256 	0.59s
```

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [TODO] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [TODO] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants