2 * Copyright 2013-2017 Nest Labs Inc. All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * This file defines C functions for safely performing simple,
20 * memory-mapped accesses, potentially to unaligned memory
27 #include <nlio-private.h>
34 * If we are compiling under clang, GCC, or any such compatible
35 * compiler, in which -fno-builtins or -ffreestanding might be
36 * asserted, thereby eliminating built-in function optimization, we
37 * STILL want built-in memcpy. We want this because it allows the
38 * compiler to use architecture-specific machine instructions or
39 * inline code generation to optimize an otherwise-expensive memcpy
40 * for unaligned reads and writes, which is exactly the kind of
41 * efficiency that would be expected of nlIO.
43 #if __nlIOHasBuiltin(__builtin_memcpy)
44 #define __nlIO_MEMCPY __builtin_memcpy
46 #define __nlIO_MEMCPY memcpy
54 * This determines whether the specified pointer is aligned on the
55 * indicated size boundary.
57 * @note The size should be a power of 2 (e.g. 1, 2, 4, 8, 16, etc.).
59 * @param[in] p The pointer to check the alignment of.
60 * @param[in] size The size, in bytes, boundary to check
61 * the alignment against.
63 * @return True if the pointer is aligned to the specified size;
66 static inline bool nlIOIsAligned(const void *p, size_t size)
68 const uintptr_t value = (uintptr_t)(p);
69 const uintptr_t mask = size - 1;
71 return ((value & mask) == 0);
75 * Perform an aligned memory read of the 8-bit value at the specified
78 * @param[in] p A pointer address to read the 8-bit value from.
80 * @return The 8-bit value at the specified pointer address.
82 static inline uint8_t nlIOGetAligned8(const void *p)
84 return *(const uint8_t *)(p);
88 * Perform an aligned memory read of the 16-bit value at the specified
91 * @param[in] p A pointer address to read the 16-bit value from.
93 * @return The 16-bit value at the specified pointer address.
95 static inline uint16_t nlIOGetAligned16(const void *p)
97 return *(const uint16_t *)(p);
101 * Perform an aligned memory read of the 32-bit value at the specified
104 * @param[in] p A pointer address to read the 32-bit value from.
106 * @return The 32-bit value at the specified pointer address.
108 static inline uint32_t nlIOGetAligned32(const void *p)
110 return *(const uint32_t *)(p);
114 * Perform an aligned memory read of the 64-bit value at the specified
117 * @param[in] p A pointer address to read the 64-bit value from.
119 * @return The 64-bit value at the specified pointer address.
121 static inline uint64_t nlIOGetAligned64(const void *p)
123 return *(const uint64_t *)(p);
127 * Perform an unaligned memory read of the 8-bit value at the specified
130 * @param[in] p A pointer address to read the 8-bit value from.
132 * @return The 8-bit value at the specified pointer address.
134 static inline uint8_t nlIOGetUnaligned8(const void *p)
136 return nlIOGetAligned8(p);
140 * Perform an unaligned memory read of the 16-bit value at the specified
143 * @param[in] p A pointer address to read the 16-bit value from.
145 * @return The 16-bit value at the specified pointer address.
147 static inline uint16_t nlIOGetUnaligned16(const void *p)
151 __nlIO_MEMCPY(&temp, p, sizeof(uint16_t));
157 * Perform an unaligned memory read of the 32-bit value at the specified
160 * @param[in] p A pointer address to read the 32-bit value from.
162 * @return The 32-bit value at the specified pointer address.
164 static inline uint32_t nlIOGetUnaligned32(const void *p)
168 __nlIO_MEMCPY(&temp, p, sizeof(uint32_t));
174 * Perform an unaligned memory read of the 64-bit value at the specified
177 * @param[in] p A pointer address to read the 64-bit value from.
179 * @return The 64-bit value at the specified pointer address.
181 static inline uint64_t nlIOGetUnaligned64(const void *p)
185 __nlIO_MEMCPY(&temp, p, sizeof(uint64_t));
191 * Perform a, potentially unaligned, memory read of the 8-bit value
192 * from the specified pointer address.
194 * @param[in] p A pointer address, potentially unaligned, to read
195 * the 8-bit value from.
197 * @return The 8-bit value at the specified pointer address.
199 static inline uint8_t nlIOGetMaybeAligned8(const void *p)
201 return nlIOGetAligned8(p);
205 * Perform a, potentially unaligned, memory read of the 16-bit value
206 * from the specified pointer address.
208 * @param[in] p A pointer address, potentially unaligned, to read
209 * the 16-bit value from.
211 * @return The 16-bit value at the specified pointer address.
213 static inline uint16_t nlIOGetMaybeAligned16(const void *p)
215 if (nlIOIsAligned(p, sizeof (uint16_t)))
216 return nlIOGetAligned16(p);
218 return nlIOGetUnaligned16(p);
222 * Perform a, potentially unaligned, memory read of the 32-bit value
223 * from the specified pointer address.
225 * @param[in] p A pointer address, potentially unaligned, to read
226 * the 32-bit value from.
228 * @return The 32-bit value at the specified pointer address.
230 static inline uint32_t nlIOGetMaybeAligned32(const void *p)
232 if (nlIOIsAligned(p, sizeof (uint32_t)))
233 return nlIOGetAligned32(p);
235 return nlIOGetUnaligned32(p);
239 * Perform a, potentially unaligned, memory read of the 64-bit value
240 * from the specified pointer address.
242 * @param[in] p A pointer address, potentially unaligned, to read
243 * the 64-bit value from.
245 * @return The 64-bit value at the specified pointer address.
247 static inline uint64_t nlIOGetMaybeAligned64(const void *p)
249 if (nlIOIsAligned(p, sizeof (uint64_t)))
250 return nlIOGetAligned64(p);
252 return nlIOGetUnaligned64(p);
256 * Perform an aligned memory write of the 8-bit value to the specified
259 * @param[in] p A pointer address to write the 8-bit value to.
261 * @param[in] v The 8-bit value to write.
264 static inline void nlIOPutAligned8(void *p, const uint8_t v)
270 * Perform an aligned memory write of the 16-bit value to the specified
273 * @param[in] p A pointer address to write the 16-bit value to.
275 * @param[in] v The 16-bit value to write.
278 static inline void nlIOPutAligned16(void *p, const uint16_t v)
280 *(uint16_t *)(p) = v;
284 * Perform an aligned memory write of the 32-bit value to the specified
287 * @param[in] p A pointer address to write the 32-bit value to.
289 * @param[in] v The 32-bit value to write.
292 static inline void nlIOPutAligned32(void *p, const uint32_t v)
294 *(uint32_t *)(p) = v;
298 * Perform an aligned memory write of the 64-bit value to the specified
301 * @param[in] p A pointer address to write the 64-bit value to.
303 * @param[in] v The 64-bit value to write.
306 static inline void nlIOPutAligned64(void *p, const uint64_t v)
308 *(uint64_t *)(p) = v;
312 * Perform an unaligned memory write of the 8-bit value to the specified
315 * @param[in] p A pointer address to write the 8-bit value to.
317 * @param[in] v The 8-bit value to write.
320 static inline void nlIOPutUnaligned8(void *p, const uint8_t v)
322 nlIOPutAligned8(p, v);
326 * Perform an unaligned memory write of the 16-bit value to the specified
329 * @param[in] p A pointer address to write the 16-bit value to.
331 * @param[in] v The 16-bit value to write.
334 static inline void nlIOPutUnaligned16(void *p, const uint16_t v)
336 __nlIO_MEMCPY(p, &v, sizeof(uint16_t));
340 * Perform an unaligned memory write of the 32-bit value to the specified
343 * @param[in] p A pointer address to write the 32-bit value to.
345 * @param[in] v The 32-bit value to write.
348 static inline void nlIOPutUnaligned32(void *p, const uint32_t v)
350 __nlIO_MEMCPY(p, &v, sizeof(uint32_t));
354 * Perform an unaligned memory write of the 64-bit value to the specified
357 * @param[in] p A pointer address to write the 64-bit value to.
359 * @param[in] v The 64-bit value to write.
362 static inline void nlIOPutUnaligned64(void *p, const uint64_t v)
364 __nlIO_MEMCPY(p, &v, sizeof(uint64_t));
368 * Perform a, potentially unaligned, memory write of the 8-bit value
369 * to the specified pointer address.
371 * @param[in] p A pointer address, potentially unaligned, to write
372 * the 8-bit value to.
374 * @param[in] v The 8-bit value to write.
377 static inline void nlIOPutMaybeAligned8(void *p, const uint8_t v)
379 nlIOPutAligned8(p, v);
383 * Perform a, potentially unaligned, memory write of the 16-bit value
384 * to the specified pointer address.
386 * @param[in] p A pointer address, potentially unaligned, to write
387 * the 16-bit value to.
389 * @param[in] v The 16-bit value to write.
392 static inline void nlIOPutMaybeAligned16(void *p, const uint16_t v)
394 if (nlIOIsAligned(p, sizeof (uint16_t)))
395 nlIOPutAligned16(p, v);
397 nlIOPutUnaligned16(p, v);
401 * Perform a, potentially unaligned, memory write of the 32-bit value
402 * to the specified pointer address.
404 * @param[in] p A pointer address, potentially unaligned, to write
405 * the 32-bit value to.
407 * @param[in] v The 32-bit value to write.
410 static inline void nlIOPutMaybeAligned32(void *p, const uint32_t v)
412 if (nlIOIsAligned(p, sizeof (uint32_t)))
413 nlIOPutAligned32(p, v);
415 nlIOPutUnaligned32(p, v);
419 * Perform a, potentially unaligned, memory write of the 64-bit value
420 * to the specified pointer address.
422 * @param[in] p A pointer address, potentially unaligned, to write
423 * the 64-bit value to.
425 * @param[in] v The 64-bit value to write.
428 static inline void nlIOPutMaybeAligned64(void *p, const uint64_t v)
430 if (nlIOIsAligned(p, sizeof (uint64_t)))
431 nlIOPutAligned64(p, v);
433 nlIOPutUnaligned64(p, v);
437 * Perform an aligned memory read of the 8-bit value at the specified
438 * pointer address and increment the pointer by 8-bits (1 byte).
440 * @param[inout] p A pointer to a pointer address to read the
441 * 8-bit value from and to then increment by
444 * @return The 8-bit value at the specified pointer address.
446 static inline uint8_t nlIOReadAligned8(const void **p)
448 const uint8_t temp = nlIOGetAligned8(*p);
450 *(const uint8_t **)(p) += sizeof (uint8_t);
456 * Perform an aligned memory read of the 16-bit value at the specified
457 * pointer address and increment the pointer by 16-bits (2 bytes).
459 * @param[inout] p A pointer to a pointer address to read the
460 * 16-bit value from and to then increment by
463 * @return The 16-bit value at the specified pointer address.
465 static inline uint16_t nlIOReadAligned16(const void **p)
467 const uint16_t temp = nlIOGetAligned16(*p);
469 *(const uint8_t **)(p) += sizeof (uint16_t);
475 * Perform an aligned memory read of the 32-bit value at the specified
476 * pointer address and increment the pointer by 32-bits (4 bytes).
478 * @param[inout] p A pointer to a pointer address to read the
479 * 32-bit value from and to then increment by
482 * @return The 32-bit value at the specified pointer address.
484 static inline uint32_t nlIOReadAligned32(const void **p)
486 const uint32_t temp = nlIOGetAligned32(*p);
488 *(const uint8_t **)(p) += sizeof (uint32_t);
494 * Perform an aligned memory read of the 64-bit value at the specified
495 * pointer address and increment the pointer by 64-bits (8 bytes).
497 * @param[inout] p A pointer to a pointer address to read the
498 * 64-bit value from and to then increment by
501 * @return The 64-bit value at the specified pointer address.
503 static inline uint64_t nlIOReadAligned64(const void **p)
505 const uint64_t temp = nlIOGetAligned64(*p);
507 *(const uint8_t **)(p) += sizeof (uint64_t);
513 * Perform an unaligned memory read of the 8-bit value at the specified
514 * pointer address and increment the pointer by 8-bits (1 byte).
516 * @param[inout] p A pointer to a pointer address to read the
517 * 8-bit value from and to then increment by
520 * @return The 8-bit value at the specified pointer address.
522 static inline uint8_t nlIOReadUnaligned8(const void **p)
524 const uint8_t temp = nlIOGetUnaligned8(*p);
526 *(const uint8_t **)(p) += sizeof (uint8_t);
532 * Perform an unaligned memory read of the 16-bit value at the specified
533 * pointer address and increment the pointer by 16-bits (2 bytes).
535 * @param[inout] p A pointer to a pointer address to read the
536 * 16-bit value from and to then increment by
539 * @return The 16-bit value at the specified pointer address.
541 static inline uint16_t nlIOReadUnaligned16(const void **p)
543 const uint16_t temp = nlIOGetUnaligned16(*p);
545 *(const uint8_t **)(p) += sizeof (uint16_t);
551 * Perform an aligned memory read of the 32-bit value at the specified
552 * pointer address and increment the pointer by 32-bits (4 bytes).
554 * @param[inout] p A pointer to a pointer address to read the
555 * 32-bit value from and to then increment by
558 * @return The 32-bit value at the specified pointer address.
560 static inline uint32_t nlIOReadUnaligned32(const void **p)
562 const uint32_t temp = nlIOGetUnaligned32(*p);
564 *(const uint8_t **)(p) += sizeof (uint32_t);
570 * Perform an unaligned memory read of the 64-bit value at the specified
571 * pointer address and increment the pointer by 64-bits (8 bytes).
573 * @param[inout] p A pointer to a pointer address to read the
574 * 64-bit value from and to then increment by
577 * @return The 64-bit value at the specified pointer address.
579 static inline uint64_t nlIOReadUnaligned64(const void **p)
581 const uint64_t temp = nlIOGetUnaligned64(*p);
583 *(const uint8_t **)(p) += sizeof (uint64_t);
589 * Perform a, potentially unaligned, memory read of the 8-bit value
590 * from the specified pointer address and increment the pointer by
593 * @param[inout] p A pointer to a pointer address, potentially
594 * unaligned, to read the 8-bit value from and to
595 * then increment by 8-bits (1 byte).
597 * @return The 8-bit value at the specified pointer address.
599 static inline uint8_t nlIOReadMaybeAligned8(const void **p)
601 const uint8_t temp = nlIOGetMaybeAligned8(*p);
603 *(const uint8_t **)(p) += sizeof (uint8_t);
609 * Perform a, potentially unaligned, memory read of the 16-bit value
610 * from the specified pointer address and increment the pointer by
613 * @param[inout] p A pointer to a pointer address, potentially
614 * unaligned, to read the 16-bit value from and to
615 * then increment by 16-bits (2 bytes).
617 * @return The 16-bit value at the specified pointer address.
619 static inline uint16_t nlIOReadMaybeAligned16(const void **p)
621 const uint16_t temp = nlIOGetMaybeAligned16(*p);
623 *(const uint8_t **)(p) += sizeof (uint16_t);
629 * Perform a, potentially unaligned, memory read of the 32-bit value
630 * from the specified pointer address and increment the pointer by
633 * @param[inout] p A pointer to a pointer address, potentially
634 * unaligned, to read the 32-bit value from and to
635 * then increment by 32-bits (4 bytes).
637 * @return The 32-bit value at the specified pointer address.
639 static inline uint32_t nlIOReadMaybeAligned32(const void **p)
641 const uint32_t temp = nlIOGetMaybeAligned32(*p);
643 *(const uint8_t **)(p) += sizeof (uint32_t);
649 * Perform a, potentially unaligned, memory read of the 64-bit value
650 * from the specified pointer address and increment the pointer by
653 * @param[inout] p A pointer to a pointer address, potentially
654 * unaligned, to read the 64-bit value from and to
655 * then increment by 64-bits (8 bytes).
657 * @return The 64-bit value at the specified pointer address.
659 static inline uint64_t nlIOReadMaybeAligned64(const void **p)
661 const uint64_t temp = nlIOGetMaybeAligned64(*p);
663 *(const uint8_t **)(p) += sizeof (uint64_t);
669 * Perform an aligned memory write of the 8-bit value to the specified
670 * pointer address and increment the pointer by 8-bits (1 byte).
672 * @param[inout] p A pointer to a pointer address to read the 8-bit
673 * value from and to then increment by 8-bits (1 byte).
675 * @param[in] v The 8-bit value to write.
678 static inline void nlIOWriteAligned8(void **p, const uint8_t v)
680 nlIOPutAligned8(*p, v); *(const uint8_t **)(p) += sizeof (uint8_t);
684 * Perform an aligned memory write of the 16-bit value to the specified
685 * pointer address and increment the pointer by 16-bits (2 bytes).
687 * @param[inout] p A pointer to a pointer address to read the 16-bit
688 * value from and to then increment by 16-bits (2 bytes).
690 * @param[in] v The 16-bit value to write.
693 static inline void nlIOWriteAligned16(void **p, const uint16_t v)
695 nlIOPutAligned16(*p, v); *(const uint8_t **)(p) += sizeof (uint16_t);
699 * Perform an aligned memory write of the 32-bit value to the specified
700 * pointer address and increment the pointer by 32-bits (4 bytes).
702 * @param[inout] p A pointer to a pointer address to read the 32-bit
703 * value from and to then increment by 32-bits (4 bytes).
705 * @param[in] v The 32-bit value to write.
708 static inline void nlIOWriteAligned32(void **p, const uint32_t v)
710 nlIOPutAligned32(*p, v); *(const uint8_t **)(p) += sizeof (uint32_t);
714 * Perform an aligned memory write of the 64-bit value to the specified
715 * pointer address and increment the pointer by 64-bits (8 bytes).
717 * @param[inout] p A pointer to a pointer address to read the 64-bit
718 * value from and to then increment by 64-bits (8 bytes).
720 * @param[in] v The 64-bit value to write.
723 static inline void nlIOWriteAligned64(void **p, const uint64_t v)
725 nlIOPutAligned64(*p, v); *(const uint8_t **)(p) += sizeof (uint64_t);
729 * Perform an unaligned memory write of the 8-bit value to the specified
730 * pointer address and increment the pointer by 8-bits (1 byte).
732 * @param[inout] p A pointer to a pointer address to read the 8-bit
733 * value from and to then increment by 8-bits (1 byte).
735 * @param[in] v The 8-bit value to write.
738 static inline void nlIOWriteUnaligned8(void **p, const uint8_t v)
740 nlIOPutUnaligned8(*p, v); *(const uint8_t **)(p) += sizeof (uint8_t);
744 * Perform an unaligned memory write of the 16-bit value to the specified
745 * pointer address and increment the pointer by 16-bits (2 bytes).
747 * @param[inout] p A pointer to a pointer address to read the 16-bit
748 * value from and to then increment by 16-bits (2 bytes).
750 * @param[in] v The 16-bit value to write.
753 static inline void nlIOWriteUnaligned16(void **p, const uint16_t v)
755 nlIOPutUnaligned16(*p, v); *(const uint8_t **)(p) += sizeof (uint16_t);
759 * Perform an unaligned memory write of the 32-bit value to the specified
760 * pointer address and increment the pointer by 32-bits (4 bytes).
762 * @param[inout] p A pointer to a pointer address to read the 32-bit
763 * value from and to then increment by 32-bits (4 bytes).
765 * @param[in] v The 32-bit value to write.
768 static inline void nlIOWriteUnaligned32(void **p, const uint32_t v)
770 nlIOPutUnaligned32(*p, v); *(const uint8_t **)(p) += sizeof (uint32_t);
774 * Perform an unaligned memory write of the 64-bit value to the specified
775 * pointer address and increment the pointer by 64-bits (8 bytes).
777 * @param[inout] p A pointer to a pointer address to read the 64-bit
778 * value from and to then increment by 64-bits (8 bytes).
780 * @param[in] v The 64-bit value to write.
783 static inline void nlIOWriteUnaligned64(void **p, const uint64_t v)
785 nlIOPutUnaligned64(*p, v); *(const uint8_t **)(p) += sizeof (uint64_t);
789 * Perform a, potentially unaligned, memory write of the 8-bit value
790 * to the specified pointer address and increment the pointer by
793 * @param[inout] p A pointer to a pointer address, potentially
794 * unaligned, to read the 8-bit value from and to
795 * then increment by 8-bits (1 byte).
797 * @param[in] v The 8-bit value to write.
800 static inline void nlIOWriteMaybeAligned8(void **p, const uint8_t v)
802 nlIOPutMaybeAligned8(*p, v); *(const uint8_t **)(p) += sizeof (uint8_t);
806 * Perform a, potentially unaligned, memory write of the 16-bit value
807 * to the specified pointer address and increment the pointer by
810 * @param[inout] p A pointer to a pointer address, potentially
811 * unaligned, to read the 16-bit value from and to
812 * then increment by 16-bits (2 bytes).
814 * @param[in] v The 16-bit value to write.
817 static inline void nlIOWriteMaybeAligned16(void **p, const uint16_t v)
819 nlIOPutMaybeAligned16(*p, v); *(const uint8_t **)(p) += sizeof (uint16_t);
823 * Perform a, potentially unaligned, memory write of the 32-bit value
824 * to the specified pointer address and increment the pointer by
827 * @param[inout] p A pointer to a pointer address, potentially
828 * unaligned, to read the 32-bit value from and to
829 * then increment by 32-bits (4 bytes).
831 * @param[in] v The 32-bit value to write.
834 static inline void nlIOWriteMaybeAligned32(void **p, const uint32_t v)
836 nlIOPutMaybeAligned32(*p, v); *(const uint8_t **)(p) += sizeof (uint32_t);
840 * Perform a, potentially unaligned, memory write of the 64-bit value
841 * to the specified pointer address and increment the pointer by
844 * @param[inout] p A pointer to a pointer address, potentially
845 * unaligned, to read the 64-bit value from and to
846 * then increment by 64-bits (8 bytes).
848 * @param[in] v The 64-bit value to write.
851 static inline void nlIOWriteMaybeAligned64(void **p, const uint64_t v)
853 nlIOPutMaybeAligned64(*p, v); *(const uint8_t **)(p) += sizeof (uint64_t);
857 * Perform a memory read of the 8-bit value at the specified pointer
860 * @param[in] p A pointer address to read the 8-bit value from.
862 * @return The 8-bit value at the specified pointer address.
864 static inline uint8_t nlIOGet8(const void *p)
866 return nlIOGetAligned8(p);
870 * Perform a, potentially unaligned, memory read of the 16-bit value
871 * from the specified pointer address.
873 * @param[in] p A pointer address, potentially unaligned, to read
874 * the 16-bit value from.
876 * @return The 16-bit value at the specified pointer address.
878 static inline uint16_t nlIOGet16(const void *p)
880 return nlIOGetMaybeAligned16(p);
884 * Perform a, potentially unaligned, memory read of the 32-bit value
885 * from the specified pointer address.
887 * @param[in] p A pointer address, potentially unaligned, to read
888 * the 32-bit value from.
890 * @return The 32-bit value at the specified pointer address.
892 static inline uint32_t nlIOGet32(const void *p)
894 return nlIOGetMaybeAligned32(p);
898 * Perform a, potentially unaligned, memory read of the 64-bit value
899 * from the specified pointer address.
901 * @param[in] p A pointer address, potentially unaligned, to read
902 * the 64-bit value from.
904 * @return The 64-bit value at the specified pointer address.
906 static inline uint64_t nlIOGet64(const void *p)
908 return nlIOGetMaybeAligned64(p);
912 * Perform a memory write of the 8-bit value to the specified pointer
915 * @param[in] p A pointer address to write the 8-bit value to.
917 * @param[in] v The 8-bit value to write.
920 static inline void nlIOPut8(void *p, uint8_t v)
922 nlIOPutAligned8(p, v);
926 * Perform a, potentially unaligned, memory write of the 16-bit value
927 * to the specified pointer address.
929 * @param[in] p A pointer address, potentially unaligned, to write
930 * the 16-bit value to.
932 * @param[in] v The 16-bit value to write.
935 static inline void nlIOPut16(void *p, uint16_t v)
937 nlIOPutMaybeAligned16(p, v);
941 * Perform a, potentially unaligned, memory write of the 32-bit value
942 * to the specified pointer address.
944 * @param[in] p A pointer address, potentially unaligned, to write
945 * the 32-bit value to.
947 * @param[in] v The 32-bit value to write.
950 static inline void nlIOPut32(void *p, uint32_t v)
952 nlIOPutMaybeAligned32(p, v);
956 * Perform a, potentially unaligned, memory write of the 64-bit value
957 * to the specified pointer address.
959 * @param[in] p A pointer address, potentially unaligned, to write
960 * the 64-bit value to.
962 * @param[in] v The 64-bit value to write.
965 static inline void nlIOPut64(void *p, uint64_t v)
967 nlIOPutMaybeAligned64(p, v);
971 * Perform a, potentially unaligned, memory read of the 16-bit value
972 * from the specified pointer address and increment the pointer by
975 * @param[inout] p A pointer to a pointer address, potentially
976 * unaligned, to read the 8-bit value from and to
977 * then increment by 8-bits (1 byte).
979 * @return The 8-bit value at the specified pointer address.
981 static inline uint8_t nlIORead8(const void **p)
983 return nlIOReadAligned8(p);
987 * Perform a, potentially unaligned, memory read of the 16-bit value
988 * from the specified pointer address and increment the pointer by
991 * @param[inout] p A pointer to a pointer address, potentially
992 * unaligned, to read the 16-bit value from and to
993 * then increment by 16-bits (2 bytes).
995 * @return The 16-bit value at the specified pointer address.
997 static inline uint16_t nlIORead16(const void **p)
999 return nlIOReadMaybeAligned16(p);
1003 * Perform a, potentially unaligned, memory read of the 32-bit value
1004 * from the specified pointer address and increment the pointer by
1005 * 32-bits (4 bytes).
1007 * @param[inout] p A pointer to a pointer address, potentially
1008 * unaligned, to read the 32-bit value from and to
1009 * then increment by 32-bits (4 bytes).
1011 * @return The 32-bit value at the specified pointer address.
1013 static inline uint32_t nlIORead32(const void **p)
1015 return nlIOReadMaybeAligned32(p);
1019 * Perform a, potentially unaligned, memory read of the 64-bit value
1020 * from the specified pointer address and increment the pointer by
1021 * 64-bits (8 bytes).
1023 * @param[inout] p A pointer to a pointer address, potentially
1024 * unaligned, to read the 64-bit value from and to
1025 * then increment by 64-bits (8 bytes).
1027 * @return The 64-bit value at the specified pointer address.
1029 static inline uint64_t nlIORead64(const void **p)
1031 return nlIOReadMaybeAligned64(p);
1035 * Perform a, potentially unaligned, memory write of the 8-bit value
1036 * to the specified pointer address and increment the pointer by
1039 * @param[inout] p A pointer to a pointer address, potentially
1040 * unaligned, to read the 8-bit value from and to
1041 * then increment by 8-bits (1 byte).
1043 * @param[in] v The 8-bit value to write.
1046 static inline void nlIOWrite8(void **p, uint8_t v)
1048 nlIOWriteAligned8(p, v);
1052 * Perform a, potentially unaligned, memory write of the 16-bit value
1053 * to the specified pointer address and increment the pointer by
1054 * 16-bits (2 bytes).
1056 * @param[inout] p A pointer to a pointer address, potentially
1057 * unaligned, to read the 16-bit value from and to
1058 * then increment by 16-bits (2 bytes).
1060 * @param[in] v The 16-bit value to write.
1063 static inline void nlIOWrite16(void **p, uint16_t v)
1065 nlIOWriteMaybeAligned16(p, v);
1069 * Perform a, potentially unaligned, memory write of the 32-bit value
1070 * to the specified pointer address and increment the pointer by
1071 * 32-bits (4 bytes).
1073 * @param[inout] p A pointer to a pointer address, potentially
1074 * unaligned, to read the 32-bit value from and to
1075 * then increment by 32-bits (4 bytes).
1077 * @param[in] v The 32-bit value to write.
1080 static inline void nlIOWrite32(void **p, uint32_t v)
1082 nlIOWriteMaybeAligned32(p, v);
1086 * Perform a, potentially unaligned, memory write of the 64-bit value
1087 * to the specified pointer address and increment the pointer by
1088 * 64-bits (8 bytes).
1090 * @param[inout] p A pointer to a pointer address, potentially
1091 * unaligned, to read the 64-bit value from and to
1092 * then increment by 64-bits (8 bytes).
1094 * @param[in] v The 64-bit value to write.
1097 static inline void nlIOWrite64(void **p, uint64_t v)
1099 nlIOWriteMaybeAligned64(p, v);
1106 #undef __nlIO_MEMCPY
1108 #endif /* NLIO_BASE_H */