Index: umsboot/libc/memcpy.c |
— | — | @@ -1,117 +0,0 @@ |
2 | | -/* |
3 | | -FUNCTION |
4 | | - <<memcpy>>---copy memory regions |
5 | | - |
6 | | -ANSI_SYNOPSIS |
7 | | - #include <string.h> |
8 | | - void* memcpy(void *<[out]>, const void *<[in]>, size_t <[n]>); |
9 | | - |
10 | | -TRAD_SYNOPSIS |
11 | | - void *memcpy(<[out]>, <[in]>, <[n]> |
12 | | - void *<[out]>; |
13 | | - void *<[in]>; |
14 | | - size_t <[n]>; |
15 | | - |
16 | | -DESCRIPTION |
17 | | - This function copies <[n]> bytes from the memory region |
18 | | - pointed to by <[in]> to the memory region pointed to by |
19 | | - <[out]>. |
20 | | - |
21 | | - If the regions overlap, the behavior is undefined. |
22 | | - |
23 | | -RETURNS |
24 | | - <<memcpy>> returns a pointer to the first byte of the <[out]> |
25 | | - region. |
26 | | - |
27 | | -PORTABILITY |
28 | | -<<memcpy>> is ANSI C. |
29 | | - |
30 | | -<<memcpy>> requires no supporting OS subroutines. |
31 | | - |
32 | | -QUICKREF |
33 | | - memcpy ansi pure |
34 | | - */ |
35 | | - |
36 | | -#include "global.h" |
37 | | -#include "include/string.h" |
38 | | -#include "include/_ansi.h" |
39 | | - |
40 | | -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ |
41 | | -#define UNALIGNED(X, Y) \ |
42 | | - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) |
43 | | - |
44 | | -/* How many bytes are copied each iteration of the 4X unrolled loop. */ |
45 | | -#define BIGBLOCKSIZE (sizeof (long) << 2) |
46 | | - |
47 | | -/* How many bytes are copied each iteration of the word copy loop. */ |
48 | | -#define LITTLEBLOCKSIZE (sizeof (long)) |
49 | | - |
50 | | -/* Threshold for punting to the byte copier. */ |
51 | | -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) |
52 | | - |
53 | | -_PTR |
54 | | -_DEFUN (memcpy, (dst0, src0, len0), |
55 | | - _PTR dst0 _AND |
56 | | - _CONST _PTR src0 _AND |
57 | | - size_t len0) ICODE_ATTR; |
58 | | - |
59 | | -_PTR |
60 | | -_DEFUN (memcpy, (dst0, src0, len0), |
61 | | - _PTR dst0 _AND |
62 | | - _CONST _PTR src0 _AND |
63 | | - size_t len0) |
64 | | -{ |
65 | | -#if defined(PREFER_SIZE_OVER_SPEED) |
66 | | - char *dst = (char *) dst0; |
67 | | - char *src = (char *) src0; |
68 | | - |
69 | | - _PTR save = dst0; |
70 | | - |
71 | | - while (len0--) |
72 | | - { |
73 | | - *dst++ = *src++; |
74 | | - } |
75 | | - |
76 | | - return save; |
77 | | -#else |
78 | | - char *dst = dst0; |
79 | | - _CONST char *src = src0; |
80 | | - long *aligned_dst; |
81 | | - _CONST long *aligned_src; |
82 | | - unsigned int len = len0; |
83 | | - |
84 | | - /* If the size is small, or either SRC or DST is unaligned, |
85 | | - then punt into the byte copy loop. This should be rare. */ |
86 | | - if (!TOO_SMALL(len) && !UNALIGNED (src, dst)) |
87 | | - { |
88 | | - aligned_dst = (long*)dst; |
89 | | - aligned_src = (long*)src; |
90 | | - |
91 | | - /* Copy 4X long words at a time if possible. */ |
92 | | - while (len >= BIGBLOCKSIZE) |
93 | | - { |
94 | | - *aligned_dst++ = *aligned_src++; |
95 | | - *aligned_dst++ = *aligned_src++; |
96 | | - *aligned_dst++ = *aligned_src++; |
97 | | - *aligned_dst++ = *aligned_src++; |
98 | | - len -= (unsigned int)BIGBLOCKSIZE; |
99 | | - } |
100 | | - |
101 | | - /* Copy one long word at a time if possible. */ |
102 | | - while (len >= LITTLEBLOCKSIZE) |
103 | | - { |
104 | | - *aligned_dst++ = *aligned_src++; |
105 | | - len -= LITTLEBLOCKSIZE; |
106 | | - } |
107 | | - |
108 | | - /* Pick up any residual with a byte copier. */ |
109 | | - dst = (char*)aligned_dst; |
110 | | - src = (char*)aligned_src; |
111 | | - } |
112 | | - |
113 | | - while (len--) |
114 | | - *dst++ = *src++; |
115 | | - |
116 | | - return dst0; |
117 | | -#endif /* not PREFER_SIZE_OVER_SPEED */ |
118 | | -} |
Index: umsboot/libc/memset.c |
— | — | @@ -1,111 +0,0 @@ |
2 | | -/* |
3 | | -FUNCTION |
4 | | - <<memset>>---set an area of memory |
5 | | - |
6 | | -INDEX |
7 | | - memset |
8 | | - |
9 | | -ANSI_SYNOPSIS |
10 | | - #include <string.h> |
11 | | - void *memset(const void *<[dst]>, int <[c]>, size_t <[length]>); |
12 | | - |
13 | | -TRAD_SYNOPSIS |
14 | | - #include <string.h> |
15 | | - void *memset(<[dst]>, <[c]>, <[length]>) |
16 | | - void *<[dst]>; |
17 | | - int <[c]>; |
18 | | - size_t <[length]>; |
19 | | - |
20 | | -DESCRIPTION |
21 | | - This function converts the argument <[c]> into an unsigned |
22 | | - char and fills the first <[length]> characters of the array |
23 | | - pointed to by <[dst]> to the value. |
24 | | - |
25 | | -RETURNS |
26 | | - <<memset>> returns the value of <[m]>. |
27 | | - |
28 | | -PORTABILITY |
29 | | -<<memset>> is ANSI C. |
30 | | - |
31 | | - <<memset>> requires no supporting OS subroutines. |
32 | | - |
33 | | -QUICKREF |
34 | | - memset ansi pure |
35 | | -*/ |
36 | | - |
37 | | -#include "global.h" |
38 | | -#include "include/string.h" |
39 | | -#include "include/_ansi.h" |
40 | | - |
41 | | -#define LBLOCKSIZE (sizeof(long)) |
42 | | -#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) |
43 | | -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) |
44 | | - |
45 | | -_PTR |
46 | | -_DEFUN (memset, (m, c, n), |
47 | | - _PTR m _AND |
48 | | - int c _AND |
49 | | - size_t n) |
50 | | -{ |
51 | | -#if defined(PREFER_SIZE_OVER_SPEED) |
52 | | - char *s = (char *) m; |
53 | | - |
54 | | - while (n-- != 0) |
55 | | - { |
56 | | - *s++ = (char) c; |
57 | | - } |
58 | | - |
59 | | - return m; |
60 | | -#else |
61 | | - char *s = (char *) m; |
62 | | - unsigned int i; |
63 | | - unsigned long buffer; |
64 | | - unsigned long *aligned_addr; |
65 | | - |
66 | | - if (!TOO_SMALL (n) && !UNALIGNED (m)) |
67 | | - { |
68 | | - /* If we get this far, we know that n is large and m is word-aligned. */ |
69 | | - |
70 | | - aligned_addr = (unsigned long*)m; |
71 | | - |
72 | | - /* Store C into each char sized location in BUFFER so that |
73 | | - we can set large blocks quickly. */ |
74 | | - c &= 0xff; |
75 | | - if (LBLOCKSIZE == 4) |
76 | | - { |
77 | | - buffer = (c << 8) | c; |
78 | | - buffer |= (buffer << 16); |
79 | | - } |
80 | | - else |
81 | | - { |
82 | | - buffer = 0; |
83 | | - for (i = 0; i < LBLOCKSIZE; i++) |
84 | | - buffer = (buffer << 8) | c; |
85 | | - } |
86 | | - |
87 | | - while (n >= LBLOCKSIZE*4) |
88 | | - { |
89 | | - *aligned_addr++ = buffer; |
90 | | - *aligned_addr++ = buffer; |
91 | | - *aligned_addr++ = buffer; |
92 | | - *aligned_addr++ = buffer; |
93 | | - n -= 4*LBLOCKSIZE; |
94 | | - } |
95 | | - |
96 | | - while (n >= LBLOCKSIZE) |
97 | | - { |
98 | | - *aligned_addr++ = buffer; |
99 | | - n -= LBLOCKSIZE; |
100 | | - } |
101 | | - /* Pick up the remainder with a bytewise loop. */ |
102 | | - s = (char*)aligned_addr; |
103 | | - } |
104 | | - |
105 | | - while (n--) |
106 | | - { |
107 | | - *s++ = (char)c; |
108 | | - } |
109 | | - |
110 | | - return m; |
111 | | -#endif /* not PREFER_SIZE_OVER_SPEED */ |
112 | | -} |