Skip to content

Commit

Permalink
runtimes/native: add w4_readf64LE
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Aug 15, 2024
1 parent 753c4d2 commit 5f3f011
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions runtimes/native/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void* xrealloc(void* ptr, size_t size) {
fputs("Allocation failed.\n", stderr);
abort();
}
return ptr;
}

uint16_t bswap16(uint16_t x) {
Expand Down Expand Up @@ -50,6 +51,19 @@ uint32_t w4_read32LE (const uint32_t* ptr) {
#endif
}

double w4_readf64LE (const uint64_t* ptr) {
union {
uint64_t u;
double d;
} u;
#ifdef W4_BIG_ENDIAN
u.u = bswap32(*ptr);
#else
u.u = *ptr;
#endif
return u.d;
}

void w4_write16LE (uint16_t* ptr, uint16_t value) {
#ifdef W4_BIG_ENDIAN
*ptr = bswap16(value);
Expand Down
1 change: 1 addition & 0 deletions runtimes/native/src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void* xrealloc(void* ptr, size_t size);

uint16_t w4_read16LE (const uint16_t* ptr);
uint32_t w4_read32LE (const uint32_t* ptr);
double w4_readf64LE (const uint64_t* ptr);

void w4_write16LE (uint16_t* ptr, uint16_t value);
void w4_write32LE (uint32_t* ptr, uint32_t value);

0 comments on commit 5f3f011

Please sign in to comment.