forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.h
More file actions
80 lines (60 loc) · 1.7 KB
/
string.h
File metadata and controls
80 lines (60 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2018 Intel Corporation. All rights reserved.
*
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
*/
#ifdef __XTOS_RTOS_STRING_H__
#ifndef __ARCH_STRING_H__
#define __ARCH_STRING_H__
#include <xtensa/hal.h>
#include <errno.h>
#include <stddef.h>
#include <string.h>
#define arch_memcpy(dest, src, size) \
xthal_memcpy(dest, src, size)
#define bzero(ptr, size) \
memset_s(ptr, size, 0, size)
void *xthal_memcpy(void *dst, const void *src, size_t len);
int memset_s(void *dest, size_t dest_size,
int data, size_t count);
int memcpy_s(void *dest, size_t dest_size,
const void *src, size_t count);
void *__vec_memcpy(void *dst, const void *src, size_t len);
void *__vec_memset(void *dest, int data, size_t src_size);
static inline int arch_memcpy_s(void *dest, size_t dest_size,
const void *src, size_t count)
{
if (!dest || !src)
return -EINVAL;
if ((dest >= src && (char *)dest < ((char *)src + count)) ||
(src >= dest && (char *)src < ((char *)dest + dest_size)))
return -EINVAL;
if (count > dest_size)
return -EINVAL;
#if __XCC__ && XCHAL_HAVE_HIFI3 && !CONFIG_LIBRARY
__vec_memcpy(dest, src, count);
#else
memcpy(dest, src, count);
#endif
return 0;
}
static inline int arch_memset_s(void *dest, size_t dest_size,
int data, size_t count)
{
if (!dest)
return -EINVAL;
if (count > dest_size)
return -EINVAL;
#if __XCC__ && XCHAL_HAVE_HIFI3 && !CONFIG_LIBRARY
if (!__vec_memset(dest, data, count))
return -ENOMEM;
#else
memset(dest, data, count);
#endif
return 0;
}
#endif /* __ARCH_STRING_H__ */
#else
#error "This file shouldn't be included from outside of sof/string.h"
#endif /* __SOF_STRING_H__ */