mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-23 07:36:33 +11:00
Merge pull request #244 from gwilymk/more-memcpy-tests
More memcpy tests
This commit is contained in:
commit
65727d1c93
2 changed files with 96 additions and 92 deletions
|
@ -22,6 +22,10 @@
|
||||||
__agbabi_memcpy:
|
__agbabi_memcpy:
|
||||||
.global __aeabi_memcpy
|
.global __aeabi_memcpy
|
||||||
__aeabi_memcpy:
|
__aeabi_memcpy:
|
||||||
|
// Handle <= 2 byte copies byte-by-byte
|
||||||
|
cmp r2, #2
|
||||||
|
ble .Lcopy1
|
||||||
|
|
||||||
// Check pointer alignment
|
// Check pointer alignment
|
||||||
eor r3, r1, r0
|
eor r3, r1, r0
|
||||||
// JoaoBapt carry & sign bit test
|
// JoaoBapt carry & sign bit test
|
||||||
|
@ -30,9 +34,6 @@ __aeabi_memcpy:
|
||||||
bcs .Lcopy2
|
bcs .Lcopy2
|
||||||
|
|
||||||
.Lcopy4:
|
.Lcopy4:
|
||||||
// Handle <= 2 byte copies byte-by-byte
|
|
||||||
cmp r2, #2
|
|
||||||
ble .Lcopy1
|
|
||||||
|
|
||||||
// Copy half and byte head
|
// Copy half and byte head
|
||||||
rsb r3, r0, #4
|
rsb r3, r0, #4
|
||||||
|
|
|
@ -109,6 +109,8 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod memcpy {
|
mod memcpy {
|
||||||
|
use core::slice;
|
||||||
|
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
|
|
||||||
use crate::Gba;
|
use crate::Gba;
|
||||||
|
@ -145,115 +147,116 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn test_memcpy_bytes_with_different_sizes(_gba: &mut Gba) {
|
fn test_all_of_memcpy(_gba: &mut Gba) {
|
||||||
let mut input = vec![0u8; 70];
|
let mut input = vec![0u8; 100];
|
||||||
let mut output = vec![0u8; 70];
|
let mut output = vec![0u8; 100];
|
||||||
|
|
||||||
for size in 0..68 {
|
for size in 0..80 {
|
||||||
|
for offset_input in 0..10 {
|
||||||
|
for offset_output in 0..10 {
|
||||||
|
// initialise the buffers
|
||||||
for (i, value) in input.iter_mut().enumerate() {
|
for (i, value) in input.iter_mut().enumerate() {
|
||||||
*value = i as u8 * 3;
|
*value = i as u8;
|
||||||
|
output[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.fill(0);
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
__agbabi_memcpy(output.as_mut_ptr(), input.as_ptr(), size);
|
__agbabi_memcpy(
|
||||||
}
|
output.as_mut_ptr().add(offset_output),
|
||||||
|
input.as_ptr().add(offset_input),
|
||||||
for i in 0..size {
|
size,
|
||||||
assert_eq!(input[i], output[i], "Failed with size = {size} at i = {i}");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i, value) in output.iter().enumerate().skip(size) {
|
|
||||||
assert_eq!(*value, 0, "overrun with size = {size} at i = {i}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test_case]
|
|
||||||
fn test_memcpy_bytes_output_offsetted_with_different_sizes(_gba: &mut Gba) {
|
|
||||||
let mut input = vec![0u8; 70];
|
|
||||||
let mut output = vec![0u8; 70];
|
|
||||||
|
|
||||||
for size in 0..60 {
|
|
||||||
for (i, value) in input.iter_mut().enumerate() {
|
|
||||||
*value = i as u8 * 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
output.fill(0);
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
__agbabi_memcpy(output.as_mut_ptr().add(1), input.as_ptr(), size);
|
|
||||||
}
|
|
||||||
|
|
||||||
for i in 0..size {
|
|
||||||
assert_eq!(
|
|
||||||
input[i],
|
|
||||||
output[i + 1],
|
|
||||||
"Failed with size = {size} at i = {i}"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, value) in output.iter().enumerate().skip(size + 1) {
|
for (i, &v) in output.iter().enumerate() {
|
||||||
assert_eq!(*value, 0, "overrun with size = {size} at i = {i}");
|
if i < offset_output {
|
||||||
|
assert_eq!(v, 0, "underrun, size: {size}, input offset: {offset_input}, output offset: {offset_output}, i: {i}");
|
||||||
|
} else if i < offset_output + size {
|
||||||
|
assert_eq!(v, (i - offset_output + offset_input) as u8, "incorrect copy, size: {size}, input offset: {offset_input}, output offset: {offset_output}, i: {i}");
|
||||||
|
} else {
|
||||||
|
assert_eq!(v, 0, "overrun, size: {size}, input offset: {offset_input}, output offset: {offset_output}, i: {i}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn test_memcpy_bytes_input_offsetted_with_different_sizes(_gba: &mut Gba) {
|
fn test_all_of_memcpy4(_gba: &mut Gba) {
|
||||||
let mut input = vec![0u8; 70];
|
let mut input = vec![0u32; 100];
|
||||||
let mut output = vec![0u8; 70];
|
let mut output = vec![0u32; 100];
|
||||||
|
|
||||||
for size in 0..60 {
|
for size in 0..80 {
|
||||||
|
for offset_input in 0..8 {
|
||||||
|
for offset_output in 0..8 {
|
||||||
|
// initialise the buffers
|
||||||
for (i, value) in input.iter_mut().enumerate() {
|
for (i, value) in input.iter_mut().enumerate() {
|
||||||
*value = i as u8 * 3;
|
*value = i as u32;
|
||||||
|
output[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.fill(0);
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
__agbabi_memcpy(output.as_mut_ptr(), input.as_ptr().add(1), size);
|
__aeabi_memcpy4(
|
||||||
}
|
output.as_mut_ptr().add(offset_output),
|
||||||
|
input.as_ptr().add(offset_input),
|
||||||
for i in 0..size {
|
size * 4,
|
||||||
assert_eq!(
|
|
||||||
input[i + 1],
|
|
||||||
output[i],
|
|
||||||
"Failed with size = {size} at i = {i}"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, value) in output.iter().enumerate().skip(size) {
|
for (i, &v) in output.iter().enumerate() {
|
||||||
assert_eq!(*value, 0, "overrun with size = {size} at i = {i}");
|
if i < offset_output {
|
||||||
|
assert_eq!(v, 0, "underrun, size: {size}, input offset: {offset_input}, output offset: {offset_output}, i: {i}");
|
||||||
|
} else if i < offset_output + size {
|
||||||
|
assert_eq!(v, (i - offset_output + offset_input) as u32, "incorrect copy, size: {size}, input offset: {offset_input}, output offset: {offset_output}, i: {i}");
|
||||||
|
} else {
|
||||||
|
assert_eq!(v, 0, "overrun, size: {size}, input offset: {offset_input}, output offset: {offset_output}, i: {i}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn test_memcpy_bytes_input_output_offsetted_with_different_sizes(_gba: &mut Gba) {
|
fn test_all_of_memcpy4_non_word_length(_gba: &mut Gba) {
|
||||||
let mut input = vec![0u8; 70];
|
let mut input = vec![0u32; 100];
|
||||||
let mut output = vec![0u8; 70];
|
let mut output = vec![0u32; 100];
|
||||||
|
|
||||||
for size in 0..60 {
|
for size in 0..40 {
|
||||||
|
for offset_input in 0..8 {
|
||||||
|
for offset_output in 0..8 {
|
||||||
|
// initialise the buffers
|
||||||
for (i, value) in input.iter_mut().enumerate() {
|
for (i, value) in input.iter_mut().enumerate() {
|
||||||
*value = i as u8 * 3;
|
*value = i as u32;
|
||||||
|
output[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.fill(0);
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
__agbabi_memcpy(output.as_mut_ptr().add(1), input.as_ptr().add(1), size);
|
__aeabi_memcpy4(
|
||||||
|
output.as_mut_ptr().add(offset_output),
|
||||||
|
input.as_ptr().add(offset_input),
|
||||||
|
size * 4,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(output[0], 0);
|
let input_bytes: &[u8] = unsafe {
|
||||||
|
slice::from_raw_parts(input.as_ptr().cast(), input.len() * 4)
|
||||||
|
};
|
||||||
|
let output_bytes: &[u8] = unsafe {
|
||||||
|
slice::from_raw_parts(output.as_ptr().cast(), output.len() * 4)
|
||||||
|
};
|
||||||
|
|
||||||
for i in 1..size + 1 {
|
for i in 0..input_bytes.len() {
|
||||||
assert_eq!(input[i], output[i], "Failed with size = {size} at i = {i}");
|
if i < offset_output * 4 {
|
||||||
}
|
assert_eq!(output_bytes[i], 0, "underrun, size: {size}, input offset: {offset_input}, output offset: {offset_output}, i: {i}");
|
||||||
|
} else if i < offset_output * 4 + size * 4 {
|
||||||
for (i, value) in output.iter().enumerate().skip(size + 1) {
|
assert_eq!(output_bytes[i], input_bytes[i - offset_output * 4 + offset_input * 4], "incorrect copy, size: {size}, input offset: {offset_input}, output offset: {offset_output}, i: {i}");
|
||||||
assert_eq!(*value, 0, "overrun with size = {size} at i = {i}");
|
} else {
|
||||||
|
assert_eq!(output_bytes[i], 0, "overrun, size: {size}, input offset: {offset_input}, output offset: {offset_output}, i: {i}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue