Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sajattack committed Aug 13, 2020
1 parent 433256c commit e9eb269
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 43 deletions.
78 changes: 38 additions & 40 deletions examples/memcpy_bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,49 @@ fn psp_main() {
sys::sceKernelChangeCurrentThreadAttr(0, ThreadAttributes::VFPU);
}

let mut size = 16;
let mut cpu_dur = Duration::default();
let mut cpu32_dur = Duration::default();
let mut dmac_dur = Duration::default();
let mut vfpu_dur = Duration::default();
//loop {
let src = unsafe { alloc::alloc::alloc(Layout::from_size_align_unchecked(size, 16)) };
let dst = unsafe { alloc::alloc::alloc(Layout::from_size_align_unchecked(size, 16)) };
cpu_dur = psp::benchmark(|| {
for _ in 0..1000 {
unsafe { memcpy(dst, src as *const u8, size); }
}
}, 10);
let size = 16;
let iterations = 1000;
let cpu_dur: Duration;
let cpu32_dur: Duration;
let dmac_dur: Duration;
let vfpu_dur: Duration;

cpu32_dur = psp::benchmark(|| {
for _ in 0..1000 {
unsafe { memcpy32(dst, src as *const u8, size); }
}
}, 10);
let src = unsafe { alloc::alloc::alloc(Layout::from_size_align_unchecked(size, 16)) };
let dst = unsafe { alloc::alloc::alloc(Layout::from_size_align_unchecked(size, 16)) };
cpu_dur = psp::benchmark(|| {
for _ in 0..iterations {
unsafe { memcpy(dst, src as *const u8, size); }
}
}, 10);

cpu32_dur = psp::benchmark(|| {
for _ in 0..iterations {
unsafe { memcpy32(dst, src as *const u8, size); }
}
}, 10);

dmac_dur = psp::benchmark(|| {
for _ in 0..1000 {
unsafe { psp::sys::sceDmacMemcpy(dst, src as *const u8, size); }
}
}, 10);

vfpu_dur = psp::benchmark(|| {
for _ in 0..1000 {
unsafe { psp::sys::sceVfpuMemcpy(dst, src as *const u8, size); }
}
}, 10);
dmac_dur = psp::benchmark(|| {
for _ in 0..iterations {
unsafe { psp::sys::sceDmacMemcpy(dst, src as *const u8, size); }
}
}, 10);

unsafe { alloc::alloc::dealloc(src, Layout::from_size_align_unchecked(size, 16)); }
unsafe { alloc::alloc::dealloc(dst, Layout::from_size_align_unchecked(size, 16)); }
//if dmac_dur < cpu32_dur {
//break;
//}
//size += 16
//}
psp::dprintln!("size: {}", size);
psp::dprintln!("cpu: {}", cpu_dur.as_nanos());
psp::dprintln!("cpu32: {}", cpu32_dur.as_nanos());
psp::dprintln!("dmac: {}", dmac_dur.as_nanos());
psp::dprintln!("vfpu: {}", vfpu_dur.as_nanos());
vfpu_dur = psp::benchmark(|| {
for _ in 0..iterations {
unsafe { psp::sys::sceVfpuMemcpy(dst, src as *const u8, size); }
}
}, 10);

unsafe { alloc::alloc::dealloc(src, Layout::from_size_align_unchecked(size, 16)); }
unsafe { alloc::alloc::dealloc(dst, Layout::from_size_align_unchecked(size, 16)); }

psp::dprintln!("size: {} bytes", size);
psp::dprintln!("iterations: {}", iterations);
psp::dprintln!("cpu: {} microseconds", cpu_dur.as_micros());
psp::dprintln!("cpu32: {} microseconds", cpu32_dur.as_micros());
psp::dprintln!("dmac: {} microseconds", dmac_dur.as_micros());
psp::dprintln!("vfpu: {} microseconds", vfpu_dur.as_micros());
}

unsafe fn memcpy(dst: *mut u8, src: *const u8, num: usize) -> *mut u8 {
Expand Down
3 changes: 0 additions & 3 deletions psp/src/sys/vfpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ pub unsafe extern "C" fn sceVfpuMemcpy(
let mut dst8 = dst;
let mut src8 = src;

let mut dst32 = dst8 as *mut u32;
let mut src32 = src8 as *const u32;

if ((src8 as u32)&0xF) == 0 //Both src and dst are 16byte aligned
{
while size > 63 {
Expand Down

0 comments on commit e9eb269

Please sign in to comment.