xref: /freebsd/sys/contrib/ncsw/inc/etc/memcpy_ext.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1 /* Copyright (c) 2008-2012 Freescale Semiconductor, Inc
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above copyright
9  *       notice, this list of conditions and the following disclaimer in the
10  *       documentation and/or other materials provided with the distribution.
11  *     * Neither the name of Freescale Semiconductor nor the
12  *       names of its contributors may be used to endorse or promote products
13  *       derived from this software without specific prior written permission.
14  *
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 
34 /**************************************************************************//**
35 
36  @File          memcpy_ext.h
37 
38  @Description   Efficient functions for copying and setting blocks of memory.
39 *//***************************************************************************/
40 
41 #ifndef __MEMCPY_EXT_H
42 #define __MEMCPY_EXT_H
43 
44 #include "std_ext.h"
45 
46 
47 /**************************************************************************//**
48  @Group         etc_id   Utility Library Application Programming Interface
49 
50  @Description   External routines.
51 
52  @{
53 *//***************************************************************************/
54 
55 /**************************************************************************//**
56  @Group         mem_cpy Memory Copy
57 
58  @Description   Memory Copy module functions,definitions and enums.
59 
60  @{
61 *//***************************************************************************/
62 
63 /**************************************************************************//**
64  @Function      MemCpy32
65 
66  @Description   Copies one memory buffer into another one in 4-byte chunks!
67                 Which should be more efficient than byte by byte.
68 
69                 For large buffers (over 60 bytes) this function is about 4 times
70                 more efficient than the trivial memory copy. For short buffers
71                 it is reduced to the trivial copy and may be a bit worse.
72 
73  @Param[in]     pDst    - The address of the destination buffer.
74  @Param[in]     pSrc    - The address of the source buffer.
75  @Param[in]     size    - The number of bytes that will be copied from pSrc to pDst.
76 
77  @Return        pDst (the address of the destination buffer).
78 
79  @Cautions      There is no parameter or boundary checking! It is up to the user
80                 to supply non-null parameters as source & destination and size
81                 that actually fits into the destination buffer.
82 *//***************************************************************************/
83 void * MemCpy32(void* pDst,void* pSrc, uint32_t size);
84 void * IO2IOCpy32(void* pDst,void* pSrc, uint32_t size);
85 void * IO2MemCpy32(void* pDst,void* pSrc, uint32_t size);
86 void * Mem2IOCpy32(void* pDst,void* pSrc, uint32_t size);
87 
88 /**************************************************************************//**
89  @Function      MemCpy64
90 
91  @Description   Copies one memory buffer into another one in 8-byte chunks!
92                 Which should be more efficient than byte by byte.
93 
94                 For large buffers (over 60 bytes) this function is about 8 times
95                 more efficient than the trivial memory copy. For short buffers
96                 it is reduced to the trivial copy and may be a bit worse.
97 
98                 Some testing suggests that MemCpy32() preforms better than
99                 MemCpy64() over small buffers. On average they break even at
100                 100 byte buffers. For buffers larger than that MemCpy64 is
101                 superior.
102 
103  @Param[in]     pDst    - The address of the destination buffer.
104  @Param[in]     pSrc    - The address of the source buffer.
105  @Param[in]     size    - The number of bytes that will be copied from pSrc to pDst.
106 
107  @Return        pDst (the address of the destination buffer).
108 
109  @Cautions      There is no parameter or boundary checking! It is up to the user
110                 to supply non null parameters as source & destination and size
111                 that actually fits into their buffer.
112 
113                 Do not use under Linux.
114 *//***************************************************************************/
115 void * MemCpy64(void* pDst,void* pSrc, uint32_t size);
116 
117 /**************************************************************************//**
118  @Function      MemSet32
119 
120  @Description   Sets all bytes of a memory buffer to a specific value, in
121                 4-byte chunks.
122 
123  @Param[in]     pDst    - The address of the destination buffer.
124  @Param[in]     val     - Value to set destination bytes to.
125  @Param[in]     size    - The number of bytes that will be set to val.
126 
127  @Return        pDst (the address of the destination buffer).
128 
129  @Cautions      There is no parameter or boundary checking! It is up to the user
130                 to supply non null parameter as destination and size
131                 that actually fits into the destination buffer.
132 *//***************************************************************************/
133 void * MemSet32(void* pDst, uint8_t val, uint32_t size);
134 void * IOMemSet32(void* pDst, uint8_t val, uint32_t size);
135 
136 /**************************************************************************//**
137  @Function      MemSet64
138 
139  @Description   Sets all bytes of a memory buffer to a specific value, in
140                 8-byte chunks.
141 
142  @Param[in]     pDst    - The address of the destination buffer.
143  @Param[in]     val     - Value to set destination bytes to.
144  @Param[in]     size    - The number of bytes that will be set to val.
145 
146  @Return        pDst (the address of the destination buffer).
147 
148  @Cautions      There is no parameter or boundary checking! It is up to the user
149                 to supply non null parameter as destination and size
150                 that actually fits into the destination buffer.
151 *//***************************************************************************/
152 void * MemSet64(void* pDst, uint8_t val, uint32_t size);
153 
154 /**************************************************************************//**
155  @Function      MemDisp
156 
157  @Description   Displays a block of memory in chunks of 32 bits.
158 
159  @Param[in]     addr    - The address of the memory to display.
160  @Param[in]     size    - The number of bytes that will be displayed.
161 
162  @Return        None.
163 
164  @Cautions      There is no parameter or boundary checking! It is up to the user
165                 to supply non null parameter as destination and size
166                 that actually fits into the destination buffer.
167 *//***************************************************************************/
168 void MemDisp(uint8_t *addr, int size);
169 
170 /**************************************************************************//**
171  @Function      MemCpy8
172 
173  @Description   Trivial copy one memory buffer into another byte by byte
174 
175  @Param[in]     pDst    - The address of the destination buffer.
176  @Param[in]     pSrc    - The address of the source buffer.
177  @Param[in]     size    - The number of bytes that will be copied from pSrc to pDst.
178 
179  @Return        pDst (the address of the destination buffer).
180 
181  @Cautions      There is no parameter or boundary checking! It is up to the user
182                 to supply non-null parameters as source & destination and size
183                 that actually fits into the destination buffer.
184 *//***************************************************************************/
185 void * MemCpy8(void* pDst,void* pSrc, uint32_t size);
186 
187 /**************************************************************************//**
188  @Function      MemSet8
189 
190  @Description   Sets all bytes of a memory buffer to a specific value byte by byte.
191 
192  @Param[in]     pDst    - The address of the destination buffer.
193  @Param[in]     c       - Value to set destination bytes to.
194  @Param[in]     size    - The number of bytes that will be set to val.
195 
196  @Return        pDst (the address of the destination buffer).
197 
198  @Cautions      There is no parameter or boundary checking! It is up to the user
199                 to supply non null parameter as destination and size
200                 that actually fits into the destination buffer.
201 *//***************************************************************************/
202 void * MemSet8(void* pDst, int c, uint32_t size);
203 
204 /** @} */ /* end of mem_cpy group */
205 /** @} */ /* end of etc_id group */
206 
207 
208 #endif /* __MEMCPY_EXT_H */
209