设置了 MSB 的指针(i.e.holding 负值)在 Win64 下总是无效的吗?

Are pointers with the MSB set (i.e.holding negative values) always invalid under Win64?

我正在重写一些快速字符串函数。
本练习的目标是消除跳跃以避免错误预测。
此代码仅在用户 space 中运行。

Win64 指针的计算结果总是为正 Int64 值吗?

function BothValid(a,b: pointer): boolean;
// a= rcx
// b= rdx
asm
  lea    rax, [rcx-4]
  lea    r8,  [rdx-4]
  or     r8,  rax
  js @OneOrMoreNullPointers 
  ....       

上面的空指针测试方法是否总是有效的?

没关系,找到了相关的link:https://msdn.microsoft.com/en-us/library/windows/hardware/hh439648%28v=vs.85%29.aspx

For a 32-bit process, the virtual address space is usually the 2-gigabyte range 0x00000000 through 0x7FFFFFFF. For a 64-bit process, the virtual address space is the 8-terabyte range 0x000'00000000 through 0x7FF'FFFFFFFF.

portions of the 248-terabyte range from 0xFFFF0800'00000000 through 0xFFFFFFFF'FFFFFFFF are used for system space.

Code running in user mode has access to user space but does not have access to system space.

在 32 位中,您可以将用户 space 的大小增加到最大 3 GB;在这种情况下,用户 space 指针可以具有负 int 值。

所以是的,Win64 中的用户 space 指针始终为正数。
内核space指针总是负数。