1/*
2 * Copyright (c) 2016, Intel Corporation
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 *
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef COPY_BYTES_H
30#define COPY_BYTES_H
31
32#include "unaligned.h"
33#include "simd_utils.h"
34
35static really_inline
36void copy_upto_32_bytes(u8 *dst, const u8 *src, unsigned int len) {
37 switch (len) {
38 case 0:
39 break;
40 case 1:
41 *dst = *src;
42 break;
43 case 2:
44 unaligned_store_u16(dst, unaligned_load_u16(src));
45 break;
46 case 3:
47 unaligned_store_u16(dst, unaligned_load_u16(src));
48 dst[2] = src[2];
49 break;
50 case 4:
51 unaligned_store_u32(dst, unaligned_load_u32(src));
52 break;
53 case 5:
54 case 6:
55 case 7:
56 unaligned_store_u32(dst + len - 4, unaligned_load_u32(src + len - 4));
57 unaligned_store_u32(dst, unaligned_load_u32(src));
58 break;
59 case 8:
60 unaligned_store_u64a(dst, unaligned_load_u64a(src));
61 break;
62 case 9:
63 case 10:
64 case 11:
65 case 12:
66 case 13:
67 case 14:
68 case 15:
69 unaligned_store_u64a(dst + len - 8, unaligned_load_u64a(src + len - 8));
70 unaligned_store_u64a(dst, unaligned_load_u64a(src));
71 break;
72 case 16:
73 storeu128(dst, loadu128(src));
74 break;
75 case 32:
76 storeu256(dst, loadu256(src));
77 break;
78 default:
79 assert(len < 32);
80 storeu128(dst + len - 16, loadu128(src + len - 16));
81 storeu128(dst, loadu128(src));
82 break;
83 }
84}
85
86#endif
87