Skip to content

Commit 436e470

Browse files
committed
littlefs: Add littlefs.intrinsics to override intrinsics support
Enables intrinsics for bit operations such as ctz, popc, and le32 conversion. Can be disabled to help debug toolchain issues. Has proven to be surprisingly useful.
1 parent afc3306 commit 436e470

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

features/filesystem/littlefs/littlefs/lfs_util.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define MBED_LFS_ENABLE_WARN true
4747
#define MBED_LFS_ENABLE_ERROR true
4848
#define MBED_LFS_ENABLE_ASSERT true
49+
#define MBED_LFS_INTRINSICS true
4950
#endif
5051

5152
// Logging functions
@@ -106,7 +107,8 @@ static inline uint32_t lfs_min(uint32_t a, uint32_t b) {
106107

107108
// Find the next smallest power of 2 less than or equal to a
108109
static inline uint32_t lfs_npw2(uint32_t a) {
109-
#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM))
110+
#if !defined(LFS_NO_INTRINSICS) && MBED_LFS_INTRINSICS && \
111+
(defined(__GNUC__) || defined(__CC_ARM))
110112
return 32 - __builtin_clz(a-1);
111113
#else
112114
uint32_t r = 0;
@@ -123,7 +125,8 @@ static inline uint32_t lfs_npw2(uint32_t a) {
123125
// Count the number of trailing binary zeros in a
124126
// lfs_ctz(0) may be undefined
125127
static inline uint32_t lfs_ctz(uint32_t a) {
126-
#if !defined(LFS_NO_INTRINSICS) && defined(__GNUC__)
128+
#if !defined(LFS_NO_INTRINSICS) && MBED_LFS_INTRINSICS && \
129+
defined(__GNUC__)
127130
return __builtin_ctz(a);
128131
#else
129132
return lfs_npw2((a & -a) + 1) - 1;
@@ -132,7 +135,8 @@ static inline uint32_t lfs_ctz(uint32_t a) {
132135

133136
// Count the number of binary ones in a
134137
static inline uint32_t lfs_popc(uint32_t a) {
135-
#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM))
138+
#if !defined(LFS_NO_INTRINSICS) && MBED_LFS_INTRINSICS && \
139+
(defined(__GNUC__) || defined(__CC_ARM))
136140
return __builtin_popcount(a);
137141
#else
138142
a = a - ((a >> 1) & 0x55555555);
@@ -149,12 +153,12 @@ static inline int lfs_scmp(uint32_t a, uint32_t b) {
149153

150154
// Convert from 32-bit little-endian to native order
151155
static inline uint32_t lfs_fromle32(uint32_t a) {
152-
#if !defined(LFS_NO_INTRINSICS) && ( \
156+
#if !defined(LFS_NO_INTRINSICS) && MBED_LFS_INTRINSICS && ( \
153157
(defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
154158
(defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
155159
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
156160
return a;
157-
#elif !defined(LFS_NO_INTRINSICS) && ( \
161+
#elif !defined(LFS_NO_INTRINSICS) && MBED_LFS_INTRINSICS && ( \
158162
(defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
159163
(defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
160164
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))

features/filesystem/littlefs/mbed_lib.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
"value": 512,
2222
"help": "Number of blocks to lookahead during block allocation. A larger lookahead reduces the number of passes required to allocate a block. The lookahead buffer requires only 1 bit per block so it can be quite large with little ram impact. Should be a multiple of 32."
2323
},
24+
"intrinsics": {
25+
"macro_name": "MBED_LFS_INTRINSICS",
26+
"value": true,
27+
"help": "Enable intrinsics for bit operations such as ctz, popc, and le32 conversion. Can be disabled to help debug toolchain issues"
28+
},
2429
"enable_info": {
2530
"macro_name": "MBED_LFS_ENABLE_INFO",
2631
"value": false,

0 commit comments

Comments
 (0)