2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 Copyright (c) 2001, 2002, 2003 Eliot Dresselhaus
18 Permission is hereby granted, free of charge, to any person obtaining
19 a copy of this software and associated documentation files (the
20 "Software"), to deal in the Software without restriction, including
21 without limitation the rights to use, copy, modify, merge, publish,
22 distribute, sublicense, and/or sell copies of the Software, and to
23 permit persons to whom the Software is furnished to do so, subject to
24 the following conditions:
26 The above copyright notice and this permission notice shall be
27 included in all copies or substantial portions of the Software.
29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #ifndef included_clib_string_h
39 #define included_clib_string_h
41 #include <vppinfra/clib.h> /* for CLIB_LINUX_KERNEL */
42 #include <vppinfra/vector.h>
44 #ifdef CLIB_LINUX_KERNEL
45 #include <linux/string.h>
52 #ifdef CLIB_STANDALONE
53 #include <vppinfra/standalone_string.h>
56 /* Exchanges source and destination. */
57 void clib_memswap (void *_a, void *_b, uword bytes);
60 * the vector unit memcpy variants confuse coverity
61 * so don't let it anywhere near them.
65 #include <vppinfra/memcpy_avx.h>
67 #include <vppinfra/memcpy_sse3.h>
69 #define clib_memcpy(a,b,c) memcpy(a,b,c)
71 #else /* __COVERITY__ */
72 #define clib_memcpy(a,b,c) memcpy(a,b,c)
76 * Copy 64 bytes of data to 4 destinations
77 * this function is typically used in quad-loop case when whole cacheline
78 * needs to be copied to 4 different places. First it reads whole cacheline
79 * to 1/2/4 SIMD registers and then it writes data to 4 destinations.
82 static_always_inline void
83 clib_memcpy64_x4 (void *d0, void *d1, void *d2, void *d3, void *s)
85 #if defined (CLIB_HAVE_VEC512)
86 u8x64 __attribute__ ((aligned (1))) r0 = *(((u8x64 *) s) + 0);
88 *(((u8x64 *) d0) + 0) = r0;
89 *(((u8x64 *) d1) + 0) = r0;
90 *(((u8x64 *) d2) + 0) = r0;
91 *(((u8x64 *) d3) + 0) = r0;
92 #elif defined (CLIB_HAVE_VEC256)
93 u8x32 __attribute__ ((aligned (1))) r0 = *(((u8x32 *) s) + 0);
94 u8x32 __attribute__ ((aligned (1))) r1 = *(((u8x32 *) s) + 1);
96 *(((u8x32 *) d0) + 0) = r0;
97 *(((u8x32 *) d0) + 1) = r1;
99 *(((u8x32 *) d1) + 0) = r0;
100 *(((u8x32 *) d1) + 1) = r1;
102 *(((u8x32 *) d2) + 0) = r0;
103 *(((u8x32 *) d2) + 1) = r1;
105 *(((u8x32 *) d3) + 0) = r0;
106 *(((u8x32 *) d3) + 1) = r1;
107 #elif defined (CLIB_HAVE_VEC128)
108 u8x16 __attribute__ ((aligned (1))) r0 = *(((u8x16 *) s) + 0);
109 u8x16 __attribute__ ((aligned (1))) r1 = *(((u8x16 *) s) + 1);
110 u8x16 __attribute__ ((aligned (1))) r2 = *(((u8x16 *) s) + 3);
111 u8x16 __attribute__ ((aligned (1))) r3 = *(((u8x16 *) s) + 4);
113 *(((u8x16 *) d0) + 0) = r0;
114 *(((u8x16 *) d0) + 1) = r1;
115 *(((u8x16 *) d0) + 2) = r2;
116 *(((u8x16 *) d0) + 3) = r3;
118 *(((u8x16 *) d1) + 0) = r0;
119 *(((u8x16 *) d1) + 1) = r1;
120 *(((u8x16 *) d1) + 2) = r2;
121 *(((u8x16 *) d1) + 3) = r3;
123 *(((u8x16 *) d2) + 0) = r0;
124 *(((u8x16 *) d2) + 1) = r1;
125 *(((u8x16 *) d2) + 2) = r2;
126 *(((u8x16 *) d2) + 3) = r3;
128 *(((u8x16 *) d3) + 0) = r0;
129 *(((u8x16 *) d3) + 1) = r1;
130 *(((u8x16 *) d3) + 2) = r2;
131 *(((u8x16 *) d3) + 3) = r3;
133 clib_memcpy (d0, s, 64);
134 clib_memcpy (d1, s, 64);
135 clib_memcpy (d2, s, 64);
136 clib_memcpy (d3, s, 64);
140 #endif /* included_clib_string_h */
143 * fd.io coding-style-patch-verification: ON
146 * eval: (c-set-style "gnu")