-
Notifications
You must be signed in to change notification settings - Fork 65
Add u16/32/64 #206
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
Add u16/32/64 #206
Changes from all commits
f3eccf2
f2fd841
bcea818
dbbf721
85edebd
f636680
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use std::bits; | ||
use std::comparator; | ||
|
||
// u8 | ||
struct Uint8 { | ||
inner: Field, | ||
bit_len: Field, | ||
} | ||
|
||
fn Uint8.new(val: Field) -> Uint8 { | ||
let bit_len = 8; | ||
|
||
// range check | ||
let ignore_ = bits::to_bits(bit_len, val); | ||
|
||
return Uint8 { | ||
inner: val, | ||
bit_len: bit_len | ||
}; | ||
} | ||
|
||
// u16 | ||
struct Uint16 { | ||
inner: Field, | ||
bit_len: Field, | ||
} | ||
|
||
fn Uint16.new(val: Field) -> Uint16 { | ||
let bit_len = 16; | ||
|
||
// range check | ||
let ignore_ = bits::to_bits(bit_len, val); | ||
|
||
return Uint16 { | ||
inner: val, | ||
bit_len: bit_len | ||
}; | ||
} | ||
|
||
// u32 | ||
struct Uint32 { | ||
inner: Field, | ||
bit_len: Field, | ||
} | ||
|
||
fn Uint32.new(val: Field) -> Uint32 { | ||
let bit_len = 32; | ||
|
||
// range check | ||
let ignore_ = bits::to_bits(bit_len, val); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usually the syntax is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the current rule doesn't allow starting with |
||
|
||
return Uint32 { | ||
inner: val, | ||
bit_len: bit_len | ||
}; | ||
} | ||
|
||
// u64 | ||
struct Uint64 { | ||
inner: Field, | ||
bit_len: Field, | ||
} | ||
|
||
fn Uint64.new(val: Field) -> Uint64 { | ||
let bit_len = 64; | ||
|
||
// range check | ||
let ignore_ = bits::to_bits(bit_len, val); | ||
|
||
return Uint64 { | ||
inner: val, | ||
bit_len: bit_len | ||
}; | ||
} | ||
|
||
// implement comparator | ||
|
||
fn Uint8.less_than(self, rhs: Uint8) -> Bool { | ||
return comparator::less_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint8.less_eq_than(self, rhs: Uint8) -> Bool { | ||
return comparator::less_eq_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint16.less_than(self, rhs: Uint16) -> Bool { | ||
return comparator::less_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint16.less_eq_than(self, rhs: Uint16) -> Bool { | ||
return comparator::less_eq_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint32.less_than(self, rhs: Uint32) -> Bool { | ||
return comparator::less_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint32.less_eq_than(self, rhs: Uint32) -> Bool { | ||
return comparator::less_eq_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint64.less_than(self, rhs: Uint64) -> Bool { | ||
return comparator::less_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint64.less_eq_than(self, rhs: Uint64) -> Bool { | ||
return comparator::less_eq_than(self.bit_len, self.inner, rhs.inner); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should also implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To take it further, maybe we can make it support builtin operations, such as + -, by mapping these operations to these functions. #214 |
||
} |
Uh oh!
There was an error while loading. Please reload this page.