Skip to content

Commit

Permalink
Merge pull request #119 from ethereum-optimism/tei/audit-16
Browse files Browse the repository at this point in the history
Rename toU64(), toU256() for consistency with other functions
  • Loading branch information
ImTei authored Jan 16, 2025
2 parents 3f1f5fc + 429e8cd commit 8355a95
Show file tree
Hide file tree
Showing 6 changed files with 410 additions and 410 deletions.
42 changes: 21 additions & 21 deletions rvgo/fast/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,74 @@ package fast
// These should 1:1 match with the same definitions in the slow package.

func parseImmTypeI(instr U64) U64 {
return signExtend64(shr64(toU64(20), instr), toU64(11))
return signExtend64(shr64(byteToU64(20), instr), byteToU64(11))
}

func parseImmTypeS(instr U64) U64 {
return signExtend64(
or64(
shl64(toU64(5), shr64(toU64(25), instr)),
and64(shr64(toU64(7), instr), toU64(0x1F)),
shl64(byteToU64(5), shr64(byteToU64(25), instr)),
and64(shr64(byteToU64(7), instr), byteToU64(0x1F)),
),
toU64(11))
byteToU64(11))
}

func parseImmTypeB(instr U64) U64 {
return signExtend64(
or64(
or64(
shl64(toU64(1), and64(shr64(toU64(8), instr), toU64(0xF))),
shl64(toU64(5), and64(shr64(toU64(25), instr), toU64(0x3F))),
shl64(byteToU64(1), and64(shr64(byteToU64(8), instr), byteToU64(0xF))),
shl64(byteToU64(5), and64(shr64(byteToU64(25), instr), byteToU64(0x3F))),
),
or64(
shl64(toU64(11), and64(shr64(toU64(7), instr), toU64(1))),
shl64(toU64(12), shr64(toU64(31), instr)),
shl64(byteToU64(11), and64(shr64(byteToU64(7), instr), byteToU64(1))),
shl64(byteToU64(12), shr64(byteToU64(31), instr)),
),
),
toU64(12),
byteToU64(12),
)
}

func parseImmTypeU(instr U64) U64 {
return signExtend64(shr64(toU64(12), instr), toU64(19))
return signExtend64(shr64(byteToU64(12), instr), byteToU64(19))
}

func parseImmTypeJ(instr U64) U64 {
return signExtend64(
or64(
or64(
and64(shr64(toU64(21), instr), shortToU64(0x3FF)), // 10 bits for index 0:9
shl64(toU64(10), and64(shr64(toU64(20), instr), toU64(1))), // 1 bit for index 10
and64(shr64(byteToU64(21), instr), shortToU64(0x3FF)), // 10 bits for index 0:9
shl64(byteToU64(10), and64(shr64(byteToU64(20), instr), byteToU64(1))), // 1 bit for index 10
),
or64(
shl64(toU64(11), and64(shr64(toU64(12), instr), toU64(0xFF))), // 8 bits for index 11:18
shl64(toU64(19), shr64(toU64(31), instr)), // 1 bit for index 19
shl64(byteToU64(11), and64(shr64(byteToU64(12), instr), byteToU64(0xFF))), // 8 bits for index 11:18
shl64(byteToU64(19), shr64(byteToU64(31), instr)), // 1 bit for index 19
),
),
toU64(19),
byteToU64(19),
)
}

func parseOpcode(instr U64) U64 {
return and64(instr, toU64(0x7F))
return and64(instr, byteToU64(0x7F))
}

func parseRd(instr U64) U64 {
return and64(shr64(toU64(7), instr), toU64(0x1F))
return and64(shr64(byteToU64(7), instr), byteToU64(0x1F))
}

func parseFunct3(instr U64) U64 {
return and64(shr64(toU64(12), instr), toU64(0x7))
return and64(shr64(byteToU64(12), instr), byteToU64(0x7))
}

func parseRs1(instr U64) U64 {
return and64(shr64(toU64(15), instr), toU64(0x1F))
return and64(shr64(byteToU64(15), instr), byteToU64(0x1F))
}

func parseRs2(instr U64) U64 {
return and64(shr64(toU64(20), instr), toU64(0x1F))
return and64(shr64(byteToU64(20), instr), byteToU64(0x1F))
}

func parseFunct7(instr U64) U64 {
return shr64(toU64(25), instr)
return shr64(byteToU64(25), instr)
}
Loading

0 comments on commit 8355a95

Please sign in to comment.