Skip to content

Instantly share code, notes, and snippets.

@dimenus
Last active August 10, 2017 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimenus/874355a2a50f6f7b474e8774a62643a7 to your computer and use it in GitHub Desktop.
Save dimenus/874355a2a50f6f7b474e8774a62643a7 to your computer and use it in GitHub Desktop.
traversal
if(counter == buf_len) {
//this bit (31) gets set when we've hit the end of a valid word
*current_slot |= (1 << 31);
break;
}
//if we're not at the end of a word and memory hasn't been allocated for the next level
//set bit 30 and get memory from the pool
if((*current_slot & (1 << 30)) == 0) {
*current_slot += MemoryPoolOffset + (1 << 30);
MemoryPoolOffset += stride_size;
assert(MemoryPoolOffset < pool_size);
}
offset = abs(tolower(buffer[counter]) - 'a');
if(offset > 26) {
offset = 26;
}
//Set the current slot pointer to the address of the bottom 30 bits of the existing value + MemoryPool + (array)offset
//u32* is 8 bytes wide on x86_64
current_slot = (u32*)(((*current_slot) & ~(0b11 << 30)) + (u64)MemoryPool + (offset * sizeof(u32)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment