Skip to content

Commit 030932f

Browse files
committed
added memcpy/memmove tests for non-zero multiples of 65536
1 parent b7e70a0 commit 030932f

3 files changed

Lines changed: 85 additions & 2 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.assume adl = 1
2+
3+
.section .text
4+
5+
.global _fill_mem32
6+
7+
; void fill_mem32(void *dst, size_t bytes, uint32_t pattern)
8+
_fill_mem32:
9+
ld iy, 0
10+
add iy, sp
11+
ld de, (iy + 3)
12+
ld hl, (iy + 6)
13+
ld bc, 4
14+
sbc hl, bc
15+
; return if bytes <= pattern_size
16+
ret c
17+
ret z
18+
push hl
19+
; copy pattern once
20+
lea hl, iy + 9
21+
ldir
22+
pop bc
23+
; now copy (bytes - pattern_size)
24+
ld hl, (iy + 3)
25+
ldir
26+
ret

test/standalone/asprintf_fprintf/src/main.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ void *T_memccpy(void *__restrict dest, const void *__restrict src, int c, size_t
4949
void *T_mempcpy(void *__restrict dest, const void *__restrict src, size_t n)
5050
__attribute__((nonnull(1, 2)));
5151

52+
void *T_memchr(const void *s, int c, size_t n)
53+
__attribute__((nonnull(1)));
54+
5255
void *T_memrchr(const void *s, int c, size_t n)
5356
__attribute__((nonnull(1)));
5457

@@ -92,6 +95,7 @@ void T_bzero(void* s, size_t n);
9295
#define T_memcmp memcmp
9396
#define T_memccpy memccpy
9497
#define T_mempcpy mempcpy
98+
#define T_memchr memchr
9599
#define T_memrchr memrchr
96100
#define T_memmem memmem
97101
#define T_memrmem memrmem
@@ -994,6 +998,54 @@ int strchrnul_test(void) {
994998
return 0;
995999
}
9961000

1001+
int mem65536_test(void) {
1002+
void fill_mem32(void *dst, size_t bytes, uint32_t pattern);
1003+
1004+
uint8_t * const dst = (uint8_t*)0xD40000;
1005+
const size_t screen_size = 320 * 240 * 2;
1006+
memset(dst, 0, screen_size);
1007+
const size_t B16 = 65536;
1008+
const size_t B17 = 131072;
1009+
1010+
/* test return values */
1011+
1012+
C(T_memcpy(SINK, SINK, B16) == SINK);
1013+
C(T_memcpy(SINK, SINK, B17) == SINK);
1014+
1015+
C(T_memmove(SINK, SINK, B16) == SINK);
1016+
C(T_memmove(SINK, SINK, B17) == SINK);
1017+
1018+
C(T_memmove(SINK + 16, SINK, B16) == SINK + 16);
1019+
C(T_memmove(SINK + 16, SINK, B17) == SINK + 16);
1020+
1021+
C(T_memmove(SINK, SINK + 16, B16) == SINK);
1022+
C(T_memmove(SINK, SINK + 16, B17) == SINK);
1023+
1024+
/* test memcpy and memmove when size is a non-zero multiple of 65536 */
1025+
1026+
fill_mem32(dst + screen_size - B16, B16, 0x78563412);
1027+
C(T_memcpy(dst + 32, dst + screen_size - B16, B16) == dst + 32);
1028+
C(T_memchr(dst, 0x00, 32) == dst);
1029+
C(T_memchr(dst, 0x12, 32) == NULL_ptr);
1030+
C(T_memchr(dst, 0x12, 33) == dst + 32);
1031+
C(T_memrchr(dst, 0x78, 32 + B16 + 32) == dst + 32 + B16 - 1);
1032+
const uint32_t pattern_1 = 0xA3A0A1A0;
1033+
const uint32_t pattern_2 = 0xFECDAB89;
1034+
fill_mem32(dst, 32, pattern_1);
1035+
fill_mem32(dst + 24576, B16, pattern_2);
1036+
1037+
C(T_memmove(dst + 61, dst, B16) == dst + 61);
1038+
C(T_memmem(dst, B17, &pattern_1, sizeof(pattern_1)) == dst);
1039+
C(T_memrmem(dst, B17, &pattern_1, sizeof(pattern_1)) == dst + 61 - 4 + 32);
1040+
C(T_memmove(dst + 24578, dst, B16) == dst + 24578);
1041+
C(T_memmem(dst, B16, &pattern_1, sizeof(pattern_1)) == dst + 0);
1042+
C(T_memrmem(dst, B16, &pattern_1, sizeof(pattern_1)) == dst + 24578 + 61 + 32 - 4);
1043+
C(T_memmem(dst, B16, &pattern_2, sizeof(pattern_2)) == dst + 24576 + 24578 + 61);
1044+
C(T_memrmem(dst, B16, &pattern_2, sizeof(pattern_2)) == dst + B16 - 4u - (((24578u - 24576u) - 61u) % 4u));
1045+
1046+
return 0;
1047+
}
1048+
9971049
int run_tests(void) {
9981050
int ret = 0;
9991051
/* boot_asprintf */
@@ -1027,6 +1079,9 @@ int run_tests(void) {
10271079
TEST(strrstr_test());
10281080
TEST(strchrnul_test());
10291081

1082+
TEST(mem65536_test());
1083+
os_ClrHome();
1084+
10301085
return 0;
10311086
}
10321087

test/standalone/asprintf_fprintf/src/rename.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
.section .text
44

5-
.global _T_memset, _T_memcpy, _T_memmove, _T_memcmp, _T_memccpy, _T_mempcpy, _T_memrchr, _T_memmem, _T_memrmem
5+
.global _T_memset, _T_memcpy, _T_memmove, _T_memcmp, _T_memccpy, _T_mempcpy, _T_memchr, _T_memrchr, _T_memmem, _T_memrmem
66
.global _T_strlen, _T_strcmp, _T_strncmp, _T_stpcpy, _T_stpncpy, _T_strlcat, _T_strchrnul, _T_strrstr
77
.global _T_bzero
88

@@ -18,6 +18,8 @@ _T_memccpy:
1818
jp _memccpy
1919
_T_mempcpy:
2020
jp _mempcpy
21+
_T_memchr:
22+
jp _memchr
2123
_T_memrchr:
2224
jp _memrchr
2325
_T_memmem:
@@ -51,6 +53,6 @@ _T_bzero:
5153
_NULL_ptr:
5254
db $00, $00, $00
5355

54-
.extern _memset, _memcpy, _memmove, _memcmp, _memccpy, _mempcpy, _memrchr, _memmem, _memrmem
56+
.extern _memset, _memcpy, _memmove, _memcmp, _memccpy, _mempcpy, _memchr, _memrchr, _memmem, _memrmem
5557
.extern _strlen, _strcmp, _strncmp, _stpcpy, _stpncpy, _strlcat, _strchrnul, _strrstr
5658
.extern _bzero

0 commit comments

Comments
 (0)