xref: /freebsd/sys/contrib/ncsw/inc/etc/memcpy_ext.h (revision d6b92ffa)
1 /* Copyright (c) 2008-2011 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  @File          memcpy_ext.h
36 
37  @Description   Efficient functions for copying and setting blocks of memory.
38 *//***************************************************************************/
39 
40 #ifndef __MEMCPY_EXT_H
41 #define __MEMCPY_EXT_H
42 
43 #include "std_ext.h"
44 
45 
46 /**************************************************************************//**
47  @Group         etc_id   Utility Library Application Programming Interface
48 
49  @Description   External routines.
50 
51  @{
52 *//***************************************************************************/
53 
54 /**************************************************************************//**
55  @Group         mem_cpy Memory Copy
56 
57  @Description   Memory Copy module functions,definitions and enums.
58 
59  @{
60 *//***************************************************************************/
61 
62 /**************************************************************************//**
63  @Function      MemCpy32
64 
65  @Description   Copies one memory buffer into another one in 4-byte chunks!
66                 Which should be more efficient than byte by byte.
67 
68                 For large buffers (over 60 bytes) this function is about 4 times
69                 more efficient than the trivial memory copy. For short buffers
70                 it is reduced to the trivial copy and may be a bit worse.
71 
72  @Param[in]     pDst    - The address of the destination buffer.
73  @Param[in]     pSrc    - The address of the source buffer.
74  @Param[in]     size    - The number of bytes that will be copied from pSrc to pDst.
75 
76  @Return        pDst (the address of the destination buffer).
77 
78  @Cautions      There is no parameter or boundary checking! It is up to the user
79                 to supply non-null parameters as source & destination and size
80                 that actually fits into the destination buffer.
81 *//***************************************************************************/
82 void * MemCpy32(void* pDst,void* pSrc, uint32_t size);
83 void * IO2IOCpy32(void* pDst,void* pSrc, uint32_t size);
84 void * IO2MemCpy32(void* pDst,void* pSrc, uint32_t size);
85 void * Mem2IOCpy32(void* pDst,void* pSrc, uint32_t size);
86 
87 /**************************************************************************//**
88  @Function      MemCpy64
89 
90  @Description   Copies one memory buffer into another one in 8-byte chunks!
91                 Which should be more efficient than byte by byte.
92 
93                 For large buffers (over 60 bytes) this function is about 8 times
94                 more efficient than the trivial memory copy. For short buffers
95                 it is reduced to the trivial copy and may be a bit worse.
96 
97                 Some testing suggests that MemCpy32() preforms better than
98                 MemCpy64() over small buffers. On average they break even at
99                 100 byte buffers. For buffers larger than that MemCpy64 is
100                 superior.
101 
102  @Param[in]     pDst    - The address of the destination buffer.
103  @Param[in]     pSrc    - The address of the source buffer.
104  @Param[in]     size    - The number of bytes that will be copied from pSrc to pDst.
105 
106  @Return        pDst (the address of the destination buffer).
107 
108  @Cautions      There is no parameter or boundary checking! It is up to the user
109                 to supply non null parameters as source & destination and size
110                 that actually fits into their buffer.
111 
112                 Do not use under Linux.
113 *//***************************************************************************/
114 void * MemCpy64(void* pDst,void* pSrc, uint32_t size);
115 
116 /**************************************************************************//**
117  @Function      MemSet32
118 
119  @Description   Sets all bytes of a memory buffer to a specific value, in
120                 4-byte chunks.
121 
122  @Param[in]     pDst    - The address of the destination buffer.
123  @Param[in]     val     - Value to set destination bytes to.
124  @Param[in]     size    - The number of bytes that will be set to val.
125 
126  @Return        pDst (the address of the destination buffer).
127 
128  @Cautions      There is no parameter or boundary checking! It is up to the user
129                 to supply non null parameter as destination and size
130                 that actually fits into the destination buffer.
131 *//***************************************************************************/
132 void * MemSet32(void* pDst, uint8_t val, uint32_t size);
133 void * IOMemSet32(void* pDst, uint8_t val, uint32_t size);
134 
135 /**************************************************************************//**
136  @Function      MemSet64
137 
138  @Description   Sets all bytes of a memory buffer to a specific value, in
139                 8-byte chunks.
140 
141  @Param[in]     pDst    - The address of the destination buffer.
142  @Param[in]     val     - Value to set destination bytes to.
143  @Param[in]     size    - The number of bytes that will be set to val.
144 
145  @Return        pDst (the address of the destination buffer).
146 
147  @Cautions      There is no parameter or boundary checking! It is up to the user
148                 to supply non null parameter as destination and size
149                 that actually fits into the destination buffer.
150 *//***************************************************************************/
151 void * MemSet64(void* pDst, uint8_t val, uint32_t size);
152 
153 /**************************************************************************//**
154  @Function      MemDisp
155 
156  @Description   Displays a block of memory in chunks of 32 bits.
157 
158  @Param[in]     addr    - The address of the memory to display.
159  @Param[in]     size    - The number of bytes that will be displayed.
160 
161  @Return        None.
162 
163  @Cautions      There is no parameter or boundary checking! It is up to the user
164                 to supply non null parameter as destination and size
165                 that actually fits into the destination buffer.
166 *//***************************************************************************/
167 void MemDisp(uint8_t *addr, int size);
168 
169 /** @} */ /* end of mem_cpy group */
170 /** @} */ /* end of etc_id group */
171 
172 
173 #endif /* __MEMCPY_EXT_H */
174