MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
proximus_operor.h
Go to the documentation of this file.
1/* MMgr - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2 * SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Commercial OR LicenseRef-Educational
3 *
4 * Every use falls under AGPL-3.0-or-later unless you hold explicit permission, which is either a
5 * negotiated commercial licensing contract or an educator's license issued to you personally.
6 */
7/**
8 * @file proximus_operor.h
9 * @brief Typed loads and stores, and the proxim dispatch table.
10 * @author dstroy0 (Douglas Quigg) <dquigg123@gmail.com>
11 * @date 2026-08-29
12 *
13 * @note load16 through put64, load, put and read take any address.
14 * @note The four al_ entries need an address aligned for the type they carry.
15 */
16#ifndef MMGR_PROXIMUS_OPEROR_H
17#define MMGR_PROXIMUS_OPEROR_H
18
19/** @addtogroup mod_proxim
20 * @{ */
21
22#include "mmgr.h"
23
24EMBED_BEGIN_DECLS
25
26/**
27 * @brief Arguments for the proxim calls.
28 *
29 * @note The loads read at. The stores read dst and val. Only the read entry reads size.
30 */
31typedef struct
32{
33 void *const dst; /**< Destination for the stores and for read [BORROWS]. */
34 const void *const at; /**< Source for the loads and for read [BORROWS]. */
35 const uint64_t val; /**< Value the stores write, taken from its low bytes. */
36 const size_t size; /**< Bytes the read entry copies. */
38
39/**
40 * @brief Type of the proxim dispatch table.
41 *
42 * @note EMBED_TABLE_LAYOUT asserts the thirteen members sit at consecutive EMBED_FUNCTION_POINTER_BYTES offsets, with
43 * nothing else.
44 * @note Each member below states its own alignment requirement.
45 */
46typedef struct
47{
48 uint16_t (*load16)(const ProximusCfg *args); /**< Reads two bytes. */
49 uint32_t (*load32)(const ProximusCfg *args); /**< Reads four bytes. */
50 uint64_t (*load64)(const ProximusCfg *args); /**< Reads eight bytes. */
51 void (*put16)(const ProximusCfg *args); /**< Writes two bytes. */
52 void (*put32)(const ProximusCfg *args); /**< Writes four bytes. */
53 void (*put64)(const ProximusCfg *args); /**< Writes eight bytes. */
54 embed_word (*load)(const ProximusCfg *args); /**< Reads one word. */
55 void (*put)(const ProximusCfg *args); /**< Writes one word. */
56 embed_word (*al_load)(const ProximusCfg *args); /**< Reads one word from an aligned address. */
57 void (*al_put)(const ProximusCfg *args); /**< Writes one word to an aligned address. */
58 uint64_t (*al_load64)(const ProximusCfg *args); /**< Reads eight bytes from an aligned address. */
59 void (*al_put64)(const ProximusCfg *args); /**< Writes eight bytes to an aligned address. */
60 void (*read)(const ProximusCfg *args); /**< Copies size bytes, with the destination on a boundary first. */
62EMBED_TABLE_LAYOUT(ProximusOperorNs, load16, load32, load64, put16, put32, put64, load, put, al_load, al_put, al_load64,
63 al_put64, read);
64
65/**
66 * @brief Reads two bytes from args->at in the target's own order.
67 *
68 * @param[in] args Address to read from [BORROWS].
69 * @return The two bytes as a uint16_t.
70 * @warning args->at must be readable for two bytes, at any alignment.
71 */
72EMBED_HOST_DEVICE uint16_t mmgr_proxim_load16(const ProximusCfg *args);
73
74/**
75 * @brief Reads four bytes from args->at in the target's own order.
76 *
77 * @param[in] args Address to read from [BORROWS].
78 * @return The four bytes as a uint32_t.
79 * @warning args->at must be readable for four bytes, at any alignment.
80 */
81EMBED_HOST_DEVICE uint32_t mmgr_proxim_load32(const ProximusCfg *args);
82
83/**
84 * @brief Reads eight bytes from args->at in the target's own order.
85 *
86 * @param[in] args Address to read from [BORROWS].
87 * @return The eight bytes as a uint64_t.
88 * @warning args->at must be readable for eight bytes, at any alignment.
89 */
90EMBED_HOST_DEVICE uint64_t mmgr_proxim_load64(const ProximusCfg *args);
91
92/**
93 * @brief Writes the low two bytes of args->val to args->dst in the target's own order.
94 *
95 * @param[in] args Destination and value [BORROWS].
96 * @note The upper six bytes of args->val take no part.
97 * @warning args->dst must be writable for two bytes, at any alignment.
98 */
99EMBED_HOST_DEVICE void mmgr_proxim_put16(const ProximusCfg *args);
100
101/**
102 * @brief Writes the low four bytes of args->val to args->dst in the target's own order.
103 *
104 * @param[in] args Destination and value [BORROWS].
105 * @note The upper four bytes of args->val take no part.
106 * @warning args->dst must be writable for four bytes, at any alignment.
107 */
108EMBED_HOST_DEVICE void mmgr_proxim_put32(const ProximusCfg *args);
109
110/**
111 * @brief Writes all eight bytes of args->val to args->dst in the target's own order.
112 *
113 * @param[in] args Destination and value [BORROWS].
114 * @warning args->dst must be writable for eight bytes, at any alignment.
115 */
116EMBED_HOST_DEVICE void mmgr_proxim_put64(const ProximusCfg *args);
117
118/**
119 * @brief Reads one word from args->at in the target's own order.
120 *
121 * @param[in] args Address to read from [BORROWS].
122 * @return The bytes as an embed_word.
123 * @warning args->at must be readable for a whole embed_word, at any alignment.
124 */
125EMBED_HOST_DEVICE embed_word mmgr_proxim_load(const ProximusCfg *args);
126
127/**
128 * @brief Writes the low word of args->val to args->dst in the target's own order.
129 *
130 * @param[in] args Destination and value [BORROWS].
131 * @warning args->dst must be writable for a whole embed_word, at any alignment.
132 */
133EMBED_HOST_DEVICE void mmgr_proxim_put(const ProximusCfg *args);
134
135/**
136 * @brief Reads one word from an aligned args->at, in the target's own order.
137 *
138 * @param[in] args Address to read from [BORROWS].
139 * @return The bytes as an embed_word.
140 * @note Reaches the same bytes as mmgr_proxim_load, through a type that retains embed_word's alignment.
141 * @warning args->at must be readable for a whole embed_word and aligned for one.
142 */
143EMBED_HOST_DEVICE embed_word mmgr_aequus_load(const ProximusCfg *args);
144
145/**
146 * @brief Writes the low word of args->val to an aligned args->dst.
147 *
148 * @param[in] args Destination and value [BORROWS].
149 * @note Reaches the same bytes as mmgr_proxim_put, through a type that retains embed_word's alignment.
150 * @warning args->dst must be writable for a whole embed_word and aligned for one.
151 */
152EMBED_HOST_DEVICE void mmgr_aequus_put(const ProximusCfg *args);
153
154/**
155 * @brief Reads eight bytes from an aligned args->at, in the target's own order.
156 *
157 * @param[in] args Address to read from [BORROWS].
158 * @return The eight bytes as a uint64_t.
159 * @note Reaches the same bytes as mmgr_proxim_load64, through a type that retains uint64_t's alignment.
160 * @warning args->at must be readable for eight bytes and aligned for a uint64_t.
161 */
162EMBED_HOST_DEVICE uint64_t mmgr_aequus_load64(const ProximusCfg *args);
163
164/**
165 * @brief Writes all eight bytes of args->val to an aligned args->dst.
166 *
167 * @param[in] args Destination and value [BORROWS].
168 * @note Reaches the same bytes as mmgr_proxim_put64, through a type that retains uint64_t's alignment.
169 * @warning args->dst must be writable for eight bytes and aligned for a uint64_t.
170 */
171EMBED_HOST_DEVICE void mmgr_aequus_put64(const ProximusCfg *args);
172
173/**
174 * @brief Copies args->size bytes from args->at to args->dst.
175 *
176 * @param[in] args Destination, source and count [BORROWS].
177 * @note Copies bytes until args->dst reaches a word boundary, then whole words, then the odd bytes left.
178 * @note This is the only entry that reads args->size.
179 * @warning Copies forward. An args->dst above args->at within one region would read bytes it has already written.
180 */
181EMBED_HOST_DEVICE void mmgr_proxim_read(const ProximusCfg *args);
182
183/**
184 * @brief Dispatch table instance named proxim.
185 *
186 * @note The nine unaligned members call the mmgr_proxim_ functions.
187 * @note The four al_ members call the mmgr_aequus_ ones.
188 */
189EMBED_TABLE_STORAGE ProximusOperorNs proxim EMBED_UNUSED = {
190 .load16 = mmgr_proxim_load16,
191 .load32 = mmgr_proxim_load32,
192 .load64 = mmgr_proxim_load64,
193 .put16 = mmgr_proxim_put16,
194 .put32 = mmgr_proxim_put32,
195 .put64 = mmgr_proxim_put64,
196 .load = mmgr_proxim_load,
197 .put = mmgr_proxim_put,
198 .al_load = mmgr_aequus_load,
199 .al_put = mmgr_aequus_put,
200 .al_load64 = mmgr_aequus_load64,
201 .al_put64 = mmgr_aequus_put64,
202 .read = mmgr_proxim_read,
203};
204
205EMBED_END_DECLS
206
207/** @} */
208
209#endif
EMBED_HOST_DEVICE uint32_t mmgr_proxim_load32(const ProximusCfg *args)
Reads four bytes from args->at in the target's own order.
static const ProximusOperorNs proxim
Dispatch table instance named proxim.
EMBED_HOST_DEVICE void mmgr_aequus_put64(const ProximusCfg *args)
Writes all eight bytes of args->val to an aligned args->dst.
EMBED_HOST_DEVICE void mmgr_proxim_put32(const ProximusCfg *args)
Writes the low four bytes of args->val to args->dst in the target's own order.
EMBED_HOST_DEVICE void mmgr_proxim_put64(const ProximusCfg *args)
Writes all eight bytes of args->val to args->dst in the target's own order.
EMBED_HOST_DEVICE void mmgr_proxim_read(const ProximusCfg *args)
Copies args->size bytes from args->at to args->dst.
EMBED_HOST_DEVICE uint64_t mmgr_aequus_load64(const ProximusCfg *args)
Reads eight bytes from an aligned args->at, in the target's own order.
EMBED_HOST_DEVICE embed_word mmgr_aequus_load(const ProximusCfg *args)
Reads one word from an aligned args->at, in the target's own order.
EMBED_HOST_DEVICE uint16_t mmgr_proxim_load16(const ProximusCfg *args)
Reads two bytes from args->at in the target's own order.
EMBED_HOST_DEVICE embed_word mmgr_proxim_load(const ProximusCfg *args)
Reads one word from args->at in the target's own order.
EMBED_HOST_DEVICE void mmgr_proxim_put(const ProximusCfg *args)
Writes the low word of args->val to args->dst in the target's own order.
EMBED_HOST_DEVICE void mmgr_aequus_put(const ProximusCfg *args)
Writes the low word of args->val to an aligned args->dst.
EMBED_HOST_DEVICE void mmgr_proxim_put16(const ProximusCfg *args)
Writes the low two bytes of args->val to args->dst in the target's own order.
EMBED_HOST_DEVICE uint64_t mmgr_proxim_load64(const ProximusCfg *args)
Reads eight bytes from args->at in the target's own order.
The embedded_types headers every module builds on.
Arguments for the proxim calls.
const uint64_t val
const void *const at
void *const dst
const size_t size
Type of the proxim dispatch table.
embed_word(*) al_load(const ProximusCfg *args)
void(*) put(const ProximusCfg *args)
void(*) al_put(const ProximusCfg *args)
void(*) read(const ProximusCfg *args)
void(*) put64(const ProximusCfg *args)
uint32_t(*) load32(const ProximusCfg *args)
uint16_t(*) load16(const ProximusCfg *args)
uint64_t(*) al_load64(const ProximusCfg *args)
uint64_t(*) load64(const ProximusCfg *args)
void(*) al_put64(const ProximusCfg *args)
void(*) put16(const ProximusCfg *args)
void(*) put32(const ProximusCfg *args)
embed_word(*) load(const ProximusCfg *args)