Implementations of programming languages that need to preserve type information at runtime often use some bits of an integer value as tagging bits. A typical expression in the C programming language dealing with such tags looks like:
(val && MASK) == TAG
In machine language, such a test has to be implemented, for example, as follows:
movq val,%rax
andq MASK,%rax
cmpq TAG,%rax
In other words, a scratch register is needed if the original value needs to be preserved. As this is typical code to implement type safety in a dynamically typed language and needs to be efficient, I wonder whether there is a single mask-and-compare instruction in the x86_64 ISA. Or is there actually such an instruction in one of the newer extensions of the AMD64 platform I don't know of?