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
+2 -2
View File
@@ -1,7 +1,7 @@
use std::{env, fs, io::Read, path::Path, process::Command};
fn main() {
let lib = "libclang_rt.builtins-riscv32.a";
let lib = "libclang_rt.builtins-riscv64.a";
let mut llvm_lib_dir = String::new();
Command::new("llvm-config")
@@ -16,7 +16,7 @@ fn main() {
let lib_path = std::path::PathBuf::from(llvm_lib_dir.trim())
.join("linux")
.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 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;
/// 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.
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 triple = "riscv32-unknown-unknown-elf"
; target datalayout = "e-m:e-p:32:32-i64:64-n32-S128"
; 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 {
%2 = tail call i256 @llvm.bswap.i256(i256 %0)
+3 -3
View File
@@ -1,7 +1,7 @@
{
"Computation": 5912,
"ERC20": 33512,
"Flipper": 3958,
"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 object_path = dir.path().join("out.o");
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:?}"))?;
@@ -58,7 +58,7 @@ pub fn link<T: AsRef<[u8]>>(input: T) -> anyhow::Result<Vec<u8>> {
"--library-path",
dir.path().to_str().expect("should be utf8"),
"--library",
"clang_rt.builtins-riscv32",
"clang_rt.builtins-riscv64",
linker_script_path.to_str().expect("should be utf8"),
object_path.to_str().expect("should be utf8"),
"-o",
@@ -24,10 +24,10 @@ pub struct TargetMachine {
impl TargetMachine {
/// The LLVM target name.
pub const VM_TARGET_NAME: &'static str = "riscv32";
pub const VM_TARGET_NAME: &'static str = "riscv64";
/// 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.
#[cfg(feature = "riscv-zbb")]
@@ -45,7 +45,7 @@ impl TargetMachine {
.ok_or_else(|| anyhow::anyhow!("LLVM target machine `{}` not found", target.name()))?
.create_target_machine(
&inkwell::targets::TargetTriple::create(target.triple()),
"generic-rv32",
"generic-rv64",
Self::VM_FEATURES,
optimizer_settings.level_back_end,
inkwell::targets::RelocMode::PIC,
@@ -19,7 +19,7 @@ impl Target {
///
pub fn name(&self) -> &str {
match self {
Self::PVM => "riscv32",
Self::PVM => "riscv64",
}
}
@@ -28,7 +28,7 @@ impl Target {
///
pub fn triple(&self) -> &str {
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> {
match string {
"riscv32" => Ok(Self::PVM),
"riscv64" => Ok(Self::PVM),
_ => Err(anyhow::anyhow!(
"Unknown target `{}`. Supported targets: {:?}",
string,
@@ -60,7 +60,7 @@ impl FromStr for Target {
impl std::fmt::Display for Target {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
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) {
let output = Command::new("clang")
.args([
"--target=riscv32",
"--target=riscv64",
"-Xclang",
"-triple=riscv32-unknown-unknown-elf",
"-march=rv32em",
"-mabi=ilp32e",
"-triple=riscv64-unknown-unknown-elf",
"-march=rv64em",
"-mabi=lp64e",
"-fno-exceptions",
"-ffreestanding",
"-Wall",