1 /*
2 * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 /** \file
19 * \brief Various memory operations
20 */
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #if defined(INLINE_MEMOPS)
27 #include <sys/types.h>
28
29 static inline void
30 __attribute__((always_inline))
__c_mzero1(char * dest,long cnt)31 __c_mzero1(char *dest, long cnt)
32 {
33 (void) __builtin_memset(dest, 0, (size_t) cnt);
34 }
35
36 static inline void
37 __attribute__((always_inline))
__c_mzero2(short * dest,long cnt)38 __c_mzero2(short *dest, long cnt)
39 {
40 (void) __builtin_memset(dest, 0, (size_t) cnt * sizeof(short));
41 }
42
43 static inline void
44 __attribute__((always_inline))
__c_mzero4(int * dest,long cnt)45 __c_mzero4(int *dest, long cnt)
46 {
47 (void) __builtin_memset(dest, 0, (size_t) cnt * sizeof(int));
48 }
49
50 static inline void
51 __attribute__((always_inline))
__c_mzero8(long long * dest,long cnt)52 __c_mzero8(long long *dest, long cnt)
53 {
54 (void) __builtin_memset(dest, 0, (size_t) cnt * sizeof(long long));
55 }
56
57 static inline void
58 __attribute__((always_inline))
__c_mcopy1(char * dest,char * src,long cnt)59 __c_mcopy1(char *dest, char *src, long cnt)
60 {
61 (void) __builtin_memcpy(dest, src, (size_t) cnt);
62 }
63
64 static inline void
65 __attribute__((always_inline))
__c_mcopy2(short * dest,short * src,long cnt)66 __c_mcopy2(short *dest, short *src, long cnt)
67 {
68 (void) __builtin_memcpy(dest, src, (size_t) cnt * sizeof(short));
69 }
70
71 static inline void
72 __attribute__((always_inline))
__c_mcopy4(int * dest,int * src,long cnt)73 __c_mcopy4(int *dest, int *src, long cnt)
74 {
75 (void) __builtin_memcpy(dest, src, (size_t) cnt * sizeof(int));
76 }
77
78 static inline void
79 __attribute__((always_inline))
__c_mcopy8(long long * dest,long long * src,long cnt)80 __c_mcopy8(long long *dest, long long *src, long cnt)
81 {
82 (void) __builtin_memcpy(dest, src, (size_t) cnt * sizeof(long long));
83 }
84
85 static inline void
86 __attribute__((always_inline))
__c_mset1(char * dest,int value,long cnt)87 __c_mset1(char *dest, int value, long cnt)
88 {
89 ssize_t i;
90 for (i = 0; i < cnt; ++i)
91 dest[i] = (char) value;
92 }
93
94 static inline void
95 __attribute__((always_inline))
__c_mset2(short * dest,int value,long cnt)96 __c_mset2(short *dest, int value, long cnt)
97 {
98 ssize_t i;
99 for (i = 0; i < cnt; ++i)
100 dest[i] = (short) value;
101 }
102
103 static inline void
104 __attribute__((always_inline))
__c_mset4(int * dest,int value,long cnt)105 __c_mset4(int *dest, int value, long cnt)
106 {
107 ssize_t i;
108 for (i = 0; i < cnt; ++i)
109 dest[i] = value;
110 }
111
112 static inline void
113 __attribute__((always_inline))
__c_mset8(long long * dest,long long value,long cnt)114 __c_mset8(long long *dest, long long value, long cnt)
115 {
116 ssize_t i;
117 for (i = 0; i < cnt; ++i)
118 dest[i] = (long long) value;
119 }
120 #else
121 void __c_mcopy1(char *dest, char *src, long cnt);
122 void __c_mcopy2(short *dest, short *src, long cnt);
123 void __c_mcopy4(int *dest, int *src, long cnt);
124 void __c_mcopy8(long long *dest, long long *src, long cnt);
125
126 void __c_mset1(char *dest, int value, long cnt);
127 void __c_mset2(short *dest, int value, long cnt);
128 void __c_mset4(int *dest, int value, long cnt);
129 void __c_mset8(long long *dest, long long value, long cnt);
130
131 void __c_mzero1(char *dest, long cnt);
132 void __c_mzero2(short *dest, long cnt);
133 void __c_mzero4(int *dest, long cnt);
134 void __c_mzero8(long long *dest, long cnt);
135 #endif
136
137 #ifdef __cplusplus
138 } /* extern "C" */
139 #endif
140
141