Added LFSR_BTREE/SHRUB_NULL, dropped lfsr_btree_alloc

Our B-trees lazily allocate their root blocks, so it makes more sense
for this to be a macro. Added/adopted a similar LFSR_SHRUB_NULL for
consistency.

Unfortunately this added a bit of code. I think because GCC struggles to
optimize compound literals, which both LFSR_BTREE_NULL and
LFSR_SHRUB_NULL expand into:

           code          stack
  before: 33538           2624
  after:  33550 (+0.0%)   2624 (+0.0%)
This commit is contained in:
Christopher Haster
2024-05-27 02:54:23 -05:00
parent 8e50e4d259
commit 5d03416c82
3 changed files with 65 additions and 124 deletions
+3 -6
View File
@@ -42,8 +42,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// set up a simulation to compare against
char *sim = malloc(N);
@@ -150,8 +149,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// set up a simulation to compare against
char *sim = malloc(N);
@@ -254,8 +252,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// set up a simulation to compare against
char *sim = malloc(N);
+50 -100
View File
@@ -20,8 +20,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create an empty tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
printf("btree: w%d 0x%x.%x\n",
btree.weight,
btree.blocks[0],
@@ -52,8 +51,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a single-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
printf("btree: w%d 0x%x.%x\n",
@@ -94,8 +92,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a two-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
lfsr_btree_commit(&lfs, &btree, 1, LFSR_ATTRS(
@@ -144,8 +141,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a two-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("b", 1)))) => 0;
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
@@ -195,8 +191,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a two-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
lfsr_btree_commit(&lfs, &btree, 1, LFSR_ATTRS(
@@ -254,8 +249,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a two-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("c", 1)))) => 0;
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
@@ -316,8 +310,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfs_size_t n = 0;
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i, LFSR_ATTRS(
@@ -367,8 +360,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfs_size_t n = 0;
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
@@ -419,8 +411,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// set up a simulation to compare against
//
@@ -502,8 +493,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfs_size_t n = 0;
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i*W, LFSR_ATTRS(
@@ -570,8 +560,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// set up a simulation to compare against
//
@@ -706,8 +695,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a single-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
// update the tree
@@ -752,8 +740,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a two-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
lfsr_btree_commit(&lfs, &btree, 1, LFSR_ATTRS(
@@ -811,8 +798,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a two-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
lfsr_btree_commit(&lfs, &btree, 1, LFSR_ATTRS(
@@ -884,8 +870,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i, LFSR_ATTRS(
LFSR_ATTR(
@@ -941,8 +926,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i, LFSR_ATTRS(
LFSR_ATTR(
@@ -1028,8 +1012,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i*W, LFSR_ATTRS(
LFSR_ATTR(
@@ -1101,8 +1084,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i*W, LFSR_ATTRS(
LFSR_ATTR(
@@ -1245,8 +1227,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a single-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
// pop!
@@ -1302,8 +1283,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a single-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
lfsr_btree_commit(&lfs, &btree, 1, LFSR_ATTRS(
@@ -1375,8 +1355,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a single-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
lfsr_btree_commit(&lfs, &btree, 1, LFSR_ATTRS(
@@ -1448,8 +1427,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a single-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("a", 1)))) => 0;
lfsr_btree_commit(&lfs, &btree, 1, LFSR_ATTRS(
@@ -1540,8 +1518,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i, LFSR_ATTRS(
LFSR_ATTR(
@@ -1620,8 +1597,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i, LFSR_ATTRS(
LFSR_ATTR(
@@ -1702,8 +1678,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i, LFSR_ATTRS(
LFSR_ATTR(
@@ -1791,8 +1766,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i*W, LFSR_ATTRS(
LFSR_ATTR(
@@ -1897,8 +1871,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// set up a simulation to compare against
//
@@ -2048,8 +2021,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(
LFSR_TAG_DATA, +1,
@@ -2107,8 +2079,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("_", 1)))) => 0;
@@ -2197,8 +2168,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(
LFSR_TAG_DATA, +W,
@@ -2257,8 +2227,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR(LFSR_TAG_DATA, +W, LFSR_DATA_BUF("_", 1)))) => 0;
@@ -2434,8 +2403,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// force it to split
@@ -2502,8 +2470,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// force it to split
@@ -2573,8 +2540,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// force it to split
@@ -2637,8 +2603,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// force it to split
@@ -2717,8 +2682,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// set up a simulation to compare against
//
@@ -2823,8 +2787,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// set up a simulation to compare against
//
@@ -2990,8 +2953,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a zero-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
printf("btree: w%d 0x%x.%x\n",
btree.weight,
btree.blocks[0],
@@ -3024,8 +2986,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a single-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR_NAME(
LFSR_TAG_NAME, +1,
@@ -3077,8 +3038,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a two-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR_NAME(
LFSR_TAG_NAME, +1,
@@ -3144,8 +3104,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a two-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR_NAME(
LFSR_TAG_NAME, +1,
@@ -3225,8 +3184,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a two-entry tree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR_NAME(
LFSR_TAG_NAME, +1,
@@ -3307,8 +3265,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
char name[3] = {
'a'+((0/26/26) % 26), 'a'+((0/26) % 26), 'a'+(0 % 26)
};
@@ -3380,8 +3337,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR_NAME(
LFSR_TAG_NAME, +1,
@@ -3495,8 +3451,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
char name[3] = {
'a'+((0/26/26) % 26), 'a'+((0/26) % 26), 'a'+(0 % 26)
};
@@ -3569,8 +3524,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR_NAME(
LFSR_TAG_NAME, +W,
@@ -3725,8 +3679,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR_NAME(
LFSR_TAG_NAME, +1,
@@ -3882,8 +3835,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfsr_btree_commit(&lfs, &btree, 0, LFSR_ATTRS(
LFSR_ATTR_NAME(
LFSR_TAG_NAME, +W,
@@ -4088,8 +4040,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a tree with N elements
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
lfs_size_t n = 0;
for (lfs_size_t i = 0; i < N; i++) {
lfsr_btree_commit(&lfs, &btree, i, LFSR_ATTRS(
@@ -4210,8 +4161,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// create a btree
lfsr_btree_t btree;
lfsr_btree_alloc(&lfs, &btree) => 0;
lfsr_btree_t btree = LFSR_BTREE_NULL();
// set up a simulation to compare against
//