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

add pvm instructions 5.10, 5.11, 5.12 #84

Merged
merged 9 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Blockchain/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let package = Package(
.package(path: "../Codec"),
.package(path: "../Utils"),
.package(path: "../TracingUtils"),
.package(path: "../PolkaVM"),
.package(url: "https://github.com/apple/swift-testing.git", branch: "0.10.0"),
],
targets: [
Expand All @@ -29,6 +30,7 @@ let package = Package(
dependencies: [
"Codec",
"Utils",
"PolkaVM",
"TracingUtils",
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension Ref where T == ProtocolConfig {
maxEncodedWorkReportSize: 96 * 1 << 10,
erasureCodedSegmentSize: 6,
ticketSubmissionEndSlot: 500,
pvmDynamicAddressAlignmentFactor: 4,
pvmDynamicAddressAlignmentFactor: 2,
pvmProgramInitInputDataSize: 1 << 24,
pvmProgramInitPageSize: 1 << 14,
pvmProgramInitSegmentSize: 1 << 16
Expand Down Expand Up @@ -70,7 +70,7 @@ extension Ref where T == ProtocolConfig {
maxEncodedWorkReportSize: 96 * 1 << 10,
erasureCodedSegmentSize: 6,
ticketSubmissionEndSlot: 500,
pvmDynamicAddressAlignmentFactor: 4,
pvmDynamicAddressAlignmentFactor: 2,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to use these in PolkaVM package, should I move this file to Utils or just move these pvm consts to PolkaVM

Copy link
Member

Choose a reason for hiding this comment

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

Try to see if we can use generic.

protocol PvmConfig {
  var pvmDynamicAddressAlignmentFactor: Int { get }
}

and

extension ProtocolConfig: PvmConfig {}

so that when testing PVM, we only need to create a PvmConfig, without get the whole ProtocolConfig in.

pvmProgramInitInputDataSize: 1 << 24,
pvmProgramInitPageSize: 1 << 14,
pvmProgramInitSegmentSize: 1 << 16
Expand Down
5 changes: 4 additions & 1 deletion Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PolkaVM
import Utils

// constants defined in the graypaper
Expand Down Expand Up @@ -94,7 +95,7 @@ public struct ProtocolConfig: Sendable {
// Y = 500: The number of slots into an epoch at which ticket-submission ends.
public var ticketSubmissionEndSlot: Int

// ZA = 4: The pvm dynamic address alignment factor.
// ZA = 2: The pvm dynamic address alignment factor.
public var pvmDynamicAddressAlignmentFactor: Int

// ZI = 2^24: The standard pvm program initialization input data size.
Expand Down Expand Up @@ -181,6 +182,8 @@ public struct ProtocolConfig: Sendable {

public typealias ProtocolConfigRef = Ref<ProtocolConfig>

extension ProtocolConfig: PvmConfig {}

extension ProtocolConfig {
public enum AuditTranchePeriod: ReadInt {
public typealias TConfig = ProtocolConfigRef
Expand Down
13 changes: 13 additions & 0 deletions PolkaVM/Sources/PolkaVM/Config.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public protocol PvmConfig {
// ZA = 2: The pvm dynamic address alignment factor.
var pvmDynamicAddressAlignmentFactor: Int { get }

// ZI = 2^24: The standard pvm program initialization input data size.
var pvmProgramInitInputDataSize: Int { get }

// ZP = 2^14: The standard pvm program initialization page size.
var pvmProgramInitPageSize: Int { get }

// ZQ = 2^16: The standard pvm program initialization segment size.
var pvmProgramInitSegmentSize: Int { get }
}
6 changes: 0 additions & 6 deletions PolkaVM/Sources/PolkaVM/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ public class Engine {

let res = inst.execute(state: state, skip: skip)

if state.pc == Constants.exitAddress {
// TODO: GP only defined this for `djump` but not `branch`
// so need to confirm this is correct
return .exit(.halt)
}

return res
}
}
57 changes: 57 additions & 0 deletions PolkaVM/Sources/PolkaVM/InstructionTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,63 @@ public class InstructionTable {
Instructions.BranchLeSImm.self,
Instructions.BranchGeSImm.self,
Instructions.BranchGtSImm.self,
Instructions.MoveReg.self,
Instructions.Sbrk.self,
Instructions.StoreIndU8.self,
Instructions.StoreIndU16.self,
Instructions.StoreIndU32.self,
Instructions.LoadIndU8.self,
Instructions.LoadIndI8.self,
Instructions.LoadIndU16.self,
Instructions.LoadIndI16.self,
Instructions.LoadIndU32.self,
Instructions.AddImm.self,
Instructions.AndImm.self,
Instructions.XorImm.self,
Instructions.OrImm.self,
Instructions.MulImm.self,
Instructions.MulUpperSSImm.self,
Instructions.MulUpperUUImm.self,
Instructions.SetLtUImm.self,
Instructions.SetLtSImm.self,
Instructions.ShloLImm.self,
Instructions.ShloRImm.self,
Instructions.SharRImm.self,
Instructions.NegAddImm.self,
Instructions.SetGtUImm.self,
Instructions.SetGtSImm.self,
Instructions.ShloLImmAlt.self,
Instructions.ShloRImmAlt.self,
Instructions.SharRImmAlt.self,
Instructions.CmovIzImm.self,
Instructions.CmovNzImm.self,
Instructions.BranchEq.self,
Instructions.BranchNe.self,
Instructions.BranchLtU.self,
Instructions.BranchLtS.self,
Instructions.BranchGeU.self,
Instructions.BranchGeS.self,
Instructions.LoadImmJumpInd.self,
Instructions.Add.self,
Instructions.Sub.self,
Instructions.And.self,
Instructions.Xor.self,
Instructions.Or.self,
Instructions.Mul.self,
Instructions.MulUpperSS.self,
Instructions.MulUpperUU.self,
Instructions.MulUpperSU.self,
Instructions.DivU.self,
Instructions.DivS.self,
Instructions.RemU.self,
Instructions.RemS.self,
Instructions.SetLtU.self,
Instructions.SetLtS.self,
Instructions.ShloL.self,
Instructions.ShloR.self,
Instructions.SharR.self,
Instructions.CmovIz.self,
Instructions.CmovNz.self,
]
var table: [Instruction.Type?] = Array(repeating: nil, count: 256)
for i in 0 ..< insts.count {
Expand Down
Loading
Loading