OpenTitan Device Memory Library. More...
#include <stdalign.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "sw/device/lib/base/macros.h"
Go to the source code of this file.
Macros | |
#define | OT_PREFIX_IF_NOT_RV32(name) ot_##name |
Functions | |
OT_WARN_UNUSED_RESULT ptrdiff_t | misalignment32_of (uintptr_t addr) |
Computes how many bytes addr is ahead of the previous 32-bit word alignment boundary. | |
OT_WARN_UNUSED_RESULT uint32_t | read_32 (const void *ptr) |
Load a word from memory directly, bypassing aliasing rules. More... | |
OT_WARN_UNUSED_RESULT uint64_t | read_64 (const void *ptr) |
Load a 64-bit word from memory directly, bypassing aliasing rules. More... | |
void | write_32 (uint32_t value, void *ptr) |
Store a word to memory directly, bypassing aliasing rules. More... | |
void | write_64 (uint64_t value, void *ptr) |
Store a 64-bit word to memory directly, bypassing aliasing rules. More... | |
void *OT_PREFIX_IF_NOT_RV32() | memcpy (void *OT_RESTRICT dest, const void *OT_RESTRICT src, size_t len) |
Copy memory between non-overlapping regions. More... | |
void *OT_PREFIX_IF_NOT_RV32() | memset (void *dest, int value, size_t len) |
Set a region of memory to a particular byte value. More... | |
int OT_PREFIX_IF_NOT_RV32() | memcmp (const void *lhs, const void *rhs, size_t len) |
Compare two (potentially overlapping) regions of memory for byte-wise lexicographic order. More... | |
int | memrcmp (const void *lhs, const void *rhs, size_t len) |
Compare two (potentially overlapping) regions of memory for reverse byte-wise lexicographic order (i.e. More... | |
void *OT_PREFIX_IF_NOT_RV32() | memchr (const void *ptr, int value, size_t len) |
Search a region of memory for the first occurrence of a particular byte value. More... | |
void *OT_PREFIX_IF_NOT_RV32() | memrchr (const void *ptr, int value, size_t len) |
Search a region of memory for the last occurrence of a particular byte value. More... | |
OpenTitan Device Memory Library.
This library provides memory functions for aligned word accesses, and some useful functions from the C library's <string.h>.
Definition in file memory.h.
void* OT_PREFIX_IF_NOT_RV32() memchr | ( | const void * | ptr, |
int | value, | ||
size_t | len | ||
) |
Search a region of memory for the first occurrence of a particular byte value.
This function conforms to the semantics defined in ISO C11 S7.24.5.1.
Since libbase does not provide a strlen()
function, this function can be used as an approximation: memchr(my_str, 0, SIZE_MAX) - my_str
.
This function will be provided by the platform's libc implementation for host builds.
ptr | the region to search. |
value | the value, converted to a byte, to search for. |
len | the length of the region, in bytes. |
int OT_PREFIX_IF_NOT_RV32() memcmp | ( | const void * | lhs, |
const void * | rhs, | ||
size_t | len | ||
) |
Compare two (potentially overlapping) regions of memory for byte-wise lexicographic order.
This function conforms to the semantics defined in ISO C11 S7.24.4.1.
This function will be provided by the platform's libc implementation for host builds.
lhs | the left-hand-side of the comparison. |
rhs | the right-hand-side of the comparison. |
len | the length of both regions, in bytes. |
lhs == rhs
, lhs > rhs
, and lhs < rhs
(as buffers, not pointers), respectively. void* OT_PREFIX_IF_NOT_RV32() memcpy | ( | void *OT_RESTRICT | dest, |
const void *OT_RESTRICT | src, | ||
size_t | len | ||
) |
Copy memory between non-overlapping regions.
This function conforms to the semantics defined in ISO C11 S7.23.2.1.
This function will be provided by the platform's libc implementation for host builds.
dest | the region to copy to. |
src | the region to copy from. |
len | the number of bytes to copy. |
dest
. void* OT_PREFIX_IF_NOT_RV32() memrchr | ( | const void * | ptr, |
int | value, | ||
size_t | len | ||
) |
Search a region of memory for the last occurrence of a particular byte value.
This function is not specified by C11, but is named for a well-known glibc extension.
ptr | the region to search. |
value | the value, converted to a byte, to search for. |
len | the length of the region, in bytes. |
int memrcmp | ( | const void * | lhs, |
const void * | rhs, | ||
size_t | len | ||
) |
Compare two (potentially overlapping) regions of memory for reverse byte-wise lexicographic order (i.e.
the same as memcmp, but starting from the end of the memory regions).
Can be used for arithmetic comparison of little-endian buffers.
This function is provided by OpenTitan in host builds, not by the platform's libc implementation.
lhs | the left-hand-side of the comparison. |
rhs | the right-hand-side of the comparison. |
len | the length of both regions, in bytes. |
lhs == rhs
, lhs > rhs
, and lhs < rhs
(as buffers, not pointers), respectively. void* OT_PREFIX_IF_NOT_RV32() memset | ( | void * | dest, |
int | value, | ||
size_t | len | ||
) |
Set a region of memory to a particular byte value.
This function conforms to the semantics defined in ISO C11 S7.23.6.1.
This function will be provided by the platform's libc implementation for host builds.
dest | the region to write to. |
value | the value, converted to a byte, to write to each byte cell. |
len | the number of bytes to write. |
dest
.
|
inline |
Load a word from memory directly, bypassing aliasing rules.
ISO C forbids, in general, casting a pointer to non-character types and reading them, though it is frequently necessary to read exactly one word out of a void *
. This function performs that action in a manner which is well-defined.
Of course, ptr
must point to word-aligned memory that is at least one word wide. To do otherwise is Undefined Behavior. It goes without saying that the memory this function intents to read must be initialized.
This function has reordering properties as weak as a normal, non-atomic, non-volatile load.
ptr | a word-aligned pointer pointed to at least four bytes of memory. |
ptr
points to.
|
inline |
Load a 64-bit word from memory directly, bypassing aliasing rules.
ISO C forbids, in general, casting a pointer to non-character types and reading them, though it is frequently necessary to read exactly one 64-bit word out of a void *
. This function performs that action in a manner which is well-defined.
Of course, ptr
must point to word-aligned memory that is at least one 64-bit word wide. To do otherwise is Undefined Behavior. It goes without saying that the memory this function intents to read must be initialized.
This function has reordering properties as weak as a normal, non-atomic, non-volatile load.
ptr | a word-aligned pointer pointed to at least four bytes of memory. |
ptr
points to.
|
inline |
Store a word to memory directly, bypassing aliasing rules.
ISO C forbids, in general, casting a pointer to non-character types and reading them, though it is frequently necessary to write exactly one word to a void *
. This function performs that action in a manner which is well-defined.
Of course, ptr
must point to word-aligned memory that is at least one word wide. To do otherwise is Undefined Behavior.
This function has reordering properties as weak as a normal, non-atomic, non-volatile load.
value | the value to store. |
ptr | a word-aligned pointer pointed to at least four bytes of memory. |
|
inline |
Store a 64-bit word to memory directly, bypassing aliasing rules.
ISO C forbids, in general, casting a pointer to non-character types and reading them, though it is frequently necessary to write exactly one 64-bit word to a void *
. This function performs that action in a manner which is well-defined.
Of course, ptr
must point to word-aligned memory that is at least one 64-bit word wide. To do otherwise is Undefined Behavior.
This function has reordering properties as weak as a normal, non-atomic, non-volatile load.
value | the value to store. |
ptr | a word-aligned pointer pointed to at least four bytes of memory. |