Skip to content
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

Tag pointers to avoid node type byte #46

Open
adamsch1 opened this issue Dec 31, 2020 · 1 comment
Open

Tag pointers to avoid node type byte #46

adamsch1 opened this issue Dec 31, 2020 · 1 comment

Comments

@adamsch1
Copy link

nice code thanks for sharing!

Was wondering if you have considered using the low bits on each child pointer to indicate the node type. Would remove the need for a 8 bit node type. There are only 4 node types I believe, and on 64 bit systems with 8 byte alignment you can use just the lower 2 bits.

Sorry not an issue really just a question :)

@mattsta
Copy link

mattsta commented Jan 9, 2021

The "leafness" is already stored as a 1-bit tag:

/* Macros to manipulate pointer tags */
#define IS_LEAF(x) (((uintptr_t)x & 1))
#define SET_LEAF(x) ((void *)((uintptr_t)x | 1))
#define LEAF_RAW(x) ((artLeaf *)((void *)((uintptr_t)x & ~1ULL)))

But over in my libart fork I did refactor bitfields for the type:

#define MAX_PREFIX_LEN 14
typedef struct artNode {
    uint8_t partialLen; /* length of 'partial' (could be 4 bits, but less
                           efficient) */
    uint8_t type : 2;
    uint8_t childrenCount : 6;
    uint8_t partial[MAX_PREFIX_LEN];
} artNode;

Seems 16 bytes is the smallest we can get for the common node metadata (having prefix len 14), so throwing two more bits away doesn't help us much right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants