diff --git a/lib/compiler-singlepass/src/emitter_arm64.rs b/lib/compiler-singlepass/src/emitter_arm64.rs index c2a306dc5a2..578dee230fa 100644 --- a/lib/compiler-singlepass/src/emitter_arm64.rs +++ b/lib/compiler-singlepass/src/emitter_arm64.rs @@ -2699,8 +2699,6 @@ pub fn gen_import_call_trampoline_arm64( #[allow(clippy::match_single_binding)] match calling_convention { _ => { - let mut param_locations: Vec = vec![]; - // Allocate stack space for arguments. let stack_offset: i32 = if sig.params().len() > 7 { 7 * 8 @@ -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 = gpr_iter + .chain(memory_iter) + .take(sig.params().len()) + .collect(); // Copy arguments. let mut caller_stack_offset: i32 = 0; diff --git a/lib/compiler-singlepass/src/machine_x64.rs b/lib/compiler-singlepass/src/machine_x64.rs index db657cdd21c..a7489fa14a6 100644 --- a/lib/compiler-singlepass/src/machine_x64.rs +++ b/lib/compiler-singlepass/src/machine_x64.rs @@ -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 = gpr_iter .chain(memory_iter) @@ -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 = gpr_iter .chain(memory_iter)