#include "iostream"
using namespace std;
/* return x % (mod) align
* eg, P2PHASE(0x1234, 0x100) == 0x34 (x-0x12*align)
* eg, P2PHASE(0x5600, 0x100) == 0x00 (x-0x56*align)
*/
#define P2PHASE(x, align) ((x) & ((align) - 1))
/*
* return how much space is left in this block (but if it's perfectly
* aligned, return 0).
* eg, P2NPHASE(0x1234, 0x100) == 0xcc (0x13*align-x)
* eg, P2NPHASE(0x5600, 0x100) == 0x00 (0x56*align-x)
*/
#define P2NPHASE(x, align) (-(x) & ((align) - 1))
int main()
{
int align = 4096;
int off = 3896;
int len = 200;
printf("%d \n", P2PHASE(off, align));
printf("%d \n", P2NPHASE(len + off, align));
getchar();
return 0;
}
C++ PHASE Align
最新推荐文章于 2024-11-12 13:55:23 发布
本文档介绍了两个C语言宏定义P2PHASE和P2NPHASE,它们用于计算内存对齐和剩余空间。P2PHASE用于求取x对齐后的余数,P2NPHASE则返回块中剩余的空间。通过示例展示了如何在实际编程中使用这两个工具。
摘要由CSDN通过智能技术生成