v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
memory.h
1 /* -*- mode: C; c-basic-offset: 4; intent-tabs-mode: nil -*-
2  *
3  * Sifteo SDK
4  *
5  * Copyright <c> 2012 Sifteo, Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 
26 #pragma once
27 #ifdef NOT_USERSPACE
28 # error This is a userspace-only header, not allowed by the current build.
29 #endif
30 
31 #include <sifteo/abi.h>
32 
33 namespace Sifteo {
34 
43 inline void memset8(uint8_t *dest, uint8_t value, unsigned count) {
45  _SYS_memset8(dest, value, count);
46 }
47 
49 inline void memset16(uint16_t *dest, uint16_t value, unsigned count) {
50  _SYS_memset16(dest, value, count);
51 }
52 
54 inline void memset32(uint32_t *dest, uint32_t value, unsigned count) {
55  _SYS_memset32(dest, value, count);
56 }
57 
59 inline void memcpy8(uint8_t *dest, const uint8_t *src, unsigned count) {
60  _SYS_memcpy8(dest, src, count);
61 }
62 
64 inline void memcpy16(uint16_t *dest, const uint16_t *src, unsigned count) {
65  _SYS_memcpy16(dest, src, count);
66 }
67 
69 inline void memcpy32(uint32_t *dest, const uint32_t *src, unsigned count) {
70  _SYS_memcpy32(dest, src, count);
71 }
72 
74 inline int memcmp8(const uint8_t *a, const uint8_t *b, unsigned count) {
75  return _SYS_memcmp8(a, b, count);
76 }
77 
79 inline void memset(uint8_t *dest, uint8_t value, unsigned count) {
80  _SYS_memset8(dest, value, count);
81 }
82 
84 inline void memset(uint16_t *dest, uint16_t value, unsigned count) {
85  _SYS_memset16(dest, value, count);
86 }
87 
89 inline void memset(uint32_t *dest, uint32_t value, unsigned count) {
90  _SYS_memset32(dest, value, count);
91 }
92 
94 inline void memcpy(uint8_t *dest, const uint8_t *src, unsigned count) {
95  _SYS_memcpy8(dest, src, count);
96 }
97 
99 inline void memcpy(uint16_t *dest, const uint16_t *src, unsigned count) {
100  _SYS_memcpy16(dest, src, count);
101 }
102 
104 inline void memcpy(uint32_t *dest, const uint32_t *src, unsigned count) {
105  _SYS_memcpy32(dest, src, count);
106 }
107 
109 inline int memcmp(const uint8_t *a, const uint8_t *b, unsigned count) {
110  return _SYS_memcmp8(a, b, count);
111 }
112 
114 inline void bzero(void *s, unsigned count) {
115  _SYS_memset8((uint8_t*)s, 0, count);
116 }
117 
119 template <typename T>
120 inline void bzero(T &s) {
121  _SYS_memset8((uint8_t*)&s, 0, sizeof s);
122 }
123 
161 inline uint32_t crc32(const void *bytes, unsigned count) {
162  return _SYS_crc32((const uint8_t*)bytes, count);
163 }
164 
166 template <typename T>
167 inline uint32_t crc32(const T &s) {
168  return _SYS_crc32((const uint8_t*)&s, sizeof s);
169 }
170 
171 
176 }; // namespace Sifteo
void bzero(T &s)
One-argument form of bzero: Templatized to zero any fixed-size object.
Definition: memory.h:120
int memcmp8(const uint8_t *a, const uint8_t *b, unsigned count)
memcmp(), with an explicit 8-bit data width
Definition: memory.h:74
uint32_t crc32(const T &s)
Templatized version of crc32() for fixed-size objects.
Definition: memory.h:167
void memset32(uint32_t *dest, uint32_t value, unsigned count)
memset(), with an explicit 32-bit data width
Definition: memory.h:54
void memcpy8(uint8_t *dest, const uint8_t *src, unsigned count)
memcpy(), with an explicit 8-bit data width
Definition: memory.h:59
void memset8(uint8_t *dest, uint8_t value, unsigned count)
memset(), with an explicit 8-bit data width
Definition: memory.h:44
void memset(uint32_t *dest, uint32_t value, unsigned count)
memset(), with an implicit 32-bit data width
Definition: memory.h:89
int memcmp(const uint8_t *a, const uint8_t *b, unsigned count)
memcmp(), with an implicit 8-bit data width
Definition: memory.h:109
Definition: array.h:34
void memset16(uint16_t *dest, uint16_t value, unsigned count)
memset(), with an explicit 16-bit data width
Definition: memory.h:49
void memcpy16(uint16_t *dest, const uint16_t *src, unsigned count)
memcpy(), with an explicit 16-bit data width
Definition: memory.h:64
void memcpy(uint32_t *dest, const uint32_t *src, unsigned count)
memcpy(), with an implicit 32-bit data width
Definition: memory.h:104
void memcpy32(uint32_t *dest, const uint32_t *src, unsigned count)
memcpy(), with an explicit 32-bit data width
Definition: memory.h:69