Skip to content

Commit

Permalink
Reorganize to put stack finalization in one place
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Feb 2, 2025
1 parent 8297eb1 commit 998f99b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 68 deletions.
2 changes: 1 addition & 1 deletion fidget/src/core/eval/test/float_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<F: Function + MathFunction> TestFloatSlice<F> {
}

pub fn test_f_stress() {
for n in [4, 8, 12, 16, 32] {
for n in [4, 8, 12, 16, 32, 256, 512] {
Self::test_f_stress_n(n);
}
}
Expand Down
7 changes: 1 addition & 6 deletions fidget/src/jit/aarch64/float_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,8 @@ impl Assembler for FloatSliceAssembler {
; ldr x22, [sp, 0x210]
; ldr x23, [sp, 0x218]
; ldr x24, [sp, 0x220]

// Fix up the stack
; add sp, sp, self.0.mem_offset as u32
; ret
);

self.0.ops.finalize()
self.0.finalize()
}
}

Expand Down
8 changes: 1 addition & 7 deletions fidget/src/jit/aarch64/grad_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,8 @@ impl Assembler for GradSliceAssembler {
; ldr x21, [sp, 0x208]
; ldr x22, [sp, 0x210]
; ldr x23, [sp, 0x218]

// Fix up the stack
; add sp, sp, self.0.mem_offset as u32
; ret

);

self.0.ops.finalize()
self.0.finalize()
}
}

Expand Down
19 changes: 1 addition & 18 deletions fidget/src/jit/aarch64/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,24 +772,7 @@ impl Assembler for IntervalAssembler {
; ldp d12, d13, [sp, 0x30]
; ldp d14, d15, [sp, 0x40]
);

// Fix up the stack
if self.0.mem_offset < 4096 {
dynasm!(self.0.ops
; add sp, sp, self.0.mem_offset as u32
);
} else {
dynasm!(self.0.ops
; mov w28, self.0.mem_offset as u64
; add sp, sp, w28
);
}

dynasm!(self.0.ops
; ret
);

self.0.ops.finalize()
self.0.finalize()
}
}

Expand Down
8 changes: 1 addition & 7 deletions fidget/src/jit/aarch64/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,8 @@ impl Assembler for PointAssembler {
; ldp d10, d11, [sp, 0x20]
; ldp d12, d13, [sp, 0x30]
; ldp d14, d15, [sp, 0x40]

// Fix up the stack
; add sp, sp, (self.0.mem_offset as u32)

; ret
);

self.0.ops.finalize()
self.0.finalize()
}
}

Expand Down
38 changes: 36 additions & 2 deletions fidget/src/jit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl<T> AssemblerData<T> {

#[cfg(target_arch = "aarch64")]
fn push_stack(&mut self) {
if self.mem_offset < 4096 {
if self.mem_offset < 4096 {
dynasm!(self.ops
; sub sp, sp, self.mem_offset as u32
);
Expand All @@ -340,7 +340,7 @@ impl<T> AssemblerData<T> {
; mov w28, self.mem_offset as u64
; sub sp, sp, w28
);
}
}
}

#[cfg(target_arch = "x86_64")]
Expand All @@ -354,6 +354,40 @@ impl<T> AssemblerData<T> {
assert!(slot >= REGISTER_LIMIT as u32);
(slot - REGISTER_LIMIT as u32) * std::mem::size_of::<T>() as u32
}

#[cfg(target_arch = "aarch64")]
fn finalize(mut self) -> Result<Mmap, Error> {
// Fix up the stack
if self.mem_offset < 4096 {
dynasm!(self.ops
; add sp, sp, self.mem_offset as u32
);
} else if self.mem_offset < 65536 {
dynasm!(self.ops
; mov w9, self.mem_offset as u64
; add sp, sp, w9
);
} else {
panic!("invalid mem offset: {}", self.mem_offset);
}

dynasm!(self.ops
; ret
);
self.ops.finalize()
}

#[cfg(target_arch = "x86_64")]
fn finalize(mut self) -> Result<Mmap, Error> {
dynasm!(self.ops
; add rsp, self.mem_offset as i32
; pop rbp
; emms
; vzeroall
; ret
);
self.ops.finalize()
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 1 addition & 7 deletions fidget/src/jit/x86_64/float_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,8 @@ impl Assembler for FloatSliceAssembler {

// Finalization code, which happens after all evaluation is complete
; ->X:
; add rsp, self.0.mem_offset as i32
; pop rbp
; emms
; vzeroall
; ret
);

self.0.ops.finalize()
self.0.finalize()
}
}

Expand Down
7 changes: 1 addition & 6 deletions fidget/src/jit/x86_64/grad_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,8 @@ impl Assembler for GradSliceAssembler {

// Finalization code, which happens after all evaluation is complete
; -> X:
; add rsp, self.0.mem_offset as i32
; pop rbp
; emms
; ret
);

self.0.ops.finalize()
self.0.finalize()
}
}

Expand Down
8 changes: 1 addition & 7 deletions fidget/src/jit/x86_64/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,13 +771,7 @@ impl Assembler for IntervalAssembler {
; mov r15, [rbp - 0x20]
);
}
dynasm!(self.0.ops
; add rsp, self.0.mem_offset as i32
; pop rbp
; emms
; ret
);
self.0.ops.finalize()
self.0.finalize()
}
}

Expand Down
8 changes: 1 addition & 7 deletions fidget/src/jit/x86_64/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,7 @@ impl Assembler for PointAssembler {
; mov r15, [rbp - 0x20]
);
}
dynasm!(self.0.ops
; add rsp, self.0.mem_offset as i32
; pop rbp
; emms
; ret
);
self.0.ops.finalize()
self.0.finalize()
}
}

Expand Down

0 comments on commit 998f99b

Please sign in to comment.