Dropped implicit buffers in LFSR_DATA_LEB128/LLEB128/*COMPAT

These should be the last implicit buffers in LFSR_DATA_* macros, leaving
only LFSR_RAT_* macros with implicit stack-allocations (which are wayyy
too useful to give up).

There's an argument to keep these macros implicit, since they represent
relatively small things, but a stack allocation is a stack allocation.
It's safer to make stack allocations explicit, though it does risk
buffer overflow if these fall out-of-sync...

I guess we're forced to choose our poison...

In the end consistency with other LFSR_DATA_* macros wins.

---

And, again, compound-literals are so poorly optimized this minor cleanup
somehow saves code:

           code          stack          ctx
  before: 38060           2608          752
  after:  38000 (-0.2%)   2608 (+0.0%)  752 (+0.0%)
This commit is contained in:
Christopher Haster
2025-01-05 17:15:12 -06:00
parent 0839ac73d6
commit ebb194bbfa
2 changed files with 113 additions and 70 deletions
+25 -11
View File
@@ -629,12 +629,14 @@ code = '''
// note we're messing around with internals to do this! this
// is not a user API
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t rcompat_buf[LFSR_RCOMPAT_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT(
LFSR_TAG_RCOMPAT, 0,
LFSR_DATA_RCOMPAT(
LFSR_RCOMPAT_COMPAT
| LFSR_RCOMPAT_NONSTANDARD)))) => 0;
| LFSR_RCOMPAT_NONSTANDARD,
rcompat_buf)))) => 0;
lfsr_unmount(&lfs) => 0;
// mount should now fail
@@ -656,12 +658,14 @@ code = '''
// note we're messing around with internals to do this! this
// is not a user API
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t wcompat_buf[LFSR_WCOMPAT_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT(
LFSR_TAG_WCOMPAT, 0,
LFSR_DATA_WCOMPAT(
LFSR_WCOMPAT_COMPAT
| LFSR_WCOMPAT_NONSTANDARD)))) => 0;
| LFSR_WCOMPAT_NONSTANDARD,
wcompat_buf)))) => 0;
lfsr_unmount(&lfs) => 0;
// mount should now fail
@@ -686,12 +690,14 @@ code = '''
// note we're messing around with internals to do this! this
// is not a user API
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t ocompat_buf[LFSR_OCOMPAT_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT(
LFSR_TAG_OCOMPAT, 0,
LFSR_DATA_OCOMPAT(
LFSR_OCOMPAT_COMPAT
| LFSR_OCOMPAT_NONSTANDARD)))) => 0;
| LFSR_OCOMPAT_NONSTANDARD,
ocompat_buf)))) => 0;
lfsr_unmount(&lfs) => 0;
// mount should _not_ fail, ocompat should always be ignored
@@ -720,10 +726,11 @@ code = '''
overflow[FLAG / 8] |= 1 << (FLAG % 8);
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t rcompat_buf[LFSR_RCOMPAT_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT_CAT(
LFSR_TAG_RCOMPAT, 0,
LFSR_DATA_RCOMPAT(LFSR_RCOMPAT_COMPAT),
LFSR_DATA_RCOMPAT(LFSR_RCOMPAT_COMPAT, rcompat_buf),
LFSR_DATA_BUF(overflow, sizeof(overflow))))) => 0;
lfsr_unmount(&lfs) => 0;
@@ -753,10 +760,11 @@ code = '''
overflow[FLAG / 8] |= 1 << (FLAG % 8);
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t wcompat_buf[LFSR_WCOMPAT_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT_CAT(
LFSR_TAG_WCOMPAT, 0,
LFSR_DATA_WCOMPAT(LFSR_WCOMPAT_COMPAT),
LFSR_DATA_WCOMPAT(LFSR_WCOMPAT_COMPAT, wcompat_buf),
LFSR_DATA_BUF(overflow, sizeof(overflow))))) => 0;
lfsr_unmount(&lfs) => 0;
@@ -786,10 +794,11 @@ code = '''
overflow[FLAG / 8] |= 1 << (FLAG % 8);
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t ocompat_buf[LFSR_OCOMPAT_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT_CAT(
LFSR_TAG_OCOMPAT, 0,
LFSR_DATA_OCOMPAT(LFSR_OCOMPAT_COMPAT),
LFSR_DATA_OCOMPAT(LFSR_OCOMPAT_COMPAT, ocompat_buf),
LFSR_DATA_BUF(overflow, sizeof(overflow))))) => 0;
lfsr_unmount(&lfs) => 0;
@@ -817,10 +826,11 @@ code = '''
memset(overflow, 0, sizeof(overflow));
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t rcompat_buf[LFSR_RCOMPAT_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT_CAT(
LFSR_TAG_RCOMPAT, 0,
LFSR_DATA_RCOMPAT(LFSR_RCOMPAT_COMPAT),
LFSR_DATA_RCOMPAT(LFSR_RCOMPAT_COMPAT, rcompat_buf),
LFSR_DATA_BUF(overflow, sizeof(overflow))))) => 0;
lfsr_unmount(&lfs) => 0;
@@ -850,10 +860,11 @@ code = '''
memset(overflow, 0, sizeof(overflow));
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t wcompat_buf[LFSR_WCOMPAT_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT_CAT(
LFSR_TAG_WCOMPAT, 0,
LFSR_DATA_WCOMPAT(LFSR_WCOMPAT_COMPAT),
LFSR_DATA_WCOMPAT(LFSR_WCOMPAT_COMPAT, wcompat_buf),
LFSR_DATA_BUF(overflow, sizeof(overflow))))) => 0;
lfsr_unmount(&lfs) => 0;
@@ -880,10 +891,11 @@ code = '''
memset(overflow, 0, sizeof(overflow));
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t ocompat_buf[LFSR_OCOMPAT_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT_CAT(
LFSR_TAG_OCOMPAT, 0,
LFSR_DATA_OCOMPAT(LFSR_OCOMPAT_COMPAT),
LFSR_DATA_OCOMPAT(LFSR_OCOMPAT_COMPAT, ocompat_buf),
LFSR_DATA_BUF(overflow, sizeof(overflow))))) => 0;
lfsr_unmount(&lfs) => 0;
@@ -968,10 +980,11 @@ code = '''
// note we're messing around with internals to do this! this
// is not a user API
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t name_limit_buf[LFSR_LLEB128_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT(
LFSR_TAG_NAMELIMIT, 0,
LFSR_DATA_LLEB128(INC_NAME_LIMIT)))) => 0;
LFSR_DATA_LLEB128(INC_NAME_LIMIT, name_limit_buf)))) => 0;
lfsr_unmount(&lfs) => 0;
// mount should now fail
@@ -992,6 +1005,7 @@ code = '''
// note we're messing around with internals to do this! this
// is not a user API
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t file_limit_buf[LFSR_LEB128_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
LFSR_RAT_CAT(
LFSR_TAG_FILELIMIT, 0,
@@ -1000,7 +1014,7 @@ code = '''
// larger value by inserting an extra byte into our
// leb128 encoding
LFSR_DATA_BUF("\xff", 1),
LFSR_DATA_LEB128(LFS_FILE_MAX)))) => 0;
LFSR_DATA_LEB128(LFS_FILE_MAX, file_limit_buf)))) => 0;
lfsr_unmount(&lfs) => 0;
// mount should now fail