Changed internal functions to return tags over pointers

One neat (if gimmicky) trick, is that each tag has a valid bit in the
highest bit position of the 32-bit word. This is used to determine when
to stop a fetch operation, but after fetch, the bit is free to use in
the driver. This means we can create a typed-union of sorts with error
codes and tags, returning both as the return value from a function.

Say what you will about this trick, it does have a significant impact on
code size. I suspect this is primarily due to the compiler having a hard
time optimizing around pointer access.
This commit is contained in:
Christopher Haster
2018-07-12 20:22:06 -05:00
parent 2b35c36b67
commit 5fc53bd726
2 changed files with 154 additions and 196 deletions

3
lfs.h
View File

@@ -262,9 +262,8 @@ struct lfs_attr {
/// littlefs data structures ///
typedef uint32_t lfs_tag_t;
typedef struct lfs_mattr {
lfs_tag_t tag;
int32_t tag;
union {
void *buffer;
lfs_block_t pair[2];