Skip to content

Fix pgm_read_float_unaligned macro #6593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ static inline uint16_t pgm_read_word_inlined(const void* addr) {
return (uint16_t) res; /* This masks the lower half-word from the returned word */
}

/* Can't legally cast bits of uint32_t to a float w/o conversion or std::memcpy, which is inefficient. */
/* The ASM block doesn't care the type, so just pass in what C thinks is a float and return in custom fcn. */
static inline float pgm_read_float_unaligned(const void *addr) {
register float res;
pgm_read_with_offset(addr, res);
return res;
}

#define pgm_read_byte(addr) pgm_read_byte_inlined(addr)
#define pgm_read_word_aligned(addr) pgm_read_word_inlined(addr)
#ifdef __cplusplus
Expand All @@ -98,7 +106,6 @@ static inline uint32_t pgm_read_dword_unaligned(const void *addr) {
return res;
}

#define pgm_read_float_unaligned(addr) ((float)pgm_read_dword_unaligned(addr))
#define pgm_read_ptr_unaligned(addr) ((void*)pgm_read_dword_unaligned(addr))
#define pgm_read_word_unaligned(addr) ((uint16_t)(pgm_read_dword_unaligned(addr) & 0xffff))

Expand Down