From 187d9c6aca05f129cd71801488bb54a7aa4c3508 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 10 Jan 2023 20:55:29 +0100 Subject: [PATCH] riscv: use 16-byte alignment everywhere Source: https://riscv.org/wp-content/uploads/2015/01/riscv-calling.pdf --- src/runtime/arch_tinygoriscv.go | 6 ++++++ src/runtime/arch_tinygoriscv32.go | 5 ----- src/runtime/arch_tinygoriscv64.go | 5 ----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/runtime/arch_tinygoriscv.go b/src/runtime/arch_tinygoriscv.go index bec0821e..904ff5d4 100644 --- a/src/runtime/arch_tinygoriscv.go +++ b/src/runtime/arch_tinygoriscv.go @@ -6,6 +6,12 @@ import "device/riscv" const deferExtraRegs = 0 +// RISC-V has a maximum alignment of 16 bytes (both for RV32 and for RV64). +// Source: https://riscv.org/wp-content/uploads/2015/01/riscv-calling.pdf +func align(ptr uintptr) uintptr { + return (ptr + 15) &^ 15 +} + func getCurrentStackPointer() uintptr { return uintptr(stacksave()) } diff --git a/src/runtime/arch_tinygoriscv32.go b/src/runtime/arch_tinygoriscv32.go index 538259f7..df076a76 100644 --- a/src/runtime/arch_tinygoriscv32.go +++ b/src/runtime/arch_tinygoriscv32.go @@ -6,8 +6,3 @@ const GOARCH = "arm" // riscv pretends to be arm // The bitness of the CPU (e.g. 8, 32, 64). const TargetBits = 32 - -// Align on word boundary. -func align(ptr uintptr) uintptr { - return (ptr + 3) &^ 3 -} diff --git a/src/runtime/arch_tinygoriscv64.go b/src/runtime/arch_tinygoriscv64.go index 23036f8d..be96e561 100644 --- a/src/runtime/arch_tinygoriscv64.go +++ b/src/runtime/arch_tinygoriscv64.go @@ -6,8 +6,3 @@ const GOARCH = "arm64" // riscv pretends to be arm // The bitness of the CPU (e.g. 8, 32, 64). const TargetBits = 64 - -// Align on word boundary. -func align(ptr uintptr) uintptr { - return (ptr + 7) &^ 7 -}