Skip to content

Commit

Permalink
Fix Shiftable trait to shift by u64. (FuelLabs#1604)
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerjohn authored May 19, 2022
1 parent 13467d9 commit 9cb14b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions sway-lib-core/src/ops.sw
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,18 @@ impl Mod for u8 {
}

pub trait Shiftable {
fn lsh(self, other: Self) -> Self;
fn rsh(self, other: Self) -> Self;
fn lsh(self, other: u64) -> Self;
fn rsh(self, other: u64) -> Self;
}

impl Shiftable for u64 {
fn lsh(self, other: Self) -> Self {
fn lsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
sll r3 r1 r2;
r3: u64
}
}
fn rsh(self, other: Self) -> Self {
fn rsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
srl r3 r1 r2;
r3: u64
Expand All @@ -221,13 +221,13 @@ impl Shiftable for u64 {
}

impl Shiftable for u32 {
fn lsh(self, other: Self) -> Self {
fn lsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
sll r3 r1 r2;
r3: u32
}
}
fn rsh(self, other: Self) -> Self {
fn rsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
srl r3 r1 r2;
r3: u32
Expand All @@ -236,13 +236,13 @@ impl Shiftable for u32 {
}

impl Shiftable for u16 {
fn lsh(self, other: Self) -> Self {
fn lsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
sll r3 r1 r2;
r3: u16
}
}
fn rsh(self, other: Self) -> Self {
fn rsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
srl r3 r1 r2;
r3: u16
Expand All @@ -251,13 +251,13 @@ impl Shiftable for u16 {
}

impl Shiftable for u8 {
fn lsh(self, other: Self) -> Self {
fn lsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
sll r3 r1 r2;
r3: u8
}
}
fn rsh(self, other: Self) -> Self {
fn rsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
srl r3 r1 r2;
r3: u8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pub trait Shiftable {
}

impl Shiftable for u64 {
fn lsh(self, other: Self) -> Self {
fn lsh(self, other: u64) -> Self {
asm(r1 : self, r2: other, r3) {
sll r3 r1 r2;
r3: u64
}
}

fn rsh(self, other: Self) -> Self {
fn rsh(self, other: u64) -> Self {
asm(r1 : self, r2: other, r3) {
srl r3 r1 r2;
r3: u64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ pub trait Shiftable {
}

impl Shiftable for u64 {
fn lsh(self, other: Self) -> Self {
fn lsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
sll r3 r1 r2;
r3: u64
}
}
fn rsh(self, other: Self) -> Self {
fn rsh(self, other: u64) -> Self {
asm(r1: self, r2: other, r3) {
srl r3 r1 r2;
r3: u64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ script;
// This bug was found by Nebula in discord. Adding this trait was causing other implementations on u64s to be overridden.

pub trait Shiftable {
fn lsh(self, other: Self) -> Self;
fn rsh(self, other: Self) -> Self;
fn lsh(self, other: u64) -> Self;
fn rsh(self, other: u64) -> Self;

}

impl Shiftable for u64 {
fn lsh(self, other: Self) -> Self {
fn lsh(self, other: u64) -> Self {
asm(r1 : self, r2: other, r3) {
sll r3 r1 r2;
r3: u64
}
}

fn rsh(self, other: Self) -> Self {
fn rsh(self, other: u64) -> Self {
asm(r1 : self, r2: other, r3) {
srl r3 r1 r2;
r3: u64
Expand Down

0 comments on commit 9cb14b5

Please sign in to comment.