Skip to content

Instantly share code, notes, and snippets.

@amckinley
Created April 18, 2014 19:46
Show Gist options
  • Save amckinley/11061307 to your computer and use it in GitHub Desktop.
Save amckinley/11061307 to your computer and use it in GitHub Desktop.
typedef unsigned __int128 TaggedPointer;
#define TP_GET_PTR(ptr) ((Node *)((ptr) >> 64))
#define TP_GET_VERSION(ptr) ((uint64_t)(ptr))
TaggedPointer pack_tagged_pointer(void *ptr, uint64_t version) {
printf("args of %p, %lu\n", ptr, version);
unsigned __int128 result = (intptr_t)ptr;
result = result << 64;
result |= version;
return result;
}
TaggedPointer tp = pack_tagged_pointer(&foo, 1);
printf("res = %d, version = %lu, ptr = %p\n", res, TP_GET_VERSION(tp), TP_GET_PTR(tp));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment