-
Notifications
You must be signed in to change notification settings - Fork 824
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
Singlepass aarch64 #2750
Merged
+8,580
−223
Merged
Singlepass aarch64 #2750
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
1e1032e
improvement(compiler) Added basic arm64 declaration for singlepass
ptitSeb d317e1e
Fixed linting
ptitSeb 69478cd
improvement(compiler) Added squeleton for arm64 singlepass
ptitSeb 26d334f
improv(compiler) Enabled aarch64 tests
ptitSeb 9002208
improv(compiler) Added some machine_arm64 methods
ptitSeb 19a9fa7
improv(compiler) Added some more machine_arm64 and emitter_arm64 meth…
ptitSeb 72eead3
improv(compiler) Calls are now working properly (and 43 tests passes)
ptitSeb a57c422
improv(compiler) Some ork on register affectation (60 tests passes now)
ptitSeb ae1925e
improv(compiler) Cleaned up warnings
ptitSeb 67e5f9c
improv(compiler) Added emit_relaxed_ldr64 utility (65 tests passes now)
ptitSeb 4a65664
improv(compiler) Fixed emit_mov_imm for 64bits values (67 tests passe…
ptitSeb 2f6264a
improv(compiler) Added emit_jmp_to_jumptable (68 tests passes now)
ptitSeb 962511d
improv(compiler) Fixed stack alignment on native function call (69 te…
ptitSeb e9b80d4
improv(compiler) Added logic and shift operations (70 tests passes now)
ptitSeb 7c2eac1
improv(compiler) Added/Fixed Store/Load of i32/i64 (74 tests passes now)
ptitSeb 6b593ed
improv(compiler) More logic oprations (91 tests passes now)
ptitSeb f23a137
improv(compiler) More memory oprations (95 tests passes now)
ptitSeb ddc1737
improv(compiler) Added CLZ, CTZ and a few float operations (99 tests …
ptitSeb 005351b
improv(compiler) Added SDIV, UDIV and UREM operations (105 tests pass…
ptitSeb 7ce5475
improv(compiler) More work on SDIV, UDIV, UREM and SREM operations (1…
ptitSeb 7cbf2fe
improv(compiler) More logic and float operations, but no canonicaliza…
ptitSeb 8d066a1
improv(compiler) More float and native call work (133 tests passes now)
ptitSeb 0bbc81a
improv(compiler) Oops, that was a mystake
ptitSeb 4f93864
improv(compiler) More native call work and fixes (166 tests passes now)
ptitSeb 8f5a30a
improv(compiler) More fixes (176 tests passes now)
ptitSeb 9d188cb
improv(compiler) Added canonicalization and rounding (182 tests passe…
ptitSeb 77e65cd
improv(compiler) Added float to int conversion, with trap (187 tests …
ptitSeb da1d96b
improv(compiler) Fixed some mystakes (207 tests passes now, 0 failed)
ptitSeb 0e2d809
imp(compiler) Add support for AppleAarch64 ABI to SinglePass
ptitSeb c8ae8c8
imp(feature) Fixed x64 backend of Singlepass
ptitSeb ab3e978
feat(compiler) Added entry in ChangeLog
ptitSeb 7f4fd02
feat(compiler) Adapted/Fixed/Removed some comments in SinglePass codegen
ptitSeb 80f9c8f
feat(compiler) Small adaption after comments
ptitSeb 61609c9
improv(compiler) Added a few more arm64 emitter, just in case
ptitSeb b676d18
Merge branch 'master' into singlepass_aarch64
ptitSeb 74779f5
Merge branch 'master' into singlepass_aarch64
ptitSeb bff3c09
Merge branch 'master' into singlepass_aarch64
ptitSeb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,305 @@ | ||
//! ARM64 structures. | ||
|
||
use crate::common_decl::{MachineState, MachineValue, RegisterIndex}; | ||
use crate::location::CombinedRegister; | ||
use crate::location::Reg as AbstractReg; | ||
use std::collections::BTreeMap; | ||
use wasmer_compiler::CallingConvention; | ||
use wasmer_types::Type; | ||
|
||
/// General-purpose registers. | ||
#[repr(u8)] | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
pub enum GPR { | ||
X0 = 0, | ||
X1 = 1, | ||
X2 = 2, | ||
X3 = 3, | ||
X4 = 4, | ||
X5 = 5, | ||
X6 = 6, | ||
X7 = 7, | ||
X8 = 8, | ||
X9 = 9, | ||
X10 = 10, | ||
X11 = 11, | ||
X12 = 12, | ||
X13 = 13, | ||
X14 = 14, | ||
X15 = 15, | ||
X16 = 16, | ||
X17 = 17, | ||
X18 = 18, | ||
X19 = 19, | ||
X20 = 20, | ||
X21 = 21, | ||
X22 = 22, | ||
X23 = 23, | ||
X24 = 24, | ||
X25 = 25, | ||
X26 = 26, | ||
X27 = 27, | ||
X28 = 28, | ||
X29 = 29, | ||
X30 = 30, | ||
XzrSp = 31, | ||
} | ||
|
||
/// NEON registers. | ||
#[repr(u8)] | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] | ||
#[allow(dead_code)] | ||
pub enum NEON { | ||
V0 = 0, | ||
V1 = 1, | ||
V2 = 2, | ||
V3 = 3, | ||
V4 = 4, | ||
V5 = 5, | ||
V6 = 6, | ||
V7 = 7, | ||
V8 = 8, | ||
V9 = 9, | ||
V10 = 10, | ||
V11 = 11, | ||
V12 = 12, | ||
V13 = 13, | ||
V14 = 14, | ||
V15 = 15, | ||
V16 = 16, | ||
V17 = 17, | ||
V18 = 18, | ||
V19 = 19, | ||
V20 = 20, | ||
V21 = 21, | ||
V22 = 22, | ||
V23 = 23, | ||
V24 = 24, | ||
V25 = 25, | ||
V26 = 26, | ||
V27 = 27, | ||
V28 = 28, | ||
V29 = 29, | ||
V30 = 30, | ||
V31 = 31, | ||
} | ||
|
||
impl AbstractReg for GPR { | ||
fn is_callee_save(self) -> bool { | ||
self as usize > 18 | ||
} | ||
fn is_reserved(self) -> bool { | ||
match self.into_index() { | ||
0..=16 | 19..=27 => false, | ||
_ => true, | ||
} | ||
} | ||
fn into_index(self) -> usize { | ||
self as usize | ||
} | ||
fn from_index(n: usize) -> Result<GPR, ()> { | ||
const REGS: [GPR; 32] = [ | ||
GPR::X0, | ||
GPR::X1, | ||
GPR::X2, | ||
GPR::X3, | ||
GPR::X4, | ||
GPR::X5, | ||
GPR::X6, | ||
GPR::X7, | ||
GPR::X8, | ||
GPR::X9, | ||
GPR::X10, | ||
GPR::X11, | ||
GPR::X12, | ||
GPR::X13, | ||
GPR::X14, | ||
GPR::X15, | ||
GPR::X16, | ||
GPR::X17, | ||
GPR::X18, | ||
GPR::X19, | ||
GPR::X20, | ||
GPR::X21, | ||
GPR::X22, | ||
GPR::X23, | ||
GPR::X24, | ||
GPR::X25, | ||
GPR::X26, | ||
GPR::X27, | ||
GPR::X28, | ||
GPR::X29, | ||
GPR::X30, | ||
GPR::XzrSp, | ||
]; | ||
match n { | ||
0..=31 => Ok(REGS[n]), | ||
_ => Err(()), | ||
} | ||
} | ||
} | ||
|
||
impl AbstractReg for NEON { | ||
fn is_callee_save(self) -> bool { | ||
self as usize > 16 | ||
} | ||
fn is_reserved(self) -> bool { | ||
false | ||
} | ||
fn into_index(self) -> usize { | ||
self as usize | ||
} | ||
fn from_index(n: usize) -> Result<NEON, ()> { | ||
const REGS: [NEON; 32] = [ | ||
NEON::V0, | ||
NEON::V1, | ||
NEON::V2, | ||
NEON::V3, | ||
NEON::V4, | ||
NEON::V5, | ||
NEON::V6, | ||
NEON::V7, | ||
NEON::V8, | ||
NEON::V9, | ||
NEON::V10, | ||
NEON::V11, | ||
NEON::V12, | ||
NEON::V13, | ||
NEON::V14, | ||
NEON::V15, | ||
NEON::V16, | ||
NEON::V17, | ||
NEON::V18, | ||
NEON::V19, | ||
NEON::V20, | ||
NEON::V21, | ||
NEON::V22, | ||
NEON::V23, | ||
NEON::V24, | ||
NEON::V25, | ||
NEON::V26, | ||
NEON::V27, | ||
NEON::V28, | ||
NEON::V29, | ||
NEON::V30, | ||
NEON::V31, | ||
]; | ||
match n { | ||
0..=15 => Ok(REGS[n]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo? Should this be 31? If not then add a comment explaining why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooops, typo yes. |
||
_ => Err(()), | ||
} | ||
} | ||
} | ||
|
||
/// A machine register under the x86-64 architecture. | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||
pub enum ARM64Register { | ||
/// General-purpose registers. | ||
GPR(GPR), | ||
/// NEON (floating point/SIMD) registers. | ||
NEON(NEON), | ||
} | ||
|
||
impl CombinedRegister for ARM64Register { | ||
/// Returns the index of the register. | ||
fn to_index(&self) -> RegisterIndex { | ||
match *self { | ||
ARM64Register::GPR(x) => RegisterIndex(x as usize), | ||
ARM64Register::NEON(x) => RegisterIndex(x as usize + 64), | ||
} | ||
} | ||
/// Convert from a GPR register | ||
fn from_gpr(x: u16) -> Self { | ||
ARM64Register::GPR(GPR::from_index(x as usize).unwrap()) | ||
} | ||
/// Convert from an SIMD register | ||
fn from_simd(x: u16) -> Self { | ||
ARM64Register::NEON(NEON::from_index(x as usize).unwrap()) | ||
} | ||
|
||
/// Converts a DWARF regnum to ARM64Register. | ||
fn _from_dwarf_regnum(x: u16) -> Option<ARM64Register> { | ||
Some(match x { | ||
0..=31 => ARM64Register::GPR(GPR::from_index(x as usize).unwrap()), | ||
64..=95 => ARM64Register::NEON(NEON::from_index(x as usize - 64).unwrap()), | ||
_ => return None, | ||
}) | ||
} | ||
} | ||
|
||
/// An allocator that allocates registers for function arguments according to the System V ABI. | ||
#[derive(Default)] | ||
pub struct ArgumentRegisterAllocator { | ||
n_gprs: usize, | ||
n_neons: usize, | ||
} | ||
|
||
impl ArgumentRegisterAllocator { | ||
/// Allocates a register for argument type `ty`. Returns `None` if no register is available for this type. | ||
pub fn next( | ||
&mut self, | ||
ty: Type, | ||
calling_convention: CallingConvention, | ||
) -> Option<ARM64Register> { | ||
match calling_convention { | ||
CallingConvention::SystemV | CallingConvention::AppleAarch64 => { | ||
static GPR_SEQ: &'static [GPR] = &[ | ||
GPR::X0, | ||
GPR::X1, | ||
GPR::X2, | ||
GPR::X3, | ||
GPR::X4, | ||
GPR::X5, | ||
GPR::X6, | ||
GPR::X7, | ||
]; | ||
static NEON_SEQ: &'static [NEON] = &[ | ||
NEON::V0, | ||
NEON::V1, | ||
NEON::V2, | ||
NEON::V3, | ||
NEON::V4, | ||
NEON::V5, | ||
NEON::V6, | ||
NEON::V7, | ||
]; | ||
match ty { | ||
Type::I32 | Type::I64 => { | ||
if self.n_gprs < GPR_SEQ.len() { | ||
let gpr = GPR_SEQ[self.n_gprs]; | ||
self.n_gprs += 1; | ||
Some(ARM64Register::GPR(gpr)) | ||
} else { | ||
None | ||
} | ||
} | ||
Type::F32 | Type::F64 => { | ||
if self.n_neons < NEON_SEQ.len() { | ||
let neon = NEON_SEQ[self.n_neons]; | ||
self.n_neons += 1; | ||
Some(ARM64Register::NEON(neon)) | ||
} else { | ||
None | ||
} | ||
} | ||
_ => todo!( | ||
"ArgumentRegisterAllocator::next: Unsupported type: {:?}", | ||
ty | ||
), | ||
} | ||
} | ||
_ => unimplemented!(), | ||
} | ||
} | ||
} | ||
|
||
/// Create a new `MachineState` with default values. | ||
pub fn new_machine_state() -> MachineState { | ||
MachineState { | ||
stack_values: vec![], | ||
register_values: vec![MachineValue::Undefined; 32 + 32], | ||
prev_frame: BTreeMap::new(), | ||
wasm_stack: vec![], | ||
wasm_inst_offset: std::usize::MAX, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get
returns anOption
,ok_or
converts it to aResult
.But perhaps this function should be changed to use plain indexing and simply panic if an out-of-range value is passed in since you're always unwraping the result anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not happy "expected enum
arm64_decl::GPR
, found&arm64_decl::GPR
"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can used
.cloned()
to turn anOption<&T>
to anOption<T>
.