experimentally switch to rv64

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-04-27 12:46:05 +02:00
parent 018d9f39fc
commit ea78e03348
11 changed files with 36 additions and 32 deletions
Generated
+7 -5
View File
@@ -1349,7 +1349,7 @@ dependencies = [
[[package]] [[package]]
name = "polkavm" name = "polkavm"
version = "0.9.3" version = "0.9.3"
source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea"
dependencies = [ dependencies = [
"libc", "libc",
"log", "log",
@@ -1361,7 +1361,7 @@ dependencies = [
[[package]] [[package]]
name = "polkavm-assembler" name = "polkavm-assembler"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea"
dependencies = [ dependencies = [
"log", "log",
] ]
@@ -1369,7 +1369,7 @@ dependencies = [
[[package]] [[package]]
name = "polkavm-common" name = "polkavm-common"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea"
dependencies = [ dependencies = [
"log", "log",
] ]
@@ -1377,7 +1377,7 @@ dependencies = [
[[package]] [[package]]
name = "polkavm-linker" name = "polkavm-linker"
version = "0.9.2" version = "0.9.2"
source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea"
dependencies = [ dependencies = [
"gimli", "gimli",
"hashbrown 0.14.3", "hashbrown 0.14.3",
@@ -1391,7 +1391,7 @@ dependencies = [
[[package]] [[package]]
name = "polkavm-linux-raw" name = "polkavm-linux-raw"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/koute/polkavm.git#4ca06cc1b7cb435b2b92e81e30c2eb0e988f563e" source = "git+https://github.com/xermicus/polkavm.git?branch=master_byteswap#73ab6d953c13de26ab75ed11707aa6d902ba47ea"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
@@ -1675,6 +1675,8 @@ dependencies = [
"polkavm", "polkavm",
"revive-differential", "revive-differential",
"revive-solidity", "revive-solidity",
"serde",
"serde_json",
"sha1", "sha1",
] ]
+3 -3
View File
@@ -27,9 +27,9 @@ path-slash = "0.2"
rayon = "1.8" rayon = "1.8"
structopt = { version = "0.3", default-features = false } structopt = { version = "0.3", default-features = false }
rand = "0.8" rand = "0.8"
polkavm-common = { git = "https://github.com/koute/polkavm.git" } polkavm-common = { branch = "master_byteswap", git = "https://github.com/xermicus/polkavm.git" }
polkavm-linker = { git = "https://github.com/koute/polkavm.git" } polkavm-linker = { branch = "master_byteswap", git = "https://github.com/xermicus/polkavm.git" }
polkavm = { git = "https://github.com/koute/polkavm.git" } polkavm = { branch = "master_byteswap", git = "https://github.com/xermicus/polkavm.git" }
alloy-primitives = "0.6" alloy-primitives = "0.6"
alloy-sol-types = "0.6" alloy-sol-types = "0.6"
env_logger = { version = "0.10.0", default-features = false } env_logger = { version = "0.10.0", default-features = false }
+3 -3
View File
@@ -37,7 +37,7 @@ cd ../compiler-rt
mkdir -p build mkdir -p build
cd build cd build
CFLAGS="--target=riscv32 -march=rv32em -mabi=ilp32e -nostdlib -nodefaultlibs -mcpu=generic-rv32" CFLAGS="--target=riscv64 -march=rv64em -mabi=lp64e -nostdlib -nodefaultlibs -mcpu=generic-rv64"
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
-DCOMPILER_RT_BUILD_BUILTINS=ON \ -DCOMPILER_RT_BUILD_BUILTINS=ON \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
@@ -46,8 +46,8 @@ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \ -DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \ -DCOMPILER_RT_BUILD_XRAY=OFF \
-DCMAKE_C_COMPILER=$INSTALL_DIR/bin/clang \ -DCMAKE_C_COMPILER=$INSTALL_DIR/bin/clang \
-DCMAKE_C_COMPILER_TARGET="riscv32" \ -DCMAKE_C_COMPILER_TARGET="riscv64" \
-DCMAKE_ASM_COMPILER_TARGET="riscv32" \ -DCMAKE_ASM_COMPILER_TARGET="riscv64" \
-DCMAKE_AR=$INSTALL_DIR/bin/llvm-ar \ -DCMAKE_AR=$INSTALL_DIR/bin/llvm-ar \
-DCMAKE_NM=$INSTALL_DIR/bin/llvm-nm \ -DCMAKE_NM=$INSTALL_DIR/bin/llvm-nm \
-DCMAKE_RANLIB=$INSTALL_DIR/bin/llvm-ranlib \ -DCMAKE_RANLIB=$INSTALL_DIR/bin/llvm-ranlib \
+2 -2
View File
@@ -1,7 +1,7 @@
use std::{env, fs, io::Read, path::Path, process::Command}; use std::{env, fs, io::Read, path::Path, process::Command};
fn main() { fn main() {
let lib = "libclang_rt.builtins-riscv32.a"; let lib = "libclang_rt.builtins-riscv64.a";
let mut llvm_lib_dir = String::new(); let mut llvm_lib_dir = String::new();
Command::new("llvm-config") Command::new("llvm-config")
@@ -16,7 +16,7 @@ fn main() {
let lib_path = std::path::PathBuf::from(llvm_lib_dir.trim()) let lib_path = std::path::PathBuf::from(llvm_lib_dir.trim())
.join("linux") .join("linux")
.join(lib); .join(lib);
let archive = fs::read(lib_path).expect("clang builtins for riscv32 not found"); let archive = fs::read(lib_path).expect("clang builtins for riscv64 not found");
let out_dir = env::var_os("OUT_DIR").expect("has OUT_DIR"); let out_dir = env::var_os("OUT_DIR").expect("has OUT_DIR");
let archive_path = Path::new(&out_dir).join(lib); let archive_path = Path::new(&out_dir).join(lib);
+1 -1
View File
@@ -9,7 +9,7 @@ pub const BYTE_LENGTH_BYTE: usize = 1;
pub const BYTE_LENGTH_X32: usize = 4; pub const BYTE_LENGTH_X32: usize = 4;
/// Native stack alignment size in bytes /// Native stack alignment size in bytes
pub const BYTE_LENGTH_STACK_ALIGN: usize = 4; pub const BYTE_LENGTH_STACK_ALIGN: usize = BYTE_LENGTH_X64;
/// The x86_64 word byte-length. /// The x86_64 word byte-length.
pub const BYTE_LENGTH_X64: usize = 8; pub const BYTE_LENGTH_X64: usize = 8;
+4 -2
View File
@@ -1,5 +1,7 @@
target datalayout = "e-m:e-p:32:32-i64:64-n32-S128" ; target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
target triple = "riscv32-unknown-unknown-elf" ; target triple = "riscv32-unknown-unknown-elf"
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64-unknown-unknown-elf"
define dso_local noundef i256 @__bswap(i256 noundef %0) local_unnamed_addr #0 { define dso_local noundef i256 @__bswap(i256 noundef %0) local_unnamed_addr #0 {
%2 = tail call i256 @llvm.bswap.i256(i256 %0) %2 = tail call i256 @llvm.bswap.i256(i256 %0)
+3 -3
View File
@@ -1,7 +1,7 @@
{ {
"Computation": 5912,
"ERC20": 33512,
"Flipper": 3958, "Flipper": 3958,
"Baseline": 3551, "Baseline": 3551,
"Fibonacci": 4909 "Computation": 5912,
"Fibonacci": 4909,
"ERC20": 1966
} }
+2 -2
View File
@@ -33,7 +33,7 @@ pub fn link<T: AsRef<[u8]>>(input: T) -> anyhow::Result<Vec<u8>> {
let output_path = dir.path().join("out.so"); let output_path = dir.path().join("out.so");
let object_path = dir.path().join("out.o"); let object_path = dir.path().join("out.o");
let linker_script_path = dir.path().join("linker.ld"); let linker_script_path = dir.path().join("linker.ld");
let compiler_rt_path = dir.path().join("libclang_rt.builtins-riscv32.a"); let compiler_rt_path = dir.path().join("libclang_rt.builtins-riscv64.a");
fs::write(&object_path, input).map_err(|msg| anyhow::anyhow!("{msg} {object_path:?}"))?; fs::write(&object_path, input).map_err(|msg| anyhow::anyhow!("{msg} {object_path:?}"))?;
@@ -58,7 +58,7 @@ pub fn link<T: AsRef<[u8]>>(input: T) -> anyhow::Result<Vec<u8>> {
"--library-path", "--library-path",
dir.path().to_str().expect("should be utf8"), dir.path().to_str().expect("should be utf8"),
"--library", "--library",
"clang_rt.builtins-riscv32", "clang_rt.builtins-riscv64",
linker_script_path.to_str().expect("should be utf8"), linker_script_path.to_str().expect("should be utf8"),
object_path.to_str().expect("should be utf8"), object_path.to_str().expect("should be utf8"),
"-o", "-o",
@@ -24,10 +24,10 @@ pub struct TargetMachine {
impl TargetMachine { impl TargetMachine {
/// The LLVM target name. /// The LLVM target name.
pub const VM_TARGET_NAME: &'static str = "riscv32"; pub const VM_TARGET_NAME: &'static str = "riscv64";
/// The LLVM target triple. /// The LLVM target triple.
pub const VM_TARGET_TRIPLE: &'static str = "riscv32-unknown-unknown-elf"; pub const VM_TARGET_TRIPLE: &'static str = "riscv64-unknown-unknown-elf";
/// LLVM target features. /// LLVM target features.
#[cfg(feature = "riscv-zbb")] #[cfg(feature = "riscv-zbb")]
@@ -45,7 +45,7 @@ impl TargetMachine {
.ok_or_else(|| anyhow::anyhow!("LLVM target machine `{}` not found", target.name()))? .ok_or_else(|| anyhow::anyhow!("LLVM target machine `{}` not found", target.name()))?
.create_target_machine( .create_target_machine(
&inkwell::targets::TargetTriple::create(target.triple()), &inkwell::targets::TargetTriple::create(target.triple()),
"generic-rv32", "generic-rv64",
Self::VM_FEATURES, Self::VM_FEATURES,
optimizer_settings.level_back_end, optimizer_settings.level_back_end,
inkwell::targets::RelocMode::PIC, inkwell::targets::RelocMode::PIC,
@@ -19,7 +19,7 @@ impl Target {
/// ///
pub fn name(&self) -> &str { pub fn name(&self) -> &str {
match self { match self {
Self::PVM => "riscv32", Self::PVM => "riscv64",
} }
} }
@@ -28,7 +28,7 @@ impl Target {
/// ///
pub fn triple(&self) -> &str { pub fn triple(&self) -> &str {
match self { match self {
Self::PVM => "riscv32-unknown-unknown-elf", Self::PVM => "riscv64-unknown-unknown-elf",
} }
} }
@@ -47,7 +47,7 @@ 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 {
"riscv32" => Ok(Self::PVM), "riscv64" => Ok(Self::PVM),
_ => Err(anyhow::anyhow!( _ => Err(anyhow::anyhow!(
"Unknown target `{}`. Supported targets: {:?}", "Unknown target `{}`. Supported targets: {:?}",
string, string,
@@ -60,7 +60,7 @@ 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 {
Target::PVM => write!(f, "riscv32"), Target::PVM => write!(f, "riscv64"),
} }
} }
} }
+4 -4
View File
@@ -3,11 +3,11 @@ use std::{env, fs, path::Path, process::Command};
fn compile(bitcode_path: &str) { fn compile(bitcode_path: &str) {
let output = Command::new("clang") let output = Command::new("clang")
.args([ .args([
"--target=riscv32", "--target=riscv64",
"-Xclang", "-Xclang",
"-triple=riscv32-unknown-unknown-elf", "-triple=riscv64-unknown-unknown-elf",
"-march=rv32em", "-march=rv64em",
"-mabi=ilp32e", "-mabi=lp64e",
"-fno-exceptions", "-fno-exceptions",
"-ffreestanding", "-ffreestanding",
"-Wall", "-Wall",