-
Notifications
You must be signed in to change notification settings - Fork 131
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
Wide Arithmetic Support (128bit uint) #236
base: feature/uint128
Are you sure you want to change the base?
Conversation
|
||
class WideUint128DivU64(WideUint128): | ||
def __init__(self, lhs: WideUint128, arg: Expr): | ||
WideUint128.__init__(self, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahangsu Request for clarification: In the following scenarios, I think programs generated via PyTeal do not produce the intended on-chain results. It's quite possible I have gaps in my understanding. Can you double check me?
- Use
WideUint128DivU64
for subsequentWideUint128
arithmetic (e.g.+
).- Concern: The result is 1 uint64. Subsequent arithmetic operations assume a
WideUint128
produces 2 outputs (2 uint64).
- Concern: The result is 1 uint64. Subsequent arithmetic operations assume a
- Produce
WideUint128
withoutputNum=2
, and supply the value as argument to@Subroutine
.- Concern: I'm concerned only 1 of 2 stack values will be passed into the subroutine. I didn't fully vet the concern before raising. Trying to gauge if you've considered it before I go deeper.
After addressing the above concerns, taking a step back:
- Is the intent to provide a general purpose wide arithmetic API or to only provide the operations needed to use wide arithmetic operations for intermediate steps?
- It feels to me like the PR attempts to provide a general purpose wide arithmetic API. Though it's unclear to me that the goal is a general purpose API.
pyteal/ast/widemath.py
Outdated
# stack: [..., A, C, D, B] | ||
TealOp(expr, Op.uncover, 2), | ||
# stack: [..., A, C, B, D] | ||
TealOp(expr, Op.swap), | ||
# stack: [..., A, C, highword(B + D), lowword(B + D)] | ||
TealOp(expr, Op.addw), | ||
# stack: [..., lowword(B + D), A, C, highword(B + D)] | ||
TealOp(expr, Op.cover, 3), | ||
# stack: [..., lowword(B + D), highword(B + D), A, C] | ||
TealOp(expr, Op.cover, 2), | ||
# stack: [..., lowword(B + D), highword(B + D), A + C] | ||
TealOp(expr, Op.add), | ||
# stack: [..., lowword(B + D), highword(B + D) + A + C] | ||
TealOp(expr, Op.add), | ||
# stack: [..., highword(B + D) + A + C, lowword(B + D)] | ||
TealOp(expr, Op.swap), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that line 88 and line 94 are not needed here.
Summary
Provides a set of uint128 (essentially two uint64 values on stack) arithmetic support from 5 wide arithmetic opcodes:
addw
mulw
divw
divmodw
expw
Closes #101
Testing
Pending, currently only local testing, waiting on e2e semantics test.