Check sizes 0..80 in size with 0..10 offset for memset

This commit is contained in:
Gwilym Kuiper 2022-06-22 22:00:26 +01:00
parent 10eeeaf9e7
commit cb5763ed53
2 changed files with 22 additions and 17 deletions

View file

@ -19,13 +19,13 @@
.balign 4 .balign 4
.section .iwram.__aeabi_memset, "ax", %progbits .section .iwram.__aeabi_memset, "ax", %progbits
.global __agbabi_memset
__agbabi_memset:
.global __aeabi_memclr .global __aeabi_memclr
__aeabi_memclr: __aeabi_memclr:
mov r2, #0 mov r2, #0
b .LskipShifts b .LskipShifts
.global __agbabi_memset
__agbabi_memset:
.global __aeabi_memset .global __aeabi_memset
__aeabi_memset: __aeabi_memset:
mov r2, r2, lsl #24 mov r2, r2, lsl #24

View file

@ -5,33 +5,38 @@ mod test {
use alloc::vec; use alloc::vec;
extern "C" { extern "C" {
fn __aeabi_memset(dest: *mut u8, n: usize, v: u8); fn __agbabi_memset(dest: *mut u8, n: usize, v: u8);
fn __aeabi_memset4(dest: *mut u8, n: usize, v: u8); fn __aeabi_memset4(dest: *mut u8, n: usize, v: u8);
} }
#[test_case] #[test_case]
fn test_memset_with_different_sizes(_gba: &mut Gba) { fn test_memset_with_different_sizes_and_offsets(_gba: &mut Gba) {
let mut values = vec![0u8; 100]; let mut values = vec![0u8; 100];
let v = 0x12; let stored_value = 0x12;
for n in 0..80 { for n in 0..80 {
for o in 0..10 {
values.fill(0xFF); values.fill(0xFF);
unsafe { unsafe {
__aeabi_memset4(values.as_mut_ptr().wrapping_offset(10), n, v); __agbabi_memset(values.as_mut_ptr().add(o), n, stored_value);
} }
for (i, &v) in values.iter().enumerate().take(10) { for (i, &v) in values.iter().enumerate().take(o) {
assert_eq!(v, 0xFF, "underrun at {}", i); assert_eq!(v, 0xFF, "underrun at {i}, offset {o}, size {n}");
} }
for i in 0..n { for (i, &v) in values.iter().enumerate().skip(o).take(n) {
assert_eq!(values[10 + i], v, "incorrect value at {}", i + 10); assert_eq!(
v, stored_value,
"incorrect value at {i}, offset {o}, size {n}"
);
} }
for (i, &v) in values.iter().enumerate().skip(10 + n) { for (i, &v) in values.iter().enumerate().skip(o + n) {
assert_eq!(v, 0xFF, "overrun at {}", i); assert_eq!(v, 0xFF, "overrun at {i}, offset {o}, size {n}");
}
} }
} }
} }