mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-07-25 03:35:43 +00:00
Switch target to 64bit and enable the zbb feature (#120)
This commit is contained in:
Generated
+532
-539
File diff suppressed because it is too large
Load Diff
+5
-5
@@ -51,10 +51,10 @@ path-slash = "0.2"
|
|||||||
rayon = "1.8"
|
rayon = "1.8"
|
||||||
clap = { version = "4", default-features = false, features = ["derive"] }
|
clap = { version = "4", default-features = false, features = ["derive"] }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
polkavm-common = "0.14"
|
polkavm-common = "0.17"
|
||||||
polkavm-linker = "0.14"
|
polkavm-linker = "0.17"
|
||||||
polkavm-disassembler = "0.14"
|
polkavm-disassembler = "0.17"
|
||||||
polkavm = "0.14"
|
polkavm = "0.17"
|
||||||
alloy-primitives = { version = "0.8", features = ["serde"] }
|
alloy-primitives = { version = "0.8", features = ["serde"] }
|
||||||
alloy-sol-types = "0.8"
|
alloy-sol-types = "0.8"
|
||||||
alloy-genesis = "0.3"
|
alloy-genesis = "0.3"
|
||||||
@@ -67,7 +67,7 @@ log = { version = "0.4" }
|
|||||||
# polkadot-sdk and friends
|
# polkadot-sdk and friends
|
||||||
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
codec = { version = "3.6.12", default-features = false, package = "parity-scale-codec" }
|
||||||
scale-info = { version = "2.11.1", default-features = false }
|
scale-info = { version = "2.11.1", default-features = false }
|
||||||
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "0449b214accd0f0fbf7ea3e8f3a8d8b7f99445e4" }
|
polkadot-sdk = { git = "https://github.com/paritytech/polkadot-sdk", rev = "447902eff4a574e66894ad60cb41999b05bf5e84" }
|
||||||
|
|
||||||
# llvm
|
# llvm
|
||||||
[workspace.dependencies.inkwell]
|
[workspace.dependencies.inkwell]
|
||||||
|
|||||||
@@ -17,56 +17,56 @@
|
|||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:--------|:------------------------|:-------------------------------- |
|
|:--------|:------------------------|:-------------------------------- |
|
||||||
| **`0`** | `5.97 us` (✅ **1.00x**) | `27.04 us` (❌ *4.53x slower*) |
|
| **`0`** | `3.36 us` (✅ **1.00x**) | `11.84 us` (❌ *3.52x slower*) |
|
||||||
|
|
||||||
### OddPorduct
|
### OddPorduct
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:-------------|:--------------------------|:-------------------------------- |
|
|:-------------|:-------------------------|:-------------------------------- |
|
||||||
| **`10000`** | `4.26 ms` (✅ **1.00x**) | `2.88 ms` (✅ **1.48x faster**) |
|
| **`10000`** | `3.11 ms` (✅ **1.00x**) | `1.53 ms` (🚀 **2.03x faster**) |
|
||||||
| **`100000`** | `42.37 ms` (✅ **1.00x**) | `28.35 ms` (✅ **1.49x faster**) |
|
| **`100000`** | `30.70 ms` (✅ **1.00x**) | `15.54 ms` (🚀 **1.98x faster**) |
|
||||||
| **`300000`** | `127.88 ms` (✅ **1.00x**) | `88.43 ms` (✅ **1.45x faster**) |
|
| **`300000`** | `92.68 ms` (✅ **1.00x**) | `45.47 ms` (🚀 **2.04x faster**) |
|
||||||
|
|
||||||
### TriangleNumber
|
### TriangleNumber
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:-------------|:--------------------------|:-------------------------------- |
|
|:-------------|:-------------------------|:-------------------------------- |
|
||||||
| **`10000`** | `2.85 ms` (✅ **1.00x**) | `2.37 ms` (✅ **1.20x faster**) |
|
| **`10000`** | `2.29 ms` (✅ **1.00x**) | `1.09 ms` (🚀 **2.11x faster**) |
|
||||||
| **`100000`** | `27.85 ms` (✅ **1.00x**) | `23.01 ms` (✅ **1.21x faster**) |
|
| **`100000`** | `22.84 ms` (✅ **1.00x**) | `10.66 ms` (🚀 **2.14x faster**) |
|
||||||
| **`360000`** | `103.01 ms` (✅ **1.00x**) | `83.66 ms` (✅ **1.23x faster**) |
|
| **`360000`** | `82.29 ms` (✅ **1.00x**) | `37.01 ms` (🚀 **2.22x faster**) |
|
||||||
|
|
||||||
### FibonacciRecursive
|
### FibonacciRecursive
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:---------|:--------------------------|:--------------------------------- |
|
|:---------|:--------------------------|:--------------------------------- |
|
||||||
| **`12`** | `195.19 us` (✅ **1.00x**) | `333.53 us` (❌ *1.71x slower*) |
|
| **`12`** | `135.67 us` (✅ **1.00x**) | `125.02 us` (✅ **1.09x faster**) |
|
||||||
| **`16`** | `1.22 ms` (✅ **1.00x**) | `1.97 ms` (❌ *1.62x slower*) |
|
| **`16`** | `903.75 us` (✅ **1.00x**) | `762.79 us` (✅ **1.18x faster**) |
|
||||||
| **`20`** | `8.14 ms` (✅ **1.00x**) | `13.20 ms` (❌ *1.62x slower*) |
|
| **`20`** | `6.12 ms` (✅ **1.00x**) | `4.96 ms` (✅ **1.23x faster**) |
|
||||||
| **`24`** | `55.09 ms` (✅ **1.00x**) | `88.56 ms` (❌ *1.61x slower*) |
|
| **`24`** | `42.05 ms` (✅ **1.00x**) | `33.86 ms` (✅ **1.24x faster**) |
|
||||||
|
|
||||||
### FibonacciIterative
|
### FibonacciIterative
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:----------|:-------------------------|:--------------------------------- |
|
|:----------|:-------------------------|:-------------------------------- |
|
||||||
| **`64`** | `33.39 us` (✅ **1.00x**) | `86.02 us` (❌ *2.58x slower*) |
|
| **`64`** | `15.04 us` (✅ **1.00x**) | `29.45 us` (❌ *1.96x slower*) |
|
||||||
| **`128`** | `52.91 us` (✅ **1.00x**) | `126.38 us` (❌ *2.39x slower*) |
|
| **`128`** | `26.36 us` (✅ **1.00x**) | `42.19 us` (❌ *1.60x slower*) |
|
||||||
| **`256`** | `82.33 us` (✅ **1.00x**) | `208.74 us` (❌ *2.54x slower*) |
|
| **`256`** | `48.61 us` (✅ **1.00x**) | `65.71 us` (❌ *1.35x slower*) |
|
||||||
|
|
||||||
### FibonacciBinet
|
### FibonacciBinet
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:----------|:-------------------------|:--------------------------------- |
|
|:----------|:-------------------------|:-------------------------------- |
|
||||||
| **`64`** | `32.29 us` (✅ **1.00x**) | `161.75 us` (❌ *5.01x slower*) |
|
| **`64`** | `15.22 us` (✅ **1.00x**) | `41.46 us` (❌ *2.72x slower*) |
|
||||||
| **`128`** | `36.02 us` (✅ **1.00x**) | `172.59 us` (❌ *4.79x slower*) |
|
| **`128`** | `17.05 us` (✅ **1.00x**) | `42.84 us` (❌ *2.51x slower*) |
|
||||||
| **`256`** | `41.21 us` (✅ **1.00x**) | `185.30 us` (❌ *4.50x slower*) |
|
| **`256`** | `19.00 us` (✅ **1.00x**) | `44.36 us` (❌ *2.34x slower*) |
|
||||||
|
|
||||||
### SHA1
|
### SHA1
|
||||||
|
|
||||||
| | `EVM` | `PVMInterpreter` |
|
| | `EVM` | `PVMInterpreter` |
|
||||||
|:----------|:--------------------------|:--------------------------------- |
|
|:----------|:--------------------------|:--------------------------------- |
|
||||||
| **`1`** | `160.17 us` (✅ **1.00x**) | `403.46 us` (❌ *2.52x slower*) |
|
| **`1`** | `110.04 us` (✅ **1.00x**) | `216.11 us` (❌ *1.96x slower*) |
|
||||||
| **`64`** | `286.69 us` (✅ **1.00x**) | `479.79 us` (❌ *1.67x slower*) |
|
| **`64`** | `209.04 us` (✅ **1.00x**) | `309.48 us` (❌ *1.48x slower*) |
|
||||||
| **`512`** | `1.18 ms` (✅ **1.00x**) | `1.37 ms` (❌ *1.16x slower*) |
|
| **`512`** | `903.65 us` (✅ **1.00x**) | `980.49 us` (✅ **1.09x slower**) |
|
||||||
|
|
||||||
---
|
---
|
||||||
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
|
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
|
||||||
|
|||||||
@@ -8,7 +8,4 @@ authors.workspace = true
|
|||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
description = "compiler builtins for the revive compiler"
|
description = "compiler builtins for the revive compiler"
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-64 = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
use std::{env, fs, io::Read, path::Path, process::Command};
|
use std::{env, fs, io::Read, path::Path, process::Command};
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv32.a";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
pub const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ description = "Shared constants of the revive compiler"
|
|||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-64 = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde = { workspace = true, features = ["derive"] }
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"Baseline": 961,
|
"Baseline": 1073,
|
||||||
"Computation": 4024,
|
"Computation": 2469,
|
||||||
"DivisionArithmetics": 31789,
|
"DivisionArithmetics": 15041,
|
||||||
"ERC20": 44214,
|
"ERC20": 23282,
|
||||||
"Events": 1737,
|
"Events": 1615,
|
||||||
"FibonacciIterative": 2929,
|
"FibonacciIterative": 1676,
|
||||||
"Flipper": 3402,
|
"Flipper": 2378,
|
||||||
"SHA1": 26003
|
"SHA1": 17076
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,6 @@ repository.workspace = true
|
|||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
description = "revive compiler linker utils"
|
description = "revive compiler linker utils"
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-64 = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
inkwell = { workspace = true }
|
inkwell = { workspace = true }
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
|
|||||||
@@ -8,14 +8,7 @@ SECTIONS {
|
|||||||
.text : { KEEP(*(.text.polkavm_export)) *(.text .text.*) }
|
.text : { KEEP(*(.text.polkavm_export)) *(.text .text.*) }
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv32.a";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
const BUILTINS_ARCHIVE_FILE: &str = "libclang_rt.builtins-riscv64.a";
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const BUILTINS_LIB_NAME: &str = "clang_rt.builtins-riscv32";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const BUILTINS_LIB_NAME: &str = "clang_rt.builtins-riscv64";
|
const BUILTINS_LIB_NAME: &str = "clang_rt.builtins-riscv64";
|
||||||
|
|
||||||
fn invoke_lld(cmd_args: &[&str]) -> bool {
|
fn invoke_lld(cmd_args: &[&str]) -> bool {
|
||||||
|
|||||||
@@ -13,15 +13,6 @@ description = "Shared front end code of the revive PolkaVM compilers"
|
|||||||
[lib]
|
[lib]
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-zbb = []
|
|
||||||
riscv-64 = [
|
|
||||||
"revive-linker/riscv-64",
|
|
||||||
"revive-builtins/riscv-64",
|
|
||||||
"revive-runtime-api/riscv-64",
|
|
||||||
"revive-common/riscv-64",
|
|
||||||
]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
semver = { workspace = true }
|
semver = { workspace = true }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/// The LLVM framework version.
|
/// The LLVM framework version.
|
||||||
pub const LLVM_VERSION: semver::Version = semver::Version::new(18, 1, 4);
|
pub const LLVM_VERSION: semver::Version = semver::Version::new(18, 1, 4);
|
||||||
|
|
||||||
/// The register width sized type
|
/// The pointer width sized type.
|
||||||
pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
pub static XLEN: usize = revive_common::BIT_LENGTH_X32;
|
||||||
|
|
||||||
/// The heap memory pointer pointer global variable name.
|
/// The heap memory pointer pointer global variable name.
|
||||||
|
|||||||
@@ -165,8 +165,9 @@ where
|
|||||||
|
|
||||||
fn link_immutable_data(&self, contract_path: &str) -> anyhow::Result<()> {
|
fn link_immutable_data(&self, contract_path: &str) -> anyhow::Result<()> {
|
||||||
let size = self.solidity().immutables_size() as u32;
|
let size = self.solidity().immutables_size() as u32;
|
||||||
let exports = revive_runtime_api::immutable_data::module(self.llvm(), size);
|
let immutables = revive_runtime_api::immutable_data::module(self.llvm(), size);
|
||||||
self.module.link_in_module(exports).map_err(|error| {
|
|
||||||
|
self.module.link_in_module(immutables).map_err(|error| {
|
||||||
anyhow::anyhow!(
|
anyhow::anyhow!(
|
||||||
"The contract `{}` immutable data module linking error: {}",
|
"The contract `{}` immutable data module linking error: {}",
|
||||||
contract_path,
|
contract_path,
|
||||||
@@ -202,6 +203,16 @@ where
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configure the revive datalayout.
|
||||||
|
fn set_data_layout(
|
||||||
|
llvm: &'ctx inkwell::context::Context,
|
||||||
|
module: &inkwell::module::Module<'ctx>,
|
||||||
|
) {
|
||||||
|
let source_module = revive_stdlib::module(llvm, "revive_stdlib").unwrap();
|
||||||
|
let data_layout = source_module.get_data_layout();
|
||||||
|
module.set_data_layout(&data_layout);
|
||||||
|
}
|
||||||
|
|
||||||
/// Initializes a new LLVM context.
|
/// Initializes a new LLVM context.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
llvm: &'ctx inkwell::context::Context,
|
llvm: &'ctx inkwell::context::Context,
|
||||||
@@ -211,6 +222,7 @@ where
|
|||||||
include_metadata_hash: bool,
|
include_metadata_hash: bool,
|
||||||
debug_config: DebugConfig,
|
debug_config: DebugConfig,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
Self::set_data_layout(llvm, &module);
|
||||||
Self::link_stdlib_module(llvm, &module);
|
Self::link_stdlib_module(llvm, &module);
|
||||||
Self::link_polkavm_imports(llvm, &module);
|
Self::link_polkavm_imports(llvm, &module);
|
||||||
Self::set_polkavm_stack_size(llvm, &module, Self::POLKAVM_STACK_SIZE);
|
Self::set_polkavm_stack_size(llvm, &module, Self::POLKAVM_STACK_SIZE);
|
||||||
@@ -261,7 +273,7 @@ where
|
|||||||
self.link_immutable_data(contract_path)?;
|
self.link_immutable_data(contract_path)?;
|
||||||
|
|
||||||
let target_machine = TargetMachine::new(Target::PVM, self.optimizer.settings())?;
|
let target_machine = TargetMachine::new(Target::PVM, self.optimizer.settings())?;
|
||||||
target_machine.set_target_data(self.module());
|
self.module().set_triple(&target_machine.get_triple());
|
||||||
|
|
||||||
self.debug_config
|
self.debug_config
|
||||||
.dump_llvm_ir_unoptimized(contract_path, self.module())?;
|
.dump_llvm_ir_unoptimized(contract_path, self.module())?;
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ where
|
|||||||
let is_success = context.builder().build_int_compare(
|
let is_success = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::EQ,
|
inkwell::IntPredicate::EQ,
|
||||||
success,
|
success,
|
||||||
context.xlen_type().const_zero(),
|
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
||||||
"is_success",
|
"is_success",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -139,8 +139,12 @@ where
|
|||||||
let arguments = &[
|
let arguments = &[
|
||||||
flags.as_basic_value_enum(),
|
flags.as_basic_value_enum(),
|
||||||
address_pointer.value.as_basic_value_enum(),
|
address_pointer.value.as_basic_value_enum(),
|
||||||
context.integer_const(64, 0).as_basic_value_enum(),
|
context
|
||||||
context.integer_const(64, 0).as_basic_value_enum(),
|
.integer_const(revive_common::BIT_LENGTH_X64, 0)
|
||||||
|
.as_basic_value_enum(),
|
||||||
|
context
|
||||||
|
.integer_const(revive_common::BIT_LENGTH_X64, 0)
|
||||||
|
.as_basic_value_enum(),
|
||||||
context.sentinel_pointer().value.as_basic_value_enum(),
|
context.sentinel_pointer().value.as_basic_value_enum(),
|
||||||
input_pointer.value.as_basic_value_enum(),
|
input_pointer.value.as_basic_value_enum(),
|
||||||
input_length.as_basic_value_enum(),
|
input_length.as_basic_value_enum(),
|
||||||
@@ -168,7 +172,7 @@ where
|
|||||||
let is_success = context.builder().build_int_compare(
|
let is_success = context.builder().build_int_compare(
|
||||||
inkwell::IntPredicate::EQ,
|
inkwell::IntPredicate::EQ,
|
||||||
success,
|
success,
|
||||||
context.xlen_type().const_zero(),
|
context.integer_const(revive_common::BIT_LENGTH_X64, 0),
|
||||||
"is_success",
|
"is_success",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|||||||
@@ -20,28 +20,16 @@ pub struct TargetMachine {
|
|||||||
|
|
||||||
impl TargetMachine {
|
impl TargetMachine {
|
||||||
/// The LLVM target name.
|
/// The LLVM target name.
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
pub const VM_TARGET_NAME: &'static str = "riscv32";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
pub const VM_TARGET_NAME: &'static str = "riscv64";
|
pub const VM_TARGET_NAME: &'static str = "riscv64";
|
||||||
|
|
||||||
/// The LLVM target triple.
|
/// The LLVM target triple.
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
pub const VM_TARGET_TRIPLE: &'static str = "riscv32-unknown-unknown-elf";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
pub const VM_TARGET_TRIPLE: &'static str = "riscv64-unknown-unknown-elf";
|
pub const VM_TARGET_TRIPLE: &'static str = "riscv64-unknown-unknown-elf";
|
||||||
|
|
||||||
/// The LLVM target cpu
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
pub const VM_TARGET_CPU: &'static str = "generic-rv32";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
pub const VM_TARGET_CPU: &'static str = "generic-rv64";
|
pub const VM_TARGET_CPU: &'static str = "generic-rv64";
|
||||||
|
|
||||||
/// LLVM target features.
|
/// LLVM target features.
|
||||||
#[cfg(feature = "riscv-zbb")]
|
pub const VM_FEATURES: &'static str =
|
||||||
pub const VM_FEATURES: &'static str = "+zbb,+a,+e,+m,+c,+fast-unaligned-access,+xtheadcondmov";
|
"+e,+m,+a,+c,+zbb,+auipc-addi-fusion,+ld-add-fusion,+lui-addi-fusion,+xtheadcondmov";
|
||||||
#[cfg(not(feature = "riscv-zbb"))]
|
|
||||||
pub const VM_FEATURES: &'static str = "+a,+e,+m,+c,+fast-unaligned-access,+xtheadcondmov";
|
|
||||||
|
|
||||||
/// A shortcut constructor.
|
/// A shortcut constructor.
|
||||||
/// A separate instance for every optimization level is created.
|
/// A separate instance for every optimization level is created.
|
||||||
@@ -70,12 +58,6 @@ impl TargetMachine {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the target-specific data in the module.
|
|
||||||
pub fn set_target_data(&self, module: &inkwell::module::Module) {
|
|
||||||
module.set_triple(&self.target_machine.get_triple());
|
|
||||||
module.set_data_layout(&self.target_machine.get_target_data().get_data_layout());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Writes the LLVM module to a memory buffer.
|
/// Writes the LLVM module to a memory buffer.
|
||||||
pub fn write_to_memory_buffer(
|
pub fn write_to_memory_buffer(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ impl Target {
|
|||||||
/// Returns the target name.
|
/// Returns the target name.
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
Self::PVM => "riscv32",
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
Self::PVM => "riscv64",
|
Self::PVM => "riscv64",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,9 +20,6 @@ impl Target {
|
|||||||
/// Returns the target triple.
|
/// Returns the target triple.
|
||||||
pub fn triple(&self) -> &str {
|
pub fn triple(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
Self::PVM => "riscv32-unknown-unknown-elf",
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
Self::PVM => "riscv64-unknown-unknown-elf",
|
Self::PVM => "riscv64-unknown-unknown-elf",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,9 +37,6 @@ impl FromStr for Target {
|
|||||||
|
|
||||||
fn from_str(string: &str) -> Result<Self, Self::Err> {
|
fn from_str(string: &str) -> Result<Self, Self::Err> {
|
||||||
match string {
|
match string {
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
"riscv32" => Ok(Self::PVM),
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
"riscv64" => Ok(Self::PVM),
|
"riscv64" => Ok(Self::PVM),
|
||||||
_ => Err(anyhow::anyhow!(
|
_ => Err(anyhow::anyhow!(
|
||||||
"Unknown target `{}`. Supported targets: {:?}",
|
"Unknown target `{}`. Supported targets: {:?}",
|
||||||
@@ -59,9 +50,6 @@ impl FromStr for Target {
|
|||||||
impl std::fmt::Display for Target {
|
impl std::fmt::Display for Target {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
Target::PVM => write!(f, "riscv32"),
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
Target::PVM => write!(f, "riscv64"),
|
Target::PVM => write!(f, "riscv64"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -55,7 +55,7 @@ pub const BOB: H160 = H160([2u8; 20]);
|
|||||||
/// The charlie test account
|
/// The charlie test account
|
||||||
pub const CHARLIE: H160 = H160([3u8; 20]);
|
pub const CHARLIE: H160 = H160([3u8; 20]);
|
||||||
/// Default gas limit
|
/// Default gas limit
|
||||||
pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000, 3 * 1024 * 1024);
|
pub const GAS_LIMIT: Weight = Weight::from_parts(100_000_000_000_000, 3 * 1024 * 1024 * 1024);
|
||||||
/// Default deposit limit
|
/// Default deposit limit
|
||||||
pub const DEPOSIT_LIMIT: Balance = 10_000_000;
|
pub const DEPOSIT_LIMIT: Balance = 10_000_000;
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ repository.workspace = true
|
|||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
description = "Implements the low level runtime API bindings with pallet contracts"
|
description = "Implements the low level runtime API bindings with pallet contracts"
|
||||||
|
|
||||||
[features]
|
|
||||||
riscv-64 = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm18-0"] }
|
inkwell = { workspace = true, features = ["target-riscv", "no-libffi-linking", "llvm18-0"] }
|
||||||
|
|||||||
@@ -1,23 +1,8 @@
|
|||||||
use std::{env, fs, path::Path, process::Command};
|
use std::{env, fs, path::Path, process::Command};
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const TARGET_TRIPLE_FLAG: &str = "-triple=riscv32-unknown-unknown-elf";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const TARGET_TRIPLE_FLAG: &str = "-triple=riscv64-unknown-unknown-elf";
|
const TARGET_TRIPLE_FLAG: &str = "-triple=riscv64-unknown-unknown-elf";
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const TARGET_FLAG: &str = "--target=riscv32";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const TARGET_FLAG: &str = "--target=riscv64";
|
const TARGET_FLAG: &str = "--target=riscv64";
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const TARGET_ARCH_FLAG: &str = "-march=rv32emac";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const TARGET_ARCH_FLAG: &str = "-march=rv64emac";
|
const TARGET_ARCH_FLAG: &str = "-march=rv64emac";
|
||||||
|
|
||||||
#[cfg(not(feature = "riscv-64"))]
|
|
||||||
const TARGET_ABI_FLAG: &str = "-mabi=ilp32e";
|
|
||||||
#[cfg(feature = "riscv-64")]
|
|
||||||
const TARGET_ABI_FLAG: &str = "-mabi=lp64e";
|
const TARGET_ABI_FLAG: &str = "-mabi=lp64e";
|
||||||
|
|
||||||
const IMPORTS_SOUCE: &str = "src/polkavm_imports.c";
|
const IMPORTS_SOUCE: &str = "src/polkavm_imports.c";
|
||||||
|
|||||||
@@ -52,29 +52,29 @@ pub fn instantiate(context: &Context) -> StructType {
|
|||||||
context.struct_type(
|
context.struct_type(
|
||||||
&[
|
&[
|
||||||
// code_hash_ptr: u32,
|
// code_hash_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// ref_time_limit: u64,
|
// ref_time_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// proof_size_limit: u64,
|
// proof_size_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// deposit_ptr: u32,
|
// deposit_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// value_ptr: u32,
|
// value_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_ptr: u32,
|
// input_data_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_len: u32,
|
// input_data_len: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// address_ptr: u32,
|
// address_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_ptr: u32,
|
// output_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_len_ptr: u32,
|
// output_len_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// salt_ptr: u32,
|
// salt_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
],
|
],
|
||||||
true,
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,25 +85,25 @@ pub fn call(context: &Context) -> StructType {
|
|||||||
// flags: u32,
|
// flags: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// address_ptr:
|
// address_ptr:
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// ref_time_limit: u64,
|
// ref_time_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// proof_size_limit: u64,
|
// proof_size_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// deposit_ptr: u32,
|
// deposit_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// value_ptr: u32,
|
// value_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_ptr: u32,
|
// input_data_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_len: u32,
|
// input_data_len: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_ptr: u32,
|
// output_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_len_ptr: u32,
|
// output_len_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
],
|
],
|
||||||
true,
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,22 +114,22 @@ pub fn delegate_call(context: &Context) -> StructType {
|
|||||||
// flags: u32,
|
// flags: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// address_ptr:
|
// address_ptr:
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// ref_time_limit: u64,
|
// ref_time_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// proof_size_limit: u64,
|
// proof_size_limit: u64,
|
||||||
context.i64_type().as_basic_type_enum(),
|
context.i64_type().as_basic_type_enum(),
|
||||||
// deposit_ptr: u32,
|
// deposit_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_ptr: u32,
|
// input_data_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// input_data_len: u32,
|
// input_data_len: u32,
|
||||||
context.i32_type().as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_ptr: u32,
|
// output_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
// output_len_ptr: u32,
|
// output_len_ptr: u32,
|
||||||
context.ptr_type(Default::default()).as_basic_type_enum(),
|
context.i32_type().as_basic_type_enum(),
|
||||||
],
|
],
|
||||||
true,
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,15 +74,15 @@ POLKAVM_IMPORT(void, block_hash, uint32_t, uint32_t)
|
|||||||
|
|
||||||
POLKAVM_IMPORT(void, block_number, uint32_t)
|
POLKAVM_IMPORT(void, block_number, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, call, uint32_t)
|
POLKAVM_IMPORT(uint64_t, call, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, delegate_call, uint32_t)
|
POLKAVM_IMPORT(uint64_t, delegate_call, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, caller, uint32_t)
|
POLKAVM_IMPORT(void, caller, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, chain_id, uint32_t)
|
POLKAVM_IMPORT(void, chain_id, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, code_size, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, code_size, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, code_hash, uint32_t, uint32_t)
|
||||||
|
|
||||||
@@ -90,13 +90,13 @@ POLKAVM_IMPORT(void, deposit_event, uint32_t, uint32_t, uint32_t, uint32_t)
|
|||||||
|
|
||||||
POLKAVM_IMPORT(void, get_immutable_data, uint32_t, uint32_t);
|
POLKAVM_IMPORT(void, get_immutable_data, uint32_t, uint32_t);
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, get_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint64_t, get_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, hash_keccak_256, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, hash_keccak_256, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, input, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, input, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, instantiate, uint32_t)
|
POLKAVM_IMPORT(uint64_t, instantiate, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, now, uint32_t)
|
POLKAVM_IMPORT(void, now, uint32_t)
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ POLKAVM_IMPORT(void, origin, uint32_t)
|
|||||||
|
|
||||||
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, seal_return, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(uint32_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(uint64_t, set_storage, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
POLKAVM_IMPORT(void, return_data_copy, uint32_t, uint32_t, uint32_t)
|
POLKAVM_IMPORT(void, return_data_copy, uint32_t, uint32_t, uint32_t)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
; Adapted from: https://github.com/matter-labs/era-compiler-llvm/blob/v1.4.0/llvm/lib/Target/EraVM/eravm-stdlib.ll
|
; Adapted from: https://github.com/matter-labs/era-compiler-llvm/blob/v1.4.0/llvm/lib/Target/EraVM/eravm-stdlib.ll
|
||||||
|
|
||||||
target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
|
target datalayout = "e-m:e-p:32:64-p1:32:64-i64:64-i128:128-n32:64-S64"
|
||||||
target triple = "riscv32-unknown-unknown-elf"
|
target triple = "riscv64-unknown-none-elf"
|
||||||
|
|
||||||
define i256 @__addmod(i256 %arg1, i256 %arg2, i256 %modulo) #4 {
|
define i256 @__addmod(i256 %arg1, i256 %arg2, i256 %modulo) #4 {
|
||||||
entry:
|
entry:
|
||||||
|
|||||||
Reference in New Issue
Block a user