Skip to content

Commit

Permalink
improve some iterator stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
silwol committed Jun 9, 2022
1 parent d4ebf48 commit 6aad82c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
21 changes: 8 additions & 13 deletions lib/compiler-singlepass/src/emitter_arm64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2699,8 +2699,6 @@ pub fn gen_import_call_trampoline_arm64(
#[allow(clippy::match_single_binding)]
match calling_convention {
_ => {
let mut param_locations: Vec<Location> = vec![];

// Allocate stack space for arguments.
let stack_offset: i32 = if sig.params().len() > 7 {
7 * 8
Expand Down Expand Up @@ -2741,17 +2739,14 @@ pub fn gen_import_call_trampoline_arm64(
GPR::X6,
GPR::X7,
];
for (i, r) in PARAM_REGS.iter().enumerate().take(sig.params().len()) {
let loc = match i {
0..=6 => {
let loc = Location::Memory(GPR::XzrSp, (i * 8) as i32);
a.emit_str(Size::S64, Location::GPR(*r), loc);
loc
}
_ => Location::Memory(GPR::XzrSp, stack_offset + ((i - 7) * 8) as i32),
};
param_locations.push(loc);
}
let gpr_iter = PARAM_REGS.iter().map(|r| Location::GPR(*r));
let memory_iter = (PARAM_REGS.len()..)
.map(|i| Location::Memory(GPR::XzrSp, stack_offset + ((i - 7) * 8) as i32));

let param_locations: Vec<Location> = gpr_iter
.chain(memory_iter)
.take(sig.params().len())
.collect();

// Copy arguments.
let mut caller_stack_offset: i32 = 0;
Expand Down
13 changes: 5 additions & 8 deletions lib/compiler-singlepass/src/machine_x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7007,9 +7007,8 @@ impl Machine for MachineX86_64 {
CallingConvention::WindowsFastcall => {
static PARAM_REGS: &[GPR] = &[GPR::RDX, GPR::R8, GPR::R9];
let gpr_iter = PARAM_REGS.iter().map(|r| Location::GPR(*r));
let memory_iter = (0..)
.map(|i| Location::Memory(GPR::RSP, 32 + 8 + ((i - 3) * 8) as i32))
.skip(PARAM_REGS.len());
let memory_iter = (PARAM_REGS.len()..)
.map(|i| Location::Memory(GPR::RSP, 32 + 8 + ((i - 3) * 8) as i32));

let param_locations: Vec<Location> = gpr_iter
.chain(memory_iter)
Expand Down Expand Up @@ -7047,11 +7046,9 @@ impl Machine for MachineX86_64 {
// Store all arguments to the stack to prevent overwrite.
static PARAM_REGS: &[GPR] = &[GPR::RSI, GPR::RDX, GPR::RCX, GPR::R8, GPR::R9];
let gpr_iter = PARAM_REGS.iter().map(|r| Location::GPR(*r));
let memory_iter = (0..)
.map(|i| {
Location::Memory(GPR::RSP, stack_offset + 8 + ((i - 5) * 8) as i32)
})
.skip(gpr_iter.len());
let memory_iter = (PARAM_REGS.len()..).map(|i| {
Location::Memory(GPR::RSP, stack_offset + 8 + ((i - 5) * 8) as i32)
});

let param_locations: Vec<Location> = gpr_iter
.chain(memory_iter)
Expand Down

0 comments on commit 6aad82c

Please sign in to comment.