git subrepo clone https://github.com/libretro/libretro-common.git deps/libretro-common
[pcsx_rearmed.git] / deps / libretro-common / include / fastcpy.h
CommitLineData
3719602c
PC
1/* Copyright (C) 2010-2020 The RetroArch team
2 *
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this file (fastcpy.h).
5 * ---------------------------------------------------------------------------------------
6 *
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23/* in the future ASM and new c++ features can be added to speed up copying */
24#include <stdint.h>
25#include <string.h>
26#include <retro_inline.h>
27
28static INLINE void* memcpy16(void* dst,void* src,size_t size)
29{
30 return memcpy(dst,src,size * 2);
31}
32
33static INLINE void* memcpy32(void* dst,void* src,size_t size)
34{
35 return memcpy(dst,src,size * 4);
36}
37
38static INLINE void* memcpy64(void* dst,void* src,size_t size)
39{
40 return memcpy(dst,src,size * 8);
41}
42
43#ifdef USECPPSTDFILL
44#include <algorithm>
45
46static INLINE void* memset16(void* dst,uint16_t val,size_t size)
47{
48 uint16_t *typedptr = (uint16_t*)dst;
49 std::fill(typedptr, typedptr + size, val);
50 return dst;
51}
52
53static INLINE void* memset32(void* dst,uint32_t val,size_t size)
54{
55 uint32_t *typedptr = (uint32_t*)dst;
56 std::fill(typedptr, typedptr + size, val);
57 return dst;
58}
59
60static INLINE void* memset64(void* dst,uint64_t val,size_t size)
61{
62 uint64_t *typedptr = (uint64_t*)dst;
63 std::fill(typedptr, typedptr + size, val);
64 return dst;
65}
66#else
67static INLINE void *memset16(void* dst,uint16_t val,size_t size)
68{
69 size_t i;
70 uint16_t *typedptr = (uint16_t*)dst;
71 for (i = 0;i < size;i++)
72 typedptr[i] = val;
73 return dst;
74}
75
76static INLINE void *memset32(void* dst,uint32_t val,size_t size)
77{
78 size_t i;
79 uint32_t *typedptr = (uint32_t*)dst;
80 for (i = 0; i < size; i++)
81 typedptr[i] = val;
82 return dst;
83}
84
85static INLINE void *memset64(void* dst,uint64_t val,size_t size)
86{
87 size_t i;
88 uint64_t *typedptr = (uint64_t*)dst;
89 for (i = 0; i < size;i++)
90 typedptr[i] = val;
91 return dst;
92}
93#endif