▲ | jandrewrogers 2 days ago | |||||||||||||||||||||||||||||||||||||||||||||||||
It wasn’t anything clever. A couple years ago I did a dive into x86 and ARM literature to determine what bits of a pointer were in use in various environments or were on a roadmap to be used in the future. To be honest, it was more bits than I was expecting. Note also that this is the intersection of bits that are available on both ARM and x86. If you want it to be portable, you need both architectures. Just because ARM64 doesn’t use a bit doesn’t mean that x86 doesn’t and vice versa. Both x86 and ARM have proposed standards for pointer tagging in the high bits. However, those bits don’t perfectly overlap. Also, some platforms don’t fully conform to this reservation of high bits for pointer tagging, so there is a backward compatibility issue. Across all of that, I found six high bits that were guaranteed to be safe for all current and future platforms. In practice you can probably use more but there is a portability risk. | ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | loeg 2 days ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
> Note also that this is the intersection of bits that are available on both ARM and x86. If you want it to be portable, you need both architectures. Just because ARM64 doesn’t use a bit doesn’t mean that x86 doesn’t and vice versa. Your mask/tag doesn't need to use the same bits on x86 and ARM to be portable, though. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | menaerus 2 days ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
How about taking the advantage of max_align_t pointer alignment guarantees, which on x86-64 Linux (glibc) is 16-bytes? This would leave you with the 4 lowest bits to be used. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|