summaryrefslogtreecommitdiffhomepage
path: root/src/mem.h
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2024-01-21 21:59:23 +0000
committerMichael Smith <mikesmiffy128@gmail.com>2024-01-21 22:02:14 +0000
commit670488716dde7ba7813dd281f24403a0b24d8690 (patch)
tree9b138c009e4131e32ed7bf4645e3eba7f8a5b18d /src/mem.h
parent506f095bcb528468f25a637977efcc408590ae67 (diff)
Rethink mem_loadoffset, and consequently, kill it
Suggested by bill. Having something semantically pointer-sized that's only ever used for stuff that's always 32-bit doesn't really make sense. Note that I intentionally did not add a copyright line for myself in hud.c because, I mean, come on. I'll just say I waive any claim to that tiny trivial change.
Diffstat (limited to 'src/mem.h')
-rw-r--r--src/mem.h35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/mem.h b/src/mem.h
index 367ed5b..d9712c0 100644
--- a/src/mem.h
+++ b/src/mem.h
@@ -1,5 +1,5 @@
/*
- * Copyright © 2023 Michael Smith <mikesmiffy128@gmail.com>
+ * Copyright © 2024 Michael Smith <mikesmiffy128@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -19,8 +19,8 @@
#include "intdefs.h"
-/* Retrieves a 32-bit integer from an unaligned pointer. */
-static inline u32 mem_load32(const void *p) {
+/* Retrieves an unsigned 32-bit integer from an unaligned pointer. */
+static inline u32 mem_loadu32(const void *p) {
// XXX: Turns out the pedantically-safe approach below causes most compilers
// to generate horribly braindead x86 output in at least some cases (and the
// cases also differ by compiler). So, for now, use the simple pointer cast
@@ -31,26 +31,41 @@ static inline u32 mem_load32(const void *p) {
//return (u32)cp[0] | (u32)cp[1] << 8 | (u32)cp[2] << 16 | (u32)cp[3] << 24;
}
-/* Retrieves a 64-bit integer from an unaligned pointer. */
-static inline u64 mem_load64(const void *p) {
+/* Retreives a signed 32-bit integer from an unaligned pointer. */
+static inline s32 mem_loads32(const void *p) {
+ return (s32)mem_loadu32(p);
+}
+
+/* Retrieves an unsigned 64-bit integer from an unaligned pointer. */
+static inline u64 mem_loadu64(const void *p) {
// this seems not to get butchered as badly in most cases?
- return (u64)mem_load32(p) | (u64)mem_load32((uchar *)p + 4) << 32;
+ return (u64)mem_loadu32(p) | (u64)mem_loadu32((uchar *)p + 4) << 32;
+}
+
+/* Retreives a signed 64-bit integer from an unaligned pointer. */
+static inline s64 mem_loads64(const void *p) {
+ return (s64)mem_loadu64(p);
}
/* Retrieves a pointer from an unaligned pointer-to-pointer. */
static inline void *mem_loadptr(const void *p) {
#if defined(_WIN64) || defined(__x86_64__)
- return (void *)mem_load64(p);
+ return (void *)mem_loadu64(p);
#else
- return (void *)mem_load32(p);
+ return (void *)mem_loadu32(p);
#endif
}
-/* Retreives a signed offset from an unaligned pointer. */
-static inline ssize mem_loadoffset(const void *p) {
+/* Retreives a signed size/offset value from an unaligned pointer. */
+static inline ssize mem_loadssize(const void *p) {
return (ssize)mem_loadptr(p);
}
+/* Retreives an unsigned size or raw address value from an unaligned pointer. */
+static inline usize mem_loadusize(const void *p) {
+ return (usize)mem_loadptr(p);
+}
+
/* Adds a byte count to a pointer and returns a freely-assignable pointer. */
static inline void *mem_offset(void *p, int off) { return (char *)p + off; }