Commit Diff


commit - 310548d292a73c9f38f28d7b2ba9f4dc8951315b
commit + f90074f5241fd3337a63a92785764d3460fa6cde
blob - 9474a14e270beffd34ffdb1cb058ab2a21253438
blob + 542df5f63f6e527be7e6dc4881fe046948404d5d
--- src/linurv.h
+++ src/linurv.h
@@ -87,15 +87,56 @@ void cpu_enter_signal (int sig, u64 handler);
 #define debug(...) log (LOG_DEBUG, __VA_ARGS__)
 #define vdebug(...) log (LOG_VDEBUG, __VA_ARGS__)
 
-#define read_u8(ptr)		(*(const u8 *)(size_t)(ptr))
-#define read_u16(ptr)		(*(const u16 *)(size_t)(ptr))
-#define read_u32(ptr)		(*(const u32 *)(size_t)(ptr))
-#define read_u64(ptr)		(*(const u64 *)(size_t)(ptr))
-#define read_i8(ptr)		(*(const i8 *)(size_t)(ptr))
-#define read_i16(ptr)		(*(const i16 *)(size_t)(ptr))
-#define read_i32(ptr)		(*(const i32 *)(size_t)(ptr))
-#define read_i64(ptr)		(*(const i64 *)(size_t)(ptr))
-#define write_u8(ptr, val)	(*(u8 *)(size_t)(ptr) = (val))
-#define write_u16(ptr, val)	(*(u16 *)(size_t)(ptr) = (val))
-#define write_u32(ptr, val)	(*(u32 *)(size_t)(ptr) = (val))
-#define write_u64(ptr, val)	(*(u64 *)(size_t)(ptr) = (val))
+inline static uint8_t read_u8 (size_t addr)
+{
+	return *(const uint8_t *)addr;
+}
+
+inline static uint16_t read_u16 (size_t addr)
+{
+	const uint16_t x0 = read_u8 (addr + 0);
+	const uint16_t x1 = read_u8 (addr + 1);
+	return x0 | (x1 << 8);
+}
+
+inline static uint32_t read_u32 (size_t addr)
+{
+	const uint32_t x0 = read_u16 (addr + 0);
+	const uint32_t x1 = read_u16 (addr + 2);
+	return x0 | (x1 << 16);
+}
+
+inline static uint64_t read_u64 (size_t addr)
+{
+	const uint64_t x0 = read_u32 (addr + 0);
+	const uint64_t x1 = read_u32 (addr + 4);
+	return x0 | (x1 << 32);
+}
+
+inline static void write_u8 (size_t addr, uint8_t x)
+{
+	*(uint8_t *)addr = x;
+}
+
+inline static void write_u16 (size_t addr, uint16_t x)
+{
+	write_u8 (addr + 0, x & 0xff);
+	write_u8 (addr + 1, x >> 8);
+}
+
+inline static void write_u32 (size_t addr, uint32_t x)
+{
+	write_u16 (addr + 0, x & 0xffff);
+	write_u16 (addr + 2, x >> 16);
+}
+
+inline static void write_u64 (size_t addr, uint64_t x)
+{
+	write_u32 (addr + 0, x & 0xffffffff);
+	write_u32 (addr + 4, x >> 32);
+}
+
+#define read_i8(a)	(int8_t) read_u8 (a)
+#define read_i16(a)	(int16_t) read_u16 (a)
+#define read_i32(a)	(int32_t) read_u32 (a)
+#define read_i64(a)	(int64_t) read_u64 (a)