2.9
[glibc/nacl-glibc.git] / sysdeps / powerpc / powerpc32 / power4 / memcopy.h
blobc05208da55818df490bf6f44a105fa2095ee2fe1
1 /* memcopy.h -- definitions for memory copy functions. Generic C version.
2 Copyright (C) 1991, 1992, 1993, 1997, 2004, 2006 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Torbjorn Granlund (tege@sics.se).
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 /* The strategy of the memory functions is:
23 1. Copy bytes until the destination pointer is aligned.
25 2. Copy words in unrolled loops. If the source and destination
26 are not aligned in the same way, use word memory operations,
27 but shift and merge two read words before writing.
29 3. Copy the few remaining bytes.
31 This is fast on processors that have at least 10 registers for
32 allocation by GCC, and that can access memory at reg+const in one
33 instruction.
35 I made an "exhaustive" test of this memmove when I wrote it,
36 exhaustive in the sense that I tried all alignment and length
37 combinations, with and without overlap. */
39 #include <sysdeps/generic/memcopy.h>
41 /* The macros defined in this file are:
43 BYTE_COPY_FWD(dst_beg_ptr, src_beg_ptr, nbytes_to_copy)
45 BYTE_COPY_BWD(dst_end_ptr, src_end_ptr, nbytes_to_copy)
47 WORD_COPY_FWD(dst_beg_ptr, src_beg_ptr, nbytes_remaining, nbytes_to_copy)
49 WORD_COPY_BWD(dst_end_ptr, src_end_ptr, nbytes_remaining, nbytes_to_copy)
51 MERGE(old_word, sh_1, new_word, sh_2)
52 [I fail to understand. I feel stupid. --roland]
56 /* Threshold value for when to enter the unrolled loops. */
57 #undef OP_T_THRES
58 #define OP_T_THRES 16
60 /* Copy exactly NBYTES bytes from SRC_BP to DST_BP,
61 without any assumptions about alignment of the pointers. */
62 #undef BYTE_COPY_FWD
63 #define BYTE_COPY_FWD(dst_bp, src_bp, nbytes) \
64 do \
65 { \
66 size_t __nbytes = (nbytes); \
67 if (__nbytes & 1) \
68 { \
69 ((byte *) dst_bp)[0] = ((byte *) src_bp)[0]; \
70 src_bp += 1; \
71 dst_bp += 1; \
72 __nbytes -= 1; \
73 } \
74 while (__nbytes > 0) \
75 { \
76 byte __x = ((byte *) src_bp)[0]; \
77 byte __y = ((byte *) src_bp)[1]; \
78 src_bp += 2; \
79 __nbytes -= 2; \
80 ((byte *) dst_bp)[0] = __x; \
81 ((byte *) dst_bp)[1] = __y; \
82 dst_bp += 2; \
83 } \
84 } while (0)
86 /* Copy exactly NBYTES_TO_COPY bytes from SRC_END_PTR to DST_END_PTR,
87 beginning at the bytes right before the pointers and continuing towards
88 smaller addresses. Don't assume anything about alignment of the
89 pointers. */
90 #undef BYTE_COPY_BWD
91 #define BYTE_COPY_BWD(dst_ep, src_ep, nbytes) \
92 do \
93 { \
94 size_t __nbytes = (nbytes); \
95 if (__nbytes & 1) \
96 { \
97 src_ep -= 1; \
98 dst_ep -= 1; \
99 ((byte *) dst_ep)[0] = ((byte *) src_ep)[0]; \
100 __nbytes -= 1; \
102 while (__nbytes > 0) \
104 byte __x, __y; \
105 src_ep -= 2; \
106 __y = ((byte *) src_ep)[1]; \
107 __x = ((byte *) src_ep)[0]; \
108 dst_ep -= 2; \
109 __nbytes -= 2; \
110 ((byte *) dst_ep)[1] = __y; \
111 ((byte *) dst_ep)[0] = __x; \
113 } while (0)